Commit Graph

3991 Commits

Author SHA1 Message Date
Liav A
c4463cb5df Kernel: Add basic AHCI functionality
The hierarchy is AHCIController, AHCIPortHandler, AHCIPort and
SATADiskDevice. Each AHCIController has at least one AHCIPortHandler.

An AHCIPortHandler is an interrupt handler that takes care of
enumeration of handled AHCI ports when an interrupt occurs. Each
AHCIPort takes care of one SATADiskDevice, and later on we can add
support for Port multiplier.

When we implement support of Message signalled interrupts, we can spawn
many AHCIPortHandlers, and allow each one of them to be responsible for
a set of AHCIPorts.
2021-03-05 11:29:34 +01:00
Liav A
b59e45e65c Kernel: Use global mechanism to determine minor number of Storage Device 2021-03-05 11:29:34 +01:00
Liav A
566c10b8b8 Kernel: Make ATA macros to be public 2021-03-05 11:29:34 +01:00
Liav A
0e9a2345f9 Kernel: Add enum values for later implementation of AHCI 2021-03-05 11:29:34 +01:00
Liav A
4f32dc2043 Kernel: Add Declaration of IDEChannel class in PATADiskDevice.h 2021-03-05 11:29:34 +01:00
Andreas Kling
50632af4de Kernel: Define a KERNEL_VIRTUAL_BASE in the linker script
Slightly nicer than saying "0xc0000000" over and over.
2021-03-04 18:25:01 +01:00
Andreas Kling
adb2e6be5f Kernel: Make the kernel compile & link for x86_64
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-04 18:25:01 +01:00
Andreas Kling
aae91dda66 Kernel: Remove repeated_{in,out}16()
These were some wrappers around x86 "insw/outsw" that are no longer
used for anything, so let's remove them.
2021-03-04 18:25:01 +01:00
Andreas Kling
2871df6f0d Kernel: Stop trying to keep InodeVMObject in sync with disk changes
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-04 15:42:51 +01:00
Andreas Kling
38c8dc22cf Kernel: Remove unused KMALLOC_DEBUG_LARGE_ALLOCATIONS mode
This was a thing back when the system was so little that any kernel
allocation above 1 MiB was basically guaranteed to be a bug. :^)
2021-03-04 11:25:45 +01:00
Andreas Kling
1208fc7d37 AK: Simplify Bitmap and implement in terms of BitmapView
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-04 11:25:45 +01:00
Andreas Kling
a1d1a3b50b Kernel: Use BitmapView instead of Bitmap::wrap() 2021-03-04 11:25:45 +01:00
William McPherson
2479ead718 Everywhere: Remove unnecessary clang-format offs
Mostly due to the fact that clang-format allows aligned comments via
AlignTrailingComments.

We could also use raw string literals in inline asm, which clang-format
deals with properly (and would be nicer in a lot of places).
2021-03-04 11:01:48 +01:00
Andreas Kling
4515652001 Kernel: Remove 1 level of indirection for AnonymousVMObject CoW bitmaps
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-04 10:11:37 +01:00
Brendan Coles
953f4f7e60 Kernel: Create /dev/full with mode 0666 2021-03-04 09:19:38 +01:00
Linus Groh
a5d6962148 AK+Kernel: Remove NO_DISCARD macro hack
This was added as clang-format would mess up the formatting when using
[[nodiscard]] on a class, which is no longer the case.
2021-03-03 23:08:42 +01:00
Andreas Kling
a819eb5016 Kernel: Skip TLB flushes while cloning regions in sys$fork()
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-03-03 22:57:45 +01:00
Andreas Kling
d96a44a738 Kernel: Avoid transient kmalloc heap allocations in sys$select()
Dynamic Vector allocations in sys$select() were showing up in the
full-system profile and since there will never be more than FD_SETSIZE
file descriptors to worry about, we can confidently add enough inline
capacity to this Vector that it never has to kmalloc.

