Kernel/SMP: Fix RecursiveSpinLock remembering the wrong CPU when locking

We have to disable interrupts before capturing the current Processor*,
or we risk storing the wrong one if we get preempted and resume on a
different CPU.

Caught by the VERIFY in RecursiveSpinLock::unlock()
This commit is contained in:
Andreas Kling 2021-08-11 00:47:07 +02:00
parent 5e27861c2e
commit 7f50805903
Notes: sideshowbarker 2024-07-18 07:07:11 +09:00

View file

@ -66,11 +66,11 @@ public:
ALWAYS_INLINE u32 lock()
{
u32 prev_flags = cpu_flags();
cli();
Processor::enter_critical();
auto& proc = Processor::current();
FlatPtr cpu = FlatPtr(&proc);
u32 prev_flags = cpu_flags();
Processor::enter_critical();
cli();
FlatPtr expected = 0;
while (!m_lock.compare_exchange_strong(expected, cpu, AK::memory_order_acq_rel)) {
if (expected == cpu)