summaryrefslogtreecommitdiff
path: root/Kernel/VM/MemoryManager.cpp
AgeCommit message (Collapse)Author
2021-07-11Kernel: Remove unused MemoryManager::find_region_from_vaddr()Andreas Kling
2021-07-11Kernel: Remove unused MemoryManager::m_physical_page_entries_freeAndreas Kling
2021-07-11Kernel: Remove pointless ref-counting from PhysicalRegionAndreas Kling
These are not multiple-owner objects and have no use for ref-counting. Make them simple value types instead (not eternal heap-allocated.)
2021-07-08Kernel: Return an already destructed PhysicalPage to the allocatorsTom
By making sure the PhysicalPage instance is fully destructed the allocators will have a chance to reclaim the PhysicalPageEntry for free-list purposes. Just pass them the physical address of the page that was freed, which is enough to lookup the PhysicalPageEntry later.
2021-07-08Kernel: Move PhysicalPage classes out of the heap into an arrayTom
By moving the PhysicalPage classes out of the kernel heap into a static array, one for each physical page, we can avoid the added overhead and easily find them by indexing into an array. This also wraps the PhysicalPage into a PhysicalPageEntry, which allows us to re-use each slot with information where to find the next free page.
2021-07-08Kernel: Use PAE to allow accessing all physical memory beyond 4GBTom
We already use PAE for the NX bit, but this changes the PhysicalAddress structure to be able to hold 64 bit physical addresses. This allows us to use all the available physical memory.
2021-06-28Kernel: Make and use KERNEL_BASEHendiadyoin1
This is to make the 0xc0000000 less a magic number, and will make it easier in the future to move the Kernel around
2021-06-27Kernel: Rename Thread::tss to Thread::regs and add x86_64 supportGunnar Beutner
We're using software context switches so calling this struct tss is somewhat misleading.
2021-06-24Kernel: Add stubs for missing x86_64 functionalityGunnar Beutner
This adds just enough stubs to make the kernel compile on x86_64. Obviously it won't do anything useful - in fact it won't even attempt to boot because Multiboot doesn't support ELF64 binaries - but it gets those compiler errors out of the way so more progress can be made getting all the missing functionality in place.
2021-06-24Kernel: Move special sections into Sections.hHendiadyoin1
This also removes a lot of CPU.h includes infavor for Sections.h
2021-05-29Kernel: Make ContiguousVMObject factory API OOM safeBrian Gianforcaro
2021-05-28Kernel: Use KString for Region namesAndreas Kling
Replace the AK::String used for Region::m_name with a KString. This seems beneficial across the board, but as a specific data point, it reduces time spent in sys$set_mmap_name() by ~50% on test-js. :^)
2021-05-26Kernel: Switch VMObject to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-26Kernel: Switch Region to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-20Kernel: Do not allocate AnonymousVMObject's under spin lockBrian Gianforcaro
Spinlocks guard short regions, with hopefully no other locks being taken in the process. Violating constraints usually had detrimental effects on platform stability as well as performance and scalability. Allocating memory takes it own locks, and can in some cases even allocate new regions, and thus violates these tenants. Move the AnonymousVMObject creation outside of the spinlock as creation does not modify any shared state.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-20Kernel: Don't consider kernel memory regions for syscall origin checkAndreas Kling
We should never enter the syscall handler from a kernel address.
2021-04-12Kernel: Replace process' regions vector with a Red Black treeIdan Horowitz
This should provide some speed up, as currently searches for regions containing a given address were performed in O(n) complexity, while this container allows us to do those in O(logn).
2021-03-30Kernel: Don't dump regions twice when crashing due to bad accessAndreas Kling
For whatever reason we were dumping regions when first handling the page fault, and then again when tearing down the process.
2021-03-21Kernel::CPU: Move headers into common directoryHendiadyoin1
Alot of code is shared between i386/i686/x86 and x86_64 and a lot probably will be used for compatability modes. So we start by moving the headers into one Directory. We will probalby be able to move some cpp files aswell.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-03-11Kernel: Add MemoryManager::set_page_writable_direct()Andreas Kling
This helper function goes directly to the page tables and makes a virtual address writable or non-writable.
2021-03-09Kernel: Convert klog() => dmesgln() in MemoryManagerAndreas Kling
2021-03-08Kernel: Make MemoryManager API type-safe for Region::Access enumBrian Gianforcaro
Increase type-safety moving the MemoryManager APIs which take a Region::Access to actually use that type instead of a `u8`. Eventually the actually m_access can be moved there as well, but I hit some weird bug where it wasn't using the correct operators in `set_access_bit(..)` even though it's declared (and tested). Something to fix-up later.
2021-03-04Kernel: Make the kernel compile & link for x86_64Andreas Kling
It's now possible to build the whole kernel with an x86_64 toolchain. There's no bootstrap code so it doesn't work yet (obviously.)
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-19Kernel: Slap UNMAP_AFTER_INIT on a whole bunch of functionsAndreas Kling
There's no real system here, I just added it to various functions that I don't believe we ever want to call after initialization has finished. With these changes, we're able to unmap 60 KiB of kernel text after init. :^)
2021-02-19Kernel: Add .unmap_after_init section for code we don't need after initAndreas Kling
You can now declare functions with UNMAP_AFTER_INIT and they'll get segregated into a separate kernel section that gets completely unmapped at the end of initialization. This can be used for anything we don't need to call once we've booted into userspace. There are two nice things about this mechanism: - It allows us to free up entire pages of memory for other use. (Note that this patch does not actually make use of the freed pages yet, but in the future we totally could!) - It allows us to get rid of obviously dangerous gadgets like write-to-CR0 and write-to-CR4 which are very useful for an attacker trying to disable SMAP/SMEP/etc. I've also made sure to include a helpful panic message in case you hit a kernel crash because of this protection. :^)
2021-02-15Kernel: Avoid some un-necessary copies coming from range based for loopsBrian Gianforcaro
- The irq_controller was getting add_ref/released needlessly during enumeration. - Used ranges were also getting needlessly copied.
2021-02-14Kernel: Add mechanism to make some memory read-only after init finishesAndreas Kling
You can now use the READONLY_AFTER_INIT macro when declaring a variable and we will put it in a special ".ro_after_init" section in the kernel. Data in that section remains writable during the boot and init process, and is then marked read-only just before launching the SystemServer. This is based on an idea from the Linux kernel. :^)
2021-02-14Kernel: Assert if rounding-up-to-page-size would wrap around to 0Andreas Kling
If we try to align a number above 0xfffff000 to the next multiple of the page size (4 KiB), it would wrap around to 0. This is most likely never what we want, so let's assert if that happens.
2021-02-14Kernel: Remove user/kernel flags from RegionAndreas Kling
Now that we no longer need to support the signal trampolines being user-accessible inside the kernel memory range, we can get rid of the "kernel" and "user-accessible" flags on Region and simply use the address of the region to determine whether it's kernel or user. This also tightens the page table mapping code, since it can now set user-accessibility based solely on the virtual address of a page.
2021-02-12Kernel: Move region dumps from dmesg to debug logAndreas Kling
Also fix a broken format string caught by the new format string checks.
2021-02-12Kernel: Convert klog() => dmesgln() / dbgln() in MemoryManagerAndreas Kling
2021-02-11Kernel: Remove a handful of unused things in VM/ directoryAndreas Kling
Also add some missing initializers.
2021-02-08Kernel: Factor address space management out of the Process classAndreas Kling
This patch adds Space, a class representing a process's address space. - Each Process has a Space. - The Space owns the PageDirectory and all Regions in the Process. This allows us to reorganize sys$execve() so that it constructs and populates a new Space fully before committing to it. Previously, we would construct the new address space while still running in the old one, and encountering an error meant we had to do tedious and error-prone rollback. Those problems are now gone, replaced by what's hopefully a set of much smaller problems and missing cleanups. :^)
2021-02-08Kernel: Remove unused MemoryManager::validate_range()Andreas Kling
This is no longer used since we've switched to using the MMU to generate EFAULT errors.
2021-02-01Kernel: Introduce the MemoryDeviceLiav A
This is a character device that is being used by the dmidecode utility. We only allow to map the BIOS ROM area to userspace with this device.
2021-01-28Kernel: Allow specifying a physical alignment when allocatingTom
Some drivers may require allocating contiguous physical pages with a specific alignment for the physical address.
2021-01-27Kernel: Release MM lock while yielding from inode page fault handlerTom
We need to make sure other processors can grab the MM lock while we wait, so release it when we might block. Reading the page from disk may also block, so release it during that time as well.
2021-01-27Kernel: Remove Range "valid" state and use Optional<Range> insteadAndreas Kling
It's easier to understand VM ranges if they are always valid. We can simply use an empty Optional<Range> to encode absence when needed.
2021-01-27Kernel: Make Processor::id a static functionTom
This eliminates the window between calling Processor::current and the member function where a thread could be moved to another processor. This is generally not as big of a concern as with Processor::current_thread, but also slightly more light weight.
2021-01-26Kernel: sys$munmap() region splitting did not preserve "shared" flagAndreas Kling
This was exploitable since the shared flag determines whether inode permission checks are applied in sys$mprotect(). The bug was pretty hard to spot due to default arguments being used instead. This patch removes the default arguments to make explicit at each call site what's being done.
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25Everywhere: Use CMake to generate AK/Debug.h.asynts
This was done with the help of several scripts, I dump them here to easily find them later: awk '/#ifdef/ { print "#cmakedefine01 "$2 }' AK/Debug.h.in for debug_macro in $(awk '/#ifdef/ { print $2 }' AK/Debug.h.in) do find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/#ifdef '$debug_macro'/#if '$debug_macro'/' {} \; done # Remember to remove WRAPPER_GERNERATOR_DEBUG from the list. awk '/#cmake/ { print "set("$2" ON)" }' AK/Debug.h.in
2021-01-22Kernel: Parse boot modules from Multiboot specificationJean-Baptiste Boric
2021-01-22Kernel: Move kmalloc heaps and super pages inside .bss segmentJean-Baptiste Boric
The kernel ignored the first 8 MiB of RAM while parsing the memory map because the kmalloc heaps and the super physical pages lived here. Move all that stuff inside the .bss segment so that those memory regions are accounted for, otherwise we risk overwriting boot modules placed next to the kernel.
2021-01-22Kernel: Remove trace log in MemoryManager::deallocate_user_physical_page()Jean-Baptiste Boric
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
2021-01-11Kernel: Remove MM_DEBUG debug spam codeAndreas Kling
This was too spammy to ever actually be used anyway.