Commit Graph
100 Commits
Author SHA1 Message Date
Augustin Cavalier 46a5ba80a3 emuxki: Allocate memory for the kernel only.
May fix #18467. Untested, I don't have this hardware.
2023-06-20 16:42:02 -04:00
Augustin Cavalier 513f86c7de user_mutex_defs: Add note that the flags area is shared with timeout flags.
No functional change.
2023-06-19 16:40:33 -04:00
Augustin Cavalier 70e8eacb35 kernel: Implement realloc_etc and make use of it. 2023-06-19 16:33:22 -04:00
Augustin Cavalier f96456d863 kernel/vfs: Fix missing lock in fs_mount().
At least a read lock of the sVnodeLock must be held when calling
lookup_vnode, but we held none at all. This rectifies that problem.

This bug appears to have been around for many years, but no-one
noticed since ASSERT_READ_LOCKED_RW_LOCK only works with more
debug options turned on than the kernel is built with. I discovered
this while working on a new version of those additional options.
2023-06-19 14:27:48 -04:00
Augustin Cavalier 5e8058566c kernel/locks: De-duplicate two inlined methods.
The functions declared in locks.h were and are exactly identical
to these inline blocks of code. So, rather than duplicate them,
just invoke them directly. The compiler will probably inline them
anyway.
2023-06-19 13:23:22 -04:00
Augustin Cavalier c5a0df2490 user_mutex: Add "user_mutex" KDL command to dump user-mutex information.
It takes one parameter to specify a thread that is blocked on such
a user mutex.

Change-Id: I513ce130137a327cbaf305d2945e6cfe3c09879e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6606
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-06-19 14:56:10 +00:00
Augustin Cavalier fb688aa144 user_mutex: Use unwired virtual addresses when possible.
This requires the use of fault handlers in the atomics.

GLTeapot now runs in the range of 590-610 FPS on my VM. However, it still
isn't using anywhere near 100% CPU usage. Some of that may be waiting for
app_server to respond to draw requests, but a lot of it still isn't.

Change-Id: I7be87d10cb1b00f07b055d9094b77837b49c5055
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6603
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-06-19 14:56:10 +00:00
Augustin Cavalier 93d7d1c52c user_mutex: Per-team contexts.
This requires the introduction of the flag B_USER_MUTEX_SHARED, and then
actually using the SHARED flags in pthread structures to determine when
it should be passed through.

This commit still uses wired memory even for per-team contexts.
That will change in the next commit.

GLTeapot FPS seems about the same.

Change-Id: I749a00dcea1531e113a65299b6d6610f57511fcc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6602
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-06-19 14:56:10 +00:00
Augustin Cavalier 0ab9f280ec user_mutex: Granularize locking.
Now the table is locked with a rw_lock, and individual entries have
each their own rw_locks also.

This improves the "contention" benchmark I have here (2 locks, 6 threads,
acquire & release one lock 50,000 times per thread) mentioned in the last
commit down to under 4s consistently, around 3.45s with the system idle
and around 3.9s when moving windows around. Before this commit, it was
around 6.7s in the best case and 7.0s in the worst, and before that,
it couldn't break 3.8s in the best case.

This does make GLTeapot just slightly worse: it is now down to 310-330
(with occasional dips to 300-310) from 320-340. But the following commits
will improve that substantially.

