Commit Graph

6423 Commits

Author SHA1 Message Date
Augustin Cavalier
87eae1e3c8 bootloader: Properly enable __PRINTFLIKE for the boot stdio.
No new warnings or errors, it appears.
2024-12-17 19:49:23 -05:00
Augustin Cavalier
f836917f47 kernel/vm: Rework ordering of _RemoveConsumer and drop "unmergeable" flag.
This reverts a8877df135.

Previously, the "unmergeable" flag was necessary for the RAMFS,
because if the last vnode reference was released while there
was still a consumer (as the old ordering of _RemoveConsumer
had), then the release of the cache reference when the vnode
was removed would result in the cache trying to merge with
its now-only consumer and sole referrer.

Now, instead, we remove the consumer before releasing the store
reference, so that there's no chance the cache will be merged
inside this method.

mmap_cut_tests still pass, web browsers using ramfs shared_memory
still seem to work.
2024-12-17 19:12:40 -05:00
X512
8ea4167e8b kernel/vm: use DoublyLinkedList for VMCache areas list
Change-Id: I0c6a231f245fa542f5d90959755de1e6ba39eb8e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8685
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-17 17:53:47 +00:00
Jérôme Duval
04c90835ac POSIX: add pthread_getcpuclockid()
fix #15615

Change-Id: I6b34f97464fac97d0b339fa338cfc5df34536080
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8681
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-12-17 09:45:13 +00:00
Augustin Cavalier
d4d55c1fbb kernel/vm: Rename _FreePageRange "discarded" argument to "freedPages".
Clarifies things. No functional change.
2024-12-16 22:06:06 -05:00
Augustin Cavalier
e52dd571d9 bootloader: Make releasing the heap the platform loader's responsibility.
Otherwise, platform loaders couldn't make heap allocations inside
platform_start_kernel(), which some loaders (e.g. EFI) do.

Implement calling heap_release() for the BIOS loaders at least.
This gets us back the ~1.5MB of bootloader heap memory there.
2024-12-16 13:36:39 -05:00
Augustin Cavalier
038d9b44d1 kernel/listeners: Use an rw_spinlock for the gWaitObjectListenerLock.
When the system profiler is in use, this spinlock is used very often.
Internally there's another spinlock which isn't (yet) rw, though.
2024-12-13 17:17:43 -05:00
Augustin Cavalier
5a39b9f82f kernel/vm: Remove unused "no_cache_change" member from VMArea. 2024-12-13 17:14:46 -05:00
Augustin Cavalier
d00cb444a6 kernel/vm: Decommit discarded pages of overcommitted caches.
Overcommitted caches should only have commitments equal to the
number of pages they actually contain, so we should decommit
whenever pages are discarded.

This changes the API of VMCache::Discard to return an ssize_t
of the size of pages that were discarded (or a negative error on
failure.) Nothing checked the return value besides things in VMCache
itself, it appears; but it apparently never fails, so that's fine.

Also add asserts to Commit() that the new commitment at least
encompasses all pages the cache actually contains.
2024-12-13 15:08:45 -05:00
Augustin Cavalier
e7af1dd2e0 kernel/vm: Introduce VMCache::CanOvercommit().
Allows the Anonymous caches to report overcommitting status.
2024-12-13 14:25:40 -05:00
Augustin Cavalier
be88b511d7 kernel/vm: Remove an unneeded and misplaced include.
VMArea.h is already included at the top of the file.
2024-12-11 14:13:36 -05:00
Augustin Cavalier
254894210c LinkedLists: Rename MoveFrom method to TakeFrom.
"Move" now sounds like it has 'move' semantics (i.e. replaces this
structure's data with the other structure's data), while MoveFrom()
really had 'move+append' semantics (appends the other list's elements
to this list, and clears the other list.) To make this clearer, it's
here renamed to "TakeFrom".

This should reduce confusion with the other move-related APIs that
are starting to show up in the Haiku tree (e.g. "MoveFrom" in BRegion.)

