FreeBSD/src ed8b9bf — sys/sys pmc.h

hwpmc: include PMC_CLASS_PERF in the PMC class range

PMC_CLASS_PERF (0x1a) was added after PMC_CLASS_RAPL, but
PMC_CLASS_LAST was left at PMC_CLASS_RAPL.

Signed-off-by:  Osvaldo Janeri Filho <ojanerif at amd.com>
Reviewed by:    Anderson Nascimento <anascime at amd.com>, mhorne
Fixes:          5369f8e73eff ("hwpmc: add MPERF/APERF MSR support for AMD/Intel CPUs")
Sponsored by:   AMD
Differential Revision:  https://reviews.freebsd.org/D60546
DeltaFile
+1-1sys/sys/pmc.h
+1-11 files

FreeBSD/src a94a632 — tests/sys/netpfil/pf Makefile pfctl_adopt.py

pf tests: exercise pfctl -l across a privilege drop

Open /dev/pf and a generic Netlink socket as root, drop to nobody and
exec pfctl with both inherited, the way authpf(8) runs it. Without -l
the load is refused with EPERM; with it the rules land in the anchor.
An unusable descriptor is an error, not a fallback to a new socket.
Skips when fdescfs is not mounted, which -p /dev/fd/N needs.

PR:             291981
Signed-off-by:  Avinash Duduskar <avinash.duduskar at gmail.com>
Reviewed by:    kp
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2508
DeltaFile
+75-0tests/sys/netpfil/pf/authpf.sh
+43-0tests/sys/netpfil/pf/pfctl_adopt.py
+3-0tests/sys/netpfil/pf/Makefile
+121-03 files

FreeBSD/src 3d5bd2c — contrib/pf/authpf authpf.c

authpf: deny tracing of the pfctl child

The child runs pfctl as the user with authpf's root-opened /dev/pf and
Netlink descriptors. Its real and effective ids match at the exec, so
the kernel clears P_SUGID and any other process of the user could attach
to it and take both descriptors. Deny tracing across the exec; root can
still attach, and core dumps are not affected.

PR:             291981
Signed-off-by:  Avinash Duduskar <avinash.duduskar at gmail.com>
Reviewed by:    kp
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2508
DeltaFile
+14-0contrib/pf/authpf/authpf.c
+14-01 files

FreeBSD/src 6749320 — contrib/pf/authpf authpf.c

authpf: pass the privileged Netlink socket to pfctl

authpf opens its pf handle as root and drops privileges before it runs
pfctl to load the per-user ruleset. The child inherits the /dev/pf
descriptor through -p /dev/fd/N, but since pf's control path moved to
Netlink, pfctl opens a Netlink socket of its own, which carries the
unprivileged credentials, and the first privileged command on it fails:
every authpf login ends with "pfctl exited abnormally" on 15.x.

Pass the socket authpf already holds with the new -l flag, next to the
device. Clear FD_CLOEXEC on both descriptors before the exec so the
handoff does not depend on how libpfctl happened to open them.

The socket already reached the child: neither libpfctl nor snl opens
its descriptors close-on-exec and authpf closes nothing before the exec,
so since pf moved to Netlink the unprivileged pfctl has inherited it
unused. Passing its number makes the handoff deliberate. The socket
carries root's credentials for every generic Netlink family, so the
child could reach pflow, carp and the kernel RPC family through it, not

    [6 lines not shown]
DeltaFile
+24-11contrib/pf/authpf/authpf.c
+24-111 files

FreeBSD/src 87a5d76 — sbin/pfctl pfctl.8 pfctl.c

pfctl: add -l to use an inherited Netlink socket

pf's Netlink commands are checked against the credentials of the socket,
so a socket opened by a privileged process keeps its authority across a
privilege drop and exec, as the /dev/pf descriptor passed as -p
/dev/fd/N already does. -l takes the descriptor number of such a socket
and uses it for every request instead of creating a new one.

authpf(8) uses this to run pfctl as the logged-in user.

