mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
Kernel: Track big lock blocked threads in separate list
When we lock a mutex, eventually `Thread::block` is invoked which could in turn invoke `Process::big_lock().restore_exclusive_lock()`. This would then try to add the current thread to a different blocked thread list then the one in use for the original mutex being locked, and because it's an intrusive list, the thread is removed from its original list during the `.append()`. When the original mutex eventually unblocks, we no longer have the thread in the intrusive blocked threads list and we panic. Solve this by making the big lock mutex special and giving it its own blocked thread list. Because the process big lock is temporary and is being actively removed from e.g. syscalls, it's a matter of time before we can also remove the fix introduced by this commit. Fixes issue #9401.
This commit is contained in:
parent
be26818448
commit
7826729ab2
4 changed files with 48 additions and 13 deletions
|
@ -27,8 +27,15 @@ class Mutex {
|
|||
public:
|
||||
using Mode = LockMode;
|
||||
|
||||
Mutex(StringView name = {})
|
||||
// FIXME: remove this after annihilating Process::m_big_lock
|
||||
enum class MutexBehavior {
|
||||
Regular,
|
||||
BigLock,
|
||||
};
|
||||
|
||||
Mutex(StringView name = {}, MutexBehavior behavior = MutexBehavior::Regular)
|
||||
: m_name(name)
|
||||
, m_behavior(behavior)
|
||||
{
|
||||
}
|
||||
~Mutex() = default;
|
||||
|
@ -72,12 +79,18 @@ public:
|
|||
private:
|
||||
using BlockedThreadList = IntrusiveList<&Thread::m_blocked_threads_list_node>;
|
||||
|
||||
// FIXME: remove this after annihilating Process::m_big_lock
|
||||
using BigLockBlockedThreadList = IntrusiveList<&Thread::m_big_lock_blocked_threads_list_node>;
|
||||
|
||||
void block(Thread&, Mode, SpinlockLocker<Spinlock>&, u32);
|
||||
void unblock_waiters(Mode);
|
||||
|
||||
StringView m_name;
|
||||
Mode m_mode { Mode::Unlocked };
|
||||
|
||||
// FIXME: remove this after annihilating Process::m_big_lock
|
||||
MutexBehavior m_behavior;
|
||||
|
||||
// When locked exclusively, only the thread already holding the lock can
|
||||
// lock it again. When locked in shared mode, any thread can do that.
|
||||
u32 m_times_locked { 0 };
|
||||
|
@ -94,6 +107,9 @@ private:
|
|||
BlockedThreadList exclusive;
|
||||
BlockedThreadList shared;
|
||||
|
||||
// FIXME: remove this after annihilating Process::m_big_lock
|
||||
BigLockBlockedThreadList exclusive_big_lock;
|
||||
|
||||
ALWAYS_INLINE BlockedThreadList& list_for_mode(Mode mode)
|
||||
{
|
||||
VERIFY(mode == Mode::Exclusive || mode == Mode::Shared);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue