Commit graph

4487 commits

Author SHA1 Message Date
Liav A 5e81464245 Kernel/Commandline: Allow the user to specify an embedded string
This is by default left empty, so people won't run the kernel in a mode
which they didn't want to. The embedded string will override the
supplied commandline from the bootloader, which is good for debugging
sessions.

This change seemed important for me, because I debug the kernel on bare
metal with iPXE, and every change to the commandline meant that I needed
rewrite a new iPXE USB image with a modified iPXE script.
2021-05-21 22:38:26 +01:00
Liav A b8f0a9c974 Kernel/CPU: Fix awkward printing early on boot
This usage of the word "installing" seemed for me for a long time as
a wrong thing, so let's make it better now.
2021-05-21 22:38:26 +01:00
Liav A df84fdfd2c Kernel: Print commandline after initializing it 2021-05-21 22:38:26 +01:00
Liav A e9ef3b59d8 Kernel/VirtualConsole: Fix grammar error in comment 2021-05-21 22:38:26 +01:00
Gunnar Beutner 7cd49ba2a2 Kernel: Ignore interfaces without an IP address when routing packages
Let's not route packages through interfaces which don't have an address
yet unless we're explicitly asked to (e.g. by DHCPClient).
2021-05-21 21:55:52 +02:00
Gunnar Beutner eb1cecc03d Kernel: Make sure network adapters have unique names
Previously we'd just slap 0 onto the adapter's basename. This ensures
we actually end up with unique names.
2021-05-21 21:55:52 +02:00
Liav A 07474b4349 Kernel/PCI: Fix support of multiple PCI host controllers enumeration
First scan PCI bus 0. Find any device on that bus, and if it's a
PCI-to-PCI bridge, recursively scan it too.

Then try to handle Multiple PCI host bridges on slot 0, device 0.
If we happen to miss some PCI buses because they are not reachable
through recursive PCI-to-PCI bridges scanning starting from bus 0, we
might find them in this scanning.
2021-05-21 17:58:53 +01:00
Liav A c6ffee7f18 Kernel/Graphics: Indicate initialization failed if no device was found 2021-05-21 17:58:53 +01:00
Brian Gianforcaro 3d7cc471d6 Revert "Kernel: Avoid allocating under spinlock in ProcessGroup::find_or_create"
This reverts commit e95eb7a51d.

This is causing some sort of list corruption, as evident by #7313
I haven't been able to figure it out yet, so lets revert this change
until I can figure out what's going on.
2021-05-21 12:36:20 +02:00
Brian Gianforcaro 124a523199 Revert "Kernel: Fix regression, removing a ProcessGroup that not in the list"
This reverts commit bbe315d8c0.

This is un-needed when reverting the parent commit.
2021-05-21 12:36:20 +02:00
Liav A 09d09b79b6 Kernel: Fix type, dectivate_writes => deactivate_writes 2021-05-21 08:08:33 +02:00
Liav A db268efa69 Kernel/Graphics: Choose VMObject considering enabled state when mmaping
When mmaping a Framebuffer from userspace, we need to check whether the
framebuffer device is actually enabled (e.g. graphical mode is being
used) or a textual VirtualConsole is active.

Considering the above state, we mmap the right VMObject to ensure we
don't have graphical artifacts if we change the resolution from
DisplaySettings, changed to textual mode and after the resolution change
was reverted, we will see the Desktop reappearing even though we are
still in textual mode.
2021-05-21 08:08:33 +02:00
Liav A 87f8f892d8 Kernel: Fix framebuffer resolution modesetting after boot
If we tried to change the resolution before of this patch, we triggered
a kernel crash due to mmaping the framebuffer device again.
Therefore, on mmaping of the framebuffer device, we create an entire new
set of VMObjects and Regions for the new settings.

Then, when we change the resolution, the framebuffersconsole needs to be
updated with the new resolution and also to be refreshed with the new
settings. To ensure we handle both shrinking of the resolution and
growth of it, we only copy the right amount of available data from the
cells Region.
2021-05-21 08:08:33 +02:00
Liav A 5f718c6b05 Kernel/TTY: Don't flush dirty lines if VirtualConsole is not active 2021-05-21 08:08:33 +02:00
Liav A 38ccdb02ce Kernel: Process request to change virtual console from the IO Work queue
Instead of processing the input after receiving an IRQ, we shift the
responsibility to the io work queue to handle this for us, so if a page
fault occurs when trying to switch the VirtualConsole, the kernel can
handle that.
2021-05-21 08:08:33 +02:00
Tom 9dcc7a67e5 Kernel: Close a Thread tid lookup race
There is a window between dropping a thread's last reference and it
being removed from the list.

