Commit graph

7034 commits

Author SHA1 Message Date
Liav A bf16061142 Kernel: Take WorkQueue item as reference instead of pointer in do_queue 2022-04-20 19:47:18 +02:00
Liav A 1462211ccf Kernel: Allow WorkQueue items allocation failures propagation
In most cases it's safe to abort the requested operation and go forward,
however, in some places it's not clear yet how to handle these failures,
therefore, we use the MUST() wrapper to force a kernel panic for now.
2022-04-20 19:47:18 +02:00
Liav A 02566d8091 Kernel: Move VMWareBackdoor to new directory in the Firmware directory 2022-04-20 19:21:32 +02:00
Liav A 063ea0088e Kernel: Enable PS2 keyboard scan code translation if not already enabled
On the QEMU microvm machine type, it became apparent that the BIOS was
not setting the i8042 controller to function as expected. To ensure that
the controller is always outputting correct scan codes, set it to scan
code 2 and enable first port translation to ensure all scan codes are
translated to scan code set 1. This is the expected behavior when using
SeaBIOS, but on qboot (the BIOS for the QEMU microvm machine type), the
firmware doesn't take care of this so we need to do this ourselves.
2022-04-18 19:36:42 +03:00
Tim Schumacher cf7a0821b5 Kernel: Increase the default userspace stack size to 4 MiB
This makes the main thread stack size the same as the default stack
size when creating new threads.
2022-04-12 16:48:15 +02:00
Tim Schumacher a1686db2de Kernel: Skip setting region name if none is given to mmap
This keeps us from accidentally overwriting an already set region name,
for example when we are mapping a file (as, in this case, the file name
is already stored in the region).
2022-04-12 01:52:21 +02:00
Idan Horowitz 2f4ab64e8c Kernel: Use kernel_mapping_base as the minimum kernel stack address
Since KASLR was added kernel_load_base only signifies the address at
which the kernel image start, not the start of kernel memory, meaning
that a valid kernel stack can be allocated before it in memory.

We use kernel_mapping_base, the lowest address covered by the kernel
page directory, as the minimal address when performing safety checks
during backtrace generation.
2022-04-10 21:57:19 +02:00
Idan Horowitz e84bbfed44 Kernel: Remove big lock from sys$mkdir
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 165a23b68c Kernel: Remove big lock from sys$rename
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 5c064d3e8e Kernel: Remove big lock from sys$rmdir
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz d4ce43cf45 Kernel: Remove big lock from sys$statvfs
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 4ae93179f1 Kernel: Remove big lock from sys$symlink
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 1474b18070 Kernel: Remove big lock from sys$link
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz fa360f7d88 Kernel: Remove big lock from sys$unlink
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 5a96260e25 Kernel: Remove big lock from sys$setsockopt
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz c2372242b1 Kernel: Remove big lock from sys$getsockopt
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 849c227f72 Kernel: Remove big lock from sys$shutdown
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz e620487b66 Kernel: Remove big lock from sys$connect
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 9547a8e8a2 Kernel: Remove big lock from sys$close
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 0297349922 Kernel: Remove big lock from sys$chown
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 8458313e8a Kernel: Remove big lock from sys$fchown
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz f986a3b886 Kernel: Remove big lock from sys$bind
This syscall doesn't access any unprotected shared data.
2022-04-09 23:46:02 +02:00
Idan Horowitz 2c025d6334 Kernel: Move NNRP<Socket>s instead of copying in queue_connection_from 2022-04-09 23:46:02 +02:00
Idan Horowitz 4a270c93ed Kernel: Accept NNRP<Socket> instead of RP<Socket> in release_for_accept
This value is always non-null, so let's make it explicit.
2022-04-09 23:46:02 +02:00
Luke Wilde 1682b0b6d8 Kernel: Remove big lock from sys$set_coredump_metadata
The only requirement for this syscall is to make
Process::m_coredump_properties SpinlockProtected.
2022-04-09 21:51:16 +02:00
Jelle Raaijmakers cc411b328c Kernel: Remove big lock from sys$accept4
The only thing we needed to check is whether `socket.accept()` returns
a socket, and if not, we go back to blocking again.
2022-04-09 17:53:18 +02:00
Jelle Raaijmakers 14fc05e912 Kernel: Verify mutex big lock behavior
These two methods are big lock specific, so verify our mutex' behavior.
2022-04-09 15:55:20 +02:00
Jelle Raaijmakers bb02e9a7b9 Kernel: Unblock big lock waiters correctly
If the regular exclusive and shared lists were empty (which they
always should be for the big lock), we were not unblocking any waiters.
2022-04-09 15:55:20 +02:00
Linus Groh 62185452f0 Kernel: Query OS-enabled CPUID features again at the end of cpu_setup()
For OSPKE this is a no-op as we don't enable PKU yet, but the state of
the OSXSAVE flag might have changed if we enabled XSAVE.
2022-04-08 18:53:42 +01:00
Linus Groh 87aabb5ef7 Kernel: Rename OSPKU CPUID feature flag to OSPKE
Unlike "XSAVE enabled by OS" being indicated by the OSXSAVE flag, in
this case it's "PKU enabled by OS" being indicated by the OSPKE flag.
2022-04-08 18:53:42 +01:00
Tiaan Louw 678555af97 Kernel: Adjust includes after file reorganization 2022-04-08 15:06:33 +01:00
Jelle Raaijmakers 7826729ab2 Kernel: Track big lock blocked threads in separate list
When we lock a mutex, eventually `Thread::block` is invoked which could
in turn invoke `Process::big_lock().restore_exclusive_lock()`. This
would then try to add the current thread to a different blocked thread
list then the one in use for the original mutex being locked, and
because it's an intrusive list, the thread is removed from its original
list during the `.append()`. When the original mutex eventually
unblocks, we no longer have the thread in the intrusive blocked threads
list and we panic.

