FreeBSD/src 54a3920sys/dev/hyperv/storvsc hv_storvsc_drv_freebsd.c

hyperv/storvsc: Avoid conditional asserts in storvsc_xferbuf_prepare()

whu@ cannot reproduce the assertion failure which led to these ifdefs
being added in the first place, and since they appear wrong, i.e., the
assertions ought to apply to all platforms, let's remove them.

This reverts commits 0af5a0cd2788efce9f444f4f781357d317bb0bb1 and
6f7b1310b6fe36f9bb653d3e97bc257adced3a2b.

PR:             285681
Tested by:      whu
MFC after:      2 weeks
DeltaFile
+0-2sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
+0-21 files

FreeBSD/src a319ba6sys/dev/hyperv/storvsc hv_storvsc_drv_freebsd.c

hyperv/storvsc: Fix busdma constraints

- The BUS_DMA_KEEP_PG_OFFSET flag is needed, since
  storvsc_xferbuf_prepare() assumes that only the first segment may have
  a non-zero offset, and that all following segments are page-sized and
  -aligned.
- storvsc_xferbuf_prepare() handles 64-bit bus addresses, so avoid
  unneeded bouncing on i386.

PR:             285681
Reported by:    dim
Tested by:      dim, whu
MFC after:      2 weeks
DeltaFile
+6-1sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
+6-11 files

FreeBSD/src 30e6e00lib/libjail jail.c, libexec/flua/libjail lua_jail.c

jail: Add meta and env parameters

Each one is an arbitrary string associated with a jail. It can be set
upon jail creation or added/modified later:

    > jail -cm ... meta="tag1=value1 tag2=value2" env="configuration"

The values are not inherited from the parent jail.

A parent jail can read both metadata parameters, while a child jail can
read only env via security.jail.env sysctl.

The maximum size of meta or env per jail is controlled by the
global security.jail.meta_maxbufsize sysctl. Decreasing it does not
alter the existing meta information.

Each metadata buffer can be handled as a set of key=value\n strings:

    > jail -cm ... meta="$(echo k1=v1; echo k2=v2)" env.1=one

    [10 lines not shown]
DeltaFile
+621-0sys/kern/kern_jailmeta.c
+588-0tests/sys/kern/jailmeta.sh
+69-15lib/libjail/jail.c
+36-0usr.sbin/jail/jail.8
+12-4libexec/flua/libjail/lua_jail.c
+10-1sys/kern/kern_jail.c
+1,336-205 files not shown
+1,351-2011 files

FreeBSD/src 12ecb0fsys/kern vfs_vnops.c, sys/sys file.h

file: Add foffset_lock_pair()

This will be used in kern_copy_file_range(), which needs to lock two
offsets.

Reviewed by:    kib, rmacklem
MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D49440
DeltaFile
+20-0sys/kern/vfs_vnops.c
+2-0sys/sys/file.h
+22-02 files

FreeBSD/src 197997asys/kern vfs_syscalls.c

file: Fix offset handling in kern_copy_file_range()

One can ask copy_file_range(2) to use the file offsets of the file
descriptions that it copies from and to.  We were updating those offsets
without any locking, which is incorrect and can lead to unkillable loops
in the event of a race (e.g., the check for overlapping ranges in
kern_copy_file_range() is subject to a TOCTOU race with the following
loop which range-locks the input and output file).

Use foffset_lock() to serialize updates to the file descriptions, as we
do for other, similar system calls.

Reported by:    syzkaller
Reviewed by:    rmacklem, kib
MFC after:      2 weeks
Fixes:          bbbbeca3e9a3 ("Add kernel support for a Linux compatible copy_file_range(2) syscall.")
Differential Revision:  https://reviews.freebsd.org/D49440
DeltaFile
+52-21sys/kern/vfs_syscalls.c
+52-211 files

FreeBSD/src 1a80a15sys/kern sys_process.c

ptrace: Do not pass a negative resid to proc_rwmem()

While here, avoid truncting uio_resid in proc_rwmem().

Reviewed by:    kib
MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D49479
DeltaFile
+5-1sys/kern/sys_process.c
+5-11 files

FreeBSD/src fe7fe3bsys/kern kern_rangelock.c

rangelock: Fix handling of trylocks

When inserting a queue entry, i.e., locking a range, there are two
points where a trylock operation may fail, one before the new entry is
inserted, one after.  In the latter case, rl_(r|w)_validate() would mark
the entry and rangelock_lock_int() would free it.  However, this is of
course incorrect, since the entry is visible to other threads, which
will eventually attempt to remove it and free it again.

