Commit Graph
314739 Commits
Author SHA1 Message Date
Kenneth D. Merry 9814633f63 cam: Add NVMe reservation, format and features CCB building functions
Add NVMe CCB (union ccb / struct ccb_nvmeio) building functions for
the four NVMe reservation opcodes, Format NVM, and Get Features /
Set Features.  These use the nvme_command building blocks added to
sys/dev/nvme/nvme.h, and are used by the new camcontrol(8) nvres,
nvformat and nvfeature subcommands that will be added separately.

sys/cam/nvme/nvme_all.c:
	Add NVMe CCB building functions for the four NVMe reservation
	opcodes: nvme_resv_report(), nvme_resv_register(),
	nvme_resv_acquire() and nvme_resv_release().  Data direction
	is set internally (CAM_DIR_IN or CAM_DIR_OUT as appropriate),
	so no flags parameter is needed.

	Add a new nvme_format() CCB building function.

	Add nvme_get_feature() and nvme_set_feature() CCB building
	functions, along with nvme_get_feature_hostid() and
	nvme_set_feature_hostid() convenience wrappers for the hostid
	feature.  nvme_set_feature_hostid() takes an sv argument so
	the caller can request that the hostid persist across reset.

sys/cam/nvme/nvme_all.h:
	Add prototypes for the above.  Wrap the declarations in
	__BEGIN_DECLS / __END_DECLS so C++ compilers don't mangle the
	names of the C symbols.

Co-authored-by:	Reid Linnemann <[email protected]>
Co-authored-by:	Dave Baukus <[email protected]>
Co-authored-by:	Claude Fable 5 <[email protected]>
Reviewed by:	imp
MFC after:	1 week
Sponsored by:	Spectra Logic
Differential Revision:	https://reviews.freebsd.org/D59532
2026-11-06 20:05:54 -05:00
Kenneth D. Merry 7a9e437531 nvme: Add reservation, format and features command building support
Add command (struct nvme_command) building functions for the four
NVMe reservation opcodes (Report, Register, Acquire and Release),
Format NVM, and Get Features / Set Features, along with the
enumerations and data structures that go with them.  These are
shared between the kernel and userland, and are the underpinnings
for new camcontrol(8) subcommands (nvres, nvformat, nvfeature) that
will be added separately.

The reservation type names are intentionally similar to the SCSI
names for the same reservation types.

sys/dev/nvme/nvme.h:
  Add NVMe command building functions for the four NVMe
  reservation opcodes: nvme_ns_resv_report_cmd(),
  nvme_ns_resv_register_cmd(), nvme_ns_resv_acquire_cmd() and
  nvme_ns_resv_release_cmd().

  Add enumerated types for the various NVMe reservation
  subcommand actions (acquire, register, release), reservation
  types, and Change Persist Through Power Loss State values.

  Add struct nvme_resv_acq_data and struct nvme_resv_reg_data,
  the data payloads for reservation Acquire and Register.

  Add a new NVMe Format NVM command building function,
  nvme_admin_format_cmd(), and an enumeration for the Secure
  Erase Setting parameter for format.

  Add nvme_admin_get_feature_cmd() and
  nvme_admin_set_feature_cmd() functions to fill a struct
  nvme_command for Get Features / Set Features.

  Add macros for bitfields in the ctratt and mic dwords of the
  NVMe Identify Controller data structure.

  Add a prototype for nvme_hostid_sbuf().

  Stop byte swapping the hostid fields in
  nvme_resv_status_swapbytes() and
  nvme_resv_status_ext_swapbytes(), and document the fields as
  little endian.  The hostid is an opaque 8 or 16 byte value;
  keep it in the byte order the device returns it in instead of
  interpreting it at this level.

  Widen the nvme_ctrlr_cmd_get_feature() and
  nvme_ctrlr_cmd_set_feature() prototypes as described below.

  While here, fix the entry count clamp in the reservation status
  swapbytes functions to use sizeof(*s) rather than sizeof(s); using
  the pointer size made the clamp one entry too permissive.

sys/dev/nvme/nvme_util.c:
  Add nvme_hostid_sbuf(), which formats an 8 or 16 byte hostid
  (from the Get Features hostid feature, in the little-endian
  byte order the device returns it in) into an sbuf as an
  integer value in base 16, most significant byte first.