Change-Id: Ie029a2510746f876f4d4c74d7e878fdadf3cf590
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6601
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-06-19 14:56:10 +00:00
Augustin Cavalier 13491fd259 kernel/user_mutex: Refactor around ConditionVariable features.
* Get rid of the multiple entries/condition-variables system.
   Instead, allocate one structure per variable and do not add/remove
   it from the hash until all waiters are gone.

 * Get rid of "locked". All wait wakeups of B_OK mean "locked". All
   nonzero values mean "not locked." This mirrors what the kernel mutex
   implementation does (however, that also tracks the owning thread,
   for assertion's sake.)

 * Remove "lastWaiter" logic (for now.) As we no longer hold a lock
   after wakeup, we cannot reliably check and act on it outside the
   "wait" function. This means that interrupted or timed-out waits
   will cause a potentially unnecessary syscall on next unblock,
   but that will be resolved in the next commit.

Due to the single global lock, user mutex acquisition is an extremely
"noisy" process that can take shorter or longer depending on what is
going on elsewhere on the system, so performance is hard to measure.

With one benchmark that acquires mutexes as fast as possible with
lots of contention, most runs came in as being around the same amount
of time both before and after this change (around 4.25s real). Moving
Terminal's window around while running the test caused runtime to go
up to around 6.7s before this change, and about 7.0s after.

GLTeapot seems to go from 350-380 FPS before this change and 320-340
after. It still spends the vast majority of its time waiting for address
space and cache locks, however.

It is expected that the next commits will build on this change to
improve performance beyond even the "before" numbers above.

Change-Id: I6581a6f7cb0ca0513ea639f8499a1c0c8596c026
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6490
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
Tested-by: Commit checker robot <[email protected]>
2023-06-19 14:56:10 +00:00
Augustin Cavalier 6554d7448d kernel: Print the first 4 chars of cvar names in KDL "threads" command.
Condition variables are now a pretty common way the kernel blocks threads.
That means the "threads" command was getting difficult to navigate, since
at any given time, a lot of threads could be blocked on "cvar".

Now we try (carefully, because it could fault!) to fetch the first 4
characters of the "type" name and display then. This suffices to
distinguish the most common object block types in the list at a glance
(e.g. "cvar:port" for port reads, the most common.)

Change-Id: I94f4b59fd78b7ebdce913944551a5e98f0ca2e33
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6605
Reviewed-by: waddlesplash <[email protected]>
2023-06-13 19:41:07 +00:00
Augustin Cavalier 496e411397 pthread_barrier: Ensure the barrier is "idle" during destruction.
If the serial thread tries to destroy barriers immediately, not all threads
may have exited yet. This takes care of that case.
2023-06-12 23:55:08 -04:00
Augustin Cavalier f79c7ae83e pthread_cond: Use test_and_set in cond_wait.
This is necessary in the case where only one thread is
being woken up at a time.
2023-06-12 23:53:39 -04:00
Augustin Cavalier ca458a2b55 user_mutex: Adjust semantics of B_USER_MUTEX_UNBLOCK_ALL.
No longer is it required that the mutex be unlocked.
This was the case before the recent refactor, though it
wasn't noted anywhere. Now it is the case once more.

Should fix #18445.
2023-06-12 23:53:02 -04:00
Augustin Cavalier 901b48c2e8 user_mutex: Fix potential race in switch_lock.
We need to set the "to" mutex as locked+waiting before performing
the unlock of the first mutex, otherwise something in userland could
unset the "locked" flag but never call the kernel because "waiting"
had not yet been set.

In practice, the one consumer of this API (pthread_cond) could not,
at present, wind up in that situation, as far as I can tell, so this
race was entirely theoretical.
2023-06-12 22:51:45 -04:00
Augustin Cavalier 6f3f29c7dd user_mutex: Refactor locking and unblocking mechanism.
Suppose the following scenario:

1. Thread A holds a mutex.

2. Thread B goes to acquire the mutex, winds up in kernel waiting.

3. Thread A unlocks; first unsets the LOCKED flag.
   As WAITING is set, it calls the kernel; but instead of processing
   this immediately, the thread is suspended for any reason (locks,
   reschedule, etc.)

4. Thread B hits a timeout, or a signal. It then unblocks in the kernel,
   which causes the WAITING flag to be unset.

5. Thread C goes to acquire the lock. It sets the LOCKED flag.
   It sees the WAITING flag is not set, so it returns at once,
   having successfully acquired the lock.

6. Thread A, suspended back in step 3, resumes.

Now we encounter the problem. Under the previous code, the following
would occur.

7. Thread A sees that no threads are waiting. It thus unsets the LOCKED
   flag, and returns from the kernel. Now we have a mutex theoretically
   held by thread C but which (illegally) has no LOCKED flag set!

8. Some other thread tries to acquire the lock, and succeeds, for LOCKED
   is not set. We now have one lock owned by two separate threads.
   That's very bad!

The solution, in this commit, is to (1) switch from using "atomic_or"
to lock mutexes, to using "atomic_test_and_set", and (2) mandate that
_kern_unblock_mutex must be invoked with the mutex already unlocked.

Trying to solve the problem with (2) but without (1) produces other
complications and would overall be more complicated. For instance,
all existing userland code expected that it would set LOCKED, but then
check LOCKED|WAITING. If _kern_mutex_unlock does not unset LOCKED,
then whichever thread sets LOCKED when it was previously unset is
now the mutex's undisputed owner, and if it fails to notice this,
would deadlock.

That could have been solved with extra checks at all lock points, but
then that would mean locks would not be acquired "fairly": it would
be possible for any thread to race with an unlocking thread, and
acquire the lock before the kernel had a chance to wake anyone up.

Given how fast atomics can be, and how slow invoking the kernel is
comparatively, that would probably make our mutexes extremely "unfair."
This would not violate the POSIX specification, but it does seem like
a dangerous choice to make in implementing these APIs.

Linux's "futex" API, which our API bears some similarities to, requires
at least one atomic test-and-set for an uncontended acquisition,
and multiple atomics more for even the simplest case of contended
acquisition. If it works for them, it should work for us, too.

Fixes #18436.

Change-Id: Ib8c28acf04ce03234fe738e41aa0969ca1917540
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6537
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-06-08 16:49:05 +00:00
Augustin Cavalier 65a76a0fb9 pthread & os/locks: Add some more assertions and error checks.
The first of these assertions in the pthread code is actually possible
to trigger under some specific circumstances, which is ticket #18436.
This makes that problem more obvious when it does happen.

Change-Id: I026ea6e4c569a7c20d82b70722f752d87e57c5a1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6536
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
2023-06-08 16:49:05 +00:00
Augustin Cavalier b24cc7ca75 pthread: Use 1 for PTHREAD_BARRIER_SERIAL_THREAD.
pthread_barrier_wait can return errors, which on Haiku are negative
and so -1 is an error condition, it should not be reused for a magic
constant.

This breaks ABI. However, until the recent fixes, barriers were so broken
that I doubt any application was using them seriously (Mesa, for instance,
has them disabled.)

Change-Id: Ica23921de012a33e9e7aded816bb1347bd157b31
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6517
Reviewed-by: Jérôme Duval <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: X512 <[email protected]>
2023-06-07 15:12:11 +00:00
Augustin Cavalier 4785ffe77c pthread_barrier: Add casts to appease GCC2. 2023-06-06 15:48:15 -04:00
Augustin Cavalier 505fdd612b pthread_barrier: Rewrite critical section.
The previous implementation was prone to deadlocks when the next round
of threads tried to enter the barrier before the prior round exited it.
This new version takes care of that problem, and also removes some
other contention.

Basic design:

 * waiter_count is now atomic, which means only the "serial" thread, or
   in case of contention threads that raced, need acquire the mutex.

 * mutex remains locked during threads wakeup, at which point waiter_count
   is negative. It is only unlocked when count reaches 0 in the last-woken
   thread. This protects against the races that lead to deadlocks.

 * Remove usage of _kern_mutex_switch_lock. This was done incorrectly;
   if it returned EINTR, the first lock would be unlocked but the second
   would not be acquired, creating further races. Instead, we leave
   the barrier lock in "LOCKED" state at all times except when we
   actually want to wake threads up, when it is left "Unlocked"
   (and "unlocked" by each successive exiting thread, just in case.)

Fixes #15736.
2023-06-06 15:25:23 -04:00
Augustin Cavalier 63396c7d13 pthread_barrier_test: Reduce sleep times and increase cycles.
This test now reliably reproduces the deadlock reported in #15736.
2023-06-06 15:25:23 -04:00
Augustin Cavalier 9686d93151 kernel/user_mutex: Fix another instance of addr_t.
Spotted by korli.
2023-06-06 10:54:16 -04:00
Augustin Cavalier 402b41562c kernel/user_mutex: Use phys_addr_t for hash keys.
This could fix address collisions on 32-bit systems with PAE.

Fixes #18435.
2023-06-05 20:56:15 -04:00
Augustin Cavalier cf1b26a933 kernel/user_mutex: Create utility functions for the user_atomics.
In the future, these should be moved to another file (and fault handlers
used), but at least this de-clutters the code a bit for now.
2023-06-05 20:53:55 -04:00
Augustin Cavalier c4c09e7fed usb_disk: Fix double-lock KDL on device removal.
Fixes #18431.
2023-06-01 11:59:01 -04:00
Augustin Cavalier 0450e7b802 USB: Acquire the device manager lock before Explore.
We must do this to prevent lock order inversion: when busses are
initialized, they are started by the (locked) device manager, and
then acquire the explore lock. We must do the same in Explore itself,
for when called by the explore thread, we would otherwise first acquire
the explore lock, then (when publishing new nodes) acquire the device lock.

Should fix #18421 and #18393.
2023-05-31 16:49:41 -04:00
Augustin Cavalier bd90416925 USB: Do not wait for first explore in Stack constructor.
Following various refactors, at the point the Stack object is created,
there are no bus managers yet, so exploring will find nothing.
2023-05-31 16:15:54 -04:00
Augustin Cavalier 1eb7837ddd usb_disk: Ensure we are in a consistent locking state before calling free.
Should fix the KDL in #16745.
2023-05-31 15:01:03 -04:00
Augustin Cavalier cb1df90e30 Revert "kernel/vm: handle page protections in cut_area"
This reverts commit de07bc3fa5.

That's what I get for fixing bugs on test branches.
2023-05-31 14:48:23 -04:00
Augustin Cavalier fbcc7b2711 BScrollView: Ajust minimum dimensions as little as necessary.
If the dimensions are already larger than needed, don't add to them.
Fixes Terminal and other non-layout applications' display
following the prior change.
2023-05-31 14:47:40 -04:00
Augustin Cavalier ef8e820bc7 FileTypes: Remove workaround.
Not needed after the previous commit.
2023-05-31 13:33:50 -04:00
Augustin Cavalier 269de6acca BScrollView: Take both minimum dimensions of scrollbars into account.
Fixes #5678.
2023-05-31 13:33:50 -04:00
Augustin Cavalier ca40d4ab5c usb_disk: Probe by USB configuration instead of attributes.
In the case of devices where the mass-storage interface is not the
first one, we will miss it unless we were to check all attributes
one at a time in order. Instead of doing that, just fetch the configuration
and enumerate it directly.
2023-05-30 15:32:49 -04:00
Augustin Cavalier e1e2a82dd2 USB: Use BStackOrHeapArray in RegisterNode.
I saw in a KDL stack trace that this function was using over 4KB of stack.
As it is called as part of device_manager startup, where there can be
pretty deep recursion happening, that seems like a bad idea.

Additionally, it did not actually do bounds checking.
Now we dynamically allocate an array of sufficient length.
2023-05-30 15:24:52 -04:00
Augustin Cavalier ac0506fd90 usb_disk: Granularize locking.
There is now an "io_lock" which must be held when performing any USB
operations. All ioctls that read basic status, size, icon, etc. information
do not need to acquire it, of course, which should improve userland
lockup occurrences on congested USB disks.
2023-05-30 15:23:36 -04:00
Augustin Cavalier 20313e56ed usb_disk: Clean up and consolidate mutex/semaphore creation/destruction. 2023-05-30 14:19:57 -04:00
Augustin Cavalier dd6e7cb90d usb_disk: Use get_attr_uint8 instead of a loop to get class/subclass/protocol.
Suggested by axeld. The original logic was copied from the USB-ECM
driver, which may also be able to be simplified here.
2023-05-30 14:19:07 -04:00
Augustin Cavalier 9b1ff49d87 kernel/io_request: Add assertion in NotifyFinished() that fStatus is set. 2023-05-30 14:01:23 -04:00
Augustin Cavalier 831bb20728 kernel/dma_resource: Add an assertion to prevent Init() from being called twice. 2023-05-30 14:00:47 -04:00
Augustin Cavalier 92b8f3e74c kernel/dma_resource: Fix tracing. 2023-05-30 14:00:44 -04:00
Augustin Cavalier 197e4b5a6a usb_disk: Use DMAResource for bouncing and support physical I/O requests.
A "bypass" mechanism is left in for when DMAResource would just add
overhead for no reason. All other I/O goes through it and is submitted
to the USB stack as physical addresses.

Tested in QEMU, can still boot from USB on all busses.

Fixes #15569.

Change-Id: I26bfd2208de4ebe1a17170a7034316076927663f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6480
Reviewed-by: waddlesplash <[email protected]>
2023-05-30 17:54:28 +00:00
Augustin Cavalier 55a468820c USB: Support physical-vector bulk requests.
Introduce a new utility method, "generic_memcpy", which takes
generic_addr_t plus indications of whether these specify virtual or
physical addresses (and potentially user addresess) and calls the
appropriate memcpy variant depending.

All bus drivers adjusted to support this at once. We don't actually
take advantage of the physical addresses in any way (yet), as USB
controllers have some pretty specific requirements that would have
to be carefully validated to use these directly.

All bus drivers tested and confirmed to still be working.

Change-Id: I66326667e148091147bb2b3d0843a26fb7e5bda6
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6479
Reviewed-by: waddlesplash <[email protected]>
2023-05-30 17:54:28 +00:00
Augustin Cavalier 99626c2908 USB: Use generic_io_vec in Transfer.
Prepares the way for actual physical-address request support,
which is not yet wired up.

Change-Id: I1b2d04a31e334a79b8361280fa0f3a5fbdb43d2b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6478
Reviewed-by: waddlesplash <[email protected]>
2023-05-30 17:54:28 +00:00
Augustin Cavalier 65cdc13e7d kernel: Migrate struct generic_io_vec to a private header outside src/.
This way it is more easily accessed from drivers outside the kernel,
which it soon will be, without having to add an explicit UseHeaders.
(The drivers that use it already all use the IOScheduler.)

No functional change.

Change-Id: Ibc2d2678e37d9d7ab73391cb17b72cca86f92132
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6477
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-05-30 17:54:28 +00:00
Augustin Cavalier c88d446192 usb_disk: Move icon data to a separate header. 2023-05-29 16:11:30 -04:00
Augustin Cavalier 5c99f9668e XHCI: Disable MSI-X for now.
Breaks USB on some hardware. This might be a bug in Haiku's
MSI-X implementation.
2023-05-29 15:47:22 -04:00
Augustin Cavalier e223e8e94b kernel/x86: Initialize IO-APIC only after PCI enumeration is complete.
Before the PCI refactor, PCI initialization/enumeration occurred
immediately after the PCI module was loaded, and so by the time
we got to IOAPIC initialization, it was already complete.

After the refactor, PCI enumeration is deferred until slightly later,
and so we would try to initialize IO-APICs without knowing PCI
information. This would fail, as read_irq_routing_table needs to
have that available.

Hopefully fixes #18425, #18393, #18398.

Change-Id: I1e4b06367da26eeb10085a1c6322ed39885b632b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6476
Reviewed-by: X512 <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-05-29 19:44:32 +00:00
Augustin Cavalier b256fa4adf usb_disk: Transition to "new" driver API.
Change-Id: Ia46cb6ddc9f83917a8f797149508d35b770e44f1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6473
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-05-29 18:11:26 +00:00
Augustin Cavalier 958b83c3ed PoorMan: Default to UTF-8 character set.
Ideally we would default to no character set, but
libhttpd does not seem to support that.

Fixes #18424.
2023-05-25 16:21:40 -04:00
Augustin Cavalier c098332d7b usb_disk: Retry actions after reset_recovery.
This is mostly important for B_GET_MEDIA_STATUS, which actually will
retry actions if the err_act is set appropriately.

Following this change, stalls are now fully recoverable without causing
the file descriptors of the mounted partition to be cleared, and the
system can resume normal operation without a problem.

Fixes part of #15569.
May help with #16745, #18185, #17543, #18421.
2023-05-25 15:47:40 -04:00
Augustin Cavalier 0a9e5c9e58 usb_disk: Cancel queued transfers when clearing HALTs.
XHCI, at least, has "sticky" HALT states which must be cleared at
the controller level. Invoking cancel_queued_transfers takes care
of this.

This fixes USB disks spontaneously unmounting whenever stalls occur.
However, trying to read anything from the mounted partition results
in "Bad file descriptor", probably due to media-status error propagation.
2023-05-25 15:31:34 -04:00
Augustin Cavalier 1886d5692e XHCI: Handle an unlikely corner case in CancelQueuedTransfers.
See inline comment with reference to the XHCI specification.
2023-05-25 15:29:31 -04:00
Augustin Cavalier 1a88b571ca pci/x86: Reimplement PCIe configuration mechanism using ECAM.
This allows us to drop the PCI-specific ACPI management entirely.
Confirmed working on x86, and the fallbacks when there is no ACPI
also still work.

Change-Id: I6dac9f5539f99b934b17b341634ce22628bc66fd
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6470
Reviewed-by: X512 <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2023-05-25 17:35:53 +00:00
Augustin Cavalier 19ae638fb6 pci/ecam: Fix reading config registers using ACPI method.
Also adjust end-address computation: we read up to 4 bytes past the offset.

Change-Id: I76343aba38cddb614394bd0dca1b36094b8dd85e
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6469
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: X512 <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
2023-05-25 17:35:53 +00:00
Augustin Cavalier 769b4ee4aa XHCI: Implement support for MSI-X.
Works in QEMU, at least.
2023-05-24 15:42:59 -04:00
Augustin Cavalier 5dcae7c6b8 ECAM ACPI PCI controller: Fix computed length being unused for 32/64.
Amends 8be0a59e77.
2023-05-24 15:03:07 -04:00
Augustin Cavalier c2e8b3177b usb_raw: Fetch default language before fetching string descriptors.
This fixes strange hangs that occur with some devices when fetching
their string descriptors with language-id "0".
2023-05-23 14:23:14 -04:00
Augustin Cavalier 57d035af1c listusb: Dump Super-Speed Endpoint Companion descriptors. 2023-05-22 20:06:14 -04:00
Augustin Cavalier ed01a46241 listusb: Split CDC listing into a separate file. 2023-05-22 19:53:10 -04:00
Augustin Cavalier 67df1af45a listusb: Fix verbose class/subclass/protocol printing.
There should always be a space between the hexadecimal number
and then the looked-up string.
2023-05-22 19:50:45 -04:00
Augustin Cavalier bcc72455d3 freebsd_network: Add missing NULL check in get_usb_device_attach_arg.
May fix #18418.
2023-05-22 19:23:04 -04:00
Augustin Cavalier 605bd3f09d termios.h: Undefine/remove some unimplemented BeOS extensions.
We did not ever implement these, it seems, and so they are just
cluttering up the global namespace.

Change-Id: Ib37c3a31663525a18268c9bfe326bfba9afbc794
2023-05-22 18:20:17 -04:00
Augustin Cavalier 5d4fe207c7 scsi_disk: Remove unused blockShift and log2.
These were used when this driver was first introduced,
but are no longer.
2023-05-22 18:10:28 -04:00
Augustin Cavalier 88306be95c drivers/pty: Check slave TTYs also in get_tty_index.
The old TTY driver had one set of indexes for both master
and slave TTYs, and it used those indexes interchangeably.
We thus need to check both lists here also.

Fixes SSH passphrase prompts not working.
2023-05-10 12:59:13 -04:00
Augustin Cavalier 071ff801ee BSerialPort: Implement WaitForInput() using wait_for_objects.
Fixes #17867.

Change-Id: Ib59781128d5d21317c4042f250333b177a0ed91b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6432
Reviewed-by: waddlesplash <[email protected]>
2023-05-09 23:33:43 +00:00
Augustin Cavalier bbb4db9276 Delete the old TTY driver.
No longer used or included in the build after the previous commit.
2023-05-09 16:04:09 -04:00
Augustin Cavalier 0c2a5bb5ea Replace the "tty" driver with a "pty" driver.
This new driver uses the "generic" TTY layer, unlike the old driver
which had its own implementation (which the generic module was derived
from, originally.)

The remaining bits of support for controlling TTYs is added to the kernel &
generic layer at the same time, which should allow for serial interfaces
to be controlling terminals now, as well.

Tested with bash, nano, vim; all seems to still be working as expected.
2023-05-09 16:04:09 -04:00
Augustin Cavalier 7a27ef1439 generic/tty: Add the undocumented BeOS 'ichr' ioctl.
This was used by the BeOS port of ncurses, as well as our own ncurses
port until not too long before the alpha1 days, so we should keep it
around for compatibility.

Implementation copied directly from the "legacy" TTY driver.
2023-05-09 16:04:09 -04:00
Augustin Cavalier bb57ea897d generic/tty: Combine settings structures.
It doesn't make much sense to have separate window sizes, termios, etc.
settings for the two halves of a TTY. Moreover, having separate settings
which can get out of sync breaks applications, e.g. double-printing
in shells.

The original TTY driver has unified settings. It seems likely that the
settings were separated as part of the locking simplification, however
the lock separation was reverted a while back, anyway.
2023-05-09 16:04:09 -04:00
Augustin Cavalier 997adc7e61 kernel/fd: Add missing NULL checks in user_io routines.
I am not sure how this path could be hit besides having
O_APPEND set on a socket, which appears to be possible,
though I don't know what purpose that would serve.

Tested by adding these two lines between the sleep() and close()
in the in-tree tcp_connection_test:

fcntl(fd, F_SETFL, O_APPEND);
write(fd, "Hello", 5);

Before this commit, the above lines cause a KDL.

May fix #18133, but I don't presently have access to the
reproduction setup described in that ticket.
2023-04-29 20:01:30 -04:00
Augustin Cavalier be8080575a IORequest: Refactor IOOperation transferred-bytes and status accounting.
Until the introduction of the nvme_disk driver, these classes were
mostly only used directly by the IO scheduler, and then a few direct
usages of IOOperation itself in the individual disk drivers; so
API confusions were easily missed.

When writing the nvme_disk driver's IORequest support, however, it
became readily apparent that there were some pretty bad confusions
around transferred-bytes accounting in IOOperation. This commit
attempts to resolve all of those.

There are two basic changes here:

1. Move transferred-bytes accounting into IOOperation::SetStatus.

The "TransferredBytes" field of IOOperation is against the *original*
range, not the actual operation's range (which will be wider, due to
bouncing, etc.), and furthermore only applies to the actual content
of the request (and not e.g. to a read half of a bounced write.)