PR:             291981
Signed-off-by:  Avinash Duduskar <avinash.duduskar at gmail.com>
Reviewed by:    kp
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2508
DeltaFile
+15-4sbin/pfctl/pfctl.c
+11-1sbin/pfctl/pfctl.8
+26-52 files

FreeBSD/src 727e413 — lib/libpfctl libpfctl.h libpfctl.c

libpfctl: add pfctl_open_from_nl_fd() and pfctl_nl_fd()

pfctl_open_from_nl_fd() opens the pf device as pfctl_open() does but,
when given a descriptor, adopts it as the Netlink socket instead of
creating one. The handle's sequence numbers start at a random value:
replies are matched by sequence number, so a random start makes it
improbable that a reply an earlier owner of the socket left unread is
taken for the answer to one of ours, or one of ours for theirs, however
many times the socket has been handed on. pfctl_open() becomes a
wrapper that passes -1.

pfctl_nl_fd() returns the handle's Netlink descriptor, as pfctl_fd()
does for the device, so a caller can hand it to a child process.

PR:             291981
Signed-off-by:  Avinash Duduskar <avinash.duduskar at gmail.com>
Reviewed by:    kp
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2508
DeltaFile
+25-3lib/libpfctl/libpfctl.c
+3-0lib/libpfctl/libpfctl.h
+28-32 files

FreeBSD/src e4c78de — share/man/man3 snl.3, sys/netlink netlink_snl.h

netlink_snl: add snl_init_fd() to adopt an already open socket

snl_init() always creates its own socket. Split out snl_init_fd(), which
initialises the state on a descriptor the caller already holds, and make
snl_init() open the socket and hand it over. The state owns the
descriptor either way, including when initialisation fails, and
snl_free() closes it; snl_clone() remains the way to borrow one.

pfctl(8) needs this to run on a socket inherited from authpf(8).

PR:             291981
Signed-off-by:  Avinash Duduskar <avinash.duduskar at gmail.com>
Reviewed by:    kp
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2508
DeltaFile
+17-1share/man/man3/snl.3
+12-4sys/netlink/netlink_snl.h
+29-52 files

FreeBSD/src 489ded6 — sys/netlink netlink_snl.h

netlink_snl: make snl_free() safe to call twice

snl_init() calls snl_free() on its own failure paths but leaves the
state marked initialised and the buffer pointers set, so a caller that
also frees the state on failure, as libpfctl's pfctl_open() does, closes
the descriptor twice and, on the lb_init() failure path, frees the
buffer twice. Reset what snl_free() releases so a second call is a
no-op.

Signed-off-by:  Avinash Duduskar <avinash.duduskar at gmail.com>
Reviewed by:    kp
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2508
DeltaFile
+8-2sys/netlink/netlink_snl.h
+8-21 files

FreeBSD/src 949ebeb — sys/dev/hwpmc hwpmc_mod.c

hwpmc: return errors from PMC_OP_PMCGETMSR

pcd_get_msr() returns a positive errno, but only a negative value was
treated as a failure, so errors were reported as success.

Signed-off-by:  Osvaldo Janeri Filho <ojanerif at amd.com>
Reviewed by:    mhorne
MFC after:      3 days
Sponsored by:   AMD
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2461

(cherry picked from commit 911fcebfc7f1e5a5dd184137c0b9d62b4b066f17)
DeltaFile
+1-1sys/dev/hwpmc/hwpmc_mod.c
+1-11 files

FreeBSD/src 466b286 — lib/libpmc libpmc_pmu_util.c

libpmc: fix the family check for the AMD DF event encoding

The check compares cpu_family with decimal 19 instead of 0x19, so
Families 17h and 19h get the Family 1Ah DF encoding.

Signed-off-by:  Osvaldo Janeri Filho <ojanerif at amd.com>
Reviewed by:    mhorne
Fixes:          00c0a1f0bf6c ("hwpmc: Fix PMC flags for AMD Zen cores")
MFC after:      3 days
Sponsored by:   AMD
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2461