sbin/nvmecontrol/resv.c:
  Decode the now little-endian hostid fields explicitly when
  printing, and zero pad the printed 64-bit values.  Previously
  the extended hostid printed in a different byte order on big
  and little endian machines, and without zero padding between
  the two halves.

sys/dev/nvme/nvme_ctrlr_cmd.c:
  Refactor nvme_ctrlr_cmd_get_feature() and
  nvme_ctrlr_cmd_set_feature() to use the new command building
  functions from nvme.h and accept a namespace ID parameter.

  Refactor nvme_ctrlr_cmd_set_feature() to also accept the sv
  (save) parameter to persist a feature value across reset.

sys/dev/nvme/nvme_ctrlr.c:
  Update the temperature threshold, autonomous power state
  transition and host memory buffer callers for the new
  nvme_ctrlr_cmd_get_feature() and nvme_ctrlr_cmd_set_feature()
  arguments.

Co-authored-by:	Reid Linnemann <[email protected]>
Co-authored-by:	Dave Baukus <[email protected]>
Co-authored-by:	Claude Fable 5 <[email protected]>
Reviewed by:	imp
MFC after:	1 week
Sponsored by:	Spectra Logic
Differential Revision:	https://reviews.freebsd.org/D59531
2026-11-06 20:05:54 -05:00
Kenneth D. Merry 46198fba6d nvmecontrol: Factor out namespace Identify printing
Move print_namespace() from identify.c to identify_ext.c and rename
it to nvme_print_namespace(), to match nvme_print_controller().
This allows other consumers (notably camcontrol(8)) to print NVMe
namespace Identify data.

No functional changes intended.

sbin/nvmecontrol/identify.c:
	Remove print_namespace(), and call nvme_print_namespace()
	instead.

sbin/nvmecontrol/identify_ext.c:
	Add nvme_print_namespace(), moved here from identify.c.

sbin/nvmecontrol/nvmecontrol.h:
	Remove the print_namespace() prototype.

sbin/nvmecontrol/nvmecontrol_ext.h:
	Add the nvme_print_namespace() prototype.

sbin/nvmecontrol/ns.c:
	Include nvmecontrol_ext.h, and rename print_namespace() calls
	to nvme_print_namespace().

Co-authored-by:	Claude Fable 5 <[email protected]>
Reviewed by:	imp
MFC after:	1 week
Sponsored by:	Spectra Logic
Differential Revision:	https://reviews.freebsd.org/D59530
2026-11-06 20:05:53 -05:00
Konstantin Belousov 9dae9b31d2 libthr: require both _Unwind_ForcedUnwind and _Unwind_GetCFA for !PIC
Static linking must bring in both symbols for the unwind to work.

The landing pads added by 2734bbbcba reference _Unwind_Resume and
__gcc_personality_v0. In a static link, these pull UnwindLevel1.o
from libgcc_eh.a, which also defines _Unwind_ForcedUnwind, but
not UnwindLevel1-gcc-ext.o, which defines _Unwind_GetCFA. Unless
something else pulls that object in, as libcxxrt does for C++ programs,
thread_unwind_stop() calls a NULL _Unwind_GetCFA on every thread exit.

Reported and tested by:	dch
Fixes:	2734bbbcba ("libthr: Create landing pad in thr_once in C++ exception")
Sponsored by:	The FreeBSD Foundation
2026-11-07 01:21:08 +02:00
Richard Scheffenegger c3a05933b3 Revert "iSCSI: Fast and per-session timeouts"
This reverts commit 6129bc4b65.
2026-11-06 23:38:25 +01:00
Alexander Ziaee b556d9c9ce ports.7: Add the DEVELOPER make variable
make.conf(5) says make variables that are for the ports tree should
be documented in ports(7). Add this from the porters handbook.

MFC after:		3 days
Reviewed by:		alven
Event:			FreeBSD 2026 Vendor Summit
Differential Revision:	https://reviews.freebsd.org/D61272
2026-11-06 16:54:10 -05:00
Richard Scheffenegger 6129bc4b65 iSCSI: Fast and per-session timeouts
Support per-session configurable ping (SCSI NOP) and login timeouts
similar to what is supported in the Linux iSCSI initiator configuration file.

