witness_checkorder() contains an assertion against acquiring a
blockable/sleepable lock within a critical section. This assertion is
not triggered if kdb_active is true. The function also returns early
when KERNEL_PANICKED() is true.
The kern_reboot() function will set kdb_active = 0 as part of the
shutdown sequence. After that it will acquire the eventhandler_mutex to
run the shutdown handlers.
When invoking the kernel debugger via console alt-break sequence, we
call kdb_enter() from an interrupt filter context (critical section). If
the "reset" command is issued in ddb, this leaves a very small window
where:
- The kernel has not panicked.
- kdb_active is false.
- We appear to be running in a critical section.
This triggers the assertion in witness_checkorder() when we try to
acquire eventhandler_mutex. To fix this we can also check against
'rebooting' variable, which is set to true in the shutdown path right
before kdb_active is adjusted.
This was made visible by my recent change to the "reset" command in
5644850620ae.
Reported by: bz