libc/fnmatch/rangematch: fix incorrect arguments to memset
strmbs variable is already a pointer, so calling memset on its address
was equivalent to setting the pointer, but the intent was to set the
pointed object.
This was found while debugging an unrelated issue in the same function.
Fixes: af79566b9315
MFC after: 1 week
libc/fnmatch/rangematch: fix uninitialized variable read in a condition
The condition was logically incorrect and could also result in access to
an uninitialized variable. The bug happened because of misplaced
parentheses in the complex condition. There is another very similar
condition in the code and it has the correct placement, so it does not
have the bug. I used it as an example for the fix. Both conditions
came from the same commit af79566b9315.
For me, the bug appeared as a random failure to match a simple pattern
with '[0-9]' in it. The value of the uninitialized variable depended on
the value left on the stack by other code, so the bug appeared only
under very specific conditions.
FWIW, gcc catches and reports the uninitialized variable problem.
clang does it only with -Wconditional-uninitialized but that flag leads
to too many false positives.
I also found a pattern that deterministically reveals the bug in a
[14 lines not shown]
hwpmc: claim stray PMI NMIs on Intel
core2_intr() claims an NMI only when IA_GLOBAL_STATUS shows an
overflow. It re-enables the LAPIC PMC vector before acking the
status bits, so a PMI raised while the handler runs can latch a
second NMI that finds the status already clear. That NMI goes
unclaimed and, with the default machdep.panic_on_nmi, panics the
machine. hwpmc_amd.c already absorbs such NMIs with a per-CPU
nmi_counter.
Give core2_intr() one credit per serviced PMI and spend it on the
next NMI on that CPU that finds no overflow.
Reproduced on a Xeon D-1518 (Broadwell-DE) running system-wide
CPU_CYCLES sampling: the unpatched kernel panicked with "NMI" after
about 47k PMIs. With this change it ran 12.5 hours (485k PMIs),
absorbed 6 empty NMIs, and did not panic.
Sponsored by: Netflix
[2 lines not shown]
x86: Do not take a CPUID leaf 1Fh module for the package
Each level of CPUID leaf 0Bh or 1Fh reports the shift that addresses
the next level up. Leaf 0Bh has only the SMT and core levels, so the
core level's shift identifies the package. Leaf 1Fh may enumerate
module, tile, die and die group levels above the core level, and then
the core level's shift identifies one of those instead.
topo_probe_intel_0xb() used the core level's shift for the package in
both cases. On a processor that enumerates a module level, every
module became a package, and the L3 cache was cut down to the module
with "WARNING: L3 data cache covers more APIC IDs than a package", so
the scheduler did not see that the modules share it. An Atom x7809C
(Amston Lake), which reports shifts of 1, 3 and 7 for its SMT, core and
module levels, came up as two packages of four cores. The N150 (Twin
Lake) in the PR is affected in the same way.
Use the shift of the last level enumerated for the package. The SDM
describes the package as the unenumerated domain above the last valid
[24 lines not shown]
nfs: Cache reply pages in an NFS-owned UMA zone
Allocate anonymous reply pages through a dedicated UMA cache and
return them in batches when the last M_EXTPG reference is released.
This reduced page-cache bucket shortages in the tested
concurrent-read workloads. The pool uses the existing UMA and
mbuf interfaces.
Once nfsd enables the pool, nfscommon refuses unload so delayed
callbacks remain valid. The usual nfsd/nfslockd dependency chain
already retains nfscommon; the explicit guard also enforces this
requirement directly. Loading nfscommon alone does not activate
that guard.
Mark Johnston suggested using a dedicated zone in the D61234 discussion.
That feedback led to this NFS implementation instead of changing UMA.
Gleb Smirnoff provided feedback on the original allocator proposal.
Reviewed by: rmacklem
[3 lines not shown]
powerpc: don't save the FPU state again in freebsd32_sigreturn()
set_mcontext32() restores the floating point registers from the context,
then freebsd32_sigreturn() called save_fpu(), which writes the hardware
registers, the ones the signal handler left behind, back into the PCB.
The process resumed with the handler's registers instead of its own.
sys_sigreturn() has no such call; drop it here too.
A 32-bit program that loads f14, takes a signal whose handler loads
another value and reads f14 back got the handler's value on a
COMPAT_FREEBSD32 kernel; it gets its own now, like the 64-bit build.
Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D61792
Add a -b option to fsck(8) to specify an alternative superblock.
Pass the -b flag from the wrapper to the underlying filesystem checker.
This allows users to specify superblock directly without the need to
invoke the underlying checker manually.
Reported by: Aadya Chinubhai <aadyachinubhai at gmail.com>
PR: 27687 (from May 2001)
MFC after: 1 week
ext2fs: Multi-block allocator with extent tree support and allocation lifecycle state machine
The idea is to have an allocator that makes better use of the locality
information and is better suited for extents. It is similar to what
Linux calls a multiblock allocator in a paper from 2005. The Linux
code was not inspected or used in this implementation.
Implement ext2_alloc_run() — a multi-block physical allocator that
reserves a contiguous physical block run and returns it via a
context-based state machine:
ALLOCATED -> MAPPED -> PUBLISHED -> ROLLED_BACK
ext2_alloc_run() enforces the reserved-block policy using struct
ucred *cred (NOCRED panics under INVARIANTS). Callers include
ext2_alloc() and ext4_new_blocks() for block allocation.
ext4_ext_split() uses scalar ext2_rollback_unpublished() for metadata
block cleanup (no context arrays). ext4_ext_insert_extent() handles
[23 lines not shown]
build: fix `delete-old` removal of efisign bits
There's a second appearance of the examples when MK_EXAMPLES == no that
we must also change.
Reported by: llm-postcr
Fixes: 537dca4c0bc3 ("uefisign: rename to efisign")
zfsbootcfg.8: list each form in the synopsis and document -d
The synopsis listed every option as optional in a single form, which
doesn't show that -k needs -v, and it didn't mention -d at all. List
the distinct forms instead: setting boot.config(5) options (or printing
them, with none), setting or deleting a key, and printing the bootenv
area. Document -d alongside the other options.
Reviewed by: avg, bcr
Sponsored by: The FreeBSD Foundation
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D61834
zfsbootcfg: don't crash on bad or incomplete options
getopt() errors fell through the switch without a default case, so
zfsbootcfg carried on with whatever options it had. Setting a key
without a value, whether with -k alone or after such an error, then
crashed in add_pair() on a NULL value.
Print a usage message and fail for unknown options, missing option
arguments, and a key with no value to set it to.
While we're here, clean up some pre-existing style issues and ensure we
properly route warnings/errors to stderr.
Reviewed by: avg, des
Sponsored by: The FreeBSD Foundation
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D61833
netipsec: Send the packet when the rest of a bundle is skipped
A policy can bundle several requests, for example an ESP tunnel and an AH
transport request. A request at level "use" that has no SA is skipped (as
is "default", which the net.inet.ipsec.*_deflev and
net.inet6.ipsec6.*_deflev sysctls make "use" by default), and the packet
is meant to leave with the transforms of the other requests.
ipsec_process_done() applies the next request of a bundle once a transform
completes. When all remaining requests are skipped,
ipsec{4,6}_perform_request() returns EJUSTRETURN and leaves the packet to
its caller, but ipsec_process_done() returned that to the transform, which
does not send the packet or free it. Keep the references to the SP and the
SA across the call, and on EJUSTRETURN send the packet with the transforms
applied so far, after the UDP encapsulation of the last SA applied.
ipcomp_output() calls ipsec_process_done() directly for packets below the
compression threshold and passed the EJUSTRETURN on to ip_output(), which
then went on with a packet that tunnel mode encapsulation had already
[7 lines not shown]
uefisign: rename to efisign
uefisign seems to have come first, but the efi* naming has won out in
our UEFI tooling and consistency is good. This fixes it so that
"efi<tab>" gives a reasonable view of what efitools we have in base.
uefi* links are added for compatibility, at least for now. Maybe it's
a reasonable idea to add such links for all of the efi tools, but I'm
punting on that for a moment.
Reviewed by: emaste, imp (both previous version), ziaee
Relnotes: maybe
Differential Revision: https://reviews.freebsd.org/D58187
syscalls.master: Add a capsicum note about sync(2)
Allowing sync(2) is technically a violation of Capsicum's "no global
namespace access" requirement, but sync does not leak or modify user-
visible state.
Reviewed by: brooks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61675
kern: Have .m rules depend on sys/tools/makeobjops.awk
Generated _if.[ch] files have to be rebuilt after commit bf362c1b41c8
("kobj: convert KOBJOPLOOKUP() to returning pointer to function"). Add
dependencies on the build tool in files.*.
Reviewed by: imp
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61821
sound: Unlock the channel when chn_reset() fails in dsp_chn_alloc()
If chn_reset() fails, dsp_chn_alloc() returns with the channel lock
held, dsp_open() calls dsp_close() as part of its cdevpriv error path,
and this causes both a mutex recursion on the channel lock in
dsp_close(), as well a lock order reversal.
Fixes: 02d4eeabfd73 ("sound: Allocate vchans on-demand")
Reported by: llm-postcr
MFC after: Immediately
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D61793
(cherry picked from commit 01a8cd5ebe9368fd115fb5060bcb1e60d1bbdf1f)
sound: Unlock the channel when chn_reset() fails in dsp_chn_alloc()
If chn_reset() fails, dsp_chn_alloc() returns with the channel lock
held, dsp_open() calls dsp_close() as part of its cdevpriv error path,
and this causes both a mutex recursion on the channel lock in
dsp_close(), as well a lock order reversal.
Fixes: 02d4eeabfd73 ("sound: Allocate vchans on-demand")
Reported by: llm-postcr
MFC after: Immediately
Sponsored by: The FreeBSD Foundation
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D61793
linux: Destroy the per-VNET unit allocator after the cloners
linux_ifnet_vnet_uninit() deletes the unit number allocator that
linux_ifnet_departure() frees into. It ran at SI_SUB_INIT_IF,
SI_ORDER_ANY, the same slot in which lagg, vlan, edsc and ng_eiface
destroy the interfaces left in a dying vnet. Destructors of equal order
run in the reverse of the order their modules were loaded, so with
linux_common loaded after if_lagg the allocator was gone by the time
vnet_lagg_uninit() detached its interfaces, and removing a vnet jail that
still held a lagg interface panicked in free_unr().
Commit a23901a37be9 moved the destructor from SI_SUB_PROTO_IF to
SI_SUB_INIT_IF for the cloners that tear down earlier, which left this
tie.
Run the destructor at SI_ORDER_FIRST, which is after every destructor of
a later order in the same subsystem, whatever the load order. Move the
constructor with it.
[6 lines not shown]
LinuxKPI: Include <linux/fs.h> from <linux/mm.h>
and <linux/kernel.h> from <linux/io.h>.
This reproduces the same namespace pollution as Linux and will help us
to fix historical bug when these files were included from <linux/fb.h>.
Fix conflicting Linux name leakage appeared in qat(4) as result.
Differential Revision: https://reviews.freebsd.org/D60798
LinuxKPI: Add mapping_gfp_mask() and four more folio/pagemap helpers
Adds mapping_gfp_mask(), mapping_gfp_constraint(), mapping_set_unevictable(),
folio_page() and folio_file_page(), which Linux's drm_gem_get_pages() uses.
drm-kmod carries them in an overlay for virtio-gpu (freebsd/drm-kmod#517) today.
The mask is GFP_KERNEL, as shmem page allocation may sleep and ignores
the other flags. folio_page() and folio_file_page() are exact copies
from D58763, to not clash with it.
Signed-off-by: Denis Borovikov <denis.borovikov at gmail.com>
Reviewed by: wulf
Differential Revision: https://reviews.freebsd.org/D61217
LinuxKPI: Add PCI method for transferring framebuffer parameters
from LKPI video driver to FreeBSD native framebuffer driver.
This makes possible to attach framebuffer driver in traditional way
using newbus interface rather than direct calls into vt internals.
It is required to make LKPI framebuffer driver compatible with
fbd/vt_fb. As a consequence that allows us to switch back to vt_fb on
radeon driver where vt_drmfb regressions have been reported [1].
The method expects fbd device ivars pointed to FreeBSD fb_info
structure embedded in to Linux fb_info structure. See linux/fb.h.
Note that some out-of-tree non-PCI drm drivers may require similar
changes in parent bus drivers.
[1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=285088
PR: 285088
Differential Revision: https://reviews.freebsd.org/D60038
kern: Have .m rules depend sys/tools/makeobjops.awk
Generated _if.[ch] files have to be rebuilt after commit bf362c1b41c8
("kobj: convert KOBJOPLOOKUP() to returning pointer to function"). Add
a dependency on the build tool, similar to kmod.mk.
Build rules using NORMAL_M (defined in kern.pre.mk) presumably need a
similar treatment, but this restores (most of) the incremental build
now.
Reviewed by: jrtc27
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61821
tests/sigtramp_test: re-enable test on aarch64
This now passes on both aarch64 (since 6a936d939b88)
and amd64. It still fails on other architectures, so
keep the xfail.
PR: 289096
Sponsored by: The FreeBSD Foundation