Reduce iscsi timer granularity to 0.1 sec.
For backwards compatibility, when all timers are selected on integer numbers,
all status messages are unchanged. If the higher granularity is used, the
log messages include sub-second granularity.

The sysctl(3) interface has changed from pure int to string, in order to
support fractional seconds in a human-readable, dotted notation.

Reviewed By: #netapp, #manpages, jhb, pauamma_chezdork.com, siderop1_netapp.com
Sponsored by: NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D32540
2026-11-06 22:21:12 +01:00
Richard Scheffenegger e0c6b88706 irdma: improve TCP header validation
iWARP handling code deals with TCP header processing outside of the normal TCP stack.
Add validation checks to verify the internal integrity of the TCP headers.

Reviewed By: tuexen, O11 Intel Networking group, #transport, bartosz.sobczak_intel.com
Sponsored by: NetApp, Inc.
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D58323
2026-11-06 21:42:45 +01:00
Mark Johnston 40371e5141 ctfconvert: Make the absence of debug info non-fatal
When compiled with gcc14, subr_ticks.o legitimately doesn't contain any
DWARF sections.  Just emit a warning in this case.  In general we still
want to run ctfconvert on asm files.

Reviewed by:	emaste, des
Fixes:		e959f2a7d8 ("ctf*: exit with error upon terminate()")
Differential Revision:	https://reviews.freebsd.org/D61231
2026-11-06 11:59:43 -05:00
Artem Bunichev d0666b1f24 uname.1: Document which flags are non-POSIX
MFC after:		3 days
Reviewed by:		ziaee
Differential Revision:	https://reviews.freebsd.org/D58476
2026-11-06 14:54:25 -05:00
Gordon Tetlow f3b6bb1404 openssl: restore removed libcrypto symbols as compat symbols
c01c0a27cb (D60397) stopped exporting 52 names from libcrypto.so.35 that
upstream does not export.  Binaries and libraries linked against the
earlier libcrypto.so.35 can still import them; the libssl.so.35 from
15.0 and 15.1 imports 15 of them, so it fails to load with the new
libcrypto.

Provide all 52 again as non-default (compat) versions, in the version
nodes they had before: OPENSSL_cpuid_setup@OPENSSL_3_0_9, the others
@OPENSSL_3_5_0.  Existing consumers resolve them; new links cannot bind
to them.  The default exports do not change and still match upstream.

The wrappers live in a new FreeBSD-only file, compat.c.  Remove it at
the next SHLIB_MAJOR bump.

Reviewed by:		ngie
Fixes:			c01c0a27cb ("openssl: make libcrypto export the same symbols as upstream")
MFC after:		2 weeks
MFC to:			stable/15
Event:			FreeBSD Vendor Summit 2026
Differential Revision:	https://reviews.freebsd.org/D61229
2026-11-06 10:54:13 -08:00
Gordon Tetlow 46453f0abb openssl: build legacy provider as upstream does
- Build with libcrypto's compile flags: modules/Makefile.inc now
  includes libcrypto's Makefile.inc, which brings in Makefile.common
  (NDEBUG, the asm dispatch defines, OPENSSL_PIC, the directory
  defines).  Before this change, assertions were enabled in legacy.so.
- Use upstream's per-architecture source list: the provider's own CPU
  capability code (cpuid asm and armcap.c/ppccap.c, or mem_clr.c
  without asm), and the MD5, RC4 and DES asm where upstream uses it.
  The provider no longer uses libcrypto's exported RC4, SHA1 and
  CRYPTO_*128 functions.
- Drop the objects that upstream's linker leaves out of legacy.so
  (fcrypt_b.c, md5_one.c, md5_sha1.c, provider_err.c and
  ciphercommon_{ccm,gcm}*.c / ciphercommon_hw.c).  Without them,
  params_idx.c is not needed either.
- Add a version script, a copy of upstream's providers/legacy.ld, so
  that only OSSL_provider_init is exported.  Around 209 symbols were
  exported before.

Reviewed by:		ngie
MFC after:		2 weeks
MFC to:			stable/15
Event:			FreeBSD Vendor Summit 2026
Differential Revision:	https://reviews.freebsd.org/D60398
2026-11-06 10:42:45 -08:00
Christos Margiolis 8fb539b081 amd64/vmm: Don't advertise AMD PerfMonV2 or performance counters
vmm does not handle CPUID leaf 0x80000022, so a FreeBSD guest on a
Family 19h or later host panics on "kldload hwpmc", which trusts the
PerfMonV2 bit and writes AMD_PMC_GLOBAL_CTL.

