mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Kernel: Verify interrupts are disabled when interacting with Mutexes
This should help prevent deadlocks where a thread blocks on a Mutex while interrupts are disabled, and makes it impossible for the holder of the Mutex to make forward progress because it cannot be scheduled in. Hide it behind a new debug macro LOCK_IN_CRITICAL_DEBUG for now, because Ext2FS takes a series of Mutexes from the page fault handler, which executes with interrupts disabled.
This commit is contained in:
parent
4f2520674c
commit
72de228695
Notes:
sideshowbarker
2024-07-18 05:08:34 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/72de228695f Pull-request: https://github.com/SerenityOS/serenity/pull/9580 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bgianfo
3 changed files with 11 additions and 0 deletions
|
@ -166,6 +166,10 @@
|
|||
#cmakedefine01 LOCK_DEBUG
|
||||
#endif
|
||||
|
||||
#ifndef LOCK_IN_CRITICAL_DEBUG
|
||||
#cmakedefine01 LOCK_IN_CRITICAL_DEBUG
|
||||
#endif
|
||||
|
||||
#ifndef LOCK_RESTORE_DEBUG
|
||||
#cmakedefine01 LOCK_RESTORE_DEBUG
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,8 @@ void Mutex::lock(Mode mode, [[maybe_unused]] LockLocation const& location)
|
|||
// NOTE: This may be called from an interrupt handler (not an IRQ handler)
|
||||
// and also from within critical sections!
|
||||
VERIFY(!Processor::current_in_irq());
|
||||
if constexpr (LOCK_IN_CRITICAL_DEBUG)
|
||||
VERIFY_INTERRUPTS_ENABLED();
|
||||
VERIFY(mode != Mode::Unlocked);
|
||||
auto current_thread = Thread::current();
|
||||
|
||||
|
@ -143,6 +145,8 @@ void Mutex::unlock()
|
|||
{
|
||||
// NOTE: This may be called from an interrupt handler (not an IRQ handler)
|
||||
// and also from within critical sections!
|
||||
if constexpr (LOCK_IN_CRITICAL_DEBUG)
|
||||
VERIFY_INTERRUPTS_ENABLED();
|
||||
VERIFY(!Processor::current_in_irq());
|
||||
auto current_thread = Thread::current();
|
||||
SpinlockLocker lock(m_lock);
|
||||
|
@ -198,6 +202,8 @@ void Mutex::unlock()
|
|||
|
||||
void Mutex::block(Thread& current_thread, Mode mode, SpinlockLocker<Spinlock<u8>>& lock, u32 requested_locks)
|
||||
{
|
||||
if constexpr (LOCK_IN_CRITICAL_DEBUG)
|
||||
VERIFY_INTERRUPTS_ENABLED();
|
||||
auto& blocked_thread_list = thread_list_for_mode(mode);
|
||||
VERIFY(!blocked_thread_list.contains(current_thread));
|
||||
blocked_thread_list.append(current_thread);
|
||||
|
|
|
@ -101,6 +101,7 @@ set(LEXER_DEBUG ON)
|
|||
set(LINE_EDITOR_DEBUG ON)
|
||||
set(LOCAL_SOCKET_DEBUG ON)
|
||||
set(LOCK_DEBUG ON)
|
||||
set(LOCK_IN_CRITICAL_DEBUG ON)
|
||||
set(LOCK_RESTORE_DEBUG ON)
|
||||
set(LOCK_TRACE_DEBUG ON)
|
||||
set(LOOKUPSERVER_DEBUG ON)
|
||||
|
|
Loading…
Reference in a new issue