FreeBSD/src c185935lib/libc/gen exterr_cat_filenames.h, sys/dev/hwpmc hwpmc_mod.c

hwpmc: Add EXTERROR diagnostics to the hwpmc syscall path

Annotate validation failures in the PMC syscall handlers (allocate,
attach, read/write) with EXTERROR(), so pmc(3) callers see which
precondition failed, not a bare errno.

Register HWPMC_MOD in exterr_cat.h and the generated filenames.h.

Signed-off-by:  Andre Silva <andasilv at amd.com>
Reviewed by:    Ali Mashtizadeh <ali at mashtizadeh.com>, mhorne
Sponsored by:   AMD
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2180
DeltaFile
+79-31sys/dev/hwpmc/hwpmc_mod.c
+1-0lib/libc/gen/exterr_cat_filenames.h
+1-0sys/sys/exterr_cat.h
+81-313 files

FreeBSD/src 8c4d570lib/libc/gen exterr_cat_filenames.h, sys/dev/hwpmc hwpmc_ibs.c hwpmc_amd.c

hwpmc: Add EXTERROR diagnostics to the AMD and IBS allocators

Replace bare EINVAL in AMD/IBS allocation and config-validation with
EXTERROR(), so a failed pmc(3) allocation names the check and value.

Register HWPMC_AMD in exterr_cat.h and the generated filenames.h.

Signed-off-by:  Andre Silva <andasilv at amd.com>
Reviewed by:    Ali Mashtizadeh <ali at mashtizadeh.com>, mhorne
Sponsored by:   AMD
Pull Request:   https://github.com/freebsd/freebsd-src/pull/2180
DeltaFile
+28-17sys/dev/hwpmc/hwpmc_ibs.c
+17-7sys/dev/hwpmc/hwpmc_amd.c
+1-1sys/sys/exterr_cat.h
+1-0lib/libc/gen/exterr_cat_filenames.h
+47-254 files

FreeBSD/src 6eaa8edlib/libfetch common.c http.c

libfetch: Reduce copying

Reduce the amount of copying we do when performing buffered reads.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D58113

(cherry picked from commit 60382b4a04fa39e9bf65b964b1b7b4bed6eaa56a)
DeltaFile
+29-16lib/libfetch/common.c
+18-23lib/libfetch/http.c
+12-11lib/libfetch/ftp.c
+2-0lib/libfetch/common.h
+61-504 files

FreeBSD/src 2902f7alib/libfetch common.h common.c

libfetch: Make fetch_ref an inline

Make fetch_ref() an inline and provide a fetch_deref().

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57944

(cherry picked from commit d4e0e1fbc237f0765b9f32b291c087348031c921)
DeltaFile
+12-1lib/libfetch/common.h
+0-11lib/libfetch/common.c
+1-1lib/libfetch/ftp.c
+13-133 files

FreeBSD/src 29564d9usr.bin/fetch fetch.c fetch.1

fetch: Stop setting an alarm

Now that fetchTimeout works reliably, setting an alarm is not only no
longer necessary but counterproductive, as it will trigger even if the
connection is not actually stalled but merely slow.

While here, improve the wording of the manual page's description of the
various options for setting a timeout.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57911

(cherry picked from commit 3dddfe29248c47d1a80dc96a76a308ae910b2a24)
DeltaFile
+9-24usr.bin/fetch/fetch.c
+6-4usr.bin/fetch/fetch.1
+15-282 files

FreeBSD/src c83d4edlib/libfetch fetch.3

libfetch: Document fetchTimeout

Document the global fetchTimeout variable, now that it works reliably.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57910

(cherry picked from commit 27b411734c75a7a5abe641d7fbb99dfc622e9aba)
DeltaFile
+16-2lib/libfetch/fetch.3
+16-21 files

FreeBSD/src 02e82d4lib/libfetch common.c http.c

libfetch: Add read buffering

Previously, we would read FTP control connection messages and HTTP
reponse headers one character at a time.  Now, we read as much as will
fit in our buffer and look for a newline.  If there is data left over,
it will be reused by the next fetch_getln() call.  This also requires
the addition of a fetch_bufread() which takes the buffer into account,
otherwise the start of the HTTP response body will be stuck in the
buffer after we read the last line of the header.

This should noticeably improve HTTP performance, especially for small
transfers.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57907

(cherry picked from commit a1978277379cf65f1339ab062f335c6f1fa6239f)
DeltaFile
+87-22lib/libfetch/common.c
+24-41lib/libfetch/http.c
+4-7lib/libfetch/ftp.c
+3-1lib/libfetch/common.h
+118-714 files

FreeBSD/src 74a9217lib/libfetch common.c

libfetch: Apply timeout to connection attempts

Mark the socket non-blocking before connecting and poll for completion,
applying fetchTimeout if set.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57909

