FreeBSD/src 153446esys/compat/linuxkpi/common/include/linux mm.h

linuxkpi: Add `split_page()`

This function is supposed to split large pages into an array of
`PAGE_SIZE`-sized pages, with correct refcounting. This is apparently
used to allow some drivers to free a part of a large page only.

I don't think we use large pages in linuxkpi. Therefore, this new
function is curently a no-op.

The DRM drivers TTM memory manager started to use it in Linux 6.15.

Reviewed by:    bz
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D58762
DeltaFile
+6-0sys/compat/linuxkpi/common/include/linux/mm.h
+6-01 files

FreeBSD/src be6e357sys/compat/linuxkpi/common/src linux_compat.c

linuxkpi: Update `struct vm_area_struct` when an existing mapping is extended

With Mesa 26 and DRM drivers in Linux 6.13, userspace will try to extend
an existing mmap, at last push the end address further.

Before this change, the mapping was not updated, but userspace would try
to access a page after the initial end address, leading to a panic
triggered by the following assertion in `vm_fault_populate()`:

    MPASS(fs->first_pindex <= pager_last);

Reviewed by:    bz
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D58195
DeltaFile
+13-0sys/compat/linuxkpi/common/src/linux_compat.c
+13-01 files

FreeBSD/src fbc89a8sys/compat/linuxkpi/common/include/linux kthread.h

linuxkpi: Add `kthread_run_worker()`

On Linux, `kthread_run_worker()` differs from `kthread_create_worker()`
by waking up the task after creating it with `kthread_create_worker()`.

On FreeBSD, we already execute it and wait for it, so probably no need
to do anything further. Therefore, `kthread_run_worker()` is an alias to
`kthread_create_worker()`.

The DRM drivers generic code started to replace
`kthread_create_worker()` by `kthread_run_worker()` as is in Linux 6.14.

Reviewed by:    bz
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57701
DeltaFile
+11-0sys/compat/linuxkpi/common/include/linux/kthread.h
+11-01 files

FreeBSD/src 33ba607sys/compat/linuxkpi/common/include/linux kobject.h

linuxkpi: Alias `sd` field of `struct kobject`

On Linux, a `struct kernfs_node *` pointer, representing a directory in
sysfs, is kept in the `sd` struct field.

We don't have that on FreeBSD because we use sysctls instead. Let's
alias the sysctl OID pointer to `sd` using an union.

This pointer is checked by the DRM drivers using:
    if (var->kobj.sd) {
        ...
    }

The amdgpu DRM driver started to use these checks in Linux 6.13.

Reviewed by:    bz
Sponsored by:   The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57586
DeltaFile
+16-1sys/compat/linuxkpi/common/include/linux/kobject.h
+16-11 files

FreeBSD/src 3732127sys/amd64/amd64 pmap.c, sys/arm64/arm64 pmap.c

amd64/arm64 pmap: consistently clear PGA_WRITEABLE

We don't consistently clear PGA_WRITEABLE on fictitious, managed pages.
Some functions do, e.g., pmap_remove_all(), but several do not.  At
worst, this is just a pessimization, but there is no good reason to be
inconsistent.  Clear PGA_WRITEABLE in those that previously did not by
introducing (and using) the helper function pmap_page_is_mapped_locked()
that implements the correct test.

Reviewed by:    kib, markj
MFC after:      3 weeks
Differential Revision:  https://reviews.freebsd.org/D59466
DeltaFile
+28-36sys/arm64/arm64/pmap.c
+25-28sys/amd64/amd64/pmap.c
+53-642 files

FreeBSD/src 4e45f4csys/kern subr_bufring.c

buf_ring: tiny style(9) fixup
DeltaFile
+2-3sys/kern/subr_bufring.c
+2-31 files

FreeBSD/src 9df7eedsys/kern kern_rangelock.c

rangelock: Fix format strings for 32-bit kernels

Reported by:    Jenkins
Fixes:          f1f58bdf7b5f ("acpi_pci: Honor device proximity for DMA tags")

(cherry picked from commit c869a36fc98a2ac1df5127e34ba7f9bffa0a5ce7)
DeltaFile
+4-4sys/kern/kern_rangelock.c
+4-41 files

FreeBSD/src 661d113lib/libsys pdfork.2

