The illumos-specific _SC_CPUID_MAX is the largest CPU ID in the system. This
was mapped to _SC_NPROCESSORS_CONF, which is the total number of CPUs recognized
by the kernel. If CPU IDs are contiguous, as is the case on amd64 and arm64,
this value is one greater than the maximum ID. As a result, when consuming
per-CPU dtrace buffers, libdtrace tries to fetch from a non-existent CPU. This
is mostly harmless in practice, but still wrong.
As we don't have a sysconf value for the maximum CPU ID, add a wrapper which
fetches it using the kern.smp.maxid sysctl.
MFC after: 2 weeks
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D49243
(cherry picked from commit 9a30c8d347bf9aaa89277b6e5a275f737be8edce)
This routine returns a monotonic count of the number of nanoseconds elapsed
since the previous call. On arm64 it uses the generic system timer. The
implementation multiplies the counter value by 10**9 then divides by the counter
frequency, but this multiplication can overflow. This can result in trace
records with non-monotonic timestamps, which breaks libdtrace's temporal
ordering algorithm.
An easy fix is to reverse the order of operations, since the counter frequency
will in general be smaller than 10**9. (In fact, it's mandated to be 1Ghz in
ARMv9, which makes life simple.) However, this can give a fair bit of error.
Adopt the calculation used on amd64, with tweaks to handle frequencies as low as
1MHz: the ARM generic timer documentation suggests that ARMv8 timers are
typically in the 1MHz-50MHz range, which is true on arm64 systems that I have
access to.
MFC after: 2 weeks
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D49244
(cherry picked from commit 36ae5ce2f2fda35763c2655a19bf1b0ee22fdf3c)
The zero'th index in the array is unused, so a priority queue of N elements
needs N+1 array slots. Fix the allocation.
Also fix the assertion in dt_pq_insert(): the assertion needs to be checked
after incrementing the count of items in the priority queue, otherwise it can
miss an overflow.
Reported by: CHERI
MFC after: 2 weeks
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D49242
(cherry picked from commit 7ee1bdd094d376fdc547e8ca33e472f1d37a7d79)
After 04207850a9b9 it is required that key length is not zero.
Add some key to avoid error.
Reported by: markj
(cherry picked from commit b6708045590712930c533e916e3d6fdfe48ec5ba)
In order to signal to Graviton [123] systems that a device is ready
to be "ejected" (after a detach request is made via the EC2 API) we
need to set PCIM_PSTAT_PME to 1 and PCIM_PSTAT_PMEENABLE to 0. We are
not aware of any rationale for this requirement beyond "another OS
kernel happens to do this", i.e. this is effectively bug-for-bug
compatibility.
Arguably this should be done by the ACPI _EJ0 method on these systems,
but it is not.
Create a new ACPI_Q_CLEAR_PME_ON_DETACH quirk and set it in EC2 AMIs,
and add the PCI register write to acpi_pci_device_notify_handler when
that quirk is set.
Reviewed by: jhb
MFC after: 1 month
Sponsored by: Amazon
Differential Revision: https://reviews.freebsd.org/D49146
(cherry picked from commit d70bac252d30adec4feba0c866dabe2c16a756d9)
We claim to support Active State Power Management, but don't appear to
do anything different in the kernel when it's enabled other than tell
the firmware we do.
This breaks VMware Fusion on Apple Silicon when it's enabled as it
expects the kernel to enable the ports. As it is reported to be needed
on some x86 servers keep it enabled there, but disable on non-x86
architectures.
Reported by: kp, tuexen
Reviewed by: tuexen, mav, imp, jhb
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D48303
(cherry picked from commit 143dff0f9ce9a6f03ae5701368c7144b30e2dc39)
In the ACPI attachment add support for the pcib_request_feature method.
This uses the common _OSC handling.
Reviewed by: imp, jhb
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D48048
(cherry picked from commit 1f5c50a8617355758510675cb9412f56fed12efc)
In the ACPI attachment support the ACPI_IVAR_HANDLE ivar. While here
use the common ivar function to support the common ivars.
Reviewed by: imp, jhb
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D48047
(cherry picked from commit deb36d0c65436d16b04f99cc2a27bd0f3980a6f0)
Allow this to be called from attachments to allow more ivars to be
implemented.
Reviewed by: imp
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D48046
(cherry picked from commit 7cafe75c8c52deffcb3e64200eb4187a52cf202d)
In pci_host_generic.c use a switch statement rather than a series
of if statements.
Reviewed by: imp
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D48045
(cherry picked from commit fafb43abd0dcaf2d36ec7344f46e7e19c42be888)
This will be used by pci_host_generic_acpi.c so needs to be in a
common location.
Reviewed by: imp, jhb
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D48044
(cherry picked from commit ba1904937d9ae0539e39001467a1519b17177118)
strings(1) is not conditional on WITH_/WITHOUT_TOOLCHAIN, as it is a
small utility that is also useful outside of the toolchain context.
As of commit 1cae7121c667 we switched to WITH_LLVM_BINUTILS by default.
After this change building world with default options but installing
WITHOUT_TOOLCHAIN failed, because we would build LLVM's strings but
attempt to install ELF Tool Chain's version, which did not exist.
Address this by always including ELF Tool Chain strings in non-install
make targets, so that it will be available if options are changed at
install time.
PR: 285556
Reported by: Michael Butler
Reviewed by: brooks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49425
(cherry picked from commit fdc4db57224ce19b867c60fce4c410068be40c27)
since the creation of libudev-devd, but also with powerd, recent libusb
changes etc. 10 client is not enough anymore to cover the desktop needs
and end users often ends up with:
sonewconn: pcb 0xfffff8004dd43780 (local:/var/run/devd.seqpacket.pipe)...
raise the maximum allowed client to 50, which should be enough to cover
user requirements.
MFC After: 1 week
(cherry picked from commit 5682eee1efd35fb65751641181ae2a50d86efaab)
- Use GETENTROPY_MAX instead of hard-coding the value.
- Check for EINVAL instead of EIO
Fixes: 473681a1a506 ("libc: Fix getentropy POSIX 2024 conformance issues")
(cherry picked from commit c5056a3931b41a803a24b89400d38d5c5f843612)
This test case verifies that grep detects symlink loops when traversing
a directory hierarchy.
Fixes: fc12c191c087 ("grep: Default to -p instead of -S.")
Reviewed by: ngie, jhb
Reported by: Jenkins
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D46544
(cherry picked from commit a700bef1e4ee3e6f4e1a86a374bf9b4044f69a70)
After commit 389a3fa693, uma_reclaim_domain(UMA_RECLAIM_DRAIN_CPU)
calls uma_zone_reclaim_domain(UMA_RECLAIM_DRAIN_CPU) twice on each zone
in addition to globally draining per-CPU caches. This was unintended
and is unnecessarily slow; in particular, draining per-CPU caches
requires binding to each CPU.
Stop draining per-CPU caches when visiting each zone, just do it once in
pcpu_cache_drain_safe() to minimize the amount of expensive sched_bind()
calls.
Fixes: 389a3fa693 ("uma: Add UMA_ZONE_UNMANAGED")
MFC after: 1 week
Sponsored by: Klara, Inc.
Sponsored by: NetApp, Inc.
Reviewed by: gallatin, kib
Differential Revision: https://reviews.freebsd.org/D49349
(cherry picked from commit f506d5af50fccc37f5aa9fe090e9a0d5f05506c8)
If the `setlocale()` call fails, emit a warning and sleep briefly so the
user has a chance to see the warning before we redraw the screen. Note
that we have no way of knowing exactly what is wrong, but at least we
can suggest that they check their environment.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D49230
(cherry picked from commit 180065eb09e699820a1e1c45d3d00156e0effe29)
We are supposed to check the result of bsd_to_linux_sockopt_level here
rather than its input.
(cherry picked from commit 9f55630b8d72602f6ec86b15b607f5fc5fde911e)
Technically mount source could be an arbitrary string (since it's
effectively ignored), but it's common to repeat fs type there.
(cherry picked from commit b9752d5d1cea30a39e89c83ea3aeb539581418cb)
The value passed via old field also needs to be validated.
PR: 283848
Fixes: f34aca55adef1e28cd68b2e6705a0cac03f0238e
(cherry picked from commit 031fbf8dc962ca8d458b217ba2b4a9e637b7e932)
of supplied nexthop sub-attributes. While here, use unsigned types for
length calculations and improve style(9).
PR: 283860
(cherry picked from commit 49a6e213416b5c0c9eccdff0af1c6b01f34c3693)
unless the dev.acpi_ibm.0.handlerevents sysctl is set to process
them internally. The default for the latter is to ignore them,
so passing to evdev(4) is enabled by default.
Reviewed by: wulf, imp
Tested on: Lenovo Thinpad X11 Carbon 7Th Gen
Differential Revision: https://reviews.freebsd.org/D48174
(cherry picked from commit c21f5751ef0932796676e55953461e0679020e28)
The SUS doesn't mention this error code as a possible one [1]. The FreeBSD
manual page specifies a possible ECONNRESET for close(2):
[ECONNRESET] The underlying object was a stream socket that was
shut down by the peer before all pending data was
delivered.
In the past it had been EINVAL (see 21367f630d), and this EINVAL was
added as a safety measure in 623dce13c6. After conversion to
ECONNRESET it had been documented in the manual page in 78e3a7fdd5, but
I bet wasn't ever tested to actually be ever returned, cause the
tcp-testsuite[2] didn't exist back then. So documentation is incorrect
since 2006, if my bet wins. Anyway, in the modern FreeBSD the condition
described above doesn't end up with ECONNRESET error code from close(2).
The error condition is reported via SO_ERROR socket option, though. This
can be checked using the tcp-testsuite, temporarily disabling the
getsockopt(SO_ERROR) lines using sed command [3]. Most of these
getsockopt(2)s are followed by '+0.00 close(3) = 0', which will confirm
that close(2) doesn't return ECONNRESET even on a socket that has the
error stored, neither it is returned in the case described in the manual
page. The latter case is covered by multiple tests residing in tcp-
testsuite/state-event-engine/rcv-rst-*.
However, the deleted block of code could be entered in a race condition
between close(2) and processing of incoming packet, when connection had
already been half-closed with shutdown(SHUT_WR) and sits in TCPS_LAST_ACK.
This was reported in the bug 146845. With the block deleted, we will
continue into tcp_disconnect() which has proper handling of INP_DROPPED.
The race explanation follows. The connection is in TCPS_LAST_ACK. The
network input thread acquires the tcpcb lock first, sets INP_DROPPED,
acquires the socket lock in soisdisconnected() and clears SS_ISCONNECTED.
Meanwhile, the syscall thread goes through sodisconnect() which checks for
SS_ISCONNECTED locklessly(!). The check passes and the thread blocks on
the tcpcb lock in tcp_usr_disconnect(). Once input thread releases the
lock, the syscall thread observes INP_DROPPED and returns ECONNRESET.
- Thread 1: tcp_do_segment()->tcp_close()->in_pcbdrop(),soisdisconnected()
- Thread 2: sys_close()...->soclose()->sodisconnect()->tcp_usr_disconnect()
Note that the lockless operation in sodisconnect() isn't correct, but
enforcing the socket lock there will not fix the problem.
[1] https://pubs.opengroup.org/onlinepubs/9799919799/
[2] https://github.com/freebsd-net/tcp-testsuite
[3] sed -i "" -Ee '/\+0\.00 getsockopt\(3, SOL_SOCKET, SO_ERROR, \[ECONNRESET\]/d' $(grep -lr ECONNRESET tcp-testsuite)
PR: 146845
Reviewed by: tuexen, rrs, imp
Differential Revision: https://reviews.freebsd.org/D48148
(cherry picked from commit 053a988497342a6fd0a717cc097d09c23f83e103)
Switching between io and cpu sorting uses a great example in the usage.
[-m io | cpu]. Use that everywhere.
MFC after: 3 days
Reviewed by: mhorne
Approved by: mhorne (mentor)
Differential Revision: https://reviews.freebsd.org/D49515
(cherry picked from commit 187d954eab94fdcb33609d91966dbd727acfd720)
Organize key bindings by ascii(7) for consistency and maintainability,
mark them as Interactive Commands, wordsmith them, and sync their
organization between the manual and help screen.
MFC after: 3 days
PR: 282734
Fixes: c8aa5e526 (move command mapping to commands.c)
Reviewed by: imp, mhorne, Jim Brown <jpb@jimby.name>
Approved by: mhorne (mentor)
Differential Revision: https://reviews.freebsd.org/D49462
(cherry picked from commit 0a85254d5a33800600477ce57fbaab64591aa6ea)
I recommended the incorrect text to the submitter.
MFC after: 3 days
Fixes: f47cbb29e1c2 (Add /dev/gpt)
Reported by: Mark Millard <marklmi@yahoo.com>
Reviewed by: imp, mhorne
Approved by: mhorne (mentor)
Differential Revision: https://reviews.freebsd.org/D49523
(cherry picked from commit 50296dccddf1a7734be2aef606cd8e0408ee8780)
Amazon EC2 m7i cloud instances use PCI hotplug rather than ACPI
hotplug. The card is removed and detach is called to remove the drive
from the system. The hardware is no longer present at this point, but
the bridge doesn't translate the now-missing hardware reads to all ff's
leading us to conclude the hardware is there and we need to do a proper
shutdown of it. Fix this oversight by asking the bridge if the device is
still present as well. We need both tests since some systems one cane
remove the card w/o a hotplug event and we want to fail-safe in those
cases.
Convert gone to a bool while I'm here and update a comment about
shutting down the controller and why that's important.
Tested by: cperciva
Sponsored by: Netflix
(cherry picked from commit dc95228d98474aba940e3885164912b419c5579d)
Since the beginning, Unix has included an ASCII chart. Over the last
half a century to this day, the most common format for lexographical
organization in files is according to ASCII. Consistency is maintainable
and for that reason, crossreference ascii(7) promenently in the
introduction to the File Formats Manual. Additionally, this demonstrates
the often softer style of bullet lists in the manual tradition.
PR: 248562
MFC after: 3 days
Reviewed by: mhorne
Approved by: mhorne (mentor)
Pull Request: https://github.com/freebsd/freebsd-src/pull/1534
(cherry picked from commit a6175f28da7018ba9f824f48fe6db732bd9cb501)
Explain a little about everything is a file,
matching the style of earlier intro pages.
PR: 248562
MFC after: 3 days
Approved by: mhorne (mentor)
Reviewed by: imp, mhorne, Lexi Winter <lexi@le-fay.org>
Pull Request: https://github.com/freebsd/freebsd-src/pull/1534
(cherry picked from commit 37508388d066826d0a36b5ec646c95a9ffb00d28)
Looking around at how everyone else is doing it, this list seems nearly
perfect to me and we should just import it from them. I have added "and
streams" because we have some explanations of those in this section too.
PR: 248562
MFC after: 3 days
Obtained from: OpenBSD
Approved by: mhorne (mentor)
Reviewed by: imp, mhorne, Lexi Winter <lexi@le-fay.org>
Pull Request: https://github.com/freebsd/freebsd-src/pull/1534
(cherry picked from commit 26ec376536622e8fec8f40847aa9b2d1121d585d)
New users are sometimes confused about the difference between /etc/ and
/usr/local/etc. Explain this in the manual as we did in intro(1). Link
hier(7) which now lists base system configuration files in /etc/. Add a
section number to HISTORY for clarity.
PR: 248562
MFC after: 3 days
Approved by: mhorne (mentor)
Reviewed by: imp, mhorne, Lexi Winter <lexi@le-fay.org>
Pull Request: https://github.com/freebsd/freebsd-src/pull/1534
(cherry picked from commit 8d65152cbfc8861f6920846dea6f540c673ab7b6)
Thus far we've relied on the firmware setting HFSCR correctly, enabling
all facilities. However, it appears some recent firmwares do not.
Linux explicitly enables all facilities it supports (including
transactional memory, which new firmwares apparently do not enable), so
do the same here, explicitly enable all the facilities FreeBSD supports.
MFC after: 1 week
(cherry picked from commit fe73eb441f1c98fe350f4822c7d2abfeef046bf8)
Treat Hypervisor Facility Unavailable as an illegal instruction in user
space. This way programs that use facilities like transactional memory,
which will never be supported as it has been removed from the ISA, will
not crash the kernel.
Tested by: pkubaj
MFC after: 1 week
(cherry picked from commit 0b663e0cee89dedf5b070ff4e839d5ad95061535)