Tested by:	Osvaldo Janeri Filho <[email protected]>
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Reviewed by:	markj, kib
Differential Revision:	https://reviews.freebsd.org/D61141
2026-11-06 16:57:18 +01:00
Christos Margiolis 0efaebd5ab hwpmc: Decline the AMD PerfMonV2 path when GLOBAL_CTL is absent
The v2 path writes AMD_PMC_GLOBAL_CTL whenever the PerfMonV2 CPUID bit
is set. bhyve passes that bit through from the host but does not emulate
the register, so loading hwpmc in a guest on a Family 19h or later host
panics the kernel.

amd_v2_hwcheck_cpu() already probes EVSEL MSRs, so probe GLOBAL_CTL
there too, in order to reject the v2 path and fall back to the generic
CPU class.

Fixes:		9d30640105 ("hwpmc_amd: add PerfMonV2 global-control path")
Tested by:	Osvaldo Janeri Filho <[email protected]>
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Reviewed by:	mhorne, [email protected]
Differential Revision:	https://reviews.freebsd.org/D61133
2026-11-06 16:57:12 +01:00
Andrew Turner e82b2913b7 arm64/acpica: Fix the IORT MSI xref type
The acpi IORT code incorrectly uses a u_int as the MSI xref type, while
INTRNG expects an intptr_t. Switch to using intptr_t to help document
this value is the xref for the MSI controller.

Reviewed by:	dsl
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D60653
2026-11-06 15:38:51 +00:00
Sarah Walker f0b589edc7 arm64/pmap: Add support for FEAT_TTL
FEAT_TTL adds a Translation Table Level field for TLB maintenance intructions,
to indicate the level holding the leaf address for the address being
invalidated. This can reduce the cost of TLB invalidation.

Reviewed by:	andrew
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D60090
2026-11-06 15:38:51 +00:00
Andre Silva e5a48c8e0d hwpmc: release a PMC whose ID could not be copied out
If copyout of the newly allocated PMC ID fails, the caller cannot use or
release the PMC. Release it in the kernel.

Reviewed by:	mhorne
MFC after:	3 days
Sponsored by:	Advanced Micro Devices, Inc.
Differential Revision:	https://reviews.freebsd.org/D60562
2026-11-06 11:21:45 -04:00
Osvaldo Janeri Filho fdfb611461 tests: add a regression test for the orphaned IBS NMI
Toggle IBS op and fetch through /dev/cpuctl0 with hwpmc loaded and
check that every NMI hwpmc declined was claimed.  Without the fix both
cases fail on an EPYC 9654.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	AMD
Signed-off-by: Osvaldo Janeri Filho <[email protected]>
Differential Revision:	https://reviews.freebsd.org/D60766
2026-11-06 10:50:59 -04:00
Osvaldo Janeri Filho f5304e44ff cpuctl, x86: claim IBS NMIs orphaned by control MSR writes
A cpuctl(4) write that stops or reprograms IBS can clear the valid bit
of a sample whose NMI is already raised.  hwpmc then declines the NMI,
no other handler claims it, and with the default machdep.panic_on_nmi
the system panics.

Have nmi_handle_intr() claim, after all handlers declined it, one NMI
per cpuctl write to an IBS control MSR.  Claiming last, rather than
from a cpuctl NMI handler, cannot take an NMI away from hwpmc.

cpuctl.ko now needs the new kernel symbols; an MFC has to update both.

Reproduced on an EPYC 9654 by toggling IBS op through /dev/cpuctlN:
about one unclaimed NMI per 2000 toggles.

Reviewed by:	kib
MFC after:	2 weeks
Sponsored by:	AMD
Signed-off-by: Osvaldo Janeri Filho <[email protected]>
Differential Revision:	https://reviews.freebsd.org/D60765
2026-11-06 10:50:59 -04:00
Brooks Davis 675739153b sys/security/audit: add kern_ implementations
Effort:		CHERI upstreaming
Sponsored by:	Innovate UK
PR:		https://github.com/freebsd/freebsd-src/pull/2284
2026-11-06 13:58:14 +00:00
Konstantin Belousov 57bc1e1c2f amd64: make hw.splitlock_force adjustable at runtime
The setting is only read on exec(2), so it can be safely modified.
This is useful to adapt the system to newly discovered buggy programs
without reboot.

