summaryrefslogtreecommitdiff
path: root/Kernel/Memory
AgeCommit message (Collapse)Author
2022-07-11Kernel: Stop committing pages for COW of uncommitted pages on sys$forkIdan Horowitz
Uncommitted pages (shared zero pages) can not contain any existing data and can not be modified, so there's no point to committing a bunch of extra pages to cover for them in the forked child.
2022-07-10Kernel: Stop leaking leftover committed cow pages from forked processesIdan Horowitz
Since both the parent process and child process hold a reference to the COW committed set, once the child process exits, the committed COW pages are effectively leaked, only being slowly re-claimed each time the parent process writes to one of them, realizing it's no longer shared, and uncommitting it. In order to mitigate this we now hold a weak reference the parent VMObject from which the pages are cloned, and we use it on destruction when available to drop the reference to the committed set from it as well.
2022-06-21Kernel: Decrease the amount of address space offset randomizationTim Schumacher
This is basically unchanged since the beginning of 2020, which is a year before we had proper ASLR. Now that we have a proper ASLR implementation, we can turn this down a bit, as it is no longer our only protection against predictable dynamic loader addresses, and it actually obstructs the default loading address of x86_64 quite frequently.
2022-06-19Kernel: Tolerate cloning MAP_STACK regions that are PROT_NONEAndrew Kaster
There's nothing stopping a userspace program from keeping a bunch of threads around with a custom signal stack in a suspended state with their normal thread stack mprotected to PROT_NONE. OpenJDK seems to do this, for example.
2022-06-06Kernel/Memory: Introduce the SharedFramebufferVMObject classLiav A
This new type of VMObject will be used to coordinate switching safely from graphical mode to text mode and vice-versa, by supplying a way to remap all Regions that were created with this object, so mappings can be changed according to the given state of system mode. This makes it quite easy to give applications like WindowServer the feeling of having full access to the framebuffer device from a DisplayConnector, but still keep the Kernel in control to be able to safely switch to text console.
2022-06-06Kernel: Verify system memory info consistencyIdan Horowitz
2022-06-06Kernel: Tighten assertion in MM::find_free_user_physical_pageIdan Horowitz
If our book-keeping of user physical pages is correct, we should always find a physical page, regardless if it was committed or uncommitted.
2022-06-06Kernel: Only use uncommitted pages when allocating contiguous user pagesIdan Horowitz
2022-06-02Kernel: Implement InterruptDisabler using generic Processor functionsTimon Kruiper
Now that the code does not use architectural specific code, it is moved to the generic Arch directory and the paths are modified accordingly.
2022-05-05Kernel/Memory: Add TypedMapping base_address methodLiav A
This method will be used to ease usage with the structure when we need to do virtual pointer arithmetics.
2022-05-03Kernel: Move Kernel/Arch/x86/SafeMem.h to Kernel/Arch/SafeMem.hTimon Kruiper
The file does not contain any specific architectural code, thus it can be moved to the Kernel/Arch directory.
2022-04-21Kernel: Limit free space between randomized memory allocationsTim Schumacher
2022-04-05Kernel: Don't unregister Region from RegionTree *before* unmapping itAndreas Kling
If we unregister from the RegionTree before unmapping, there's a race where a new region can get inserted at the same address that we're about to unmap. If this happens, ~Region() will then unmap the newly inserted region, which now finds itself with cleared-out page table entries.
2022-04-05Kernel: Remove MemoryManager::region_tree() accessorAndreas Kling
Let's not have a way to grab at the RegionTree from outside of MM.
2022-04-05Kernel: Move allocate_unbacked_region_anywhere() to MemoryManagerAndreas Kling
This didn't need to be in RegionTree, and since it's specific to kernel VM anyway, let's move it to MemoryManager.
2022-04-05Kernel: Move create_identity_mapped_region() to MemoryManagerAndreas Kling
This had no business being in RegionTree, since RegionTree doesn't track identity-mapped regions anyway. (We allow *any* address to be identity mapped, not just the ones that are part of the RegionTree's range.)
2022-04-05Kernel: Add RegionTree::find_region_containing(address or range)Andreas Kling
Let's encapsulate looking up regions so clients don't have to dig into RegionTree internals.
2022-04-05Kernel: Add RegionTree::remove(Region&)Andreas Kling
This allows clients to remove a region from the tree without reaching into the RegionTree internals.
2022-04-05Kernel: Take the RegionTree spinlock when inspecting tree from outsideAndreas Kling
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.
2022-04-05Kernel: Remove unused ShouldDeallocateVirtualRange parametersAndreas Kling
Since there is no separate virtual range allocator anymore, this is no longer used for anything.
2022-04-04Kernel: Add debug logging to learn more about unexpected NP faultsAndreas Kling
2022-04-04Kernel: Remove unused Region::try_create_kernel_only()Andreas Kling
2022-04-04Kernel: Use the InstrusiveRedBlackTree::begin_from(V&) APIIdan Horowitz
This let's us skip an O(logn) tree traversal.
2022-04-04Kernel: Remove false condition in RegionTree::allocate_range_specificIdan Horowitz
Since find_largest_not_above returns the highest region that is below the end of the request range, no region after it can intersect with it.
2022-04-03Kernel: Actually fix accidental overlaps in allocate_range_specific()Andreas Kling
Thanks to Idan for spotting this! :^)
2022-04-03Kernel: Fix accidental overlaps in RegionTree::allocate_range_specific()Andreas Kling
Thanks to Idan for spotting this! :^)
2022-04-03Kenrel: Update a dmesgln() to say "RegionTree" instead of old class nameAndreas Kling
2022-04-03Kernel: Add a little explainer comment above RegionTreeAndreas Kling
2022-04-03Kernel: Improve RegionTree's internal helper function namesAndreas Kling
It's a bit nicer if functions that allocate ranges have some kind of name that includes both "allocate" and "range". :^)
2022-04-03Kernel: Add missing include to PageDirectory.hAndreas Kling
2022-04-03Kernel: Unbreak ASLR in the new RegionTree worldAndreas Kling
Functions that allocate and/or place a Region now take a parameter that tells it whether to randomize unspecified addresses.
2022-04-03Kernel: Stop exposing RegionTree API for VM range allocationAndreas Kling
...and remove the last remaining client of the API. It's no longer possible to ask the RegionTree for a VM range. You can only ask it to place your Region somewhere in available space.
2022-04-03Kernel: Make VM allocation atomic for userspace regionsAndreas Kling
This patch move AddressSpace (the per-process memory manager) to using the new atomic "place" APIs in RegionTree as well, just like we did for MemoryManager in the previous commit. This required updating quite a few places where VM allocation and actually committing a Region object to the AddressSpace were separated by other code. All you have to do now is call into AddressSpace once and it'll take care of everything for you.
2022-04-03LibWeb: Make VM allocation atomic for kernel regionsAndreas Kling
Instead of first allocating the VM range, and then inserting a region with that range into the MM region tree, we now do both things in a single atomic operation: - RegionTree::place_anywhere(Region&, size, alignment) - RegionTree::place_specifically(Region&, address, size) To reduce the number of things we do while locking the region tree, we also require callers to provide a constructed Region object.
2022-04-03Kernel: Remove now-unused VirtualRangeAllocatorAndreas Kling
This has been replaced with the allocation-free RegionTree. :^)
2022-04-03Kernel: Use intrusive RegionTree solution for kernel regions as wellAndreas Kling
This patch ports MemoryManager to RegionTree as well. The biggest difference between this and the userspace code is that kernel regions are owned by extant OwnPtr<Region> objects spread around the kernel, while userspace regions are owned by the AddressSpace itself. For kernelspace, there are a couple of situations where we need to make large VM reservations that never get backed by regular VMObjects (for example the kernel image reservation, or the big kmalloc range.) Since we can't make a VM reservation without a Region object anymore, this patch adds a way to create unbacked Region objects that can be used for this exact purpose. They have no internal VMObject.)
2022-04-03Kernel: Add Memory::RegionTree to share code between AddressSpace and MMAndreas Kling
RegionTree holds an IntrusiveRedBlackTree of Region objects and vends a set of APIs for allocating memory ranges. It's used by AddressSpace at the moment, and will be used by MM soon.
2022-04-03Kernel: Use AddressSpace region tree for range allocationAndreas Kling
This patch stops using VirtualRangeAllocator in AddressSpace and instead looks for holes in the region tree when allocating VM space. There are many benefits: - VirtualRangeAllocator is non-intrusive and would call kmalloc/kfree when used. This new solution is allocation-free. This was a source of unpleasant MM/kmalloc deadlocks. - We consolidate authority on what the address space looks like in a single place. Previously, we had both the range allocator *and* the region tree both being used to determine if an address was valid. Now there is only the region tree. - Deallocation of VM when splitting regions is no longer complicated, as we don't need to keep two separate trees in sync.
2022-04-03Kernel: Store AddressSpace memory regions in an IntrusiveRedBlackTreeAndreas Kling
This means we never need to allocate when inserting/removing regions from the address space.
2022-04-02Kernel: Make MemoryManager compile on aarch64James Mintram
2022-04-02Kernel: Make handle_crash available to aarch64James Mintram
2022-04-02Kernel: Make PageDirectory.cpp compile on aarch64James Mintram
2022-04-02Kernel: Make AddressSpace.cpp compile on aarch64James Mintram
2022-04-02Kernel: Make Region.cpp compile on aarch64James Mintram
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-23Kernel: Use the whole kernel PD range when randomizing the KASLR offsetIdan Horowitz
Now that we reclaim the memory range that is created by KASLR before the start of the kernel image, there's no need to be conservative with the KASLR offset.
2022-03-22Kernel: Use the pre-image kernel memory range introduced by KASLRIdan Horowitz
This ensures we don't just waste the memory range between the default base load address and the actual load address that was shifted by the KASLR offset.
2022-03-17Kernel: Use default constructors/destructorsLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-02-14Kernel: Make Inode::set_shared_vmobject() OOM-fallibleIdan Horowitz
Allocating a WeakPtr can fail, so this let's us properly propagate said failure.
2022-02-11Kernel: Stop trying to write unmapped Process regions into CoreDumpsIdan Horowitz
If we crashed in the middle of mapping in Regions, some of the regions may not have a page directory yet, and will result in a crash when Region::remap() is called.