(cherry picked from commit ca9c5718017fc34d34f2dfe90020644aad3588d3)
DeltaFile
+1-1lib/libpmc/libpmc_pmu_util.c
+1-11 files

FreeBSD/src 64cbdf1 — sys/dev/hwpmc hwpmc_x86.c

hwpmc(4): stop overwalking past _start on amd64 user callchains

pmc_save_user_callchain() emits the pc it just loaded before checking
whether fp is the ABI's zero frame-chain terminator. At the bottom of
a well-formed chain under _start, fp comes back 0 as expected, but the
paired pc is stale rtld data left on the stack -- a legal userspace VA
that still passes PMC_IN_USERSPACE(), so it gets emitted as a bogus
extra frame. This shows up in flame graphs as a spurious hex-valued
root frame below _start.

Check fp == 0 alongside the existing checks before emitting, matching
how arm/arm64/powerpc already load the next fp before their check.

Measured via 1kHz hwpmc sampling on an OCA: stacks with any unresolved
hex frame drop from 23.9% to 1.3%, and stacks with hex at the root drop
from 5.5% to 0.3%.

Reviewed by:    mhorne, Ali Mashtizadeh <ali at mashtizadeh.com>, gallatin
MFC after:      3 days

    [4 lines not shown]
DeltaFile
+2-1sys/dev/hwpmc/hwpmc_x86.c
+2-11 files

FreeBSD/src e3ba0d3 — sys/dev/usb/net if_smsc.c

smsc: Add Microchip EVB-LAN8670-USB 10BASE-T1S USB adapter

Reviewed by:    adrian
Sponsored by:   The FreeBSD Foundation
DeltaFile
+1-0sys/dev/usb/net/if_smsc.c
+1-01 files

FreeBSD/src 83d0eed — sys/conf files, sys/dev/mii miidevs lan867xphy.c

lan867xphy: New driver for Microchip LAN8670/1/2 10BASE-T1S PHYs

10BASE-T1S is a Single Pair Ethernet (SPE) standard, intended for
automotive and industrial applications.  It supports a multidrop "mixing
segment" of at least 25m with up to 8 nodes.

This driver currently does not support per-silicon-revision config or
PHY-Level Collision Avoidance (PLCA), but is sufficient for establishing
basic connectivity.

Device details are available in the "Microchip LAN8670/1/2 10BASE-T1S
Ethernet PHY Transceiver Datasheet".

Reviewed by:    adrian
Differential Revision: https://reviews.freebsd.org/D60979
DeltaFile
+110-0sys/dev/mii/lan867xphy.c
+3-1sys/modules/mii/Makefile
+1-0sys/dev/mii/miidevs
+1-0sys/conf/files
+115-14 files

FreeBSD/src b166461 — sys/modules/hwpmc Makefile

sys/modules/hwpmc/Makefile: tidy up

This module has several source files, with many conditional on the
platform architecture. Make it easier to read, and better for future
diffs against these lists.

- Convert to one SRC per line
- Simplify arm/armv7 condition
- Remove now-empty header comment
- Minor formatting

MFC after:      1 week
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit cac0eab342c702dc73e566e2038208c0bbc8fbd3)
DeltaFile
+36-27sys/modules/hwpmc/Makefile
+36-271 files

FreeBSD/src 9bd3091 — lib/libthr/tests Makefile pthread_query_test.c

libthr: test pthread_query_np(3) and pthread_query_all_np(3)

Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D60838
DeltaFile
+123-0lib/libthr/tests/pthread_query_test.c
+1-0lib/libthr/tests/Makefile
+124-02 files

FreeBSD/src 7e904a6 — share/man/man3 Makefile pthread_query_np.3

man3: document pthread_query_np(3) and pthread_query_all_np(3)

Reviewed by:    aokblast, markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D60838
DeltaFile
+254-0share/man/man3/pthread_query_np.3
+2-0share/man/man3/Makefile
+256-02 files