Note that that running processes keep their mode until they exec again.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2026-11-06 15:31:28 +02:00
Dag-Erling Smørgrav feab010f44 libfetch: Use monotonic clock for timeouts
MFC after:	1 week
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D61225
2026-11-06 12:16:42 +01:00
Abdelkader Boudih e6fc1765bd nvme: drop the S3X single-outstanding-I/O quirk
The quirk's 8KB transfer clamp exposed raw character-device I/O to
the oversized-mapping stall fixed earlier, and its single tracker
turned a stranded request into a complete I/O stall. Without it an
S3X controller runs 128 trackers at its MDTS-derived transfer size
with no retries, failures, or timeouts, at about seven times the
serialized throughput.

Reviewed by:	imp, adrian, ngie
Approved by:	ngie (co-mentor)
Differential Revision:	https://reviews.freebsd.org/D59156
2026-11-06 09:59:18 +01:00
Abdelkader Boudih 764761d316 nvme: program the arbitration burst from Identify RAB
The controller's Recommended Arbitration Burst was ignored; the
specification advises matching the Arbitration feature's burst to it
even under plain round robin. Some controllers report unusable
values: programming the Apple S3X with its reported RAB wedged
sustained I/O, so quirked controllers keep their default
configuration. The hw.nvme.arb_burst tunable overrides the
recommendation.

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D59155
2026-11-06 09:58:08 +01:00
Christos Margiolis 66d078c172 netlink: Pre-register the missing devctl event systems
devctl_notify() can be called with a mutex held. If the event system is
not listed in devctl_systems[], sysevent_get_group() calls
sysevent_new_group(), which calls strdup() with M_WAITOK, and we may end
up sleeping while holding a non-sleepable mutex.

Add the missing systems.

While here, remove the nonexistent KERNEL system.

PR:		299272
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D61161
2026-11-06 09:42:37 +01:00
Simon J. Gerraty b22b999afc libsecureboot restore default trust anchors
If site.trust.mk does not set VE_SIGNATURE_LIST
initialize it based on content of VE_SIGNATURE_EXT_LIST
which is in turn initialized from TRUST_ANCHORS.

Sponsored by:	Hewlett Packard Enterprise Development LP

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D61245
2026-11-05 16:27:00 -08:00
Vinicius Ferrao cf59649539 xdr_mbuf.c: Add a check for the return value for xdrmbuf_getbytes()
The xdrmbuf_getlong() function failed to check for the return
value from xdrmbuf_getbytes().  This could have resulted in
a failure during NFS RPC message processing.

Reviewed by:	rmacklem
MFC after:	2 weeks
Sponsored by:	VersatusHPC
2026-11-05 15:58:56 -08:00
Kyle Evans 12f90bbd30 virtio_random: defer first enqueue until after DRIVER_OK
According to the virtio spec:

> The driver MUST NOT send any buffer available notifications to the
> device before setting DRIVER_OK.

DRIVER_OK isn't set until after attach completes, so defer the first
enqueue.  We haven't found any problems as a result of this to the best
of my knowledge: q35 and other devices that we *have* been used with
will apparently check when we go DRIVER_OK.

Tested with q35 virtio-random, which still works.

Reported by:	llm-postcr
Reviewed by:	kfv, markj
Fixes:	f1c5a2e3a6 ("virtio_random: Pipeline fetching the data")
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D61228
2026-11-05 15:53:30 -06:00
Dag-Erling Smørgrav 878084c774 nfsserver: Do not increment seqid on BADSEQID
When returning NFSERR_BADSEQID, the server should not have incremented
the sequence ID, yet the call to nfsrv_checkseqid() a few lines above
does precisely that.  Instead, check for a legitimate retransmission
of the original successful request, and reject otherwise, before the
ticket is used and sequence ID incremented.