These two facts meant that determining what value to pass to
SetTransferredBytes was not trivial, and was easy to get wrong.
I recall messing that up when working on nvme_disk multiple times
before reading the API carefully.

2. Do not pass redundant values to IORequest::OperationFinished.

All of the values here can be derived (albeit indirectly) from the
IOOperation, and all consumers of this API basically did just that.
Rather than make them do it, make the IORequest take care of
computing all of those values itself.

Change-Id: Ic9ae29e1100319e5b7647647c4db7e5aad4d125e
2023-04-28 14:59:21 -04:00
Augustin Cavalier 103c671ef0 AbstractModuleDevice: Add generic read/write hooks via "io" hook.
This substitutes for the already-existing behavior of scsi_cd, scsi_disk,
and virtio_block, so we can delete their hooks and let them use
these new generic fallbacks.

Some other drivers perform clamping, and so using these fallbacks would
constitute a behavioral change.

Change-Id: I9a2e503f2e03abc276bdfc02d1cff1565a9742e9
2023-04-27 16:24:08 -04:00
Augustin Cavalier be67f14dcb mmc_disk: Refactor read/write/io hooks.
* Move geometry fetching to open(); it was not done
   in io() and was duplicated in multiple places.

 * Clean up clamping and bounds checking.

 * Use IORequest::TransferredBytes().

 Change-Id: I4157e516098dc0362c1478abd21a545c1f235cd7
