Commit graph

8689 commits

Author SHA1 Message Date
implicitfield 1bf7f99a7b Kernel/Ext2FS: Support writing holes
With this change, we no longer preallocate blocks when an inode's size
is updated, and instead only allocate the minimum amount of blocks when
the inode is actually written to.
2024-06-29 19:16:08 +02:00
implicitfield 180f3f29ab Kernel/Ext2FS: Refactor computing and flushing blocks
This is a large commit, since this is essentially a complete rewrite of
the key low-level functions that handle reading/writing blocks. This is,
however, a necessary prerequisite of being able to write holes.

The previous version of `flush_block_list()` (along with its numerous
helper functions) was entirely reliant on all blocks being sequential.
In contrast to the previous implementation, the new version
of `flush_block_list()` simply writes out the difference between the old
block list and the new block list by calculating the correct indirect
block(s) to update based on the relevant block's logical index.

`compute_block_list()` has also been rewritten, since the estimated
amount of meta blocks was incorrectly calculated for files with holes as
a result of the estimated amount of blocks being a function of the file
size. Since it isn't possible to accurately compute the shape of the
block list without traversing it, we no longer try to perform such a
computation, and instead simply search through all of the allocated
indirect blocks.

`compute_block_list_with_meta_blocks()` has also been removed in favor
of the new `compute_meta_blocks()`, since meta blocks are fundamentally
distinct from data blocks due to there being no mapping between any
logical block index and the physical block index.
2024-06-29 19:16:08 +02:00
implicitfield 06d4672564 Kernel/Ext2FS: Store the block list as a HashMap rather than a Vector
Since we now only store blocks that are actually allocated, it is
entirely valid for the block list to be empty, so this commit lifts the
restrictions on accessing inodes with an empty block list.
2024-06-29 19:16:08 +02:00
implicitfield ba96a0e4f8 Kernel/Ext2FS: Simplify read/write loops
This removes removes the need to know the last block in advance, and
makes the loops slightly easier to reason about by depending on fewer
conditions.
2024-06-29 19:16:08 +02:00
Sönke Holz facca92780 Kernel/Storage: Dump storage devices to the framebuffer console as well
This is helps bringing up bare metal devices without having to use the
serial console.
2024-06-26 08:47:00 +02:00
Idan Horowitz 3aa1bd520b Kernel: Support re-mapping MMIOVMObject-backed regions
This is required for example when write combine is enabled on a region
after the initial mapping.
2024-06-25 17:46:37 +02:00
brody-qq 5058873d45 Kernel/Memory: Make release_all_clean_pages use try_release_clean_pages
The methods try_release_clean_pages() and release_all_clean_pages() in
InodeVMObject are almost identical. This commit makes them both use the
same code path.
2024-06-09 14:00:41 -04:00
brody-qq a4ca757db9 Kernel: Add method to clean up remapping region loops
In the VMObject code there are multiple examples of loops over
the VMObject's regions (using for_each_region()) that call remap()
on each region.

To clean up usage of this pattern, this patch adds a method in
VMObject that does this remapping loop. VMObject code that needs
to remap its regions call the new method.
2024-06-08 22:36:03 +01:00
brody-qq 6f6966fb55 Kernel: Remove redundant VERIFY()
Removes a VERIFY() that is already checked earlier in the function
2024-06-05 20:18:44 +01:00
implicitfield ef766b0b5f Kernel/FUSE: Allow buffering multiple requests
It can be possible for a request to be blocked on another request, so
this patch allows us to send more requests even when a request is
already pending.
2024-06-01 14:47:58 -06:00
implicitfield 727881f3d1 Kernel/FUSE: Log IDs of mismatched requests 2024-06-01 14:47:58 -06:00
implicitfield 7acc5763ed Kernel/FUSE: Fill in uid, gid, and pid records 2024-06-01 14:47:58 -06:00
implicitfield a343c7cde4 Kernel/FUSE: Clarify the license of Definitions.h 2024-06-01 14:47:58 -06:00
Liav A. ecc9c5409d Kernel: Ignore dirfd if absolute path is given in VFS-related syscalls
To be able to do this, we add a new class called CustodyBase, which can
be resolved on-demand internally in the VirtualFileSystem resolving path
code.