Factor out conflict handling in rl_(r|w)_validate() to a common function
as they are functionally the same.  Then, introduce a new result which
indicates that a trylock failed but that the queue entry must not be
cleaned up.

While here, assert that a conflicting range isn't owned by the current
thread, as that would indicate a bug in the consumer.

Reviewed by:    olce, kib
Reported by:    syzkaller

    [2 lines not shown]
DeltaFile
+79-43sys/kern/kern_rangelock.c
+79-431 files

FreeBSD/src 590b450sys/kern uipc_socket.c uipc_domain.c

socket: Handle the possibility of a protocol with no ctloutput

Add a default ctloutput handler and remove various NULL checks.  This
fixes a problem wherein the generic SO_SETFIB handler did not check
whether the protocol has a ctloutput implementation before calling the
function pointer.

Reported by:    syzkaller
Reviewed by:    glebius
Fixes:          caccbaef8e26 ("socket: Move SO_SETFIB handling to protocol layers")
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D49436
DeltaFile
+3-9sys/kern/uipc_socket.c
+7-0sys/kern/uipc_domain.c
+10-92 files

FreeBSD/src a6268f8sys/kern kern_time.c kern_exit.c

proc: Disallow re-enabling of process itimers during exit

During process exit, it's possible for the exiting thread to send a
signal to its process, via killjobc().  This happens after the itimer is
drained.  If itimers are stopped, i.e., P2_ITSTOPPED is set, then
itimer_proc_continue() will resume the callout after it has been
drained.

Fix the problem by simply clearing P2_ITSTOPPED as part of the drain.
Then, a signal received after that point will not re-enable the callout.
For good measure, also make sure that we don't reset the itimer callout
in an exiting process.

Reported by:    syzkaller
Reviewed by:    kib
MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D49529
DeltaFile
+2-0sys/kern/kern_time.c
+1-0sys/kern/kern_exit.c
+3-02 files

FreeBSD/src 6091e2asbin/pfctl pfctl.8

pfctl.8: fix typo in reference to rc.conf variable

Reviewed by:    kp, @concussious, @ImAwsumm
Pull Request:   https://github.com/freebsd/freebsd-src/pull/1630
DeltaFile
+1-1sbin/pfctl/pfctl.8
+1-11 files

FreeBSD/src b68c7ebsys/vm vm_reserv.c

vm_reserv: extract common gap-checking code

vm_reserv_alloc_contig and vm_reserv_alloc_page both have code to
determine whether a new reservation will fit between the predecessor
and successor. Extract this code into a separate function rather than
having it appear twice. Optimize slightly to avoid checking object
size limit when there is a successor, and to avoid checking the upper
bound at all when the size to be allocated is a multiple of
reservation size.

Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D49460
DeltaFile
+80-95sys/vm/vm_reserv.c
+80-951 files

FreeBSD/src 526becbtests/sys/kern ptrace_test.c

ptrace_test: add test for expanded reporting of syscall args

Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D49430
DeltaFile
+48-0tests/sys/kern/ptrace_test.c
+48-01 files

FreeBSD/src fd5bc30sys/kern kern_sig.c sys_process.c

ptrace(2): expand ability to fetch syscall parameters

Do not limit lwpinfo reporting of syscall number and args to SCE/SCX
events. When td_sa holds the values, we can report them. Clear
td_sa.code in TDA_SIG ast handler: this handler is run when the process
is traced, and it is run with the last ptracestop() points before the
return to userspace.

This allows debugger to infer the interrupted syscall immediately after
PT_ATTACH without the need to loose control to the debuggee' thread. It
should work even when the debuggee is stopped in AST.

Reviewed by:    markj
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential revision:  https://reviews.freebsd.org/D49430
DeltaFile
+8-0sys/kern/kern_sig.c
+3-5sys/kern/sys_process.c
+11-52 files

FreeBSD/src fb8c944usr.bin/procstat procstat_files.c

procstat: decode SOCK_SEQPACKET unix domain socket type

(cherry picked from commit 8011df62f57f021a1b4f62d9beea4c25d9b37a23)
DeltaFile
+2-0usr.bin/procstat/procstat_files.c
+2-01 files

FreeBSD/src 04e4ddausr.bin/procstat procstat.1

procstat.1: document local SOCK_SEQPACKET socket display