MFC after:	1 week
Fixes:		ff45b9fc1a ("Bjorn reported a problem...")
Sponsored by:	Klara, Inc.
Reviewed by:	rmacklem
Differential Revision:	https://reviews.freebsd.org/D61156
2026-11-05 22:11:30 +01:00
Faraz Vahedi 3ac9299ee9 libc: Export timespec_getres(3) and add tests
timespec_getres() has been declared in <time.h> and built into libc,
but never listed in a symbol map.  It is therefore local to libc.so,
and dynamically linked callers fail to link.

Reviewed by:	ziaee, fuz, des
Approved by:	fuz (mentor)
Fixes:		9b5d724cad ("libc: Add timespec_getres(3) as per C23.")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D60799
2026-11-05 23:39:01 +03:30
Olivier Cochard bfe4be85a9 tpm_crb: wait for idle and locality release after each command
transmit only requested GO_IDLE and the locality release, so a back-to-back
command could see stale state and fail with EIO.
A post-send idle timeout no longer discards a completed response.

Reviewed by:	kbowling
Approved by:	kbowling
Differential Revision:	https://ron-dev.freebsd.org/FreeBSD/src/pulls/93
2026-11-05 20:51:20 +01:00
R. Christian McDonald 843cb77850 e6000sw: Write the value, not the register, in Clause 45 writes
e6000sw_write_xmdio() loaded the Clause 45 register address into the
SMI PHY data register a second time, where the value to write belongs,
so every Clause 45 write stored the register address.

Its only caller, e6000sw_serdes_power(), runs at attach for ports 9 and
10 of the 88E6190 and 88E6190X to power one SERDES interface up and the
other down.  It wrote 0x2000 to the SGMII control register and 0x1000
to the 10GBASE-R PCS control register instead, so neither interface was
powered down and the rest of each register was overwritten.

Fixes:		9aba06377d ("Add support for the Marvell 88E6190 11 ports switch.")
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2026-11-05 12:25:03 -05:00
Andrew Gallatin 4b732459f0 iflib: Use a single tx dma map
The need for a separate map for TSO and non-TSO seems to have arisen from
a misunderstanding about the DMA requirements for Intel drivers like
ice/ixl/iavf. Specifically, this Intel hardware has a quirk where no
more than N (=8) segs can be DMA'ed per packet on the wire. This limit
was enforced using a DMA map with a low segment limit for non-TSO and a
driver specific check for TSO. This led to a *lot* of complexity in
iflib (~80 extra lines of code that this change removes) when the
limit can simply be enforced via the existing EFBIG mechanisms.

This change adds a new flag, IFLIB_SPARSE_TX, that drivers for hardware
with this quirk must set.  When set, it causes non-TSO sends that
exceed isc_tx_nsegment to be treated as if bus_dmamap_load_mbuf_sg()
had returned EFBIG.

Due to the API/KABI change, I've bumped the FreeBSD version as well.

Note kgalazka suggested the flag, rather than a more awkward
mechanism that I had in my initial patch.

Reviewed by: kbowling
Sponsored by: Netflix
Differential Revision:  https://reviews.freebsd.org/D60175
2026-11-05 11:55:28 -05:00
ShengYi Hung 2734bbbcba libthr: Create landing pad in thr_once in C++ exception
In _thr_once, if init_routine fails with exception, the stack allocate
__cup will become invalid when unwinder walk back and free the stack of
thr_once. This cause cleanup linked list be dangling. In here, we give
the cleanup function a landing pad so that we td can correctly point
to previous cleanup function.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D61212
2026-11-06 03:01:55 +11:00
ShengYi Hung 71937d8e11 libthr: Predict libthr is initialized in _thr_check_init
_thr_check_init() is called on hot paths such as pthread_once(), and
the uninitialized case can only happen once. Mark it with
__predict_false so the compiler lays out the initialized case as the
fall-through path.

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D61213
2026-11-06 03:00:27 +11:00
ShengYi Hung 1e1ce1f6f9 libthr: Fix whitespace in thr_once.c
Remove trailing whitespace and replace space indentation with a tab.

No functional change.
2026-11-06 03:00:27 +11:00
Poul-Henning Kamp 5ed9f98d75 mrsas(4): Add missing Xr to mrsasutil(8) 2026-11-05 15:21:29 +00:00
Emmanuel Vadot c502df9eb1 sdiotool: Do not treat an unknown chip ID as fatal
The tool is useful for probing any SDIO card, not only the BCM4330.  Print the chip ID, report a failed backplane read, and only note when the ID is not the expected REPLY_MAGIC instead of exiting.