pdfork.2: document kern.pdfork_implicit_nowaitpid

Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D59349
DeltaFile
+11-0lib/libsys/pdfork.2
+11-01 files

FreeBSD/src 24d3cbasys/kern kern_fork.c

kern_fork.c: add kern.pdfork_implicit_nowaitpid sysctl

Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D59349
DeltaFile
+7-1sys/kern/kern_fork.c
+7-11 files

FreeBSD/src c63c77bsys/kern vfs_lookup.c

vp_crossmp: weaken the assert and make it more precise

Since the vp_crossmp vnode can leak into vn_vptocnp() calls due to
nullfs file mounting, not all lock requests are non-sleeping. The
requirement for the crossmp locking is that all lock requests should be
shared. Then, it does not matter if the requests allow sleeping, since
all locks are shared.

Also, check the lock type by correctly masking it with LK_TYPE_MASK.

Reported and tested by: pho
Reviewed by:    jah, markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D59468
DeltaFile
+1-1sys/kern/vfs_lookup.c
+1-11 files

FreeBSD/src a725815sys/dev/sound/pci emu10kx-pcm.c

snd_emu10kx: Make sure the block count and size cover the whole buffer

The playback voices always loop over the whole EMU_PLAY_BUFSZ buffer,
but emupchan_setblocksize() only recorded the new block size and left
the block count as it was set up by emu_vinit(). The blocks then no
longer covered the whole buffer, and the part they left out was played
without ever being written to, which became audible as distortion once
playback started going through a virtual channel.

Resize the buffer, so that the block count and size always cover it.

Fixes:          02d4eeabfd73 ("sound: Allocate vchans on-demand")
PR:             287687
MFC after:      1 week
Sponsored by:   The FreeBSD Foundation
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D59444
DeltaFile
+19-2sys/dev/sound/pci/emu10kx-pcm.c
+19-21 files

FreeBSD/src 358fe14sys/dev/sound dummy.c

snd_dummy: Bump primary channel count

Makes it easier to test scenarios involving more than 1 primary channels
per direction.

Sponsored by:   The FreeBSD Foundation
MFC after:      2 weeks
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D59085
DeltaFile
+2-2sys/dev/sound/dummy.c
+2-21 files

FreeBSD/src 5e02679sys/dev/sound/pcm dsp.c

sound: Prefer idle primary channels when allocating

dsp_chn_alloc() stopped at the first primary channel that was either
idle or already had vchans. Since the list is walked in order, the first
channel matched both conditions once it had been used, so every client
after the first was stacked onto it as a vchan and the remaining primary
channels were never allocated at all.

This is invisible on devices with a single primary channel, but not on
those which provide several. snd_emu10kx(4), for instance, registers
four primary channels for its front device, each able to run with its
own rate.

Look for an idle primary channel first, and only fall back to sharing
one that already has vchans when there is none left.

Sponsored by:   The FreeBSD Foundation
MFC after:      2 weeks
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D59084
DeltaFile
+17-7sys/dev/sound/pcm/dsp.c
+17-71 files

FreeBSD/src 5cc1427usr.sbin/syslogd syslogd.c

syslogd: Pipes need the CAP_PDGETPID right as well

While here, use caph_rights_limit(), as syslogd already uses
caph_enter().

PR:             298104
Reported by:    mi
Fixes:          24816abb8740 ("syslogd: Limit rights on procdescs")
MFC after:      3 days

(cherry picked from commit 87cfe4a62078bc8ff14671fde3af347e7c7e3a26)
DeltaFile
+4-3usr.sbin/syslogd/syslogd.c
+4-31 files

FreeBSD/src 7b76afdsys/netipsec keysock.c

netipsec: Implement pr_disconnect for PF_KEY sockets

Otherwise close() fails.

PR:             297977
Reviewed by:    glebius
Fixes:          ea7be1293b48 ("keysock: do not use raw socket code")
MFC after:      1 week

(cherry picked from commit fef9077cf816a6499bd6a7f9678c179194463e43)
DeltaFile
+7-0sys/netipsec/keysock.c
+7-01 files

FreeBSD/src 6a80c0esys/kern uipc_shm.c kern_rangelock.c

rangelock: Reimplement _rangelock_cookie_assert()