Change-Id: Ib0a61a9c12fe8812020efd55a2a0818883883e2a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8634
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Reviewed-by: X512 X512 <danger_mail@list.ru>
2024-12-11 19:09:25 +00:00
Augustin Cavalier
c4a59a7a5f file_systems/QueryParser: Don't try to read the key size of invalid indexes.
Fixes a rare corner case.
2024-12-10 16:28:28 -05:00
Augustin Cavalier
cd730cbd7c kernel/vm: Drop an actually obsolete comment.
This was introduced in hrev27179 to refer to the member "merge_swap",
which is now gone. The "busy_writing" field isn't used in Merge().
2024-12-05 17:13:26 -05:00
Augustin Cavalier
5cf7633a39 Revert "kernel/vm: Remove an obsolete comment."
This reverts commit 1db0961121.

It turns out the comment is not obsolete; what it refers to isn't
PAE systems but true 32-bit ones. I'm not sure we should use
64-bit cache offsets even there, but that's a decision for another
time.
2024-12-05 17:05:44 -05:00
Augustin Cavalier
896f7fdb75 kernel/disk_device_manager: Cleanup code style, fix some minor TODOs. 2024-12-03 12:31:20 -05:00
Augustin Cavalier
bb1f240594 file_systems: Invert query equation scoring values.
Previously, lower was better, and higher was worse. But really we want
the scores to be based primarily around the index sizes, which can
grow to be very large, so a maximum score is hard to determine.

Instead, start with the index size, and then divide to make it smaller
based on how "useful" the equation terms will be in searching it.

Improves the performance of queries like those in #19080; according
to humdinger's testing, the query with the most expensive term first
went from ~2.0s execution time down to ~0.7s, same as the query with
the least expensive term first.

Change-Id: Id71fa21c95cfe3d8d0019ff356bdf4935446411f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8593
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-11-26 17:13:29 +00:00
Augustin Cavalier
9708b08060 KPath: Use a default buffer size of B_PATH_NAME_LENGTH without + 1.
B_PATH_NAME_LENGTH == PATH_MAX, and PATH_MAX is inclusive of the final
NULL terminator, so we don't need a + 1 here.

The original KPath default was to not use + 1, but that was changed in
42e3c6f978 due to all the consumers that did.

But all those consumers are wrong, it appears; they should just be
using the default length instead. So now we do that.
2024-11-22 16:56:15 -05:00
Augustin Cavalier
cc9ea55c59 file_systems/QueryParser: Coerce types up front, and handle B_TIME_TYPE better.
* If we coerce types inside the switch(), then the "type already converted"
   check at the beginning will fail every time, causing us to reconvert,
   which is surely bad for performance.

 * B_TIME_TYPE should be INT32 or INT64 depending on what its size is.

May help with #19080.
2024-11-21 23:19:09 -05:00
Augustin Cavalier
f72d1684e5 kernel/debug: Initialize the frame buffer console much earlier, if possible.
Previously it was not initialized until "post-VM", but there are
a number of ways VM initialization can go wrong that it would
be nice to know about without needing a serial port.

On arches which map the whole physical memory into the kernel
address space (x86_64, at least), we can get the bluescreen facility
initialized using KERNEL_PMAP_BASE. On other architectures, we
just fail to init then, and do the usual setup later on.

A slight bit of extra code cleanup in blue_screen_init_early:
we now just call module->info.std_ops() rather than a
frame-buffer-console specific method.
2024-11-19 21:35:31 -05:00
Augustin Cavalier
a9b5f684f1 kernel/fs: Make io_context rw_lock'ed.
Applications that don't call open() or like functions too often,
and call many FD-related methods across multiple threads at once
(like "git status") now don't wait on the context lock as much.

("git status" performance isn't much improved because threads just
hit the "unused vnodes" lock instead.)
2024-11-18 13:25:43 -05:00
Jim906
9bb1816c14 block_cache: enable prefetching
* Allocate blocks and add them to the hash table so they are
  available for a future block_cache_get call.
