From ae3fa2025283687ed554f81690a81ba5e1ad9c8e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 17 Aug 2022 22:41:06 +0200 Subject: [PATCH] Kernel/x86: Don't re-enable interrupts too soon when unlocking spinlocks To ensure that we stay on the same CPU that acquired the spinlock until we're completely unlocked, we now leave the critical section *before* re-enabling interrupts. --- Kernel/Arch/x86/common/Spinlock.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Kernel/Arch/x86/common/Spinlock.cpp b/Kernel/Arch/x86/common/Spinlock.cpp index e442377598..4de2eecfc0 100644 --- a/Kernel/Arch/x86/common/Spinlock.cpp +++ b/Kernel/Arch/x86/common/Spinlock.cpp @@ -24,12 +24,13 @@ void Spinlock::unlock(u32 prev_flags) VERIFY(is_locked()); track_lock_release(m_rank); m_lock.store(0, AK::memory_order_release); + + Processor::leave_critical(); + if ((prev_flags & 0x200) != 0) sti(); else cli(); - - Processor::leave_critical(); } u32 RecursiveSpinlock::lock() @@ -60,12 +61,13 @@ void RecursiveSpinlock::unlock(u32 prev_flags) track_lock_release(m_rank); m_lock.store(0, AK::memory_order_release); } + + Processor::leave_critical(); + if ((prev_flags & 0x200) != 0) sti(); else cli(); - - Processor::leave_critical(); } }