2023-04-27 16:24:02 -04:00
Augustin Cavalier e0f07d3ce0 IORequest: Add an assertion in SetTransferredBytes. 2023-04-27 15:20:17 -04:00
Augustin Cavalier f64b099191 scsi & virtio: Clean up IORequest usage.
* Use TransferredBytes() instead of assuming length.
 * Consolidate checks and invoke io hook instead of scheduler directly.
2023-04-27 15:19:39 -04:00
Augustin Cavalier 8d2c997da2 nvme_disk: Add missing bounds check and adjust clamping. 2023-04-27 15:12:14 -04:00
Augustin Cavalier 8540053c8a xsi_message_queue & xsi_semaphore: Downgrade a lot of traces.
Reduces syslog spam.
2023-04-26 17:17:57 -04:00
Augustin Cavalier d8f78afc8a xsi_message_queue: Permit incoming buffer to be NULL.
The user address space has not included NULL for a while, so this
has actually been broken for years, and nobody noticed. I guess
XSI message queues are not very well used?

Fixes the in-tree "xsi_msg_queue_test1".
2023-04-26 17:17:19 -04:00
Augustin Cavalier 6acd708e97 xsi_message_queue & xsi_semaphore: Use condition variables to wait.
This removes a lot of custom logic for managing waiting threads,
which was not even correct in all cases (and the code actually
acknowledged this with a big TODO about it, which weinhold
added all the way back in 2008!)
2023-04-26 17:16:07 -04:00
Augustin Cavalier 9747721a43 kernel/condition_variable: Add a fast-exit from Wait() for negative timeouts.
acquire_sem_etc does something very similar.
2023-04-26 17:12:24 -04:00
Augustin Cavalier d8e4f52b78 kernel/condition_variable: Add a ConditionVariable::EntriesCount() routine.
Will be useful in changing the XSI subsystems to use condvars.
2023-04-26 17:08:15 -04:00
Augustin Cavalier 484bf053dc VMCache: Use THREAD_BLOCK_TYPE_OTHER_OBJECT.
This would have assisted in debugging #18390.
2023-04-26 15:34:24 -04:00
Augustin Cavalier 557f0446b3 kernel: Introduce THREAD_BLOCK_TYPE_OTHER_OBJECT.
THREAD_BLOCK_TYPE_OTHER implies the "object" pointer in the
wait information is a string. But sometimes we want to pass
through objects which are not strings, for inspection in KDL.
2023-04-26 15:33:53 -04:00
Augustin Cavalier f5e531e92e kernel/thread_types: Remove Thread::condition_variable_entry.
Unused, and "struct PrivateConditionVariableEntry" no longer exists, anyway.
2023-04-26 15:32:20 -04:00
Augustin Cavalier 3c51bd6a2b libroot: Fix initialization of LocaleNumericDataBridge.
We need to store the isGlobal value, so that the destructor
can take care of unsetting the glibc locale properly.