* Make use of prefetching in FAT driver.
* A client filesystem may request to prefetch a block run that
  contains some blocks that are already cached.  The request will
  be truncated at the first such block in the run.
* Fixes #19186.

Change-Id: I8d2e3cff15e5b46569438e0dc085e2b391aa57a5
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8525
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-11-16 18:26:21 +00:00
Augustin Cavalier
de8d5cfb5f bootloader & kernel: Unify computation of splash logo and icons placement.
Removes some more code duplication.

Change-Id: I9423be740015bef996b77bf2c30652fdadbd8a50
2024-11-12 23:51:52 -05:00
Augustin Cavalier
029e447bde bootloader & kernel: Unify bitmap blitting routines.
They were more-or-less duplicated between the two.
2024-11-12 23:44:31 -05:00
X512
2b0aa4245b BShape: use BShape::Private class to access private methods.
Avoid declaring random friend classes in public header. Allow to access
private methods from arbitrary source if needed.

Change-Id: Iac2cf0ca59e483aa0657e3fe1fc47080c661cf8b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8534
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-11-11 16:56:19 +00:00
Augustin Cavalier
36708e6ab8 network: Let modules process all ancillary data at once, and adjust UNIX.
This way, modules can decide to do different things based on having
all the ancillary data available. In particular, the UNIX module will
now post only one message header for all the FDs, even if they came
from multiple sets of ancillary data.

This should fix "Message needs unreceived descriptors" from the Chromium
IPC code (which is used by Firefox).
2024-11-05 15:23:24 -05:00
Augustin Cavalier
e9c9b2e448 kernel/condition_variable: Make the debug type fetcher a static function.
No behavioral change intended.
2024-11-05 13:46:53 -05:00
Jérôme Duval
6beff0d163 kernel/libnetwork: add accept4() from POSIX.1/2024
* add SOCK_NONBLOCK and SOCK_CLOEXEC
* also extends the type parameter on socketpair() and socket()

Change-Id: I73570d5bfb57c2da00c1086149c9f07547ba61ce
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8515
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-11-04 17:55:40 +00:00
Jérôme Duval
966076b273 kernel/libroot: add dup3() from POSIX.1-2024
this adds a parameter to the dup2 syscall. Adjust strace.

Change-Id: Icc2d0e054365865d38e5d596843a47c95100ca59
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8514
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-11-04 17:55:40 +00:00
Jérôme Duval
11cd4af6e1 kernel/libroot: add pipe2() from POSIX.1-2024
this adds a parameter to the create_pipe syscall. Adjust strace.

Change-Id: I83e9f039eb28c862458654b66c03e2e21a258822
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8513
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-11-04 17:55:40 +00:00
John Scipione
406f30c616 Tracker: Commands.h (and tracker_private.h) updates
* Add kDeleteSelection command alias in Commands.h, keep kDelete.
* Add kMoveSelectionToTrash and use it in place of kMoveToTrash.
  - kMoveToTrash in kept in tracker_private.h for use outside.
* Create a new constant kRestoreSelectionFromTrash for Tracker.
  - Move kRestoreFromTrash to tracker_private.h

Change-Id: I3cdefe97e8359fb53bacfc3319b046b051c6f7db
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8225
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
2024-10-17 16:21:51 +00:00
Augustin Cavalier
8fbb862695 fs_shell: Adjust following block_cache API change. 2024-10-17 12:15:11 -04:00
Augustin Cavalier
086f997e50 kernel/vm: Move most kernel debugger routines to a new vm_debug.cpp.
Reduces the size of vm.cpp by over 800 lines.
No behavioral change intended.
2024-10-16 14:43:20 -04:00
Augustin Cavalier
0a5c9ef0a4 kernel: Move get_mount_point from VMUtils to KPartition.
There's nothing VM-specific about it; it just builds paths
that partitions should be mounted at.