FreeBSD/src 588bd8b — include pthread_np.h, lib/libthr pthread.map

libthr: pthread_query_np(3) and pthread_query_all_np(3)

Reviewed by:    aokblast, markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D60838
DeltaFile
+116-0lib/libthr/thread/thr_query.c
+30-0include/pthread_np.h
+2-0lib/libthr/pthread.map
+1-0lib/libthr/thread/Makefile.inc
+149-04 files

FreeBSD/src 7f309ac — lib/libc/include libc_private.h, lib/libthr/sys thr_error.c

libc: provide the declaration for __libsys_errno in libc_private.h

Reviewed by:    aokblast, markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D60838
DeltaFile
+0-2lib/libthr/thread/thr_rtld.c
+0-2lib/libthr/sys/thr_error.c
+2-0lib/libc/include/libc_private.h
+2-43 files

FreeBSD/src 49e0c62 — lib/libthr/thread thr_exit.c thr_list.c

libthr: fix the race between pthread_getname_np() and thread exit

The exiting thread frees the thread name in exit_thread() without
holding the thread lock.  This makes it possible for a thread doing
pthread_getname_np() to observe the non-null thread->name and try to
copy its content, accessing the memory after free.

Set the thread->name to NULL under the thread lock.  Note that other
thread might still set the exiting thread name, until the PS_DEAD state
is assigned.  Since code should not call free() after
_malloc_thread_cleanup(), re-check thread->name in _thr_free().

Reviewed by:    aokblast, markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D60838
DeltaFile
+4-0lib/libthr/thread/thr_list.c
+2-0lib/libthr/thread/thr_exit.c
+6-02 files

FreeBSD/src 880d299 — sys/amd64/amd64 trap.c

amd64 FRED: get out of NMI blocking mode unconditionally

When NMI interrupted userspace (ring 3), unconditionally unblock NMI,
not only for the pmc backtrace sampling. Return to userspace needs
to deliver ASTs and do userret(), which should not be done with NMIs
blocking.

Note that NMI from ring 3 is always delivered at stack level 0, i.e. the
thread's kernel stack.

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
DeltaFile
+1-1sys/amd64/amd64/trap.c
+1-11 files

FreeBSD/src 91d9fbb — sys/amd64/amd64 trap.c

amd64 FRED: enable interrupts after user EXTINTs and NMIs

This is needed to run userret() with interrupts enabled.

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
DeltaFile
+3-3sys/amd64/amd64/trap.c
+3-31 files

FreeBSD/src 614b659 — sys/amd64/amd64 genassym.c exception.S

amd64 FRED: use symbolic constant for the NMI unblocking bit for ERETS

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
DeltaFile
+2-1sys/amd64/amd64/exception.S
+1-0sys/amd64/amd64/genassym.c
+3-12 files

FreeBSD/src 2e9ac12 — sys/netpfil/pf pf.c

pf: fix pf_krule_item memory leak during counters:match_fail

If pf_counters_inc() did not increment the counters because the rule
failed to apply it potentially failed to free match rules (which were
not bound to a state already).

Do so.

While here explicitly hand match_rules over from the pf_test_ctx to the
state so we never list them in two places.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+3-1sys/netpfil/pf/pf.c
+3-11 files

FreeBSD/src 9e7d555 — sys/net pfvar.h, sys/netpfil/pf pf_nl.c pf_norm.c

pf: remove armv7-specific counter code

The armv7 specific counter code is less useful now that armv7 is
basically end-of-life.

This removes a lot of armv7-specific code.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+6-262sys/net/pfvar.h
+20-156sys/netpfil/pf/pf.c
+40-112sys/netpfil/pf/pf_ioctl.c
+15-46sys/netpfil/pf/pf_if.c
+12-20sys/netpfil/pf/pf_norm.c
+6-25sys/netpfil/pf/pf_nl.c
+99-6212 files not shown
+103-6258 files

