From f0f97e1db028050a5014a6950a4a5c43bd424aff Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 5 Apr 2022 01:07:23 +0200 Subject: Kernel: Take the RegionTree spinlock when inspecting tree from outside This patch adds RegionTree::get_lock() which exposes the internal lock inside RegionTree. We can then lock it from the outside when doing lookups or traversal. This solution is not very beautiful, we should find a way to protect this data with SpinlockProtected or something similar. This is a stopgap patch to try and fix the currently flaky CI. --- Kernel/Memory/MemoryManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Kernel/Memory/MemoryManager.cpp') diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp index e6cc5b7d74..7bce3b3504 100644 --- a/Kernel/Memory/MemoryManager.cpp +++ b/Kernel/Memory/MemoryManager.cpp @@ -664,6 +664,8 @@ Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr) return nullptr; SpinlockLocker lock(s_mm_lock); + SpinlockLocker tree_locker(MM.m_region_tree.get_lock()); + auto* region = MM.m_region_tree.regions().find_largest_not_above(vaddr.get()); if (!region || !region->contains(vaddr)) return nullptr; @@ -1167,6 +1169,7 @@ void MemoryManager::unregister_kernel_region(Region& region) { VERIFY(region.is_kernel()); SpinlockLocker lock(s_mm_lock); + SpinlockLocker tree_locker(m_region_tree.get_lock()); m_region_tree.regions().remove(region.vaddr().get()); } @@ -1181,6 +1184,7 @@ void MemoryManager::dump_kernel_regions() dbgln("BEGIN{} END{} SIZE{} ACCESS NAME", addr_padding, addr_padding, addr_padding); SpinlockLocker lock(s_mm_lock); + SpinlockLocker tree_locker(m_region_tree.get_lock()); for (auto const& region : m_region_tree.regions()) { dbgln("{:p} -- {:p} {:p} {:c}{:c}{:c}{:c}{:c}{:c} {}", region.vaddr().get(), -- cgit v1.2.3