Page MenuHomeFreeBSD

powerpc: Avoid deadlock when CPUs exchange threads
Needs ReviewPublic

Authored by mchoo on Wed, Sep 16, 8:50 PM.
Tags
None
Referenced Files
F172258160: D59742.diff
Thu, Sep 17, 7:37 AM
F172221497: D59742.id186917.diff
Wed, Sep 16, 11:47 PM
F172220920: D59742.diff
Wed, Sep 16, 11:38 PM
F172214676: D59742.id186917.diff
Wed, Sep 16, 10:16 PM
F172214463: D59742.diff
Wed, Sep 16, 10:13 PM
Subscribers

Details

Reviewers
jhb
adrian
jhibbits
Group Reviewers
PowerPC
scheduler
Summary

The PowerPC context switch waited for the incoming thread to leave
blocked_lock before releasing the outgoing thread. If two CPUs selected
each other's running threads concurrently, both CPUs waited for the
other to perform the release and neither could progress. This appeared
as intermittent boot hangs under QEMU MTTCG when taskqueue threads were
bound to opposite CPUs.

Match the ordering used by other architectures: publish the outgoing
thread's new lock before waiting for the incoming thread. Move isync
after the wait so subsequent context loads retain acquire ordering.
Apply the correction to both 32-bit and 64-bit switch paths.

The 2015 change moved the release after the stack switch because the old
implementation continued through pmap_activate() and optional state
restoration on the outgoing thread's stack after making that thread
runnable. The switch path has since changed: after the release it only
polls wired td_lock state using registers, then immediately loads the
incoming PCB_SP before updating per-CPU state or making any calls.
cpu_switch() also runs with external and decrementer interrupts disabled
by spinlock_enter(). Thus this does not restore the post-release call
window that the 2015 change corrected.

Fixes: 53607fe3cc8d ("Fix an extremely subtle concurrency bug...")
Fixes: 7a49d964d3f9 ("Merge r278429 from ppc64:")
MFC after: 2 weeks
MFC to: stable/14, stable/15
Sponsored by: FreeBSD Foundation

Test Plan

No more random hangs observed on QEMU multithreaded TCG (20 trials)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
No Test Coverage
Build Status
Buildable 77000
Build 73883: arc lint + arc unit

Event Timeline

mchoo requested review of this revision.Wed, Sep 16, 8:50 PM

oooo! i found and thought i fixed one of these a while back. lemme try this locally to see if it also fixes my boot time hangs!