Differential Revision:	https://reviews.freebsd.org/D61030
2026-11-05 15:52:20 +01:00
Emmanuel Vadot e5b68a6a00 sdiotool: Use (void) for functions taking no arguments
Use (void) instead of an empty parameter list, as required by style(9), and let the compiler diagnose calls with unexpected arguments.

Reviewed by:	oh
Differential Revision:	https://reviews.freebsd.org/D61029
2026-11-05 15:52:17 +01:00
Emmanuel Vadot c67a07eb2c sdiotool: Remove the unused -f option
The -f option was parsed but never used.  Its argument handling was also broken: getopt(3) binds the argument to the last option letter, so "fu:" made -f take no argument at all.  Remove it.

Reviewed by:	oh
Differential Revision:	https://reviews.freebsd.org/D61028
2026-11-05 15:52:14 +01:00
Emmanuel Vadot be1bdeb36c sdiotool: Use the system bool type
linux_compat.h redefined bool as int8_t, overriding the _Bool definition provided by sys/types.h.  This changes the size and semantics of bool and conflicts with headers that include stdbool.h, such as cam/cam.h.  Rely on the system definition instead.

Reviewed by:	oh
Differential Revision:	https://reviews.freebsd.org/D61027
2026-11-05 15:52:11 +01:00
Emmanuel Vadot d61de53d18 sdiotool: Fix writes being issued as reads
sdio_write_1() passed 0 as the write flag to sdio_rw_direct(), so every write was performed as a read and the value was never sent to the card.  Pass 1 so that the data is actually written.

Reviewed by:	oh
Differential Revision:	https://reviews.freebsd.org/D61026
2026-11-05 15:52:08 +01:00
Emmanuel Vadot 1af3197bbe mmccam: Wait for the power to settle when probing a card
The mmc(4) stack waits after powering up a card: mmc_power_up() waits 1 ms
after the supplies are on and 2 ms after the clock is running, before the
first command is sent.  The MMCCAM probe had no such wait: it went from the
power_up request to the power_on request to CMD0 without any delay.

Some devices do not answer the first commands if they are sent too early and
then never enumerate, with no error.  On a RockPro64 the Broadcom SDIO Wi-Fi
(BCM4359) was not detected on any of 8 boots without a delay.  It was
detected on 8 out of 8 with the same waits as mmc_power_up() added to the
probe.

Add the same two waits, once the power_up request and once the power_on
request are done.  This replaces the delay that was in mmc_fdt_set_power(),
which was a fixed 10 ms for FDT hosts only; the waits of the legacy stack are
enough and apply to every MMCCAM host.

MFC after:	1 week
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D61077
2026-11-05 15:51:36 +01:00
Emmanuel Vadot 604e2b5c2a mmc: Fix clock handling in mmc-pwrseq-simple set_power()
set_power() enabled the ext_clock on power-on and called clk_stop() on
power-off.  This was wrong in three ways:

- clk_stop() is not the counterpart of clk_enable() (it KASSERTs
  enable_cnt == 0), so it panics once the clock has been enabled.
- set_power() is driven by the MMC power_mode IOS and is called
  repeatedly for the same state during probing and tuning, so the
  enable/disable refcount over- or underflows and panics.
- The ext_clock may be a shared PMIC output (e.g. rk808-clkout2 on the
  RockPro64, also feeding the companion Bluetooth controller), so gating
  it here disturbs the other consumers.

The external clock is a free-running low-power oscillator the device
needs for its whole lifetime, so enable it once at attach and leave it
running.  Only act on real power-mode transitions in set_power() and
limit it to driving the reset line, which is what actually sequences the
device.

Tested on a RockPro64 (Broadcom BCM4359 SDIO Wi-Fi): the SDIO function
now enumerates and the module is reachable from userspace.

MFC after:	1 week
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D61023
2026-11-05 15:51:34 +01:00
Emmanuel Vadot bf99b74302 cam: Fix the mmc_data mapping length for XPT_MMC_IO
cam_periph_mapmem() and cam_periph_unmapmem() map the user-provided
struct mmc_data for XPT_MMC_IO CCBs, but use sizeof(struct mmc_data *)
instead of sizeof(struct mmc_data) as the length.  Only the pages
covering a pointer are mapped, so accessing a field past the first
pointer-sized region (for instance cmd->data->flags) faults if the
structure happens to straddle a page boundary and the following page is
not mapped.