(cherry picked from commit 03dfb8d0211cf9d7405c4fd7d541dde28047001c)
DeltaFile
+2-0usr.bin/procstat/procstat.1
+2-01 files

FreeBSD/src 192aae0lib/libprocstat core.c

libprocstat: constify psc_type_info[]

(cherry picked from commit debcd4c05701be0ff48c6b350ed6b3a80e5f0b1f)
DeltaFile
+1-1lib/libprocstat/core.c
+1-11 files

FreeBSD/src a02f377usr.bin/procstat procstat.1

procstat.1: correct local socket types descriptions.

(cherry picked from commit 991329f507a893076a4119c90bb463de0ac15be9)
DeltaFile
+2-6usr.bin/procstat/procstat.1
+2-61 files

FreeBSD/src 8056c96lib/libprocstat core.c core.h

libprocstat: change psc_type_info array to use designated initializers

(cherry picked from commit ba2fb6b367fd513ea5812a496254d3a05ec380b8)
DeltaFile
+48-12lib/libprocstat/core.c
+1-1lib/libprocstat/core.h
+49-132 files

FreeBSD/src f6deb9esys/netinet/tcp_stacks rack.c tcp_rack.h

tcp rack: cleanup storing values for beta and beta_ecn

beta and beta_ecn were stored using a variable of type struct newreno
in struct rack_control. Later, struct newreno was extended and now
contains several more fields.
This results in a memory inefficiency and also in copying around
uninitialized memory.
This patch fixes this by storing beta and beta_ecn individually in
struct rack_control.
Please note that the newreno_flags field was only stored and never
used. Therefore, this is not stored anymore in struct rack_control.
No functional change intended.

CID:                    1523796
Reviewed by:            rrs
MFC after:              1 week
Sponsored by:           Netflix, Inc.
Differential Revision:  https://reviews.freebsd.org/D49578
DeltaFile
+20-25sys/netinet/tcp_stacks/rack.c
+4-3sys/netinet/tcp_stacks/tcp_rack.h
+24-282 files

FreeBSD/src e862383sys/netinet sctp_pcb.c

sctp: fix double unlock in case adding a remote address fails

Thanks to glebius@ for pointing to the problem.

