summaryrefslogtreecommitdiff
path: root/Kernel/VM
AgeCommit message (Collapse)Author
2021-05-03Kernel: Mark AsyncBlockDeviceRequest + AnonymousVMObject as finalBrian Gianforcaro
Mark final to aid in de-virtualization since they are not currently derived from.
2021-05-02Kernel: Change Inode::{read/write}_bytes interface to KResultOr<ssize_t>Brian Gianforcaro
The error handling in all these cases was still using the old style negative values to indicate errors. We have a nicer solution for this now with KResultOr<T>. This change switches the interface and then all implementers to use the new style.
2021-05-01Everywhere: Turn #if *_DEBUG into dbgln_if/if constexprGunnar Beutner
2021-04-29Everywhere: Use "the SerenityOS developers." in copyright headersLinus Groh
We had some inconsistencies before: - Sometimes "The", sometimes "the" - Sometimes trailing ".", sometimes no trailing "." I picked the most common one (lowecase "the", trailing ".") and applied it to all copyright headers. By using the exact same string everywhere we can ensure nothing gets missed during a global search (and replace), and that these inconsistencies are not spread any further (as copyright headers are commonly copied to new files).
2021-04-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
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-17Kernel: Implement a simple Scatter/Gather ListIdan Horowitz
This allows converting a single virtual buffer into its non-physically contiguous parts, this is especially useful for DMA-based devices that support scatter/gather-like functionality, as it eliminates the need to clone outgoing buffers into one physically contiguous buffer.
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-04-12Kernel: Remove old region from process' regions vector before splittingIdan Horowitz
This does not affect functionality right now, but it means that the regions vector will now never have any overlapping regions, which will allow the use of balance binary search trees instead of a vector in the future. (since they require keys to be exclusive)
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-13Kernel: Implement helper to find multiple Regions in a RangeHendiadyoin1
2021-03-13Kernel: Add a Range::intersect(other) helperHendiadyoin1
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-03-12Kernel: Convert klog() => AK::Format in PurgeablePageRangesAndreas Kling
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-09Kernel: Convert klog() => dmesgln() in PageDirectoryAndreas Kling
2021-03-09Kernel: Convert klog() to dmesgln() in RegionAndreas Kling
2021-03-09Kernel: Convert klog() => dmesgln() in AnonymousVMObjectAndreas 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-05Kernel: Add AnonymousVMObject constructor for a Vector of physical pagesLiav A
This will be used later on by the AHCI code to create a Region that spans over scattered DMA pages.
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-03-04Kernel: Stop trying to keep InodeVMObject in sync with disk changesAndreas Kling
As it turns out, Dr. POSIX doesn't require that post-mmap() changes to a file are reflected in the memory mappings. So we don't actually have to care about the file size changing (or the contents.) IIUC, as long as all the MAP_SHARED mappings that refer to the same inode are in sync, we're good. This means that VMObjects don't need resizing capabilities. I'm sure there are ways we can take advantage of this fact.
2021-03-04AK: Simplify Bitmap and implement in terms of BitmapViewAndreas Kling
Add Bitmap::view() and forward most of the calls to BitmapView since the code was identical. Bitmap is now primarily concerned with its dynamically allocated backing store and BitmapView deals with the rest.
2021-03-04Kernel: Remove 1 level of indirection for AnonymousVMObject CoW bitmapsAndreas Kling
Instead of keeping AnonymousVMObject::m_cow_map in an OwnPtr<Bitmap>, just make the Bitmap a regular value member. This increases the size of the VMObject by 8 bytes, but removes some of the kmalloc/kfree spam incurred by sys$fork().
2021-03-03Kernel: Skip TLB flushes while cloning regions in sys$fork()Andreas Kling
Since we know for sure that the virtual memory regions in the new process being created are not being used on any CPU, there's no need to do TLB flushes for every mapped page.
2021-02-28Kernel: Use default con/de-structorsBen Wiederhake
This may seem like a no-op change, however it shrinks down the Kernel by a bit: .text -432 .unmap_after_init -60 .data -480 .debug_info -673 .debug_aranges 8 .debug_ranges -232 .debug_line -558 .debug_str -308 .debug_frame -40 With '= default', the compiler can do more inlining, hence the savings. I intentionally omitted some opportunities for '= default', because they would increase the Kernel size.
2021-02-27Kernel: Use get_fast_random() for MAP_RANDOMIZED addressesAndreas Kling
Let's not block sys$mmap() on kernel randomness.
2021-02-25Kernel: Move SMAP disabler RAII helper to its own fileAndreas Kling
Added this in a new directory called Kernel/Arch/x86/ where stuff that applies to both i386 and x86_64 can live.
2021-02-25Kernel: Move the VM Range class to its own filesAndreas Kling
2021-02-23Kernel: Expand the kernel memory slot from 8 MiB to 16 MiBAndreas Kling
We were only 448 KiB away from filling up the old slot size we reserve for the kernel above the 3 GiB mark. This expands the slot to 16 MiB, which allows us to continue booting the kernel until somebody takes the time to improve our loader.
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: Panic on attempt to map mmap'ed page at a kernel addressAndreas Kling
If we somehow get tricked into mapping user-controlled mmap memory at a kernel address, let's just panic the kernel.
2021-02-14Kernel: Make the Region constructor privateAndreas Kling
We can use adopt_own(*new T) instead of make<T>().
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-13Kernel: Sanity check the VM range when constructing a RegionAndreas Kling
This should help us catch bogus VM ranges ending up in a process's address space sooner.
2021-02-13Kernel: Round up ranges to page size multiples in munmap and mprotectAndreas Kling
This prevents passing bad inputs to RangeAllocator who then asserts. Found by fuzz-syscalls. :^)
2021-02-12Kernel: Make MAP_RANDOMIZED honor alignment requestsAndreas Kling
Previously, we only cared about the alignment on the fallback path.
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-12Kernel: Convert klog() to dmesgln() in RangeAllocatorAndreas Kling
2021-02-11Kernel: Oops, add missing #include to fix ENABLE_ALL_THE_DEBUG_MACROSAndreas Kling