Found in #5541
2021-05-20 22:08:36 +02:00
Idan Horowitz df7d938808 Kernel: Stop allocating the PS2KeyboardDevice in the eternal heap
The PS2KeyboardDevice can be free'd in try_to_initialize if the
initialization failed, resulting in an assertion.
2021-05-20 18:40:02 +02:00
Ali Mohammad Pur c6b12841ee Meta: Make generate_state_machine() generate a proper target
And use GENERATED_SOURCES (or add_dependencies) to make LibVT depend on
that target.
Fixes a FIXME.
2021-05-20 12:11:27 +01:00
Brian Gianforcaro bbe315d8c0 Kernel: Fix regression, removing a ProcessGroup that not in the list
I introduced this bug in e95eb7a51, where it's possible that the
ProcessGroup is created, but we never add it to the list. Make sure we
check that we are in the list before removal. This only broke booting in
self-test mode oddly enough.

Reported-By: Andrew Kaster <andrewdkaster@gmail.com>
2021-05-20 09:41:52 +02:00
Gunnar Beutner 8495d6aeca Kernel: Use the Function class for smp_broadcast()/smp_unicast()
This avoids allocations for smp_broadcast() and smp_unicast() by
using the Function class.
2021-05-20 09:09:10 +02:00
Gunnar Beutner cac7a8ced9 Kernel: Use the Function class for deferred_call_queue()
This avoids allocations for deferred_call_queue().
2021-05-20 09:09:10 +02:00
Gunnar Beutner 7557f2db90 Kernel: Remove an allocation when blocking a thread
When blocking a thread with a timeout we would previously allocate
a Timer object. This removes the allocation for that Timer object.
2021-05-20 09:09:10 +02:00
Brian Gianforcaro e95eb7a51d Kernel: Avoid allocating under spinlock in ProcessGroup::find_or_create
Avoid allocating while holding the g_process_groups_lock spinlock, it's
a pattern that has a negative effect on performance and scalability,
especially given that it is a global lock, reachable by all processes.
2021-05-20 08:10:07 +02:00
Brian Gianforcaro bb91bed576 Kernel: Make ProcessGroup::find_or_create API OOM safe
Make ProcessGroup::find_or_create & ProcessGroup::create OOM safe, by
moving to adopt_ref_if_nonnull.
2021-05-20 08:10:07 +02:00
Brian Gianforcaro 7540f4268b Kernel: Remove s_processor_lock by making s_processors statically sized
Currently in SMP mode we hard code support for up to only 8 processors.
There is no reason for this to be a dynamic allocation that needs to be
guarded by a spinlock. Instead use a Array<T* with inline storage of 8,
allowing each processor to initialize it self in place, avoiding all
the need for locks.
2021-05-20 08:10:07 +02:00
Brian Gianforcaro 1415b2cfc3 Kernel: Do not allocate AnonymousVMObject's under spin lock
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-05-20 08:10:07 +02:00
Brian Gianforcaro 83fc591cea Kernel: Generate page fault events from the kernel profiler
Hook the kernel page fault handler and capture page fault events when
the fault has a current thread attached in TLS. We capture the eip and
ebp so we can unwind the stack and locate which pieces of code are
generating the most page faults.

Co-authored-by: Gunnar Beutner <gbeutner@serenityos.org>
2021-05-19 22:51:42 +02:00
Gunnar Beutner 7dc77bd833 Kernel: Avoid an allocation in sys$poll 2021-05-19 22:51:42 +02:00
Gunnar Beutner 277f333b2b Kernel: Add support for profiling kmalloc()/kfree() 2021-05-19 22:51:42 +02:00
Gunnar Beutner 572bbf28cc Kernel+LibC: Add support for filtering profiling events
This adds the -t command-line argument for the profile tool. Using this
argument you can filter which event types you want in your profile.
2021-05-19 22:51:42 +02:00
Gunnar Beutner 8b2ace0326 Kernel: Track performance events for context switches 2021-05-19 22:51:42 +02:00
Lenny Maiorani 5751327195 Kernel: static vs non-static constexpr variables
Problem:
- `static` variables consume memory and sometimes are less
  optimizable.
- `static const` variables can be `constexpr`, usually.
- `static` function-local variables require an initialization check
  every time the function is run.

Solution:
- If a global `static` variable is only used in a single function then
  move it into the function and make it non-`static` and `constexpr`.
- Make all global `static` variables `constexpr` instead of `const`.
- Change function-local `static const[expr]` variables to be just
  `constexpr`.
2021-05-19 21:21:47 +01:00
Gunnar Beutner e9898a6031 Kernel: Use plain Function objects for the WorkQueue
The WorkQueue class previously had its own inline storage functionality
for function pointers. With the recent changes to the Function class
this is no longer necessary.
2021-05-19 21:36:57 +02:00
Justin 1c3badede3 Kernel: Add statvfs & fstatvfs Syscalls
These syscalls fill a statvfs struct with various data
about the mount on the VFS.
2021-05-19 21:33:29 +02:00
Justin 721a867c65 Kernel: Expose FileSystem's fragment size
This commit will add a fragment_size() function similar to the
block_size() function.
2021-05-19 21:33:29 +02:00
Max Wipfli 9cc201fb29 Kernel: Ignore null parent custody without error in VFS::open
This modifies the error checks in VFS::open after the call to
resolve_path to ignore a null parent custody if there is no error, as
this is expected when the path to resolve points to "/". Rather, a null
parent custody only constitutes an error if it is accompanied by ENOENT.
This behavior is documented in the VFS::resolve_path_without_veil
method.