Solve this by making the big lock mutex special and giving it its own
blocked thread list. Because the process big lock is temporary and is
being actively removed from e.g. syscalls, it's a matter of time before
we can also remove the fix introduced by this commit.

Fixes issue #9401.
2022-04-06 18:27:19 +02:00
James Mintram d94c7fa417 Kernel: Improve the aarch64 kernel source files disk layout 2022-04-06 08:56:20 +01:00
Andreas Kling 9b9b05eabf Kernel: Make sys$mmap() round requested VM size to page size multiple
This fixes an issue where File::mmap() overrides would fail because they
were expecting to be called with a size evenly divisible by PAGE_SIZE.
2022-04-05 22:26:37 +02:00
Andreas Kling b28beb691e Kernel: Protect Mutex's thread lists with a spinlock 2022-04-05 14:44:50 +02:00
Andreas Kling 0a83c03546 Kernel: Don't unregister Region from RegionTree *before* unmapping it
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-05 13:46:50 +02:00
Andreas Kling a3db0ab14f Kernel: Remove MemoryManager::region_tree() accessor
Let's not have a way to grab at the RegionTree from outside of MM.
2022-04-05 13:45:10 +02:00
Andreas Kling f8d798b667 Kernel: Move allocate_unbacked_region_anywhere() to MemoryManager
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-05 13:45:10 +02:00
Andreas Kling e0da8da657 Kernel: Move create_identity_mapped_region() to MemoryManager
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-05 13:45:10 +02:00
Andreas Kling cfb61cbd54 Kernel: Add RegionTree::find_region_containing(address or range)
Let's encapsulate looking up regions so clients don't have to dig into
RegionTree internals.
2022-04-05 12:23:47 +02:00
Andreas Kling da7ea2556e Kernel: Add RegionTree::remove(Region&)
This allows clients to remove a region from the tree without reaching
into the RegionTree internals.
2022-04-05 11:57:53 +02:00
Andreas Kling f0f97e1db0 Kernel: Take the RegionTree spinlock when inspecting tree from outside
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-05 01:15:22 +02:00
Andreas Kling e3e1d79a7d Kernel: Remove unused ShouldDeallocateVirtualRange parameters
Since there is no separate virtual range allocator anymore, this is
no longer used for anything.
2022-04-05 01:15:22 +02:00
James Mintram df9a833d7a Kernel: Add VERIFY_NOT_REACHED to aarch64 PageDirectory.cpp 2022-04-04 14:35:54 -07:00
James Mintram 283d8e8f51 Kernel: Add VERIFY_NOT_REACHED to aarch64 locking functions 2022-04-04 14:35:54 -07:00
James Mintram e98ea8a977 Kernel: Add VERIFY_NOT_REACHED to the aarch64 handle_crash function 2022-04-04 14:35:54 -07:00
James Mintram d014c0501d Kernel: Remove unused dummy function from dummy.cpp 2022-04-04 14:35:54 -07:00
James Mintram bd7acd4b90 Kernel: Add VERIFY_NOT_REACHED to stub functions in aarch64 dummy.cpp 2022-04-04 14:35:54 -07:00
James Mintram 92a8383101 Kernel: Add VERIFY_NOT_REACHED to stub aarch64 Processor functions 2022-04-04 14:35:54 -07:00
James Mintram 463910df98 Kernel: Print out assertion info in __assertion_failed on aarch64 2022-04-04 22:25:33 +01:00
Andreas Kling 9bb45ab3a6 Kernel: Add debug logging to learn more about unexpected NP faults 2022-04-04 17:10:30 +02:00
Andreas Kling d1f2d63840 Kernel: Remove unused Region::try_create_kernel_only() 2022-04-04 12:34:13 +02:00
Andreas Kling 63ddbaf68a Kernel: Tweak broken dbgln_if() in sys$fork() after RegionTree changes 2022-04-04 11:05:49 +02:00
Andreas Kling 12b612ab14 Kernel: Mark sys$adjtime() as not needing the big lock
This syscall works on global kernel state and so doesn't need protection
from threads in the same process.
2022-04-04 00:42:18 +02:00
Andreas Kling 4306422f29 Kernel: Mark sys$clock_settime() as not needing the big log
This syscall ends up disabling interrupts while changing the time,
and the clock is a global resource anyway, so preventing threads in the
same process from running wouldn't solve anything.
2022-04-04 00:42:18 +02:00
Andreas Kling 55814f6e0e Kernel: Mark sys$sched_{set,get}param() as not needing the big lock
Both of these syscalls take the scheduler lock while accessing the
thread priority, so there's no reliance on the process big lock.
2022-04-04 00:42:18 +02:00
Andreas Kling 9250ac0c24 Kernel: Randomize non-specific VM allocations done by sys$execve()
Stuff like TLS regions, main thread stacks, etc. All deserve to be
randomized unless the ELF requires specific placement. :^)
2022-04-04 00:42:18 +02:00
Brian Gianforcaro 8b750998d2 Kernel: Fix aarch64 kernel build on case sensitive file systems
The dummy file has the wrong case, so it would fail to be found on case
sensitive file systems.
2022-04-03 15:18:36 -07:00
Idan Horowitz d6e4a25e0c Kernel: Use the InstrusiveRedBlackTree::begin_from(V&) API
This let's us skip an O(logn) tree traversal.
2022-04-04 00:16:11 +02:00
Idan Horowitz 30e6b313b4 Kernel: Remove false condition in RegionTree::allocate_range_specific
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-04 00:16:11 +02:00
James Mintram f943e97b76 Kernel: Add RegionTree and remove VirtualRangeAllocator from aarch64 2022-04-04 00:14:20 +02:00
Andreas Kling db75bab493 Kernel: Actually fix accidental overlaps in allocate_range_specific()
Thanks to Idan for spotting this! :^)
2022-04-03 23:58:57 +02:00
James Mintram 2b442ae44f Kernel: Add kmalloc.cpp to aarch64 2022-04-03 23:21:04 +02:00
Linus Groh b0f701d053 Kernel: Convert ProcessorInfo::build_brand_string() to StringBuilder 2022-04-03 23:20:33 +02:00
Linus Groh 33004f9b9d Kernel: Add hypervisor_vendor_id entry to /proc/cpuinfo 2022-04-03 23:20:33 +02:00
Linus Groh 0f27432ec6 Kernel+SystemMonitor+lscpu: Rename 'CPUID' -> 'Vendor ID'
This is what the Intel manual, as well as Linux's cpuinfo calls it.
2022-04-03 23:20:33 +02:00
Linus Groh 3f9c2495e5 Kernel: Remove EBX, ECX, and EDX values from hypervisor dmesgln() 2022-04-03 23:20:33 +02:00
Linus Groh 8d96525b9d Kernel: Move hypervisor vendor ID string to ProcessorInfo
This will make it possible to expose it in /proc/cpuinfo. :^)
2022-04-03 23:20:33 +02:00
Linus Groh f6181cd47e Kernel: Make ProcessorInfo::build_foo_string() private 2022-04-03 23:20:33 +02:00
Linus Groh afce63fffc Kernel: Move feature string building to ProcessorInfo
Other than a dmesgln(), ProcessorInfo is the only user of this function
and is already responsible for building other CPUID-related strings.
2022-04-03 23:20:33 +02:00
Linus Groh 53a95a5347 Kernel: Rename some ProcessorInfo members to match Intel manual
Let's use terminology from the the Intel manual to avoid confusion.
Also add `_string` suffixes to better distinguish the numeric values
from the string values.
2022-04-03 23:20:33 +02:00
Linus Groh ebe2cf8995 Kernel: Move private ProcessorInfo members to the end 2022-04-03 23:20:33 +02:00
Andreas Kling 9765f9f67e Kernel: Fix accidental overlaps in RegionTree::allocate_range_specific()
Thanks to Idan for spotting this! :^)
2022-04-03 23:07:29 +02:00
Andreas Kling 36d829b97c Kernel: Mark sys$listen() as not needing the big lock
This syscall already performs the necessary locking and so doesn't
need to rely on the process big lock.
2022-04-03 22:22:22 +02:00
Andreas Kling e103c5fe2d Kernel: Don't hog file descriptor table lock in sys$bind()
We don't need to hold the lock across the entire syscall. Once we've
fetched the open file description we're interested in, we can let go.
2022-04-03 22:20:34 +02:00
Andreas Kling 85ceab1fec Kernel: Don't hog file descriptor table lock in sys$listen()
We don't need to hold the lock across the entire syscall. Once we've
fetched the open file description we're interested in, we can let go.
2022-04-03 22:18:57 +02:00
Andreas Kling bc4282c773 Kernel: Mark sys$sendfd() and sys$recvfd() as not needing the big lock
These syscalls already perform the necessary locking and don't rely on
the process big lock.
2022-04-03 22:06:03 +02:00
Andreas Kling 92dfcdb6b1 Kenrel: Update a dmesgln() to say "RegionTree" instead of old class name 2022-04-03 22:00:19 +02:00
Andreas Kling 9e1da1f4f5 Kernel: Add a little explainer comment above RegionTree 2022-04-03 21:59:48 +02:00
Andreas Kling 8b01789ec4 Kernel: Improve RegionTree's internal helper function names
It's a bit nicer if functions that allocate ranges have some kind of
name that includes both "allocate" and "range". :^)
2022-04-03 21:56:16 +02:00
Andreas Kling 32dea6bde5 Kernel: Add missing include to PageDirectory.h 2022-04-03 21:51:58 +02:00
Andreas Kling 858b196c59 Kernel: Unbreak ASLR in the new RegionTree world
Functions that allocate and/or place a Region now take a parameter
that tells it whether to randomize unspecified addresses.
2022-04-03 21:51:58 +02:00
Andreas Kling e89c9ed2ca Kernel: Stop exposing RegionTree API for VM range allocation
...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-03 21:51:58 +02:00
Andreas Kling 07f3d09c55 Kernel: Make VM allocation atomic for userspace regions
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-03 21:51:58 +02:00
Andreas Kling e852a69a06 LibWeb: Make VM allocation atomic for kernel regions
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-03 21:51:58 +02:00
Andreas Kling cbf52d474c Kernel: Remove now-unused VirtualRangeAllocator
This has been replaced with the allocation-free RegionTree. :^)
2022-04-03 21:51:58 +02:00
Andreas Kling e8f543c390 Kernel: Use intrusive RegionTree solution for kernel regions as well
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-03 21:51:58 +02:00
Andreas Kling ffe2e77eba Kernel: Add Memory::RegionTree to share code between AddressSpace and MM
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-03 21:51:58 +02:00
Andreas Kling 02a95a196f Kernel: Use AddressSpace region tree for range allocation
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-03 21:51:58 +02:00
Andreas Kling 2617adac52 Kernel: Store AddressSpace memory regions in an IntrusiveRedBlackTree
This means we never need to allocate when inserting/removing regions
from the address space.
2022-04-03 21:51:58 +02:00
Tim Schumacher 4ba39c8d63 Kernel: Implement f_basetype in statvfs 2022-04-03 19:15:14 +02:00
James Mintram 9186ed3101 Kernel: Add all memory files to aarch64 and fix resulting linker errors 2022-04-02 19:34:20 -07:00
James Mintram 2e63215346 Kernel: Re-add AK files to aarch64 2022-04-02 19:34:20 -07:00
James Mintram d79c772c87 Kernel: Make MemoryManager compile on aarch64 2022-04-02 19:34:20 -07:00
James Mintram 6299a69253 Kernel: Make handle_crash available to aarch64 2022-04-02 19:34:20 -07:00
James Mintram d3b6201b40 Kernel: Make PageDirectory.cpp compile on aarch64 2022-04-02 19:34:20 -07:00
James Mintram 783a44b18e Kernel: Make PhysicalRegion.cpp compile on aarch64 2022-04-02 19:34:20 -07:00
James Mintram 0d7eee625f Kernel: Make AddressSpace.cpp compile on aarch64 2022-04-02 19:34:20 -07:00
James Mintram 627fd231d5 Kernel: Make Region.cpp compile on aarch64 2022-04-02 19:34:20 -07:00
James Mintram a883079b29 Kernel: Add missing new/delete and kcalloc to dummy.cpp 2022-04-02 19:34:20 -07:00