(cherry picked from commit 848f360c8f9ae8d1d97c61f5d63fc624926d5dcd)
DeltaFile
+42-7lib/libfetch/common.c
+42-71 files

FreeBSD/src edf0ba5lib/libfetch common.c common.h

libfetch: Overhaul socket read / write

* Make fetch_ssl_read() and fetch_ssl_write() behave more like read(2)
  and write(2), and drop fetch_socket_read() in favor of read(2).

* Don't request POLLERR, it's implied.

* Don't needlessly set errno, it's relatively costly.

* Always check for EAGAIN from writev(2), otherwise we will abort on a
  short write instead of proceeding to poll(2).

* Always check for EAGAIN from poll(2) even though it can't happen on
  FreeBSD; POSIX says it can, and it might in the future.

* Rewrite fetch_read() and fetch_writev() to be more similar to each
  other.  The main difference is that a partial read is treated as
  success while a partial write is treated as failure.


    [6 lines not shown]
DeltaFile
+131-87lib/libfetch/common.c
+2-2lib/libfetch/common.h
+133-892 files

FreeBSD/src 520105clib/libfetch common.c http.c

libfetch: Reduce copying

Reduce the amount of copying we do when performing buffered reads.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D58113

(cherry picked from commit 60382b4a04fa39e9bf65b964b1b7b4bed6eaa56a)
DeltaFile
+29-16lib/libfetch/common.c
+18-23lib/libfetch/http.c
+12-11lib/libfetch/ftp.c
+2-0lib/libfetch/common.h
+61-504 files

FreeBSD/src 0786814lib/libfetch common.h common.c

libfetch: Make fetch_ref an inline

Make fetch_ref() an inline and provide a fetch_deref().

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57944

(cherry picked from commit d4e0e1fbc237f0765b9f32b291c087348031c921)
DeltaFile
+12-1lib/libfetch/common.h
+0-11lib/libfetch/common.c
+1-1lib/libfetch/ftp.c
+13-133 files

FreeBSD/src 98bfed5usr.bin/fetch fetch.c fetch.1

fetch: Stop setting an alarm

Now that fetchTimeout works reliably, setting an alarm is not only no
longer necessary but counterproductive, as it will trigger even if the
connection is not actually stalled but merely slow.

While here, improve the wording of the manual page's description of the
various options for setting a timeout.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57911

(cherry picked from commit 3dddfe29248c47d1a80dc96a76a308ae910b2a24)
DeltaFile
+9-24usr.bin/fetch/fetch.c
+6-4usr.bin/fetch/fetch.1
+15-282 files

FreeBSD/src a69d286lib/libfetch fetch.3

libfetch: Document fetchTimeout

Document the global fetchTimeout variable, now that it works reliably.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57910

(cherry picked from commit 27b411734c75a7a5abe641d7fbb99dfc622e9aba)
DeltaFile
+16-2lib/libfetch/fetch.3
+16-21 files

FreeBSD/src ad7a144lib/libfetch common.c

libfetch: Apply timeout to connection attempts

Mark the socket non-blocking before connecting and poll for completion,
applying fetchTimeout if set.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57909

(cherry picked from commit 848f360c8f9ae8d1d97c61f5d63fc624926d5dcd)
DeltaFile
+42-7lib/libfetch/common.c
+42-71 files

FreeBSD/src b56f3ealib/libfetch common.c common.h

libfetch: Overhaul socket read / write

* Make fetch_ssl_read() and fetch_ssl_write() behave more like read(2)
  and write(2), and drop fetch_socket_read() in favor of read(2).

* Don't request POLLERR, it's implied.

* Don't needlessly set errno, it's relatively costly.

* Always check for EAGAIN from writev(2), otherwise we will abort on a
  short write instead of proceeding to poll(2).

* Always check for EAGAIN from poll(2) even though it can't happen on
  FreeBSD; POSIX says it can, and it might in the future.

* Rewrite fetch_read() and fetch_writev() to be more similar to each
  other.  The main difference is that a partial read is treated as
  success while a partial write is treated as failure.


    [6 lines not shown]
DeltaFile
+131-87lib/libfetch/common.c
+2-2lib/libfetch/common.h
+133-892 files

FreeBSD/src fdef039lib/libfetch common.c http.c

libfetch: Add read buffering

Previously, we would read FTP control connection messages and HTTP
reponse headers one character at a time.  Now, we read as much as will
fit in our buffer and look for a newline.  If there is data left over,
it will be reused by the next fetch_getln() call.  This also requires
the addition of a fetch_bufread() which takes the buffer into account,
otherwise the start of the HTTP response body will be stuck in the
buffer after we read the last line of the header.

This should noticeably improve HTTP performance, especially for small
transfers.