When being resolved, CustodyBase will return a known custody if it was
constructed with such, if that's not the case it will provide the root
custody if the original path is absolute.
Lastly, if that's not the case as well, it will resolve the given dirfd
to provide a Custody object.
2024-06-01 19:25:15 +02:00
Idan Horowitz b4cdd6a55c Kernel: Prevent integer overflow in USB::Hub::check_for_port_updates()
The maximum valid value is 255, so max + 1 doesn't fit in a u8.
2024-05-27 17:35:42 +02:00
Sönke Holz de02a2680f Kernel/riscv64: Handle breakpoint traps
This means that userspace breakpoint traps no longer panic the kernel.
This also causes us to no longer panic on failed assertions in userspace
when using gcc, as gcc compiles __builtin_trap to breakpoint
instructions on RISC-V.
2024-05-23 14:11:36 -06:00
Sönke Holz 018a28cf4a Kernel/HID: Add support for virtio input devices 2024-05-23 11:16:57 -06:00
Liav A. c48d540230 Kernel: Move VGATextModeConsole code to the Arch/x86_64/ISABus directory
This code is specific to x86 machines, as virtually no other computer
architecture has any compatibility with old VGA legacy functionality.
2024-05-23 05:07:56 -06:00
Kirill Nikolaev 99f6528009 Kernel: Implement virtio-blk driver 2024-05-23 00:59:39 -06:00
Liav A. 3ba5daeca9 Kernel: Actually set physical base pointer correctly in prekernel stage
I did a mistake and set the kernel_physical_base value to be just on
the actual linked kernel ELF start offset, while this value should
represent together with KERNEL_MAPPING_BASE the actual higher-half load
address.

By changing this value, we resolve a bug in which disabling KASLR
doesn't work and will cause the prekernel to hang on this statement:
```c++
VERIFY(kernel_load_base >= kernel_mapping_base + 0x200000);
```
2024-05-22 23:25:51 +02:00
Dan Klishch 38b51b791e AK+Kernel+LibVideo: Include workarounds for missing P0960 only in Xcode
With this change, ".*make.*" function family now does error checking
earlier, which improves experience while using clangd. Note that the
change also make them instantiate classes a bit more eagerly, so in
LibVideo/PlaybackManager, we have to first define SeekingStateHandler
and only then make() it.

Co-Authored-By: stelar7 <dudedbz@gmail.com>
2024-05-21 14:24:59 +02:00
Idan Horowitz 26cff62a0a Kernel: Rename Memory::PhysicalPage to Memory::PhysicalRAMPage
Since these are now only used to represent RAM pages, (and not MMIO
pages) rename them to make their purpose more obvious.
2024-05-17 15:38:28 -06:00
Idan Horowitz 827322c139 Kernel: Stop allocating physical pages for mapped MMIO regions
As MMIO is placed at fixed physical addressed, and does not need to be
backed by real RAM physical pages, there's no need to use PhysicalPage
instances to track their pages.
This results in slightly reduced allocations, but more importantly
makes MMIO addresses which end up after the normal RAM ranges work,
like 64-bit PCI BARs usually are.
2024-05-17 15:38:28 -06:00
Liav A. 5f3ef1aa9e Kernel: Remove includes of PCI API.h file
This file will be removed in a future commit, so let's get rid of what
we can right now.
2024-05-14 15:42:29 -06:00
Liav A. e1d435d0b0 Kernel/x86_64: Rename PCI HostBridge => PIIX4HostBridge
This code is actually for the old PIIX4 PCI host bridge, which requires
to use legacy x86 IO instructions.
2024-05-14 15:42:29 -06:00
Liav A. 69a3602237 Kernel/GPU: Rename GenericGraphicsAdapter => GPUDevice
GenericGraphicsAdapter is mouthful. Also, the idea is to move towards a
more advanced subsystem that handles GPUs, not merely graphics adapters.
2024-05-14 15:42:29 -06:00
Liav A 6014ce0552 Kernel/PCI: Add small access spinlock to each HostController
Prepare to remove biglock on PCI::Access in a future commit, so we can
ensure we only lock a spinlock on a precise PCI HostController if needed
instead of the entire subsystem.
2024-05-14 15:42:29 -06:00
Liav A. 0bab9a9313 Kernel: Move VirtIO RNG implementation to the Security/Random directory 2024-05-14 15:42:29 -06:00
Liav A. bbb749ab47 Kernel: Move VirtIO console code to the Devices/Serial/VirtIO directory 2024-05-14 15:42:29 -06:00
Liav A. cb558f4459 Kernel/Devices: Remove SerialDevice::initialize method
We can just do the initialization sequence in the constructor.
2024-05-14 15:42:29 -06:00
Liav A. b4c218168f Kernel/Storage: Remove StorageController reset and shutdown methods
We never used these virtual methods outside their own implementation,
so let's stop pretending that we should be able to utilize this for
unknown purpose.
2024-05-14 15:42:29 -06:00
Liav A. eadf2bf29f Kernel/Devices: Remove UNMAP_AFTER_INIT from SerialDevice code 2024-05-14 15:42:29 -06:00
Liav A. 136d5b12d5 Kernel/VirtIO: Remove stale detect method 2024-05-14 15:42:29 -06:00
Liav A. d73c82d746 Kernel: Remove UNMAP_AFTER_INIT from VGA text mode console 2024-05-14 15:42:29 -06:00
Liav A d068af89d5 Kernel/x86: Bake the Prekernel and the Kernel into one image
The new baked image is a Prekernel and a Kernel baked together now, so
essentially we no longer need to pass the Prekernel as -kernel and the
actual kernel image as -initrd to QEMU, leaving the option to pass an
actual initrd or initramfs module later on with multiboot.
2024-05-14 23:37:38 +02:00
implicitfield 4574a8c334 Kernel+LibC+LibCore: Implement mknodat(2) 2024-05-14 22:30:39 +02:00
implicitfield 05cf1327ed Kernel: Make utimensat ignore the dirfd when given an absolute path 2024-05-14 22:30:39 +02:00
Sönke Holz fe12a413a1 Kernel: Use AK::unwind_stack_from_frame_pointer 2024-05-14 14:02:06 -06:00
Liav A. 5194ab59b5 Kernel/Memory: Make has_been_{r,w,x} flags clearly being set
Before of this change, actually setting the m_access to contain the
HasBeen{Readeable,Writable,Executable} bits was done by the method of
Region set_access_bit which added ORing with (access << 4) when enabling
a certain access bit to achieve this.

