1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 18:10:56 +09:00

Kernel: Fix deadlock in ~Memory::Region()

First off: unregister the region from MemoryManager before unmapping it.
The order of operations here was a bit strange, presumably to avoid a
situation where a fault would happen while unmapping, and the fault
handler would find the MemoryManager region list in an invalid state.

Unregistering it before unmapping sidesteps the whole problem, and
allows us to easily fix another problem: a deadlock could occur due
to inconsistent acquisition order (PageDirectory must come before MM.)
This commit is contained in:
Andreas Kling 2021-08-09 02:21:04 +02:00
parent 95c8e421ae
commit 08b4d8f0de
Notes: sideshowbarker 2024-07-18 07:11:32 +09:00

View file

@ -40,16 +40,14 @@ Region::~Region()
{
m_vmobject->remove_region(*this);
// Make sure we disable interrupts so we don't get interrupted between unmapping and unregistering.
// Unmapping the region will give the VM back to the VirtualRangeAllocator, so an interrupt handler would
// find the address<->region mappings in an invalid state there.
ScopedSpinLock lock(s_mm_lock);
MM.unregister_region(*this);
if (m_page_directory) {
ScopedSpinLock page_lock(m_page_directory->get_lock());
ScopedSpinLock lock(s_mm_lock);
unmap(ShouldDeallocateVirtualRange::Yes);
VERIFY(!m_page_directory);
}
MM.unregister_region(*this);
}
OwnPtr<Region> Region::clone()