After rangelocks were reimplemented, _rangelock_cookie_assert() became a
stub.  Re-provide an implementation.

Reviewed by:    kib
MFC after:      1 week
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D59222

(cherry picked from commit 2e376cca379b744ce24c849aced684bf770c0f75)
DeltaFile
+52-0sys/kern/kern_rangelock.c
+3-3sys/kern/uipc_shm.c
+55-32 files

FreeBSD/src f51ad3asys/dev/e1000 if_em.c

e1000: Fence DMA when hardware reset fails

iflib releases queue mappings after IFDI_STOP() returns.  If a
Physical Function reset fails, returning with PCI bus mastering
enabled can therefore leave the device able to access mappings which
the framework is about to recycle.

Disable bus mastering and drain pending PCIe transactions when reset
fails during initialization or stop.  Re-enable and verify bus
mastering only after a later reset succeeds and before queue
programming begins.  Treat inability to establish the DMA fence as a
fail-stop invariant violation.

MFC after:      2 weeks
Sponsored by:   BBOX.io
DeltaFile
+3-1sys/dev/e1000/if_em.c
+3-11 files

FreeBSD/src 9490296share/man/man4 rtnetlink.4

rtnetlink(4): Qualify VF status descriptions

Driver-specific extension namespaces are optional.  Describe their
role without implying that every provider supplies one.

Clarify that the VLAN count excludes membership installed implicitly by
the PF without implying that an explicit VID 0 request cannot consume a
reported filter.

Sponsored by:   BBOX.io
DeltaFile
+5-3share/man/man4/rtnetlink.4
+5-31 files

FreeBSD/src c6df112sys/kern sched_4bsd.c

sched_4bsd: Allocate runqueues only for present CPUs

4BSD has been allocating an array of MAXCPU runqueues, runq_pcpu[],
instead of one runqueue per actually present CPU.  On amd64, MAXCPU is
1024 and 'struct runq' is 4128 bytes, causing runq_pcpu[] to take more
than 4 MiB of memory.  On the vast majority of current systems, which
have at most 32 cores with SMT, this is a waste of memory.

Besides providing per-CPU runqueues, runq_pcpu[] has also been used to
determine the CPU ID of a given thread's associated runqueue through
pointer arithmetic.

Since per-CPU structures are only allocated for present CPUs, in order
to save space, move the runqueues to per-CPU fields and, for each thread
('struct ts_sched'), replace its runqueue pointer by the CPU ID of the
runqueue it is in (new 'ts_rqcpu' field).  Set the thread's CPU ID to
the special NOCPU value when it is running on the global runqueue.

Drop the SKE_RUNQ_PCPU() macro as it is now simply equivalent to

    [13 lines not shown]
DeltaFile
+30-27sys/kern/sched_4bsd.c
+30-271 files

FreeBSD/src 5806717sys/kern sched_4bsd.c

sched_4bsd: Remove obsolete SMP scaling for ticks per priority level

