FreeBSD/src 3b0b9eb — sys/kern subr_epoch.c

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]
DeltaFile
+13-5sys/kern/subr_epoch.c
+13-51 files

FreeBSD/src a9067a5 — sys/dev/rge if_rge.c

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
DeltaFile
+6-0sys/dev/rge/if_rge.c
+6-01 files

FreeBSD/src e3ded94 — sys/dev/rge if_rgevar.h if_rgereg.h

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]
DeltaFile
+153-0sys/dev/rge/if_rge.c
+4-0sys/dev/rge/if_rge_sysctl.c
+2-0sys/dev/rge/if_rgereg.h
+1-0sys/dev/rge/if_rgevar.h
+160-04 files

FreeBSD/src 3719269 — sys/kern subr_sglist.c

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
DeltaFile
+8-3sys/kern/subr_sglist.c
+8-31 files

FreeBSD/src 7b8f10e — sys/kern subr_sglist.c

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
DeltaFile
+1-1sys/kern/subr_sglist.c
+1-11 files

FreeBSD/src a4ccfb2 — sys/kern subr_sglist.c

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
DeltaFile
+17-5sys/kern/subr_sglist.c
+17-51 files

FreeBSD/src efda129 — tests/sys/netpfil/pf pfsync_upd_c.py

tests/pfsync_upd_c: only import necessary scapy modules

This test currently fails in Jenkins CI[0] because the runner
does not have an /etc/resolv.conf file while scapy expects one[1].

Instead, avoid the full scapy.all import path (which calls
read_nameservers(...)) and only import the modules we need.

[0] https://ci.freebsd.org/job/FreeBSD-main-amd64-test/30046/testReport/sys.netpfil.pf/pfsync/stale_upd_c/
[1] https://github.com/secdev/scapy/blob/123e241/scapy/arch/common.py#L176

Fixes:          4a97b40891f0 ("pfsync: don't apply a stale dst peer...")
MFC after:      3 days
Reviewed by:    ngie
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D62141
DeltaFile
+4-2tests/sys/netpfil/pf/pfsync_upd_c.py
+4-21 files

FreeBSD/src 0b2cc30 — share/man/man4 mgb.4, sys/dev/mgb if_mgb.h if_mgb.c

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
DeltaFile
+3-1share/man/man4/mgb.4
+3-0sys/dev/mgb/if_mgb.c
+1-0sys/dev/mgb/if_mgb.h
+7-13 files

FreeBSD/src cd6143b — sys/dev/nvme nvme_private.h nvme_qpair.c

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
DeltaFile
+20-11sys/dev/nvme/nvme_qpair.c
+2-0sys/dev/nvme/nvme_private.h
+22-112 files

FreeBSD/src 3d35051 — sys/kern subr_unit.c

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
DeltaFile
+55-8sys/kern/subr_unit.c
+55-81 files

FreeBSD/src cec3503 — sys/netpfil/ipfw ip_dn_io.c

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")
DeltaFile
+3-3sys/netpfil/ipfw/ip_dn_io.c
+3-31 files

FreeBSD/src b65057a — sys/netpfil/pf pf_ioctl.c, tests/sys/netpfil/pf/ioctl validation.c

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")
DeltaFile
+73-0tests/sys/netpfil/pf/ioctl/validation.c
+8-4sys/netpfil/pf/pf_ioctl.c
+81-42 files

FreeBSD/src f3cb62f — sys/netpfil/pf if_pfsync.c

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")
DeltaFile
+9-8sys/netpfil/pf/if_pfsync.c
+9-81 files

FreeBSD/src 34b0e01 — sys/dev/cpufreq cpufreq_dt.c

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
DeltaFile
+9-3sys/dev/cpufreq/cpufreq_dt.c
+9-31 files

FreeBSD/src c54c8a5 — sys/dev/cpufreq cpufreq_dt.c

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
DeltaFile
+14-2sys/dev/cpufreq/cpufreq_dt.c
+14-21 files

FreeBSD/src 3343e51 — sys/dev/rtwn/rtl8192f r92f_calib.c

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")
DeltaFile
+5-8sys/dev/rtwn/rtl8192f/r92f_calib.c
+5-81 files