To compensate for the increased stack usage, reduce the size of the
FDInfo struct while we're here. :^)
2021-03-03 20:37:23 +01:00
Marco
9b27b0cd1a Kernel: init: Make comment clearer 2021-03-03 14:18:43 +01:00
Brian Gianforcaro
afe099388e Kernel: Add 'boot_prof' option to enable full system profiling on boot
The full system profiling functionality is useful for profiling the
boot performance of the system. Add a new kernel boot option to start
the system with profiling enabled. This lets you disable and view a
profile once the system is booted.

You can use it by running:
```
$ run.sh qcmd boot_prof
```
2021-03-03 11:05:16 +01:00
Brian Gianforcaro
0f424afd5a Kernel: Mark more of the kernel initialization as UNMAP_AFTER_INIT 2021-03-03 11:05:16 +01:00
Brian Gianforcaro
84a399de5d Kernel: Move Kernel CommandLine parsing to strongly typed API.
Previously all of the CommandLine parsing was spread out around the
Kernel. Instead move it all into the Kernel CommandLine class, and
expose a strongly typed API for querying the state of options.
2021-03-03 11:05:16 +01:00
Nick Johnson
74881ac649
Kernel: Make InstructionFetch PageFault flags match up (#5608)
Previously, the instruction fetch flag of the page fault handler
did not have the currect binary representation, and would always
return false. This aligns these flags.
2021-03-03 11:04:51 +01:00
Ben Wiederhake
add94aebfa Kernel: Don't trust user-supplied bool in sys$stat
Found by fuzz-syscalls. Can be reproduced by running this in the Shell:
    $ syscall stat [ Desktop 7 buf 2 ]

Fixes #5316.
2021-03-03 11:03:03 +01:00
Andreas Kling
5e7abea31e Kernel+Profiler: Capture metadata about all profiled processes
The perfcore file format was previously limited to a single process
since the pid/executable/regions data was top-level in the JSON.

This patch moves the process-specific data into a top-level array
named "processes" and we now add entries for each process that has
been sampled during the profile run.

This makes it possible to see samples from multiple threads when
viewing a perfcore file with Profiler. This is extremely cool! :^)
2021-03-02 22:38:06 +01:00
Andreas Kling
ea500dd3e3 Kernel: Start work on full system profiling :^)
The superuser can now call sys$profiling_enable() with PID -1 to enable
profiling of all running threads in the system. The perf events are
collected in a global PerformanceEventBuffer (currently 32 MiB in size.)

The events can be accessed via /proc/profile
2021-03-02 22:38:06 +01:00
Andreas Kling
b425c2602c Kernel: Better handling of allocation failure in profiling
If we can't allocate a PerformanceEventBuffer to store the profiling
events, we now fail sys$profiling_enable() and sys$perf_event()
with ENOMEM instead of carrying on with a broken buffer.
2021-03-02 22:38:06 +01:00
Ashleigh Newman-Jones
f0912027ff Kernel: Enable AVX flags if supported by cpu
This enables AVX and its dependency CR4.OSXSAVE when both are available on the cpu.
2021-03-02 16:35:06 +01:00
Andreas Kling
dce030eefc Kernel: Use RDTSC instead of get_fast_random() for syscall stack noise
This was the original approach before we switched to get_fast_random()
which wasn't fast enough, so we added a buffer.

Unfortunately that buffer is racy and we can actually skid past the end
of it and continue fetching "random" offsets from the adjacent memory
for a while, until we run out of kernel data segment and trip a fault.

Instead of making this even more convoluted, let's just go back to the
pleasantly simple (RDTSC & 0xff) approach. :^)

