summaryrefslogtreecommitdiff
path: root/Kernel/VM/MemoryManager.cpp
AgeCommit message (Collapse)Author
2020-05-08Kernel: Assert on startup if we don't find any physical pagesAndreas Kling
Instead of checking this on every page allocation, just check it once on startup. :^)
2020-05-08Kernel: Add for_each_vmobject_of_type<T>Andreas Kling
This makes iterating over a specific type of VMObjects a bit nicer.
2020-05-08Kernel: Propagate failure to commit VM regions in more placesAndreas Kling
Ultimately we should not panic just because we can't fully commit a VM region (by populating it with physical pages.) This patch handles some of the situations where commit() can fail.
2020-05-08Kernel: Use NonnullRefPtrVector<T> instead of Vector<RefPtr<T>> someAndreas Kling
2020-05-07Kernel: Memory purging was incorrectly "purging" the shared zero pageAndreas Kling
This caused us to report one purged page per occurrence of the shared zero page in a purgeable memory region, despite it being a no-op. Thanks to Sergey for spotting the bad assertion removal that led to this being found!
2020-05-06Kernel: Don't assert on OOM in allocate_user_physical_page()Andreas Kling
We now give callers a chance to react to OOM situations.
2020-04-13Kernel: Switch the first-8MB-of-upper-3GB pseudo mappings to 4KB pagesAndreas Kling
This memory range was set up using 2MB pages by the code in boot.S. Because of that, the kernel image protection code didn't work, since it assumed 4KB pages. We now switch to 4KB pages during MemoryManager initialization. This makes the kernel image protection code work correctly again. :^)
2020-03-23AK: Reduce header dependency graph of String.hAndreas Kling
String.h no longer pulls in StringView.h. We do this by moving a bunch of String functions out-of-line.
2020-03-08Kernel: Allow contiguous allocations in physical memoryLiav A
For that, we have a new type of VMObject, called ContiguousVMObject, that is responsible for allocating contiguous physical pages.
2020-03-08Kernel: Add missing #includes now that <AK/StdLibExtras.h> is smallerAndreas Kling
2020-03-08AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)Andreas Kling
Use this instead of uintptr_t throughout the codebase. This makes it possible to pass a FlatPtr to something that has u32 and u64 overloads.
2020-03-06Kernel: Simplify a bunch of dbg() and klog() callsAndreas Kling
LogStream can handle VirtualAddress and PhysicalAddress directly.
2020-03-02Kernel: Use klog() instead of kprintf()Liav A
Also, duplicate data in dbg() and klog() calls were removed. In addition, leakage of virtual address to kernel log is prevented. This is done by replacing kprintf() calls to dbg() calls with the leaked data instead. Also, other kprintf() calls were replaced with klog().
2020-03-01Kernel: Reduce code duplication a little bit in Region allocationAndreas Kling
This patch reduces the number of code paths that lead to the allocation of a Region object. It's quite hard to follow the various ways in which this can happen, so this is an effort to simplify.
2020-03-01Kernel: Move ProcessPagingScope to its own filesAndreas Kling
2020-03-01Kernel: Remove some Region construction helpersAndreas Kling
It's now up to the caller to provide a VMObject when constructing a new Region object. This will make it easier to handle things going wrong, like allocation failures, etc.
2020-02-28Kernel: Rename InodeVMObject => SharedInodeVMObjectAndreas Kling
2020-02-27MemoryManager: Use dbg() instead of dbgprintf()Liav A
2020-02-23Kernel: Dump all kernel regions when we hit a page fault during IRQAndreas Kling
This way you can try to figure out what the faulting address is.
2020-02-22Kernel: Put "Couldn't find user region" spam behind MM_DEBUGAndreas Kling
This basically never tells us anything actionable anyway, and it's a real annoyance when doing something validation-heavy like profiling.
2020-02-21Kernel: Log instead of crashing when getting a page fault during IRQAndreas Kling
This is definitely a bug, but it seems to happen randomly every now and then and we need more info to track it down, so let's log for now.
2020-02-21Kernel: Don't trigger page faults during profiling stack walkAndreas Kling
The kernel sampling profiler will walk thread stacks during the timer tick handler. Since it's not safe to trigger page faults during IRQ's, we now avoid this by checking the page tables manually before accessing each stack location.
2020-02-21Kernel: Assert on page fault during IRQAndreas Kling
We're not equipped to deal with page faults during an IRQ handler, so add an assertion so we can immediately tell what's wrong. This is why profiling sometimes hangs the system -- walking the stack of the profiled thread causes a page fault and things fall apart.
2020-02-17Kernel: Replace "current" with Thread::current and Process::currentAndreas Kling
Suggested by Sergey. The currently running Thread and Process are now Thread::current and Process::current respectively. :^)
2020-02-16Kernel: Reduce header dependencies of MemoryManager and RegionAndreas Kling
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-15Kernel: Use a shared physical page for zero-filled pages until writtenAndreas Kling
This patch adds a globally shared zero-filled PhysicalPage that will be mapped into every slot of every zero-filled AnonymousVMObject until that page is written to, achieving CoW-like zero-filled pages. Initial testing show that this doesn't actually achieve any sharing yet but it seems like a good design regardless, since it may reduce the number of page faults taken by programs. If you look at the refcount of MM.shared_zero_page() it will have quite a high refcount, but that's just because everything maps it everywhere. If you want to see the "real" refcount, you can build with the MAP_SHARED_ZERO_PAGE_LAZILY flag, and we'll defer mapping of the shared zero page until the first NP read fault. I've left this behavior behind a flag for future testing of this code.
2020-02-10Kernel: Add getter and setter for the X86 CR3 registerAndreas Kling
This gets rid of a bunch of inline assembly.
2020-02-10AK: Remove bitrotted Traits::dump() mechanismAndreas Kling
This was only used by HashTable::dump() which I used when doing the first HashTable implementation. Removing this allows us to also remove most includes of <AK/kstdio.h>.
2020-02-09Kernel: Apply changes to use LibBareMetal definitionsLiav A
2020-02-08x86: Simplify region unmapping a bitAndreas Kling
Add PageTableEntry::clear() to zero out a whole PTE, and use that for unmapping instead of clearing individual fields.
2020-01-29Kernel: Fail with EFAULT for any address+size that would wrap aroundAndreas Kling
Previously we were only checking that each of the virtual pages in the specified range were valid. This made it possible to pass in negative buffer sizes to some syscalls as long as (address) and (address+size) were on the same page.
2020-01-28Kernel: AnonymousVMObject::create_for_physical_range() should fail moreAndreas Kling
Previously it was not possible for this function to fail. You could exploit this by triggering the creation of a VMObject whose physical memory range would wrap around the 32-bit limit. It was quite easy to map kernel memory into userspace and read/write whatever you wanted in it. Test: Kernel/bxvga-mmap-kernel-into-userspace.cpp
2020-01-28Kernel: Remove outdated comment in MemoryManagerAndreas Kling
Regions *do* zero-fill on demand now. :^)
2020-01-21Kernel: Tidy up debug logging a little bitAndreas Kling
When using dbg() in the kernel, the output is automatically prefixed with [Process(PID:TID)]. This makes it a lot easier to understand which thread is generating the output. This patch also cleans up some common logging messages and removes the now-unnecessary "dbg() << *current << ..." pattern.
2020-01-21Kernel: Remove map_for_kernel() in MemoryManagerLiav A
We don't need to have this method anymore. It was a hack that was used in many components in the system but currently we use better methods to create virtual memory mappings. To prevent any further use of this method it's best to just remove it completely. Also, the APIC code is disabled for now since it doesn't help booting the system, and is broken since it relies on identity mapping to exist in the first 1MB. Any call to the APIC code will result in assertion failed. In addition to that, the name of the method which is responsible to create an identity mapping between 1MB to 2MB was changed, to be more precise about its purpose.
2020-01-20Use uintptr_t instead of u32 when storing pointers as integersAndreas Kling
uintptr_t is 32-bit or 64-bit depending on the target platform. This will help us write pointer size agnostic code so that when the day comes that we want to do a 64-bit port, we'll be in better shape.
2020-01-19Kernel: Make ProcessPagingScope restore CR3 properlyAndreas Kling
Instead of restoring CR3 to the current process's paging scope when a ProcessPagingScope goes out of scope, we now restore exactly whatever the CR3 value was when we created the ProcessPagingScope. This fixes breakage in situations where a process ends up with nested ProcessPagingScopes. This was making profiling very fragile, and with this change it's now possible to profile g++! :^)
2020-01-18Kernel: Move all CPU feature initialization into cpu_setup()Andreas Kling
..and do it very very early in boot.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-18Kernel: Always dump kernel regions when dumping process regionsAndreas Kling
2020-01-18Kernel: Remove two unused MemoryManager functionsAndreas Kling
2020-01-18Kernel: Clean up MemoryManager initialization a bit moreAndreas Kling
Move the CPU feature enabling to functions in Arch/i386/CPU.cpp.
2020-01-17Kernel: Stop allocating page tables from the super pages poolAndreas Kling
We now use the regular "user" physical pages for on-demand page table allocations. This was by far the biggest source of super physical page exhaustion, so that bug should be a thing of the past now. :^) We still have super pages, but they are barely used. They remain useful for code that requires memory with a low physical address. Fixes #1000.
2020-01-17Kernel: Re-enable protection of the kernel image in memoryAndreas Kling
2020-01-17Kernel: Tidy up the lowest part of the address spaceAndreas Kling
After MemoryManager initialization, we now only leave the lowest 1MB of memory identity-mapped. The very first (null) page is not present. All other pages are RW but not X. Supervisor only.
2020-01-17Kernel: Move Multiboot memory map parsing to its own functionAndreas Kling
2020-01-17Kernel: Clean up ensure_pte()Andreas Kling
2020-01-17Kernel: Move kernel above the 3GB virtual address markAndreas Kling
The kernel and its static data structures are no longer identity-mapped in the bottom 8MB of the address space, but instead move above 3GB. The first 8MB above 3GB are pseudo-identity-mapped to the bottom 8MB of the physical address space. But things don't have to stay this way! Thanks to Jesse who made an earlier attempt at this, it was really easy to get device drivers working once the page tables were in place! :^) Fixes #734.
2020-01-14Kernel: Change Region allocation helpersLiav A
We now can create a cacheable Region, so when map() is called, if a Region is cacheable then all the virtual memory space being allocated to it will be marked as not cache disabled. In addition to that, OS components can create a Region that will be mapped to a specific physical address by using the appropriate helper method.