Also move the tests.
2024-10-16 14:25:17 -04:00
Augustin Cavalier
5f87420792 kernel: Add maxAddress constraint to vm_allocate_early_physical_page.
Needed by the x86 PAE code.

Change-Id: I982dfa96427addfc903205f49f53a46462534843
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8457
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-10-16 16:17:13 +00:00
Augustin Cavalier
916e681ca5 kernel.h: Add a HOWMANY macro and make use of it. 2024-10-14 13:53:50 -04:00
Augustin Cavalier
875b13d582 bootloader: Overhaul heap region allocation.
Previously, there was only platform_init_heap/platform_release_heap,
which allocated a single static heap region for the heap to use,
and any subsequent heap allocations had to go through the standard
platform_allocate_region, which allocates regions visible both
to the bootloader and the kernel.

But as mentioned in previous changes, it isn't always easy to
release regions allocated that way. And besides, some bootloaders
(like EFI) use a completely separate mechanism to allocate
bootloader-local memory, which will never get "leaked" into
the kernel.

So instead, refactor all platforms to instead provide two
new methods: platform_{allocate,free}_heap_region. On EFI
this is easy to implement; on most other platforms we have
logic based more on the old platform_init_heap or allocate_region.

(On the BIOS loader in particular, we can only fully release
the memory if it's the last thing we allocated in the physical
addresses. If the "large allocation" threshhold is lowered
back to 16 KB, then we are unable to do this enough times
that we will run past the end of the 8 MB identity map and
thus fail to boot. But with the larger threshhold, we don't
leak nearly as much, and don't hit the threshhold.)

This should further reduce the amount of bootloader memory
permanently "leaked" into the kernel's used memory, though
on some platforms it may still be nonzero.

Change-Id: I5b2257fc5a425c024f298291f1401a26ea246383
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8440
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-10-10 16:13:11 +00:00
Augustin Cavalier
d1ef184af6 bootloader: Add remove_{physical|virtual}_allocated_range methods.
Will be used in following commits.

Change-Id: Ica89d28cbf6980aca8dc347dfdcb200a0e637e9a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8442
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-10-10 16:13:11 +00:00
Augustin Cavalier
1db0961121 kernel/vm: Remove an obsolete comment.
page_num_t is typedef'd to phys_addr_t, so it's 64-bits on 32-bit
platforms with PAE. In fact it's been so since the introduction
of phys_addr_t, so this comment was obsolete from the start...
2024-10-10 11:20:20 -04:00
Owen Anderson
df59dfec3b arm64: Set MMU granule sizes to a consistent value in bootloader.
Change-Id: Ia36885df6dec5ac0ac9ce41271115aa7a8c3e6df
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8418
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-09-30 15:48:51 +00:00
Owen Anderson
1fa60a5cda arm64: Fix TLB flushing in interrupts to handle kernel vs user space
Change-Id: Id19236345cf05284c8c5f02360a4a2b3f22fd16d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8365
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-09-30 15:48:51 +00:00
Augustin Cavalier
b47e8b0cad build: Unify BeOS ABI compatibility ifdefs around __HAIKU_BEOS_COMPATIBLE.
_BEOS_R5_COMPATIBLE_ was defined in ArchitectureRules while
__HAIKU_BEOS_COMPATIBLE is defined in HaikuConfig.h (which is
in the include path for sys/types, SupportDefs, and other
base headers.)
2024-09-24 12:09:33 -04:00
Owen Anderson
c2f3786ab0 arm64: Save all integer registers in exception handlers.
* This is needed in order to support syscalls and other exceptions
  that need to be able to inspect/modify userspace register contents.

Change-Id: I8a638c0c40dd44ed882adad0591ae3bf5493a6b9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8329
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-09-18 19:34:15 +00:00
Jérôme Duval
0f807f4401 kernel/x86: dump hwpstate, cpb, proc_feedback features
Change-Id: I06b6da05013c7271d0a97d5aa3af2b6f416496a9
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8331
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-09-18 16:21:44 +00:00
Michael Lotz
32a3bddfdf x86: Implement PAT support for memory type configuration.
Using the page attribute table to set the memory type on a per page
mapping basis is the more modern and flexible approach to physical
memory type handling compared to using MTRRs.

Most of the needed infrastructure was already in place, as setting the
page table entry attributes was already done for uncachable and
write-back memory types. Using the PAT now also allows to set the last
remaining memory type of write-combining through the PTE flags. The PAT
is configured to have entry 4 mean write-combining and the PAT bit in
the PTE is set to point to that.

When PAT is supported and not disabled, MTRRs are completely ignored
and left as set up by the system firmware, where the basic uncachable
and RAM ranges are supposed to be set up. These configurations are then
overridden by the PTE flags as needed.

Change-Id: I0a74b3fc7d3ba9fa384251290ce41621b69d3a02
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8340
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-09-17 20:45:28 +00:00
Michael Lotz
8271b4a8bf x86/arch_vm: Allow arch_vm_set_memory_type to override type.
We allow requesting an explicit memory type when calling
map_physical_memory but default to the uncached B_MTR_UC when not given.

When called without an explicitly requested memory type, allow
arch_vm_set_memory_type to modify and return an effective memory type.
When an overlapping range already exists, the effective memory type is
set to the one of the existing mapping. If there is an explicit memory
type request that conflicts with an existing range, or if multiple
overlaps with conflicting types would be produced, the mapping is
disallow (and a panic is triggered under KDEBUG).

This effectively detects and panics when conflicting aliases of physical
memory would be created. This is also useful on an MTRR based setup,
as such overlaps cannot be properly represented.

When using the page attribute table (PAT) to set the memory type on a
per page virtual memory mapping basis, this is needed to prevent
aliasing of the same physical memory with different types. As per the
specs, such aliasing is unsupported and may result in undefined
operations that lead to system failure.

The mechanism is extended to the general arch_vm_set_memory_type as such
aliasing prevention also seems to apply to other architectures (at least
on ARM, aliasing is also strongly discouraged).

Change-Id: I7aaf6ea8415e92e74cd1643b67793a6857619eea
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8339
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-09-17 20:45:28 +00:00
Augustin Cavalier
2eb83002c5 strace: Add FlagsTypeHandler for the mutex option flags.
So that MUTEX_SHARED etc. are displayed in strace output.
Also fix indentation, and the name of the "toFlags" parameter
in syscall definitions.
2024-09-16 15:36:12 -04:00
Owen Anderson
edb17c548f Revert "arm64: Use DEVICE_GRE memory when mapping MTR_WC."
This reverts commit 0caf23319c.
This change is not safe because changing MAIR may invalidate
early mappings. It's also not clear if it's needed, as e.g.
FreeBSD does not use Device GRE mappings.

Change-Id: I95a904ee928281d44989ce707ed1ac59985a308d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8268
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Reviewed-by: Milek7 Milek7 <me@milek7.pl>
2024-09-10 18:46:23 +00:00
Augustin Cavalier
b4798ac6a7 kernel: Add assertions to ensure vm_page_reservation is destroyed with a count of 0.
Inspired by some of jpelczar's changes.
2024-09-10 12:13:38 -04:00
Augustin Cavalier
f4e0ce8d61 kernel/lock: Fix ABI compatibility between KDEBUG and non-KDEBUG builds.
This breaks kernel ABI on KDEBUG builds (but not non-KDEBUG builds),
but it does so in order to resolve a long-standing incompatibility
between them: until now, any kernel add-ons built against one which
made use of these lock facilities could not be run on the other;
instead you would get hangs and/or crashes.

After this change, kernel add-ons built with a KDEBUG configuration
should work on a non-KDEBUG kernel, while add-ons built with a
non-KDEBUG configuration will fail to load on a KDEBUG kernel
with unresolved symbols, preventing incorrect and broken operation.
2024-09-09 22:35:05 -04:00