The INVERSE_ESTCPU_WEIGHT scaling had been introduced by commit
b698380f33ef ("Quick fix for scaling of statclock ticks in the SMP
case. ...") to leave more discrimination room for multiple CPUs possibly
adding their ticks to the same 'struct ksegrp' (but also slightly
changing how CPU hogs are penalized).

Then, commit 8460a577a4b4 ("Make KSE a kernel option, ...") introduced
the current thread-based code, where tick accounting is only done on the
current thread, which renders this trick obsolete on !KSE.

Finally, when KSE was removed, the trick became generally obsolete.

The trick is actually even harmful because it changes the intended
behavior of priorizing more the CPUs that use the less ticks (and so,
impairs boosting "interactive" processes).

Remove it now.  Clamping of 'ts_estcpu' and its relation to the

    [8 lines not shown]
DeltaFile
+0-4sys/kern/sched_4bsd.c
+0-41 files

FreeBSD/src 5db755asys/kern sched_4bsd.c

sched_4bsd: Fix conflating priority of differently-niced CPU-bound threads

We introduced (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) as part of
ESTCPULIM() in commit eebc148f25c3 ("sched_4bsd: ESTCPULIM(): Allow any
value in the timeshare range") in order to use more than a fixed number
(40) of all the available priority levels in the timeshare range (136
before the 256-queue runqueue work, 224 now) to take into account the
number of ticks a thread has run ('ts_estcpu').

In the computation of a new thread's priority (resetpriority()), in
addition to the "ticks running" contribution, the final priority also
includes a "nice" value contribution.  The final value is clamped into
the [PRI_MIN_TIMESHARE; PRI_MAX_TRIMESHARE] range.

Problem is that the new "ticks running" contribution now can lead to
a computed priority value that exceeds PRI_MAX_TRIMESHARE, and is thus
finally clamped to PRI_MAX_TIMESHARE, which becomes an alias for all
out-of-bound values.  In particular, this can conflate CPU-hungry
threads.  With at least two of them competing on the same CPU, with an

    [22 lines not shown]
DeltaFile
+7-5sys/kern/sched_4bsd.c
+7-51 files

FreeBSD/src 554eb7bsys/kern sched_4bsd.c

sched_4bsd: Rename the global runqueue

In an upcoming change whose purpose is to stop having 4BSD always
allocate MAXCPU runqueues, wasting space on most machines, 'struct
td_sched' will store the CPU ID to which a thread is bound/pinned
instead of a pointer to the corresponding runqueue.  As a consequence,
existing functions manipulating a thread's runqueue will need to point
to the inferred runqueue through a local variable.  The name 'runq' is
the ideal one for these local variables, but before this change it
designated the global runqueue, also causing unnecessary ambiguity.

Thus, rename the global runqueue to the more explicit 'runq_global'.
Arguably, this should have been performed as part of commit e17c57b14ba9
("- Implement cpu pinning and binding. (...)").

No functional change (intended).

[olce: Massaged the commit message.  Tested with source builds.]


    [7 lines not shown]
DeltaFile
+16-16sys/kern/sched_4bsd.c
+16-161 files

FreeBSD/src afd1ae5sys/kern sched_ule.c

sched_ule: Fix selecting lowest priority thread early in corner case

When transferring a thread with near 100% CPU statistics (but not 100%;
up to 57.5/59≈97.46%) to a CPU where the enqueue offset is ahead of at
least 2 from the dequeue one, which requires peculiar conditions to
happen (transfer triggered by a bind request or cpuset change, or during
balancing if a thread or more existed from a brief amount of time on the
origin CPU), the transferred thread can get placed after the dequeue
offset, effectively making it appear as a high priority one unduly,
causing latency increase for other threads.

The change here was missed when changing the enqueue and dequeue offsets
update mechanism to recover pre-256-queue-runqueue ULE anti-starvation
and fairness behavior.  That change opened up the possibility that these
two offsets are apart by more than one.

Reviewed by:    markj
Discussed with: Minsoo Choo <minsoo at minsoo.io>
Fixes:          6792f3411f6d ("sched_ule: Recover previous nice and anti-starvation behaviors")

    [5 lines not shown]
DeltaFile
+36-9sys/kern/sched_ule.c
+36-91 files

FreeBSD/src 0a35e0asys/netpfil/pf pf.c, tests/sys/netpfil/pf mld.py

pf: allow unspecified addressed for certain MLD messages

As per RFC 3590 MLD Report and Done messages are permitted to use the
unspecified address as a source address (e.g. during duplicate address
detection for the first IPv6 address). Allow this, but only this.

Reported by:    Alexander Leidinger <Alexander at Leidinger.net>
Reviewed by:    bms
See also:       OpenBSD, sashan <sashan at openbsd.org>, 60036e8507
Sponsored by:   Rubicon Communications, LLC ("Netgate")
Differential Revision:  https://reviews.freebsd.org/D59334
DeltaFile
+57-0tests/sys/netpfil/pf/mld.py
+9-1sys/netpfil/pf/pf.c
+66-12 files

FreeBSD/src 7d810f2sys/netpfil/pf pf.c

pf: Prevent pf dropping TCP state with crafted reset packet.

Revision 1.1212 of pf.c weakened the TCP reset check in stateful
connection tracking to let legitimate resets pass in the backwards
window.  Such a reset is accepted only if its acknowledgment number
matches perfectly.  But as a workaround for broken stacks, pf
replaces an acknowledgment number of 0 in a reset with the tracked
sequence of the peer.  Then the perfect match always succeeds, and
an attacker can spoof resets more easily than intended.  Use the
acknowledgment number from the wire, before the workaround has
modified it.

discovered by Minghao Zhang; OK sashan@

Obtained from:  OpenBSD, bluhm <bluhm at openbsd.org>, 1e0a1f4b82
Sponsored by:   Rubicon Communications, LLC ("Netgate")
DeltaFile
+3-2sys/netpfil/pf/pf.c
+3-21 files

FreeBSD/src fb144a7usr.sbin/pw pw.8

pw(8): Brace the name-or-id synopsis so it matches the code

An unbraced pipe list made -n look like it could take a uid (or gid).
Use braces for a single choice of name or id, and keep -u newuid /
-g newgid on the name invocation only. Drop the USER/GROUP OPTIONS
sentences that said -n could be a numeric id.

PR:     269193
MFC after:      3 days
Reviewed by:    bapt
Differential Revision:  https://reviews.freebsd.org/D59472
DeltaFile
+9-16usr.sbin/pw/pw.8
+9-161 files

FreeBSD/src a971034release Makefile.vm, release/tools ec2_setpass ec2_desktop_extras

EC2: Add desktop flavour

Desktop AMIs have xrdp enabled and boot to a KDE desktop; they are
as compatible as possible with EC2 Windows AMIs, setting a random
password and printing it to the console in encrypted format to be
retrieved using the EC2 GetPasswordData API.

Two rc.d scripts are included in this commit which will not exist
in the long term: ec2_addpass will become part of the ec2-scripts
package, and ec2_desktop_extras will go away once its functionality
is included elsewhere.

MFC After:      1 month
Relnotes:       yes
Sponsored by:   Amazon
DeltaFile
+73-0release/tools/ec2-desktop.conf
+60-0release/tools/ec2_desktop_extras
+58-0release/tools/ec2_setpass
+2-1release/Makefile.vm
+193-14 files

FreeBSD/src 6624f3clib/libarchive/tests Makefile

[tests] libarchive: mark `test_read_filter_lz4_raw_skip` broken

This test has not passed since 185becb1e1bd2657c156f78aeb52edac05ba5fb5
(the libarchive 3.8.9 upgrade).

PR:             297505
MFC after:      1 week
Reviewed by:    siva
Differential Revision:  https://reviews.freebsd.org/D59314

(cherry picked from commit 064d190cdac48465083da1798a36d923f50790ac)
DeltaFile
+6-1lib/libarchive/tests/Makefile
+6-11 files

FreeBSD/src 5cef979lib/libarchive/tests Makefile

[tests] libarchive: mark `test_read_filter_lz4_raw_skip` broken

This test has not passed since 185becb1e1bd2657c156f78aeb52edac05ba5fb5
(the libarchive 3.8.9 upgrade).

PR:             297505
MFC after:      1 week
Reviewed by:    siva
Differential Revision:  https://reviews.freebsd.org/D59314

(cherry picked from commit 064d190cdac48465083da1798a36d923f50790ac)
DeltaFile
+6-1lib/libarchive/tests/Makefile
+6-11 files

FreeBSD/src 1cc8353sys/dev/e1000 if_em.c e1000_osdep.h

e1000: Serialize 82579 CSR writes with the Management Engine

The 82579 PCIm2PCI arbiter can acknowledge a host MAC CSR write while
the Management Engine is accessing another CSR.  The host write can be
lost; subsequent target accesses may no longer be claimed by the MAC and
can hang the system.

For 82579 controllers with valid management firmware, wait for the ME
CSR access indication before every MAC CSR write.  Keep the wait bounded
and use DELAY because writes occur in interrupt and datapath contexts.
Verify every transmit and receive tail write.  If a tail does not hold
the requested value, disable its datapath direction and request a full
iflib reset.

Keep the ordinary register-write path as a direct MMIO write behind a
predicted per-device gate.  Contain the wait and tail recovery in the
82579 slow path rather than adding tail-specific accessors and state to
the rest of the e1000 family.


    [12 lines not shown]
DeltaFile
+60-0sys/dev/e1000/e1000_osdep.c
+13-7sys/dev/e1000/e1000_osdep.h
+9-0sys/dev/e1000/if_em.c
+82-73 files