Commit graph

5110 commits

Author SHA1 Message Date
Andreas Kling 5217875f6a Kernel: Consolidate API for creating AnonymousVMObject with given pages
We don't need to have a dedicated API for creating a VMObject with a
single page, the multi-page API option works in all cases.

Also make the API take a Span<NonnullRefPtr<PhysicalPage>> instead of
a NonnullRefPtrVector<PhysicalPage>.
2021-07-22 09:17:02 +02:00
Andreas Kling 9e15708aa0 Kernel: Convert VMObject & subclasses to east-const style 2021-07-22 09:17:02 +02:00
Gunnar Beutner eaad94751c Kernel: Fix incorrect format template 2021-07-22 08:57:01 +02:00
Gunnar Beutner b4272d731f Kernel: Make sure crash dumps are properly aligned on x86_64 2021-07-22 08:57:01 +02:00
Gunnar Beutner 36e36507d5 Everywhere: Prefer using {:#x} over 0x{:x}
We have a dedicated format specifier which adds the "0x" prefix, so
let's use that instead of adding it manually.
2021-07-22 08:57:01 +02:00
Gunnar Beutner 31f30e732a Everywhere: Prefix hexadecimal numbers with 0x
Depending on the values it might be difficult to figure out whether a
value is decimal or hexadecimal. So let's make this more obvious. Also
this allows copying and pasting those numbers into GNOME calculator and
probably also other apps which auto-detect the base.
2021-07-22 08:57:01 +02:00
Andreas Kling f9b7ea6de9 Revert "Kernel: Use IntrusiveList for keeping track of InodeWatchers"
This reverts commit 43d6a7e74e.

This breaks multi-inode watchers.
2021-07-21 21:24:26 +02:00
Andreas Kling 79745507a9 Kernel: Use IntrusiveList for keeping track of GenericInterruptHandlers 2021-07-21 20:21:29 +02:00
Andreas Kling a9f76b8270 Kernel: Remove Inode's inheritance from Weakable
Nobody was using WeakPtr<Inode> anywhere, so there's no need for this
to inherit from Weakable.
2021-07-21 20:17:55 +02:00
Andreas Kling 43d6a7e74e Kernel: Use IntrusiveList for keeping track of InodeWatchers 2021-07-21 20:17:55 +02:00
Tom 5ae42736f8 Kernel: VirtIO framebuffer should clamp pending dirty rects if needed
If we change to a resolution smaller than what any pending dirty
rectangles contain, we need to clamp them to the new resolution.
2021-07-21 00:06:58 +02:00
Andreas Kling f85b94e6d4 Kernel: Remove KBufferBuilder's can_expand restriction
KBufferBuilder is always allowed to expand if it wants to. This
restriction was added a long time ago when it was unsafe to allocate
VM while generating ProcFS contents.
2021-07-20 18:05:05 +02:00
Andreas Kling fef835de7f Kernel: Remove KBufferBuilder API for reusing an existing buffer
This is not used anywhere anymore anyway.
2021-07-20 18:05:05 +02:00
Andreas Kling a3063dfd33 Kernel: Simplify ProcFS generated buffer caching
Use a Mutex instead of a SpinLock to protect the per-FileDescription
generated data cache. This allows processes to go to sleep while
waiting their turn.

Also don't try to be clever by reusing existing cache buffers.
Just allocate KBuffers as needed (and make sure to surface failures.)
2021-07-20 18:05:05 +02:00
Andreas Kling 4d2473b7fa Kernel: Remove confused comment in KBufferBuilder::appendff()
KBufferBuilder exists for code that wants to build a KBuffer instead
of a String. KBuffer is backed by anonymous VM, while String is backed
by a kernel heap allocation.
2021-07-20 18:05:05 +02:00
Peter Elliott 3fa2816642 Kernel+LibC: Implement fcntl(2) advisory locks
Advisory locks don't actually prevent other processes from writing to
the file, but they do prevent other processes looking to acquire and
advisory lock on the file.

This implementation currently only adds non-blocking locks, which are
all I need for now.
2021-07-20 17:44:30 +04:30
Gunnar Beutner 4fdee56ba3 Prekernel: Make sure to reload CR3 after modifying the page tables 2021-07-20 15:12:19 +02:00
Gunnar Beutner 05fc75f994 Prekernel: Don't wrap around the PTE index improperly
The boot_pd0_pts variable contains more than 512 PTEs so we shouldn't
wrap the index here.
2021-07-20 15:12:19 +02:00
Gunnar Beutner d29981e4a1 Prekernel: Properly initialize variables 2021-07-20 15:12:19 +02:00
Gunnar Beutner ac1455d3ba Kernel: Specify protection flags for ELF load headers
These are currently unused by the prekernel and ld used the same flags
by default - except for the .ksyms section which was marked as
read-write.
2021-07-20 15:12:19 +02:00
Gunnar Beutner 2019cf3289 Kernel: Use the C preprocessor to avoid two copies of the linker script 2021-07-20 15:12:19 +02:00
Gunnar Beutner 56f952a5f2 Prekernel: Don't assume that PT_LOAD headers are ordered by address
These headers are ordered by virtual address - at least with GCC - but
that might not always be the case.
2021-07-20 15:12:19 +02:00
Gunnar Beutner 5188185374 Kernel: Rename .boot_bss to .super_pages to better reflect what it is
This also removes the section attribute for kernel_base which had no
effect because the section wasn't included in the linker script.
2021-07-20 15:12:19 +02:00
Gunnar Beutner be795d5812 Prekernel: Use physical addresses for some of the BootInfo parameters
The kernel would just turn those virtual addresses into physical
addresses later on, so let's just use physical addresses right from the
start.
2021-07-20 15:12:19 +02:00
Gunnar Beutner dd42093b93 Kernel: Move boot info declarations to a header file
Instead of manually redeclaring those variables in various files this
now adds a header file for them.
2021-07-20 15:12:19 +02:00
Gunnar Beutner b4600f2996 Kernel: Initialize serial debug after setting kernel command-line 2021-07-20 11:38:45 +01:00
Brian Gianforcaro 8f01a8b741 Kernel: Disable big process lock for sys$yield() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro 5c10fb4007 Kernel: Disable big process lock for sys$gettid()
This syscall reads a read only value from the current thread, and hence
has no need for the big process lock.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro 638598b15d Kernel: Disable big process lock for sys$getpid() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro bfd4635274 Kernel: Disable big process lock for sys$uname() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro 10ce896d4f Kernel: Disable big process lock in sys$gethostname() sys$sethostname() 2021-07-20 03:21:14 +02:00
Brian Gianforcaro 9201a06027 Kernel: Annotate all syscalls with VERIFY_PROCESS_BIG_LOCK_ACQUIRED
Before we start disabling acquisition of the big process lock for
specific syscalls, make sure to document and assert that all the
lock is held during all syscalls.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro 120b9bc05b Kernel: Conditionally acquire the big lock based on syscall metadata 2021-07-20 03:21:14 +02:00
Brian Gianforcaro bb1fa019de Kernel: Allow MutexLocker to be conditionally initialized
There are cases where we want to conditionally take a lock, but still
would like to use an RAII type to make sure we don't leak the lock.

This was previously impossible to do with `MutexLocker` due to it's
design. This commit tweaks the design to allow the object to be
initialized to an "empty" state without a lock associated, so it does
nothing, and then later a lock can be "attached" to the locker.

I realized that the get_lock() API's where also unused, and would no
longer make sense for empty locks, so they were removed.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro 354e18a5a0 Kernel: Move validate_syscall_preconditions outside of the big lock
Now that we hold the space lock for the duration of the validation
it should be safe to move the validation outside the big lock.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro 85e95105c6 Kernel: Mark read only RegisterState function parameters as const 2021-07-20 03:21:14 +02:00
Brian Gianforcaro 27e1120dff Kernel: Move syscall precondition validates to MM
Move these to MM to simplify the flow of the syscall handler.

While here, also make sure we hold the process space lock for
the duration of the validation to avoid potential issues where
another thread attempts to modify the process space during the
validation. This will allow us to move the validation out of the
big process lock scope in a future change.

Additionally utilize the new no_lock variants of functions to avoid
unnecessary recursive process space spinlock acquisitions.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro af543328ea Kernel: Instrument syscalls with their process big lock requirements
Currently all syscalls run under the Process:m_big_lock, which is an
obvious bottleneck. Long term we would like to remove the big lock and
replace it with the required fine grained locking.

To facilitate this goal we need a way of gradually decomposing the big
lock into the all of the required fine grained locks. This commit
introduces instrumentation to the syscall table, allowing the big lock
requirement to be toggled on/off per syscall.

Eventually when we are finished, no syscall will required the big lock,
and we'll be able to remove all of this instrumentation.
2021-07-20 03:21:14 +02:00
Brian Gianforcaro 308396bca1 Kernel: No lock validate_user_stack variant, switch to Space as argument
The entire process is not needed, just require the user to pass in the
Space. Also provide no_lock variant to use when you already have the
VM/Space lock acquired, to avoid unnecessary recursive spinlock
acquisitions.
2021-07-20 03:21:14 +02:00
Gunnar Beutner 69fd68b1c8 Prekernel: Make sure we're not overwriting the ELF header
This copies the ELF header because we might end up overwriting when
loading the ELF sections.
2021-07-20 01:50:55 +02:00
ls 222b97488a VirtualFileSystem: Check for '.' '..' and empty filenames
This commit adds a check, to prevent empty dot or dot-dot filenames when
renaming a file and returns EINVAL in that case.
2021-07-19 18:20:34 +02:00
Gunnar Beutner 3678f78bfb Prekernel: Make sure the last few bytes of the kernel image are mapped
Depending on the exact layout of the .ksyms section the kernel would
fail to boot because the kernel_load_end variable didn't account for the
section's size.
2021-07-19 17:47:54 +02:00
Gunnar Beutner 675de847f7 Kernel: Remove obsolete code 2021-07-19 11:29:09 +02:00
Gunnar Beutner b6ddb4b70f Kernel: Simplify the linker script for the prekernel 2021-07-19 11:29:09 +02:00
Gunnar Beutner a364f5c7b7 Kernel: Make sure super pages are in the first 16MiB of physical memory
This was broken by recent changes.
2021-07-19 11:29:09 +02:00
Brian Gianforcaro 121e7626d0 Kernel: Rename PerformanceEvent methods to be more ARCH independent 2021-07-19 08:46:55 +02:00
Brian Gianforcaro 1cffecbe8d Kernel: Push ARCH specific ifdef's down into RegisterState functions
The non CPU specific code of the kernel shouldn't need to deal with
architecture specific registers, and should instead deal with an
abstract view of the machine. This allows us to remove a variety of
architecture specific ifdefs and helps keep the code slightly more
portable.

We do this by exposing the abstract representation of instruction
pointer, stack pointer, base pointer, return register, etc on the
RegisterState struct.
2021-07-19 08:46:55 +02:00
Andreas Kling e49af4bac9 Kernel/E1000: Consolidate RX and TX buffer regions
Allocate all the RX buffers in one big memory region (and same for TX.)
This removes 38 lines from every crash dump (and just seems like a
reasonable idea in general.)
2021-07-19 02:16:24 +02:00
Tom 668de76fa7 Kernel: Don't truncate physical address in ACPI table to 32 bits
We need to cast physical addresses to PhysicalPtr instead of FlatPtr,
which is currently always 64 bits. However, if one day we were to
support 32 bit non-pae mode then it would also truncate appropriately.
2021-07-18 22:09:05 +02:00
Tom a635ff4e60 Everywhere: Make tracking cpu usage independent from system ticks
This switches tracking CPU usage to more accurately measure time in
user and kernel land using either the TSC or another time source.
This will also come in handy when implementing a tickless kernel mode.
2021-07-18 22:08:26 +02:00