MFC after:      1 week
Reviewed by:    op
Differential Revision:  https://reviews.freebsd.org/D57907

(cherry picked from commit a1978277379cf65f1339ab062f335c6f1fa6239f)
DeltaFile
+87-22lib/libfetch/common.c
+24-41lib/libfetch/http.c
+4-7lib/libfetch/ftp.c
+3-1lib/libfetch/common.h
+118-714 files

FreeBSD/src 2e38926sys/dev/hid u2f.c

hid: u2f: stop interrupts on last-close

This fixes an issue with the Solo2 (and likely some of the Nitrokey
family) where hangs would occur with OpenSSH- it issues a CANCEL prior
to closing the device unconditionally, and without draining the read
endpoint we end up seeing the response to that CANCEL the next time
OpenSSH tries to connect.  This throws the entire command/response
sequence out of whack.

This call used to break Yubikeys in some situations, but the fix that
landed in 28d85db46b48 ("xhci: Do not drop and add bits in xhci") seems
to have addressed that- presumably we sometimes end up stopping the
command and desyncing at the controller level.  This probably implies
that we need a SYNCWRITE HID quirk, but that requires a little more work
in usbhid_sync_xfer() and this doesn't seem to cause any problems in
normal usage.

Reviewed by:    aokblast, wulf
Differential Revision:  https://reviews.freebsd.org/D58199
DeltaFile
+0-3sys/dev/hid/u2f.c
+0-31 files

FreeBSD/src a5307a5sys/dev/usb/video uvideo.c

uvideo: fix use-after-free in mmap buffer lifetime management

The uvideo driver freed the mmap buffer (contigmalloc'd) in several
paths (VIDIOC_STREAMOFF, last close, detach) without coordinating
with the lifetime of existing user-space mmap mappings.  This could
lead to use-after-free when user-space continued to access the
mapped memory after the backing pages had been freed.

Fix this by switching from the simple d_mmap callback to d_mmap_single
with custom cdev_pager_ops, and by attaching the contig buffer to a
single shared vm_object created at REQBUFS time:

- uvideo_reqbufs() allocates a uvideo_mmap_state (independent of the
  softc) and a shared vm_object via cdev_pager_allocate() that spans
  the whole buffer; the softc holds one reference to it.
- uvideo_cdev_mmap_single() simply hands out additional references to
  that shared object; the requested offset selects which buffer is
  mapped.  The VM system tracks mapping lifetime through the object
  reference count, so no per-mapping bookkeeping is needed.

    [18 lines not shown]
DeltaFile
+162-14sys/dev/usb/video/uvideo.c
+162-141 files

FreeBSD/src a141337usr.sbin/bsdinstall/scripts netconfig

bsdinstall/netconfig: use a better heuristic for wlan dev desc

For devices like the rtw88, they will show up in `ifconfig -l` as
rtw880, rtw881, etc. We want to query the rtw88.0 and rtw88.1 sysctl
respectively, not rtw.880.

Chances are that there aren't more than 9 wlan devices using the same
driver. Use a better heuristic to get the device description.

Reviewed by:    bz
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit c4b0b13cadac46b7c2cdfeeedeffa596c62568fa)
DeltaFile
+1-1usr.sbin/bsdinstall/scripts/netconfig
+1-11 files

FreeBSD/src d860a73usr.bin/awk/tests/bugs-fixed bug_fix_test.sh

awk/tests: xfail inf-nan-torture on riscv64

The fix for this is being tracked upstream here:
https://github.com/onetrueawk/awk/issues/269

While here, just cd into $SRCDIR while executing tests,
since the test engine isolates every testcase's working
directory. This ensures that the xfail actually applies
to the next command.

Reviewed by:    mhorne
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit d0b1a389003b1e6ff5bcf35a7c04654ea7ff87bd)
DeltaFile
+8-4usr.bin/awk/tests/bugs-fixed/bug_fix_test.sh
+8-41 files

FreeBSD/src 5aa70e0usr.sbin/bsdinstall/scripts netconfig

bsdinstall/netconfig: use a better heuristic for wlan dev desc

For devices like the rtw88, they will show up in `ifconfig -l` as
rtw880, rtw881, etc. We want to query the rtw88.0 and rtw88.1 sysctl
respectively, not rtw.880.

Chances are that there aren't more than 9 wlan devices using the same
driver. Use a better heuristic to get the device description.

Reviewed by:    bz
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit c4b0b13cadac46b7c2cdfeeedeffa596c62568fa)
DeltaFile
+1-1usr.sbin/bsdinstall/scripts/netconfig
+1-11 files

FreeBSD/src a4f38a5usr.bin/awk/tests/bugs-fixed bug_fix_test.sh

awk/tests: xfail inf-nan-torture on riscv64

The fix for this is being tracked upstream here:
https://github.com/onetrueawk/awk/issues/269