Now this is changed and when calling set_{readeable,writable,executable}
methods, they will set an appropriate SetOnce flag that could be checked
later.
2024-05-14 12:41:51 -06:00
Liav A. 15ddc1f17a Kernel+Userland: Reject W->X prot region transition after a prctl call
We add a prctl option which would be called once after the dynamic
loader has finished to do text relocations before calling the actual
program entry point.

This change makes it much more obvious when we are allowed to change
a region protection access from being writable to executable.
The dynamic loader should be able to do this, but after a certain point
it is obvious that such mechanism should be disabled.
2024-05-14 12:41:51 -06:00
Liav A. e756567341 Kernel+Userland: Convert process syscall region enforce flag to SetOnce
This flag is set only once, and should never reset once it has been set,
making it an ideal SetOnce use-case.
It also simplifies the expected conditions for the enabling prctl call,
as we don't expect a boolean flag, but rather the specific prctl option
will always set (enable) Process' AddressSpace syscall region enforcing.
2024-05-14 12:41:51 -06:00
Liav A. 2cb86c1309 Kernel/Storage: Remove ATA IDE support
Nobody uses this functionality. I used this code on my old 2007 ICH7
test machine about a year ago, but bare metal is a small aspect of the
project, so it's safe to assume that nobody really tests this piece of
code.
Therefore, let's drop this for good and focus on more modern hardware.
2024-05-14 12:38:05 -06:00
Matthew Olsson 4ae7bbda52 Lagom: Add ClangPlugins to the build system 2024-05-13 16:50:54 -06:00
Timothy Flynn 3ff1d7da59 Kernel: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There was a recent release of clang-format version 18.1.5 which fixes
errant spaces around `->` in these files.
2024-05-12 15:44:27 -04:00
Isaac 3d2fcf4244 Kernel/net: Add tracking of dropped packets per adapter 2024-05-09 12:02:26 +02:00
Liav A. f7a85401bb Kernel/Storage: Remove a stale StorageDevice constructor method
ramdisk devices are long gone by now, so this is a stale method.
2024-05-07 17:02:09 -06:00
implicitfield a08d1637e2 Kernel: Add FUSE support
This adds both the fuse device (used for communication between the
kernel and the filesystem) and filesystem implementation itself.
2024-05-07 16:54:27 -06:00
Dan Klishch cc5bacf886 Kernel: Allow annotating initially loaded executable segments
This allows marking regions as VirtualMemoryRangeFlags::SyscallCode in
static executables.
2024-05-07 16:36:38 -06:00
Hendiadyoin1 b17f080dcc Kernel/riscv: Use new DeviceTree helpers in PCI initializations
This also changes the PCI interface slightly to be a bit nicer to work
with.
2024-05-02 07:44:13 -06:00
Hendiadyoin1 8ea8b7a6e5 Kernel/MM: Parse /memreserve/ blocks in FDT based memory mapping mode
These seem to be actually used in the RPi FDTs
2024-05-02 07:44:13 -06:00