Reported by:    syzbot+1d5c164f1c10de84ad8a at syzkaller.appspotmail.com
Fixes:          2d5c48eccd9f ("sctp: Tighten up locking around sctp_aloc_assoc()"
MFC after:      3 days
DeltaFile
+0-1sys/netinet/sctp_pcb.c
+0-11 files

FreeBSD/src 25df691sys/dev/nvme nvme_ctrlr.c

nvme: Fix hotplug on one of the amazon platforms

Amazon EC2 m7i cloud instances use PCI hotplug rather than ACPI
hotplug. The card is removed and detach is called to remove the drive
from the system. The hardware is no longer present at this point, but
the bridge doesn't translate the now-missing hardware reads to all ff's
leading us to conclude the hardware is there and we need to do a proper
shutdown of it. Fix this oversight by asking the bridge if the device is
still present as well. We need both tests since some systems one cane
remove the card w/o a hotplug event and we want to fail-safe in those
cases.

Convert gone to a bool while I'm here and update a comment about
shutting down the controller and why that's important.

Tested by: cperciva
Sponsored by: Netflix

(cherry picked from commit dc95228d98474aba940e3885164912b419c5579d)
DeltaFile
+19-12sys/dev/nvme/nvme_ctrlr.c
+19-121 files

FreeBSD/src b6420b5sys/dev/sound/pcm feeder_mixer.c

sound: Fix regression in pcm/feeder_mixer.c

This call was meant to be the default case in the first place, but
somehow missed this.

Reported by:    glebius
Fixes:          4021fa32d92d ("sound: Simplify pcm/feeder_mixer.c")
MFC after:      1 week
Sponsored by:   The FreeBSD Foundation
DeltaFile
+4-2sys/dev/sound/pcm/feeder_mixer.c
+4-21 files

FreeBSD/src 3540067sys/dev/sound/pcm vchan.c sound.c

sound: Use bus_topo_lock() where appropriate

Lock around uses of devclass_*() and replace leftover
CTLFLAG_NEEDGIANTs with CTLFLAG_MPSAFE.

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Reviewed by:    imp, jhb
Differential Revision:  https://reviews.freebsd.org/D46700
DeltaFile
+23-5sys/dev/sound/pcm/vchan.c
+17-2sys/dev/sound/pcm/sound.c
+6-0sys/dev/sound/pcm/dsp.c
+4-2sys/dev/sound/pcm/channel.c
+5-0sys/dev/sound/pcm/mixer.c
+3-1sys/dev/sound/pcm/feeder_rate.c
+58-106 files

FreeBSD/src a4aff02sys/dev/sound/pcm channel.c

sound: Improve afmt_tab

Reduce ifdefs, and add aliases for the unsigned formats.

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Reviewed by:    dev_submerge.ch
Differential Revision:  https://reviews.freebsd.org/D48009
DeltaFile
+18-13sys/dev/sound/pcm/channel.c
+18-131 files

FreeBSD/src 1166cfdusr.bin/beep beep.c

beep(1): Use AFMT_FLOAT

AFMT_FLOAT is supported by sound(4) as of FILLME, so use it here, since
the whole program works with floats already.

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D47639
DeltaFile
+4-4usr.bin/beep/beep.c
+4-41 files

FreeBSD/src e1bbaa7sys/dev/sound/pcm pcm.h sound.h, sys/sys soundcard.h

sound: Implement AFMT_FLOAT support

Even though the OSS manual [1] advises against using AFMT_FLOAT, there
are applications that expect the sound driver to support it, and might
not work properly without it.

This patch adds AFMT_F32_LE|BE (as well as AFMT_FLOAT for OSS
compatibility) in sys/soundcard.h and implements AFMT_F32_LE|BE <->
AFMT_S32_LE|BE conversion functions. As a result, applications can
write/read floats to/from sound(4), but internally, because sound(4)
works with integers, we convert floating point samples to integer ones,
before doing any processing.

The reason for encoding/decoding IEEE754s manually, instead of using
fpu_kern(9), is that fpu_kern(9) is not supported by all architectures,
and also introduces significant overhead.

The IEEE754 encoding/decoding implementation has been written by Ariff
Abdullah [2].

    [9 lines not shown]
DeltaFile
+64-3sys/dev/sound/pcm/pcm.h
+8-5sys/dev/sound/pcm/sound.h
+8-0sys/sys/soundcard.h
+6-0tests/sys/sound/pcm_read_write.c
+4-0sys/dev/sound/pcm/feeder_rate.c
+4-0sys/dev/sound/pcm/channel.c
+94-82 files not shown
+98-88 files

FreeBSD/src e372211sys/dev/sound/pcm vchan.c channel.c

sound: Fix vchanrate and vchanformat

Make vchanrate and vchanformat reflect the primary channel's software
buffer's rate and format respectively. Fix previous inconsistencies.

Get rid of the initializations in vchan_create() and move them to
chn_init().

Without the feeder_rate_round check in sysctl_dev_pcm_vchanrate(), we
can set the software rate to anything between feeder_rate_min and
feeder_rate_max. If we keep the check, however, the rate is limited to
whatever the driver's min/max is, which can be a problem if, for
example, the driver supports only a single rate, in which case we won't
be able to set anything other than the driver rate.

Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D48961
DeltaFile
+3-79sys/dev/sound/pcm/vchan.c
+10-2sys/dev/sound/pcm/channel.c
+13-812 files

FreeBSD/src 0cc5e57share/man/man5 src.conf.5

src.conf.5: regen after riscv EFI change

Reported by:    jlduran
Fixes: 269cbe092da3 ("kern.opts.mk: Remove EFI from riscv BROKEN_OPTIONS")
DeltaFile
+3-3share/man/man5/src.conf.5
+3-31 files

FreeBSD/src 83d13d8sys/kern kern_rwlock.c kern_mutex.c

locks: run the extra NULL check only with INVARIANTS

This reverts commit 73da0265c29c79641dab3e6b98452bd5afca01fb.
This reverts commit 87ee63bac69dc49291f55590b8baa57cad6c7d85.

Discussed with:         mjg
DeltaFile
+4-12sys/kern/kern_rwlock.c
+1-3sys/kern/kern_mutex.c
+5-152 files

FreeBSD/src cd46e98sys/kern kern_prot.c, sys/sys ucred.h

cred: fix struct credbatch to use long for refcount

This structure collects count from multiple cred structures.  Of course it
can't use a smaller type.

PR:                     283747
Reviewed by:            olce, mjg, markj
Differential Revision:  https://reviews.freebsd.org/D49562
Fixes:                  37337709d3334f32650ba3a7c529fa013ed5e1f2
DeltaFile
+2-2sys/sys/ucred.h
+1-1sys/kern/kern_prot.c
+3-32 files