The failure is intermittent because it depends on where the caller places
the struct mmc_data.  Issuing a CMD53 CCB through pass(4) to an MMCCAM
SDIO card whose struct mmc_data lands at the end of a page panics with
"data abort in critical section or under mutex" in the host driver.

Map the whole structure in both the map and unmap paths.

MFC after:	1 week
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D61022
2026-11-05 15:51:31 +01:00
Emmanuel Vadot 49204732f6 cam: Fix XPT_MMC_IO buffer unmap order in cam_periph_unmapmem()
XPT_MMC_IO maps two nested buffers: cmd.data, then cmd.data->data whose
address is derived from cmd.data.  cam_periph_unmapmem() restored them in
forward order, so it put cmd.data back to its userspace value and then
dereferenced that pointer to reach cmd.data->data from kernel context,
panicking in vm_fault_lookup().

Unmap in reverse order, mirroring how the mappings were created.  This is
a no-op for single-buffer func_codes and for the other two-buffer cases
(XPT_DEV_MATCH, XPT_SMP_IO), whose buffers are independent.

The bug is only reachable via the pass(4) userspace path, which maps and
unmaps CCB buffers; in-kernel MMCCAM consumers never call
cam_periph_{map,unmap}mem().  Triggered by a userspace SDIO CMD53
transfer from sdiotool(8) through pass(4).

MFC after:	1 week
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D61021
2026-11-05 15:51:26 +01:00
Emmanuel Vadot bbb90912eb sdhci: Defer XPT_SET_TRAN_SETTINGS to the slot taskqueue
Only XPT_MMC_SET_TRAN_SETTINGS was handed to the slot taskqueue.
XPT_SET_TRAN_SETTINGS, which mmc_xpt.c issues too, still called
sdhci_cam_settran_settings() directly from the CAM done thread with the
CAM device lock held.  Changing the bus clock can sleep (clk_set_freq()
takes the clock topology sx lock), which panics with "sleeping thread
holds CAM device lock".

Handle both opcodes the same way and complete the request from the
taskqueue.

Differential Revision:	https://reviews.freebsd.org/D61013
2026-11-05 15:50:51 +01:00
Emmanuel Vadot 3e9ff26d2a sdhci: Do not reprogram an unchanged clock
sdhci_set_clock() compared the requested clock with slot->clock, which holds
the rate that the host driver actually applied.  Some drivers do not apply
the requested rate: the RK3568 one maps the 400kHz identification frequency
to 375kHz.  The two values then never match and every update_ios call goes
through SDHCI_SET_CLOCK() again, even when the clock did not change.

That ends in clk_set_freq(), which takes a sleepable lock, from the done
context of the mmc probe with the CAM locks held.  With another thread
holding the clock topology lock this panics with "sleeping thread holds CAM
device lock".

Remember the last requested clock in a new field and compare against it.
Clear it wherever slot->clock is cleared so that a reset still forces an
update.

Tested on a Quartz64 Model A with an NVMe drive on the PCIe slot, where the
panic was seen: 5 cold boots out of 5 attached everything.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D61012
2026-11-05 15:50:42 +01:00
Emmanuel Vadot 40363144e8 sdhci: rockchip: rk3568: Fix the eMMC card clock
The divider of the controller is not functional on Rockchip, the card clock
is the rate of the core clock.  Request the core clock rounded down so that
the closest available rate is selected and report a failure, which was
ignored before.  The eMMC was identified at the wrong clock and was never
detected.

Reviewed by:	mmel
Differential Revision:	https://reviews.freebsd.org/D60893
2026-11-05 15:50:38 +01:00
Emmanuel Vadot 6925f2caed clk: rockchip: rk3568: Select the eMMC core clock by rate
The eMMC core clock is a mux without a divider, whose parents provide the
375kHz clock for card identification and the 24MHz to 200MHz clocks for the
other modes.  Use RK_CLK_MUX_ROUND_PARENT so that the host driver can change
the card clock, which could not be done before.

Reviewed by:	mmel
Differential Revision:	https://reviews.freebsd.org/D60892
2026-11-05 15:50:36 +01:00