While here, just cd into $SRCDIR while executing tests,
since the test engine isolates every testcase's working
directory. This ensures that the xfail actually applies
to the next command.

Reviewed by:    mhorne
MFC after:      3 days
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit d0b1a389003b1e6ff5bcf35a7c04654ea7ff87bd)
DeltaFile
+8-4usr.bin/awk/tests/bugs-fixed/bug_fix_test.sh
+8-41 files

FreeBSD/src f22b084sys/netinet tcp_hostcache.c

tcp_hostcache: explicitly typecast atomic_load_int to (int) for comparison

Sponsored by:   NetApp, Inc.
MFC after:      1 week
Reviewed By:    tuexen, #transport, markj
Differential Revision: https://reviews.freebsd.org/D58360
DeltaFile
+1-1sys/netinet/tcp_hostcache.c
+1-11 files

FreeBSD/src c817e3clib/libc/resolv res_init.c

libc/resolv: Refactor the configuration parser

This was previously all a single loop in res_init(), apart from option
parsing which we cleaned up in a previous commit.  Break it out into
separate functions for reading the configuration line by line, setting
the default domain, setting the search list, and adding a nameserver
to the nameserver list.  Sprinkle bounds checks and code comments all
around.

The sortlist code, which has been disabled for the past 20 years, will
be dealt with in a separate commit.

MFC after:      1 week
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57924

(cherry picked from commit ffeb56905ed6a7ac759367096d6dc0596e82e03f)
DeltaFile
+381-268lib/libc/resolv/res_init.c
+381-2681 files

FreeBSD/src fc00e7alib/libc/resolv res_init.c Makefile.inc, share/man/man5 resolver.5

libc/resolv: Reimplement the sortlist parser

When we switched from the BIND4 resolver to the BIND9 resolver, the
sortlist parser was inadvertently disabled due to a missing #define, and
nobody seemed to notice.  The sorting code remained enabled in the
resolver, but there was no way to set a sort order.

Reimplement the sortlist parser, but correctly, and update the manual
accordingly.  The new parser accepts IPv4 and IPv6 addresses with or
without a mask or prefix length, just like the old one, except IPv6
support was a bit wonky in the original code.

Fixes:          5342d17f09a8 ("Update the resolver in libc to BIND9's one.")
Relnotes:       yes
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57925

(cherry picked from commit fbe0257b5613f457af42f82efb2e3bc9395d0557)
DeltaFile
+136-110lib/libc/resolv/res_init.c
+23-13share/man/man5/resolver.5
+1-0lib/libc/resolv/Makefile.inc
+160-1233 files

FreeBSD/src 19d044blib/libc/resolv res_init.c

libc/resolv: Dead code and style cleanup

Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57928

(cherry picked from commit 4805b88edb009e53c4fee159138d2cbe0c848da7)
DeltaFile
+17-42lib/libc/resolv/res_init.c
+17-421 files

FreeBSD/src c6030cainclude resolv.h

resolv.h: Remove unused parts

Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57927

(cherry picked from commit 3f15998d25da08677d2c40bc2240de293aec4205)
DeltaFile
+0-49include/resolv.h
+0-491 files

FreeBSD/src 345d104lib/libc/resolv res_init.c, share/man/man5 resolver.5

libc/resolv: Add no-debug and no-rotate options

These are simply the reverse of the debug and rotate options.

Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D57926

(cherry picked from commit 60827d7885016861dc02caa45f3ce873ad2a020e)
DeltaFile
+12-0share/man/man5/resolver.5
+4-0lib/libc/resolv/res_init.c
+16-02 files

FreeBSD/src 2bab563share/man/man5 resolver.5

resolver(5): Overhaul

* Modernize the markup

* Describe the comment syntax

* Drop obsolete advice

* Capitalize sentences

* Improve the language

* Replace no_tld_query with no-tld-query; both are supported, but all the
  other multi-word options use hyphens rather than underscores.

* Add missing ENVIRONMENT section

* Redo the example


    [5 lines not shown]
DeltaFile
+116-111share/man/man5/resolver.5
+116-1111 files

FreeBSD/src b796284lib/libc/net gethostbydns.c, lib/libc/resolv res_send.c res_init.c

libc: Disable debugging code in the resolver.

Reviewed by:    kevans
Differential Revision:  https://reviews.freebsd.org/D37319

(cherry picked from commit cd0756cef21079104967969e275c18b84dc45053)
DeltaFile
+10-8lib/libc/resolv/res_send.c
+0-6lib/libc/resolv/res_init.c
+6-0lib/libc/net/gethostbydns.c
+0-5lib/libc/resolv/res_mkquery.c
+0-5lib/libc/resolv/res_query.c
+0-4lib/libc/resolv/res_mkupdate.c
+16-282 files not shown
+19-318 files