kernel/sched: Correct locking in essential thread panic

Calling a (handled/ignored) panic with the scheduler lock held
produces spinlock errors in some circumstances, depending on whether
or not the swap gets reached before another context switch.  Release
the lock around the call, we don't touch any scheduler state on the
path to z_swap(), so this is safe.

Signed-off-by: Andy Ross <andyross@google.com>
This commit is contained in:
Andy Ross 2025-02-19 14:57:05 -08:00 committed by Fabio Baltieri
commit ddee1ab4cf

View file

@ -434,7 +434,9 @@ static ALWAYS_INLINE void z_thread_halt(struct k_thread *thread, k_spinlock_key_
halt_thread(thread, terminate ? _THREAD_DEAD : _THREAD_SUSPENDED);
if ((thread == _current) && !arch_is_in_isr()) {
if (z_is_thread_essential(thread)) {
k_spin_unlock(&_sched_spinlock, key);
k_panic();
key = k_spin_lock(&_sched_spinlock);
}
z_swap(&_sched_spinlock, key);
__ASSERT(!terminate, "aborted _current back from dead");