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
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
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
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]
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
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
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
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
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)
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)
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]
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
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)
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
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
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
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
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")
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")
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")
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
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
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
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