From 4bf1a72d2158f7a1531f643444cb896558094973 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 3 Nov 2019 20:59:54 +0100 Subject: [PATCH] Kernel: Teach Region how to remap itself Now remapping (i.e flushing kernel metadata to the CPU page tables) is done by simply calling Region::remap(). --- Kernel/Process.cpp | 4 ++-- Kernel/SharedBuffer.cpp | 2 +- Kernel/VM/InodeVMObject.cpp | 10 ++++------ Kernel/VM/MemoryManager.cpp | 7 ------- Kernel/VM/MemoryManager.h | 2 -- Kernel/VM/Region.cpp | 8 +++++++- Kernel/VM/Region.h | 1 + 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 74a643ee6e4..1ff6fd85864 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -283,7 +283,7 @@ int Process::sys$mprotect(void* addr, size_t size, int prot) if (!region) return -EINVAL; region->set_writable(prot & PROT_WRITE); - MM.remap_region(page_directory(), *region); + region->remap(); return 0; } @@ -885,7 +885,7 @@ void create_signal_trampolines() memcpy(code_ptr, trampoline, trampoline_size); trampoline_region->set_writable(false); - MM.remap_region(*trampoline_region->page_directory(), *trampoline_region); + trampoline_region->remap(); } int Process::sys$restore_signal_mask(u32 mask) diff --git a/Kernel/SharedBuffer.cpp b/Kernel/SharedBuffer.cpp index d95e9ba2243..87b119cad02 100644 --- a/Kernel/SharedBuffer.cpp +++ b/Kernel/SharedBuffer.cpp @@ -155,7 +155,7 @@ void SharedBuffer::seal() for (auto& ref : m_refs) { if (ref.region) { ref.region->set_writable(false); - MM.remap_region(*ref.region->page_directory(), *ref.region); + ref.region->remap(); } } } diff --git a/Kernel/VM/InodeVMObject.cpp b/Kernel/VM/InodeVMObject.cpp index e96e44b4733..93bcc65bf3f 100644 --- a/Kernel/VM/InodeVMObject.cpp +++ b/Kernel/VM/InodeVMObject.cpp @@ -47,9 +47,8 @@ void InodeVMObject::inode_size_changed(Badge, size_t old_size, size_t new m_physical_pages.resize(new_page_count); // FIXME: Consolidate with inode_contents_changed() so we only do a single walk. - for_each_region([](Region& region) { - ASSERT(region.page_directory()); - MM.remap_region(*region.page_directory(), region); + for_each_region([](auto& region) { + region.remap(); }); } @@ -99,9 +98,8 @@ void InodeVMObject::inode_contents_changed(Badge, off_t offset, ssize_t s #endif // FIXME: Consolidate with inode_size_changed() so we only do a single walk. - for_each_region([](Region& region) { - ASSERT(region.page_directory()); - MM.remap_region(*region.page_directory(), region); + for_each_region([](auto& region) { + region.remap(); }); } diff --git a/Kernel/VM/MemoryManager.cpp b/Kernel/VM/MemoryManager.cpp index bb3adcfe889..67cddbf1446 100644 --- a/Kernel/VM/MemoryManager.cpp +++ b/Kernel/VM/MemoryManager.cpp @@ -673,13 +673,6 @@ void MemoryManager::unquickmap_page() m_quickmap_in_use = false; } -void MemoryManager::remap_region(PageDirectory& page_directory, Region& region) -{ - InterruptDisabler disabler; - ASSERT(region.page_directory() == &page_directory); - map_region_at_address(page_directory, region, region.vaddr()); -} - void MemoryManager::map_region_at_address(PageDirectory& page_directory, Region& region, VirtualAddress vaddr) { InterruptDisabler disabler; diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index 7a77933127d..38ed88ba42b 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -64,8 +64,6 @@ public: void deallocate_user_physical_page(PhysicalPage&&); void deallocate_supervisor_physical_page(PhysicalPage&&); - void remap_region(PageDirectory&, Region&); - void map_for_kernel(VirtualAddress, PhysicalAddress, bool cache_disabled = false); OwnPtr allocate_kernel_region(size_t, const StringView& name, bool user_accessible = false, bool should_commit = true); diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index e1901350864..c47d1c8eb48 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -75,7 +75,7 @@ NonnullOwnPtr Region::clone() #endif // Set up a COW region. The parent (this) region becomes COW as well! ensure_cow_map().fill(true); - MM.remap_region(current->process().page_directory(), *this); + remap(); auto clone_region = Region::create_user_accessible(m_range, m_vmobject->clone(), m_offset_in_vmo, m_name, m_access); clone_region->ensure_cow_map(); return clone_region; @@ -220,3 +220,9 @@ void Region::map(PageDirectory& page_directory) { MM.map_region_at_address(page_directory, *this, vaddr()); } + +void Region::remap() +{ + ASSERT(m_page_directory); + MM.map_region_at_address(*m_page_directory, *this, vaddr()); +} diff --git a/Kernel/VM/Region.h b/Kernel/VM/Region.h index cc8c2766405..104661bfad3 100644 --- a/Kernel/VM/Region.h +++ b/Kernel/VM/Region.h @@ -121,6 +121,7 @@ public: }; void unmap(ShouldDeallocateVirtualMemoryRange = ShouldDeallocateVirtualMemoryRange::Yes); + void remap(); void remap_page(size_t index); // For InlineLinkedListNode