Fix SBP-2 session-scheduler deadlock (kernel registry busy-timeout panic)#33
Open
mhellevang wants to merge 1 commit into
Open
Fix SBP-2 session-scheduler deadlock (kernel registry busy-timeout panic)#33mhellevang wants to merge 1 commit into
mhellevang wants to merge 1 commit into
Conversation
WakeAtTime is RPC-dispatched to the timer's queue, whose handlers re-enter the scheduler and take lock_. Holding lock_ across it deadlocked the user-client teardown queue against the driver queue and tripped the 60s IOKit registry busy-timeout kernel panic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A full kernel panic (
busy timeout (60s): multiple entries holding the registry busy ... @IOService.cpp) can be triggered during SBP-2 sessionteardown. The dext wedges instead of terminating, the IOKit termination
queue backs up, and after 60s the registry-busy watchdog panics the machine.
Root cause is an AB-BA deadlock between the user-client queue and the driver
queue, over the
DriverKitSessionSchedulerlock:ASFWDriverUserClient-Default(teardown):UserClient::Stop→
SessionRegistry::ReleaseOwner→LoginSession::Logout→
StartLogoutTimer→ScheduleAfter→ArmNextLocked, which callstimer_->WakeAtTime()while holdinglock_.WakeAtTimeisRPC-dispatched to the timer's queue (
ASFWDriver-Default), so the threadblocks waiting for that queue.
ASFWDriver-Default(concurrent logout-write completion off the ARinterrupt):
OnLogoutWriteComplete→StartLogoutTimer→ScheduleAfter→ tries to take
lock_.Thread A holds
lock_and waits for the driver queue; the driver queue holdsnothing but is blocked trying to take
lock_. Deadlock → panic.Fix
Move the
WakeAtTime()call out of the critical section.ArmNextLockedissplit into:
EarliestDeadlineLocked()— pure read of the next deadline underlock_.ArmTimerUnlocked()— callsWakeAtTime()withlock_released.Each call site computes the deadline (and retains an
OSSharedPtrto thetimer for lifetime safety) inside the lock, then arms outside it. The timer's
queue handlers can now take
lock_while another thread arms, so the cyclecan't form.
Testing
login + forced-
Stopteardown cycles with the patched dext — no panic,dext stayed responsive every cycle. The same teardown path reliably
panicked the machine before the fix.
Note
A benign residual race remains (two threads can arm concurrently, so the
timer may arm slightly late); it self-corrects on the next
HandleTimerFiredre-arm and never drops a callback. Fully serializing arming onto the timer's
own queue is possible but pulls in lifetime concerns, left out of this
minimal fix.