To accompany this change, the order of the error checks have been
changed to more naturally fit the new logic.
2021-05-19 12:27:25 +02:00
Hendiadyoin1 ef425a02f7 Kernel: Implement mprotect for multiple Regions 2021-05-18 16:50:52 +02:00
Sahan Fernando 63a1be1406 Kernel: Don't update write_pos in DoubleBuffer if userspace copy fails 2021-05-18 16:47:26 +02:00
Sahan Fernando c3b670c092 Kernel: Acknowledge partial writes from TTYs
Fixes a bug where TTY::write will attempt to write into the underlying
device but will not acknowledge the result of that write, instead
assuming that the write fully completed.
2021-05-18 16:47:26 +02:00
Sahan Fernando d0f314b23c Kernel: Fix subtle race condition in sys$write implementation
There is a slight race condition in our implementation of write().
We call File::can_write() before attempting to write to it (blocking if
it returns false). If it returns true, we assume that we can write to
the file, and our code assumes that File::write() cannot possibly fail
by being blocked. There is, however, the rare case where another process
writes to the file and prevents further writes in between the call to
Files::can_write() and File::write() in the first process. This would
result in the first process calling File::write() when it cannot be
written to.

We fix this by adding a mechanism for File::can_write() to signal that
it was blocked, making it the responsibilty of File::write() to check
whether it can write and then finally making sys$write() check if the
write failed due to it being blocked.
2021-05-18 16:33:15 +02:00
Idan Horowitz 208cfcb0a5 Kernel: Add support for multiple serial ports per device
This commit adds support for initializing multiple serial ports per
PCI board, as well as initializing multiple different pci serial boards

Currently we just choose the first PCI serial port seen as the debug
port, but this should probably be made configurable some how in the
future.
2021-05-18 16:31:39 +02:00
Gunnar Beutner 093818de62 Kernel: Avoid allocations when receiving network packets
This avoids two allocations when receiving network packets. One for
inserting a PacketWithTimestamp into m_packet_queue and another one
when inserting buffers into the list of unused packet buffers.

With this fixed the only allocations in NetworkTask happen when
initially allocating the PacketWithTimestamp structs and when switching
contexts.
2021-05-18 16:06:27 +02:00
Lenny Maiorani ebb1d9740e BitmapView: Disable mutations of the underlying Bitmap
Problem:
- `BitmapView` permits changing the underlying `Bitmap`. This violates
  the idea of a "view" since views are simply overlays which can
  themselves change but do not change the underlying data.

Solution:
- Migrate all non-`const` member functions to Bitmap.
2021-05-18 08:10:45 +02:00
Gunnar Beutner 3cafdca868 Kernel: Disable profile timer when the process exits
When profiling a single process we didn't disable the profile timer.
enable_profile_timer()/disable_profiler_timer() support nested calls
so no special care has to be taken here to only disable the timer when
nobody else is using it.
2021-05-17 21:53:04 +02:00
Gunnar Beutner 52a4a1ec75 Kernel: Fix return value for {enable,disable}_profile_timer()
These functions should return success when being called when profiling
has been requested from multiple callers because enabling/disabling the
timer is a no-op in that case and thus didn't fail.
2021-05-17 21:53:04 +02:00
Idan Horowitz 79d3910145 Kernel: Stop overriding built-in serial port with PCI serial port
On a second thought, theres nothing stopping us from allowing poeple to
use both if they want to :^)
2021-05-17 19:45:35 +01:00
Idan Horowitz 51e9fdebea Kernel: Add support for QEMU's emulated pci serial (-pci-serial option) 2021-05-17 19:45:35 +01:00
Andreas Kling a15c7b7944 Build: Stop using precompiled headers (PCH)
This had very bad interactions with ccache, often leading to rebuilds
with 100% cache misses, etc. Ali says it wasn't that big of a speedup
in the end anyway, so let's not bother with it.

We can always bring it back in the future if it seems like a good idea.
2021-05-17 19:30:12 +02:00
Idan Horowitz a5603c35df Kernel: Fix spelling mistake in HPETComparator::try_to_set_frequency 2021-05-17 19:29:55 +02:00
Idan Horowitz 0ac3317764 Kernel: Set InterruptEnable on HPET Comparators when frequency is set
This fixes non-periodic comparators not receiving interrupts, as we
were never setting the InterruptEnable bit in their capabilities
register (unlike periodic comparators's bit, which was set as a side
effect of calling set_periodic on them to set their periodic bit).

This should help getting profiling work on bare-metal SerenityOS
installations, which were not guaranteed to have 2 periodic
comparators available.
2021-05-17 19:29:55 +02:00