FreeBSD/src 8a8a527 — sys/amd64/amd64 fpu.c

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
DeltaFile
+11-2sys/amd64/amd64/fpu.c
+11-21 files

FreeBSD/src b75ceca — sys/ofed/drivers/infiniband/ulp/nfsclrdma clnt_rdma.c xprt_verbs.c

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")
DeltaFile
+6-6sys/ofed/drivers/infiniband/ulp/nfsclrdma/xprt_verbs.c
+2-5sys/ofed/drivers/infiniband/ulp/nfsclrdma/clnt_rdma.c
+8-112 files

FreeBSD/src 493c847 — etc/mtree BSD.tests.dist, lib/libsys Makefile

libsys: add test checking that -lsys alone is linkable

Reviewed by:    jrtc27 (previous version)
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D62131
DeltaFile
+25-0lib/libsys/tests/Makefile
+24-0lib/libsys/tests/hermetic_test.sh
+18-0lib/libsys/tests/hermetic.c
+3-0lib/libsys/Makefile
+2-0etc/mtree/BSD.tests.dist
+72-05 files

FreeBSD/src 0425a73 — lib/libsys Makefile

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
DeltaFile
+10-1lib/libsys/Makefile
+10-11 files

FreeBSD/src d64d2be — lib/libsys Makefile

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
DeltaFile
+3-0lib/libsys/Makefile
+3-01 files

FreeBSD/src 98a7f08 — lib/libsys Makefile

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
DeltaFile
+1-1lib/libsys/Makefile
+1-11 files

FreeBSD/src 2fbea17 — lib/libsys auxv.c

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
DeltaFile
+10-16lib/libsys/auxv.c
+10-161 files

FreeBSD/src 570f922 — sys/vm vm_page.h vm_pageout.c

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
DeltaFile
+8-2sys/vm/vm_pageout.c
+2-2sys/vm/vm_page.h
+10-42 files

FreeBSD/src 83d1b68 — sys/i386/include sdt_machdep.h, sys/x86/x86 sdt_machdep.c

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
DeltaFile
+6-5sys/x86/x86/sdt_machdep.c
+6-1sys/i386/include/sdt_machdep.h
+12-62 files

FreeBSD/src 1f0e186 — sys/contrib/dev/rtwn rtwn-rtl8192fufw.fw.uu, sys/dev/rtwn/rtl8192f r92f_priv.h r92f_chan.c

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
DeltaFile
+1,087-0sys/dev/rtwn/rtl8192f/r92f_calib.c
+695-0sys/contrib/dev/rtwn/rtwn-rtl8192fufw.fw.uu
+544-0sys/dev/rtwn/rtl8192f/usb/r92fu_init.c
+332-0sys/dev/rtwn/rtl8192f/r92f_chan.c
+320-0sys/dev/rtwn/rtl8192f/r92f_priv.h
+232-0sys/dev/rtwn/rtl8192f/usb/r92fu_attach.c
+3,210-034 files not shown
+4,424-1340 files

FreeBSD/src 1751658 — sys/dev/hid hid.h

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)
DeltaFile
+1-1sys/dev/hid/hid.h
+1-11 files

FreeBSD/src 16b877c — sys/dev/hid hid.h

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)
DeltaFile
+1-1sys/dev/hid/hid.h
+1-11 files

FreeBSD/src e62e2bb — sys/powerpc/linux linux_syscalls.c linux_sysent.c

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]
DeltaFile
+8,751-0sys/powerpc/linux/linux_systrace_args.c
+2,209-0sys/powerpc/linux/syscalls.master
+2,095-0sys/powerpc/linux/linux_proto.h
+765-0sys/powerpc/linux/linux_sysvec.c
+531-0sys/powerpc/linux/linux_sysent.c
+462-0sys/powerpc/linux/linux_syscalls.c
+14,813-028 files not shown
+16,739-2034 files

FreeBSD/src b030920 — sys/modules Makefile, sys/modules/linux_common Makefile

linuxulator/powerpc: Add ELFv2 and powerpc64le support

Differential Revision:  https://reviews.freebsd.org/D42992
DeltaFile
+85-2sys/powerpc/linux/linux_sysvec.c
+2-2sys/modules/linux_common/Makefile
+2-2sys/modules/Makefile
+89-63 files