Fixes #4912.
2021-03-02 14:25:38 +01:00
Ben Wiederhake
25301e450a Kernel: Fix sign error in TCP resend logic 2021-03-02 08:36:08 +01:00
Ben Wiederhake
5c15ca7b84 Kernel: Make sockets use AK::Time 2021-03-02 08:36:08 +01:00
Ben Wiederhake
719cb93a1a Kernel: Make clang(?) happy about templates(?)
This caused some issues with QtCreator, and since it's not wrong and improves
readability very slightly, I adopt it.
2021-03-02 08:36:08 +01:00
Ben Wiederhake
336303bda4 Kernel: Make kgettimeofday use AK::Time 2021-03-02 08:36:08 +01:00
Ben Wiederhake
05d5e3fad9 Kernel: Remove duplicative kgettimeofday(timeval&) function 2021-03-02 08:36:08 +01:00
Ben Wiederhake
c040e64b7d Kernel: Make TimeManagement use AK::Time internally
I don't dare touch the multi-threading logic and locking mechanism, so it stays
timespec for now. However, this could and should be changed to AK::Time, and I
bet it will simplify the "increment_time_since_boot()" code.
2021-03-02 08:36:08 +01:00
Ben Wiederhake
91c72faa3c Kernel: Make TimerQueue use AK::Time in interface 2021-03-02 08:36:08 +01:00
Ben Wiederhake
2b6546c40a Kernel: Make Thread use AK::Time internally
This commit is very invasive, because Thread likes to take a pointer and write
to it. This means that translating between timespec/timeval/Time would have been
more difficult than just changing everything that hands a raw pointer to Thread,
in bulk.
2021-03-02 08:36:08 +01:00
Ben Wiederhake
65b36e42b8 Kernel: Make TimerId a distinct type
Well, that was easy\! :^)
2021-03-02 08:36:08 +01:00
Ben Wiederhake
94e0a603f2 Kernel: Make TimerQueue use AK::Time internally 2021-03-02 08:36:08 +01:00
Ben Wiederhake
e510c41fd2 Kernel: Prevent using copy_from_user() for timespec/timeval
These structs can be inconsistent, for example if the amount of microseconds is
negative or larger than 1'000'000. Therefore, they should not be copied as-is.
Use copy_time_from_user instead.
2021-03-02 08:36:08 +01:00
Ben Wiederhake
8598240193 Kernel: Sanitize all user-supplied timeval's/timespec's
This also removes a bunch of unnecessary EINVAL. Most of them weren't even
recommended by POSIX.
2021-03-02 08:36:08 +01:00
Ben Wiederhake
649abc01bc Kernel: Implement 'copy_time_from_user' functions to sanitize arguments 2021-03-02 08:36:08 +01:00
Ben Wiederhake
b374dd03bd Kernel: Prevent inconsistent state after invalid read
copy_from_user can fail, for example when the user-supplied pointer is just before
the end of mapped address space. In that case, the first few bytes would get copied,
permanently overwriting the internal state of the Socket, potentially leaving it
in an inconsistent or at least difficult-to-predict state.
2021-03-02 08:36:08 +01:00
Andreas Kling
14aa8e3708 Kernel: Oops, SC_abort was actually calling sys$exit_thread() 2021-03-01 19:47:16 +01:00
Andreas Kling
4d006de2b9 Kernel: Fix build with IO_DEBUG 2021-03-01 16:07:50 +01:00
Andreas Kling
272c2e6ec5 Kernel: Use Userspace<T> in sys${munmap,mprotect,madvise,msyscall}() 2021-03-01 15:53:33 +01:00
Andreas Kling
bebceaa32c Kernel: Use Userspace<T> in sys$select() 2021-03-01 15:07:01 +01:00
Andreas Kling
a1a82c1d95 Kernel: Use Userspace<T> in sys$get_dir_entries() 2021-03-01 15:04:31 +01:00
Andreas Kling
b5f32be577 Kernel: Use Userspace<T> in sys$get_stack_bounds() 2021-03-01 14:50:36 +01:00
Andreas Kling
122c7b6cbb Kernel: Use Userspace<T> in sys$write() 2021-03-01 14:35:06 +01:00