epoch: Zero the drain count under the drain mutex
epoch_drain_cb() decrements e_drain_count with an atomic and only then
takes e_drain_mtx to wake the drainer. epoch_drain_callbacks() holds
that mutex while it schedules the drain callbacks and checks the count
before it sleeps. If the last callback of the final pass runs in that
window, the drainer sees zero, does not sleep, and returns before the
callback has locked and unlocked the mutex. epoch_free() then destroys
the mutex and zeroes the epoch under it. Its epoch_wait(global_epoch)
does not help, since epoch_call_task() runs the callbacks after leaving
the global epoch.
Each CPU's drain callback drops the count once, so the one that finds
it at one is the last. Have that callback take the mutex before it
drops the count to zero. The drainer reads the count only with the
mutex held, so it cannot see zero until that callback has dropped the
mutex, and the callback does not touch the epoch after that.
Use refcount(9) for the count, so that the other callbacks still drop
[13 lines not shown]
rge: Make the TX watchdog reset the chip
If the cable is pulled, and re-inserted, the driver does not
re-establish any connections, inet nor inet6. rge_init_locked() returns
too early when IFF_DRV_RUNNING is set, so the watchdog's reset doesn't
help, only a full ifconfig rge0 down/up is sufficient.
Clearing the flag & calling rge_init_locked() addresses this, but it
takes around 5 seconds to completely recover.
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D62221
rge(4): Implement RTL8125 UDP hardware workaround
Directly quoting Kevin Lo <kevlo at openbsd.org>
"The RTL8125/RTL8125B parses short udp frames for ptp messages.
If a frame shorter than 175 bytes reads port 319 or 320 where the chip
expects the udp destination port and fewer than 47 bytes of udp data follow,
the transmitter stops for good."
Separately, the hw doesn't checksum frames shorter than 60 bytes
properly.
We get around both by padding and computing the checksums for these frames.
Both OpenBSD and Linux have implemented a similar workaround [1][2].
[1] https://marc.info/?l=openbsd-tech&m=179358733449818&w=2
[2] https://github.com/torvalds/linux/commit/8d520b4de3edca4f4fb242b5ddc659b6a9b9e65e
Signed-off-by: Aaron Espinoza <acesp25 at freebsd.org>
[3 lines not shown]
sglist: Cosmetic cleanups to sglist_join
- Don't create an out-of-bounds pointer in flast. Instead, use NULL
for the case that first is empty for a more deterministic failure.
- Use a helper variable to de-duplicate an expression
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D62005
sglist: Correct order of operands to bcopy in sglist_join
This was trashing the second list with uninitialized garbage from the
first list.
Reviewed by: markj
Fixes: b36cfff75df4 ("Add a simple API to manage scatter/gather...")
Differential Revision: https://reviews.freebsd.org/D62004
sglist: Avoid an out-of-bounds access in sglist_append_sglist
If the destination sglist is empty, then the first matching segment
from the source sglist should be added as the first segment in the
destination list. This happened to work by accident when sg_nseg was
a u_short as ss pointed to the sglist header which never had a
matching paddr so _sglist_append_range fell through to appending a new
range, but that was still buggy. After sg_nseg changed to an unsigned
int, the initial ss now points way out of range on 64-bit platforms
resulting in reading from a random (possibly unmapped) kernel address.
Reported by: llm-postcr
Reviewed by: markj
Fixes: 00f6cd3f5682 ("Add sglist_append_sglist().")
Differential Revision: https://reviews.freebsd.org/D62003
mgb: Add PCI11010 support
The Microchip PCI11010 is a PCIe switch with embedded multi-Gigabit
Ethernet controller. Only a new PCI ID is needed, as commit
da8a529bc01f ("mgb: support for PCI11414.") added required new
functionality.
Reviewed by: br
Sponsored by: The FreeBSD Foundation
Sponsored by: Microchip (hardware)
Differential Revision: https://reviews.freebsd.org/D62208
nvme: do not submit Abort commands with the qpair lock held
The Abort for a timed-out admin command is submitted to the queue
whose lock the watchdog holds. For an I/O command, a failed admin
queue completes the Abort during submission, and nvme_abort_complete()
takes the I/O takes the I/O qpair lock again.
Either way the thread recurses on a non-recursive mutex.
Abort command: NVM Express Base Specification 2.4, section 5.2.1.
Fixes: 2a6b7055a980 ("nvme: Timeout expired transactions")
Reviewed by: rz_fabmicro.ru, ngie
Differential Revision: https://reviews.freebsd.org/D61625
unr(9): fix iterator with trivial unit allocations
Hoist the check that we've scanned all the unrs to the top of the
loop since none might have been allocated e.g., if we've only used
allocated units in order with alloc_unr() and never freed any.
Add a test of the trivial case.
Reviewed by: kib, markj
Sponsored by: Innovate UK
Fixes: a014e0a3987a ("unr(9): add iterator interface")
Differential Revision: https://reviews.freebsd.org/D62139
dummynet: mark sysctls as CTLFLAG_VNET
sysctl_hash_size() and sysctl_limits() read and write V_dn_cfg, the current
VNET's dummynet configuration, but their sysctls lack CTLFLAG_VNET, so a VNET
jail reads its own values (100 slots, 64 buckets) and cannot set them: a queue
longer than 100 packets cannot be configured in a jail, and the host's setting
Reviewed by: kp
Sponsored by: Rubicon Communications, LLC ("Netgate")
pf: fix error handling in pf_ioctl_addrule()
If we bail out of pf_ioctl_addrule() before the pf_addr_setup() calls
the subsequent pf_free_rule() will end up dereferencing a NULL pointer.
Check for NULL before freeing dynaddr or tables.
PR: 301184
Submitted by: laamalif at proton.me
Reviewed by: kp
Sponsored by: Rubicon Communications, LLC ("Netgate")
pfsync: account for second tickover in bulk updates
When one peer requests a bulk update it keeps track of when it sent this
request. The exporting peer includes 'endtime', indicating how long it
took to send the entire update along with its final message.
That allows the receiving peer to verify that the entire update was done
in response to its most recent request. However, due to different second
tickovers this calculation might be off by one.
Use milliseconds internally. This does not change the wire protocol,
'endtime' is still expressed in seconds. When the exporting peer
computes this value it will implicitly round down.
PR: 300824
Sponsored by: Rubicon Communications, LLC ("Netgate")
cpufreq_dt: Do not use an uninitialised OPP when restoring the state
cpufreq_dt_set() only looks up the current OPP (copp) when the voltage
cannot be read from the regulator. When it can, which is the usual
case, copp is never set but the two error paths that restore the
previous state still use it: a failure to set the clock reads the
voltage limits of copp and a failure to lower the voltage reads its
frequency.
Restore the frequency with the one that was read from the clock before
the change, and look up the current OPP when the voltage has to be
restored, skipping it if there is none.
Fixes: a701764e9c50 ("Improve cpufreq_dt.")
Reported by: llm-postcr
cpufreq_dt: Use all the OPPs when the hardware version is unknown
An OPP with opp-supported-hw is only used if the hardware version, given
by the vendor specific code, matches it. When no vendor class handles
the OPP table, for example the ones of the TI and i.MX SoCs, the version
is unknown, so every OPP that has the property was dropped and the table
ended up empty. The driver still attached and cpufreq_dt_find_opp()
returned a pointer to an entry that does not exist, using an
uninitialised index.
Use all the OPPs when the hardware version is unknown, as if the
property was not there, which is what the driver did before the
property was honored. Also make cpufreq_dt_find_opp() return NULL for
an empty table, as its callers already expect.
Fixes: 7178a47a4ffd ("cpufreq_dt: Honor opp-supported-hw and opp-microvolt-<name>")
Reported by: llm-postcr
rtwn: fix the build without RTWN_DEBUG
RTWN_DPRINTF() compiles to nothing without RTWN_DEBUG, which leaves four
of the IQK result copies in r92f_iq_calib() set but never read. Kernels
with "device rtwn" in their config, LINT among them, then fail with
-Werror,-Wunused-but-set-variable. The module build does not hit this
because its generated opt_rtwn.h always defines RTWN_DEBUG.
Print the result array directly and drop the four locals.
Fixes: 1f0e186e1832 ("rtwn: added support for Realtek RTL8192FU...")
Sponsored by: Rubicon Communications, LLC ("Netgate")
amd64: Avoid redundant CR0 writes on switches to kernel threads
fpu_activate_sw() sets CR0.TS whenever it switches to a kernel thread,
or to a thread inside fpu_kern_enter(). The bit is clear only while a
thread owns the FPU, and at a context switch the only possible owner is
the old thread. When fpcurthread is NULL the bit is already set and
the write to CR0, which is serializing, changes nothing. That is the
common case for switches between kernel threads, such as the idle
thread and interrupt threads on a router.
Write CR0 only when fpcurthread was set, as cpu_switch() did before
the eager FPU switch became the default in d1a07e31e5cc, and assert
that TS is set otherwise.
Reviewed by: kib
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D62206
nfsclrdma: Fix a few things in the RDMA client module
This patch fixes a few things in the nfsclrdma module:
- A typo that caused _rpcrdma_get_srcaddr() to return 0
when it should have returned 1.
- Don't consider a server returning RPC_SYSTEMERROR or
RPC_FAILED as needing a new connection, to be compatible
with clnt_vc.c for TCP.
- Fix off by one checks in the KASSERT()s for the RPC index.
Reported by: llm-postcr
MFC after: 1 month
Fixes: 80bee4d83637 ("nfsclrdma: Add code to support client side NFS over RDMA")
libsys: link internal copies of fls*(3), str*(3), and mem*(3) functions used by libsys
To avoid undef symbols which get resolved from libc.
Reviewed by: brooks, jrtc27
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62131
libsys: do not link in csu, and compile as freestanding
This is a library below implementation of the C runtime. It should not
(and really cannot) use any of that.
In particular, libsys no longer has undef __cxa_finalize.
Reviewed by: brooks, jrtc27
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62131
libsys: this is libsys, not libc
Reviewed by: brooks, jrtc27
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62131
libsys: avoid depending on libc _once()
The __init_elf_aux_vector() function is idempotent, so do not bother
ensuring a single call. Just tolerate a possible race.
Reviewed by: brooks, jrtc27 (previous version)
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D62131
vm_pageout: Recheck PGA_SWAP_FREE after locking
vm_pageout_scan_active() reads PGA_SWAP_FREE without the object lock,
and once VM_OBJECT_TRYWLOCK() succeeds it calls
vm_pager_page_unswapped() without rereading the flag. In between,
another thread can move the page to the laundry, e.g., by performing
madvise(MADV_DONTNEED) on a dirty page, where swap_pager_putpages()
clears PGA_SWAP_FREE and assigns a new swap block. Then, the scan frees
that block, perhaps while the write to it is still in flight, and the
page's contents are lost or corrupted.
Recheck the flag with the object locked, and document the rule where
the flag is defined.
Found by: Claude Code (Opus 5.5)
Reviewed by: kib, markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D62202
i386/sdt: Use a single NOP for disabled probes
As on amd64, a disabled tracepoint must be a single instruction, so
that a thread cannot be interrupted inside it and resume in the middle
of the jump written when the probe is enabled. On i386, both
_SDT_ASM_PATCH_INSTR and sdt_tracepoint_restore() used five one-byte
NOPs.
Use "leal %ds:0(%esi,%eiz,1), %esi" (3e 8d 74 26 00) instead. The
multi-byte NOP (0f 1f) is avoided because i386 GENERIC still supports
CPUs without it.
Tested on stable/15 i386 under bhyve with a reproducer that toggles a
probe while other CPUs run its sites.
Reviewed by: markj
MFC after: 1w
Co-authored-by: Claude Opus 5.5
Differential Revision: https://reviews.freebsd.org/D62198
rtwn: added support for Realtek RTL8192FU chipset
Added support for Realtek RTL8192FU chipset using rtwn driver.
* Used Linux's rtl8xxxu driver for reference.
* New registers derived from it are saved in r92f_reg.h.
* Current additions include:
IQ/LC calibration, channel configuration, LED configuration.
* Firmware image added as uuencoded rtwn-rtl8192fufw.fw.uu with a new
rtwnfw/rtwnrtl8192fu module.
Sponsored by: Alchemilla Ventures Private Limited
Reviewed by: adrian
Differential Revision: https://reviews.freebsd.org/D61728
hid: Increase HID_ITEM_MAXUSAGE to 32
I have a Logitech mouse that reports 16 buttons. Bump to 32 to be a
little more future proof. This increases the size of struct hid_item
but this struct is not exported to userland.
Reviewed by: wulf
Differential Revision: https://reviews.freebsd.org/D59273
(cherry picked from commit 5cc15fef2656b078982d453b8915379b47ff0e88)
hid: Increase HID_ITEM_MAXUSAGE to 32
I have a Logitech mouse that reports 16 buttons. Bump to 32 to be a
little more future proof. This increases the size of struct hid_item
but this struct is not exported to userland.
Reviewed by: wulf
Differential Revision: https://reviews.freebsd.org/D59273
(cherry picked from commit 5cc15fef2656b078982d453b8915379b47ff0e88)
powerpc: Add first Linuxulator support (ELFv1, BE, powerpc64)
Introduce the first cut of the Linuxulator for powerpc64. This was a
GSoC project for 2022, and consists of the following:
* ELFv1
* Limited shared page (no timekeep fallback)
* Most, if not all, syscalls are implemented, all common ones, no
arch-specific ones.
At completion of the GSoC period this was able to run through the LTP
test suite, with a very high pass rate. More work remains, as always,
and will be done as needed.
Further work is still necessary, but this lays the groundwork. Expected
future work includes:
* ELFv2
* 32-bit support (running legacy Linux applications)
[4 lines not shown]