FreeBSD/src 2636cc0 — sys/netpfil/pf pf_ioctl.c

pf: have DIOCXBEGIN/DIOCXROLLBACK/DIOCXCOMMIT use the new functions

The netlink begin/rollback/commit code has separate functions for this.
Deduplicate the code and just use those functions.

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+39-285sys/netpfil/pf/pf_ioctl.c
+39-2851 files

FreeBSD/src a7aad5b — lib/libpfctl libpfctl.c, sbin/pfctl pfctl_parser.c pfctl.c

pf: convert DIOCXBEGIN, DIOCXROLLBACK, DIOCXCOMMIT to netlink

Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+224-0sys/netpfil/pf/pf_ioctl.c
+200-0lib/libpfctl/libpfctl.c
+145-0sys/netpfil/pf/pf_nl.c
+41-33sbin/pfctl/pfctl.c
+0-37sbin/pfctl/pfctl_parser.c
+18-0sys/net/pfvar.h
+628-705 files not shown
+673-7611 files

FreeBSD/src 0974ef0 — sys/dev/virtio/network if_vtnet.c

vtnet: honor the advertised MTU limit on attach

When VIRTIO_NET_F_MTU is negotiated, virtio_net_config.mtu specifies
the maximum MTU the driver may use. vtnet_ioctl_mtu() enforces this
limit for subsequent MTU changes, but ether_ifattach() unconditionally
initializes the interface MTU to ETHERMTU (1500).

So a device advertising a maximum below 1500 starts with an MTU above
its limit. So make sure to set the initial MTU no larger than
vtnet_max_mtu. That is, for vtnet_max_mtu less than 1500
interface MTU will be set to this value, otherwise the current behaviour
is preserved, MTU will be set to 1500.

Reviewed by:    kfv, tuexen
Sponsored by:   The FreeBSD Foundation
MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D60980
DeltaFile
+2-0sys/dev/virtio/network/if_vtnet.c
+2-01 files

FreeBSD/src e32b082 — sys/conf files.arm64, sys/dev/clk/rockchip rk_cru.c rk_cru.h

clk: rockchip: Add the MMC phase clock

Add a clock node type for the Rockchip MMC sample and drive clocks.  These
clocks have a phase in degrees controlled by a delay line and a fine-grained
phase selector, and implement the new clknode phase methods.

Reviewed by:    mmel
Differential Revision:  https://reviews.freebsd.org/D60886
DeltaFile
+219-0sys/dev/clk/rockchip/rk_clk_mmc.c
+41-0sys/dev/clk/rockchip/rk_clk_mmc.h
+18-0sys/dev/clk/rockchip/rk_cru.h
+3-0sys/dev/clk/rockchip/rk_cru.c
+1-0sys/conf/files.arm64
+282-05 files

FreeBSD/src 2a6580e — sys/cam/mmc mmc_da.c

mmccam: Add a helper to change the host settings

The same five lines to build and send an XPT_SET_TRAN_SETTINGS request to the
controller were repeated for the bus timing, bus width, VCCQ and clock
changes.  Add sdda_set_host_ios() and use it at those places.

No functional change.

Reviewed by:    bz
Differential Revision:  https://reviews.freebsd.org/D60921
DeltaFile
+22-36sys/cam/mmc/mmc_da.c
+22-361 files

FreeBSD/src a2ae5a2 — sys/dev/clk clk.h clknode_if.m

clk: Add a clknode method to get and set the phase

Add clknode_get_phase/clknode_set_phase (and the clk_get_phase and
clk_set_phase consumer API) so that clocks which can shift their phase,
such as the MMC sample and drive clocks of some SoCs, can expose it.

Reviewed by:    mmel
Differential Revision:  https://reviews.freebsd.org/D60883
DeltaFile
+58-0sys/dev/clk/clk.c
+20-0sys/dev/clk/clknode_if.m
+4-0sys/dev/clk/clk.h
+82-03 files