It seems this has been broken since d338200e2b.

Fixes #18344 and probably #18336.
2023-04-25 15:55:42 -04:00
Augustin Cavalier 419abdb265 openbsd_wlan: Add implementation of IEEE80211_IOC_SCAN_REQ.
We cannot actually initiate scans, but we can at least detect when
one is in progress.

This fixes "ifconfig ... scan" on OpenBSD devices returning errors
instead of scan results ("list" always worked.)
2023-04-25 13:37:52 -04:00
Augustin Cavalier 6fa3716c79 docs/user: Import syslog documentation from an old Haiku newsletter article. 2023-04-25 13:10:59 -04:00
Augustin Cavalier 4ba629698f pci/designware: Add another missing include. 2023-04-25 12:50:58 -04:00
Augustin Cavalier 69929490eb locale_t.h: Add missing newline at end of file.
Fixes #18369.
2023-04-25 12:38:37 -04:00
Augustin Cavalier 3ce66fb079 pci/designware: Add missing include. 2023-04-25 12:38:13 -04:00
Augustin Cavalier c4737dcb22 freebsd_network: Be lenient, do not assert if the callout mutex is &Giant.
Same as FreeBSD. Should fix #18356.
2023-04-17 22:47:14 -04:00
Augustin Cavalier 97d55ad49d freebsd_network: Add missing LOCKGIANT to the close() hook.
Should fix #18363.
2023-04-17 21:51:29 -04:00
Augustin Cavalier 6347519ab1 pthread_once: Add static assertions for ONCE_INITs.
Both of these need to be here, they cannot be in the C sources,
as the static assertions throw "non-constant expression" when
placed there.
2023-04-10 11:51:43 -04:00
Augustin Cavalier d9e8ef7f66 threads.h: Fix value of ONCE_FLAG_INIT.
Fixes #18348.
2023-04-10 11:50:33 -04:00
Augustin Cavalier 5cbb772a4d libroot: Fix handling of n=0 in mbrtowc.
Fixes #18350.
2023-04-10 11:25:15 -04:00
Augustin Cavalier 33dd436f25 kernel/team: Fix race condition in team loading wait.
The condition variable that the load_image'ing thread is waiting on
is also owned by that same thread, so as soon as it wakes up, it
will soon return, thus destroying it. Under high load or other unlucky
scheduling conditions, it seems this could occur before the other thread
had even returned from the condition variable's NotifyAll.

Since team->loading_info is protected by the team lock, simply
acquire the team lock once more after being awoken and returning,
to synchronize and prevent this race.

Should fix #18352.
2023-04-08 15:10:35 -04:00
Augustin Cavalier 23e3c5fa0c libroot/icu: Add missing include of assert.h.
Needed everywhere other than GCC2.
2023-04-08 15:06:13 -04:00
Augustin Cavalier adc3561bed libroot: Suppress signed-unsigned comparison warning. 2023-04-08 14:50:13 -04:00
Augustin Cavalier c3c213810b libroot: Do not include terminating NULL byte in result of [wc]strxfrm.
Fixes #18347.
2023-04-08 14:48:48 -04:00
Augustin Cavalier 3e1163d6af libroot: Disambiguate parameters of ICUCollateData::Strxfrm.
Same thing that was done for wcsxfrm in 218604196a.
2023-04-08 14:17:15 -04:00