]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
6 months agoinpcb: poison several inpcb pointer in in_pcbfree()
Gleb Smirnoff [Wed, 27 Dec 2023 16:34:37 +0000 (08:34 -0800)]
inpcb: poison several inpcb pointer in in_pcbfree()

There are few subsystems that reference inpcb and allow it to outlive
in_pcbfree().  There are no known bugs with them to unreference the
options pointers for a freed inpcb.  Enforce this so that such bugs
don't appear in the future.

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

6 months agoinpcb: reoder inpcb destruction
Gleb Smirnoff [Wed, 27 Dec 2023 16:34:37 +0000 (08:34 -0800)]
inpcb: reoder inpcb destruction

First, merge in_pcbdetach() with in_pcbfree().  The comment for
in_pcbdetach() was no longer correct.  Then, make sure we remove
the inpcb from the hash before we commit any destructive actions
on it.  There are couple functions that rely on the hash lock
skipping SMR + inpcb lock to lookup an inpcb.  Although there are
no known functions that similarly rely on the global inpcb list
lock, also do list removal before destructive actions.

PR: 273890
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D43122

6 months agofortune: update mailing list search url
Christos Margiolis [Wed, 27 Dec 2023 16:28:11 +0000 (18:28 +0200)]
fortune: update mailing list search url

Markmail no longer exists.

Reviewed by: markj
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D43209

6 months agodaemon: fix recent style regressions
Kyle Evans [Wed, 27 Dec 2023 16:08:28 +0000 (10:08 -0600)]
daemon: fix recent style regressions

Re-wrap the read(2) line, and make the listen_child loop more explicit
in intent.

Reported by: kib
Fixes: 6ac7c9f06ae9 ("daemon: remove redundant parameter from [...]")

6 months agonetmap: Ignore errors in CSB_WRITE()
Mark Johnston [Wed, 27 Dec 2023 15:13:29 +0000 (10:13 -0500)]
netmap: Ignore errors in CSB_WRITE()

The CSB_WRITE() and _READ() macros respectively write to and read from
userspace memory and so can in principle fault.  However, we do not
check for errors and will proceed blindly if they fail.  Add assertions
to verify that they do not.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: vmaffione
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43200

6 months agolinux: Check for copyout errors in ioctl handlers
Mark Johnston [Wed, 27 Dec 2023 15:13:15 +0000 (10:13 -0500)]
linux: Check for copyout errors in ioctl handlers

In preparation for annotating copyin() and friends with
__result_use_check.

Reviewed by: dchagin
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43199

6 months agolinuxkpi: Annotate an unused variable as such
Mark Johnston [Wed, 27 Dec 2023 15:11:33 +0000 (10:11 -0500)]
linuxkpi: Annotate an unused variable as such

This addresses a -Wunused-but-set-variable warning in the gcc builds.

No functional change intended.

Reported by: Jenkins

6 months agoConvert fsidcmp(9) from macro to inline function
Konstantin Belousov [Tue, 26 Dec 2023 19:39:33 +0000 (21:39 +0200)]
Convert fsidcmp(9) from macro to inline function

This allows type checking the arguments.

Explicit structure members comparisions are done to avoid introducting
string.h pollution for userspace.

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D43205

6 months agogpioevents: Fix a typo in a diagnostic output message
Gordon Bergling [Wed, 27 Dec 2023 08:41:48 +0000 (09:41 +0100)]
gpioevents: Fix a typo in a diagnostic output message

- s/recieved/received/

MFC after: 3 days

6 months agoipfw(4): Fix a typo in a source code comment
Gordon Bergling [Wed, 27 Dec 2023 08:38:43 +0000 (09:38 +0100)]
ipfw(4): Fix a typo in a source code comment

- s/preserv/preserve/

MFC after: 3 days

6 months agohvsock: Fix a typo in a source code comment
Gordon Bergling [Wed, 27 Dec 2023 08:37:29 +0000 (09:37 +0100)]
hvsock: Fix a typo in a source code comment

- s/recieved/received/

MFC after: 3 days

6 months agotcp_stacks: Fix two typos in a source code comments
Gordon Bergling [Wed, 27 Dec 2023 08:36:30 +0000 (09:36 +0100)]
tcp_stacks: Fix two typos in a source code comments

- s/recieved/received/

MFC after: 3 days

6 months agotail(1): Fix a typo in a source code comment
Gordon Bergling [Wed, 27 Dec 2023 08:35:38 +0000 (09:35 +0100)]
tail(1): Fix a typo in a source code comment

- s/recieved/received/

MFC after: 3 days

6 months agodaemon: separate pipe_fd[2] into pipe_rd and pipe_wr
Ihor Antonov [Wed, 27 Dec 2023 06:07:26 +0000 (00:07 -0600)]
daemon: separate pipe_fd[2] into pipe_rd and pipe_wr

This improves code readability and prevents mixing up read and write
ends of the pipe.

Reviewed by: cperciva, kevans
Requested by: kevans

6 months agodaemon: replace memchr with memrchr
Ihor Antonov [Wed, 27 Dec 2023 06:07:26 +0000 (00:07 -0600)]
daemon: replace memchr with memrchr

Looping over lines in the buffer is not needed.
Same effect can be achieved by looking for the last new line.
If found the buffer is guaranteed to have one or more complete lines.
All complete lines are flushed at once with no looping.

Reviewed by: cperciva, kevans

6 months agodaemon: move buffer into daemon_state
Ihor Antonov [Wed, 27 Dec 2023 06:07:25 +0000 (00:07 -0600)]
daemon: move buffer into daemon_state

There is no reason for a buffer in listen_child()
to be a static function variable. The buffer and
its position are parts of the daemon state and should
live together with the rest of the state variables.

Reviewed by: cperciva, kevans

6 months agodaemon: remove redundant parameter from listen_child()
Ihor Antonov [Wed, 27 Dec 2023 06:07:25 +0000 (00:07 -0600)]
daemon: remove redundant parameter from listen_child()

state already contains pipe fd

Reviewed by: cperciva, kevans

6 months agodaemon: fix clang-tidy warnings
Ihor Antonov [Wed, 27 Dec 2023 06:07:25 +0000 (00:07 -0600)]
daemon: fix clang-tidy warnings

Fixed narrowing conversions:
- strtol replaced with strtonum with range check
- read returns ssize_t
- kevent.data explicitly cast to int before passing into strerror

While we we're here:
- Defined and documented maximum restart delay.
- Fixed typo in a comment.
- Remove unused includes

Reviewed by: cperciva, kevans

6 months agonetlink: simplify socket destruction
Gleb Smirnoff [Wed, 27 Dec 2023 04:22:12 +0000 (20:22 -0800)]
netlink: simplify socket destruction

Destroy the socket at the file descriptor close(2).  There is no
reason to linger for any longer, there are no external references.
Remove pr_detach method as nothing left to do after pr_close.
Remove pr_abort method as it shall never be executed for this type
of socket.

Reviewed by: melifaro
Differential Revision: https://reviews.freebsd.org/D42521

6 months agolinux/netlink: don't override sopt level
Gleb Smirnoff [Wed, 27 Dec 2023 04:21:58 +0000 (20:21 -0800)]
linux/netlink: don't override sopt level

This override effectively prevents correct entering of netlink
protocol specific pr_ctloutput in sosetopt().

Reviewed by: melifaro
Differential Revision: https://reviews.freebsd.org/D42520

6 months agonetlink: remove unused structure
Gleb Smirnoff [Wed, 27 Dec 2023 04:21:58 +0000 (20:21 -0800)]
netlink: remove unused structure

6 months agoSchedule fast taskqueue callouts on right CPU.
Alexander Motin [Wed, 27 Dec 2023 03:30:56 +0000 (22:30 -0500)]
Schedule fast taskqueue callouts on right CPU.

With fast taskqueues using direct callouts we can reduce number of
CPU wakeups by scheduling callout on current CPU if taskqueue calls
taskqueue_enqueue_timeout() on itself.  The trick won't work for
regular taskqueues, since the callout thread will occupy the CPU.
It also may not work in case of multiple threads since we do not
know which thread will pick the task, and we do not want excessive
callout migrations.  So we optimize only the other cases we can.

In practice this allows iichid(4) taskqueue to stay on CPU where
underlying ig4(4) interrupts are routed and to not kick CPU 0 with
timer interrupts on each sampling period (every 2nd/3rd sleep).

MFC after: 1 month

6 months agonetpfil: Use accessor functions and named constants for all tcphdr flags
Richard Scheffenegger [Mon, 25 Dec 2023 11:26:25 +0000 (12:26 +0100)]
netpfil: Use accessor functions and named constants for all tcphdr flags

Update all remaining references to the struct tcphdr th_x2 field.
This completes the compatibilty of various aspects with AccECN
(TH_AE), after the internal ipfw "re-checksum required" was moved
to use the TH_RES1 flag.

No functional change.

Reviewed By:           tuexen, #transport, glebius
Sponsored by:          NetApp, Inc.
Differential Revision: https://reviews.freebsd.org/D43172

6 months agoiichid(4): Switch taskqueue to "fast"
Alexander Motin [Wed, 27 Dec 2023 00:36:34 +0000 (19:36 -0500)]
iichid(4): Switch taskqueue to "fast"

While "fast" taskqueue may be more expensive due to spinlock use,
when used mainly for timeout tasks it allows to avoid extra context
switches to and from callout thread, that is even more expensive.

MFC after: 1 month

6 months agoiichid(4): Unify two taskqueue tasks
Alexander Motin [Wed, 27 Dec 2023 00:28:56 +0000 (19:28 -0500)]
iichid(4): Unify two taskqueue tasks

taskqueue_enqueue_timeout(0) is equivalent to taskqueue_enqueue(),
so no need to create a separate periodic_task and event_task to run
exactly the same handler.

MFC after: 1 month

6 months agofb: Explicitly handle errors when getting or setting a colour palette
Mark Johnston [Wed, 27 Dec 2023 00:00:14 +0000 (19:00 -0500)]
fb: Explicitly handle errors when getting or setting a colour palette

In the VESA driver, simply ignore errors.  It is not clear to me how to
return them to userspace.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

MFC after: 1 week

6 months agohptmv: Handle errors from copyout() in hpt_set_info()
Mark Johnston [Wed, 27 Dec 2023 00:00:01 +0000 (19:00 -0500)]
hptmv: Handle errors from copyout() in hpt_set_info()

This is in preparation for annotating copyin() and related functions
with __result_use_check.

MFC after: 1 week

6 months agotdfx: Handle errors from copyin() and copyout()
Mark Johnston [Tue, 26 Dec 2023 23:59:21 +0000 (18:59 -0500)]
tdfx: Handle errors from copyin() and copyout()

This is in preparation for annotating copyin() and related functions
with __result_use_check.

MFC after: 1 week

6 months agoti: Handle errors from copyin() and copyout()
Mark Johnston [Tue, 26 Dec 2023 23:58:24 +0000 (18:58 -0500)]
ti: Handle errors from copyin() and copyout()

This is in preparation for annotating copyin() and related functions
with __result_use_check.

MFC after: 1 week

6 months agocat: Use present tense
Zhan-Wei [Tue, 26 Dec 2023 23:52:22 +0000 (16:52 -0700)]
cat: Use present tense

Event: Advanced UNIX Programming Course (Fall23) at NTHU.
Reviewed by: imp, lwhsu
Pull Request: https://github.com/freebsd/freebsd-src/pull/923

6 months agoncal(1): print the correct option name when -B is specified twice
Daniel Tameling [Tue, 26 Dec 2023 23:44:47 +0000 (16:44 -0700)]
ncal(1): print the correct option name when -B is specified twice

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/911

6 months agotimeout_test.sh: Fix typo
Elyes Haouas [Tue, 26 Dec 2023 23:39:25 +0000 (16:39 -0700)]
timeout_test.sh: Fix typo

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/906

6 months agosys: ${CFLAGS:N-flto} -> ${CFLAGS:N-flto*}
Alex Xu (Hello71) [Tue, 26 Dec 2023 23:24:53 +0000 (16:24 -0700)]
sys: ${CFLAGS:N-flto} -> ${CFLAGS:N-flto*}

For the same reason as the original https://reviews.freebsd.org/D9659:
-flto=<N>, -flto=full, and -flto=thin also produce the GIMPLE/bitcode
which is not supported by genassym, so filter those out as well.

Signed-off-by: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/898

6 months agoatf-sh: fix comment typo
Igor Ostapenko [Tue, 26 Dec 2023 23:21:54 +0000 (16:21 -0700)]
atf-sh: fix comment typo

Signed-off-by: Igor Ostapenko <pm@igoro.pro>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/895

6 months agoRELNOTES: Add an entry for commit 1a878807006c
Rick Macklem [Tue, 26 Dec 2023 23:01:42 +0000 (15:01 -0800)]
RELNOTES: Add an entry for commit 1a878807006c

6 months agonfscl: Fix handling of expired Kerberos credentials (NFSv4.1/4.2)
Rick Macklem [Tue, 26 Dec 2023 22:33:39 +0000 (14:33 -0800)]
nfscl: Fix handling of expired Kerberos credentials (NFSv4.1/4.2)

If the NFS server detects that the Kerberos credentials provided
by a NFSv4.1/4.2 mount using sec=krb5[ip] have expired, the NFS
server replies with a krpc layer error of RPC_AUTHERROR.
When this happened, the client erroneously left the NFSv4.1/4.2
session slot busy, so that it could not be used by other RPCs.
If this happened for all session slots, the mount point would
hang.

This patch fixes the problem by releasing the session slot
and resetting its sequence# upon receiving a RPC_AUTHERROR
reply.

This bug only affects NFSv4.1/4.2 mounts using sec=krb5[ip],
but has existed since NFSv4.1 client support was added to
FreeBSD.

So, why has the bug remained undetected for so long?
I cannot be sure, but I suspect that, often, the client detected
the Kerberos credential expiration before attempting the RPC.
For this case, the client would not do the RPC and, as such,
there would be no busy session slot.  Also, no hang would
occur until all session slots are busied (64 for a FreeBSD
client/server), so many cases of the bug probably went undetected?
Also, use of sec=krb5[ip] mounts are not that common.

PR: 275905
Tested by: Lexi <lexi.freebsd@le-fay.org>
MFC after: 1 week

6 months agohpts: avoid duplicate call to tcp_output()
Gleb Smirnoff [Tue, 26 Dec 2023 21:09:09 +0000 (13:09 -0800)]
hpts: avoid duplicate call to tcp_output()

Obtained from: rrs

6 months agoofed: use ANSI C functions definitions in opensm/sm.c
Konstantin Belousov [Tue, 26 Dec 2023 19:16:49 +0000 (21:16 +0200)]
ofed: use ANSI C functions definitions in opensm/sm.c

Sponsored by: NVidia networking
MFC after: 1 week

6 months agocat(1): Fix typo
Kai-Yang Chen [Tue, 26 Dec 2023 17:42:38 +0000 (10:42 -0700)]
cat(1): Fix typo

Fix type: rebiuld -> rebuild in Makefile

Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Reviewed by: imp, Mina Galić
Pull Request: https://github.com/freebsd/freebsd-src/pull/933

6 months agosh(1): Fix typo
Pei-Ju Chien [Tue, 26 Dec 2023 17:39:10 +0000 (10:39 -0700)]
sh(1): Fix typo

Remove extra 'ing' from 'bookinging.'

Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Reviewed by: imp, Mina Galić
Pull Request: https://github.com/freebsd/freebsd-src/pull/934

6 months agosh(1): Fix typo
Kai-Yang Chen [Tue, 26 Dec 2023 17:33:20 +0000 (10:33 -0700)]
sh(1): Fix typo

Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Reviewed by: imp, @rilysh on github
Pull Request: https://github.com/freebsd/freebsd-src/pull/935

6 months agosh(1): Fix typo
WEININGCHIU [Tue, 26 Dec 2023 17:30:20 +0000 (10:30 -0700)]
sh(1): Fix typo

nozero -> non-zero

Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Reviewed by: imp, Mina Galić
Pull Request: https://github.com/freebsd/freebsd-src/pull/936

6 months agoRemove SVN related Git attributes
Minsoo Choo [Tue, 26 Dec 2023 17:24:59 +0000 (10:24 -0700)]
Remove SVN related Git attributes

Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Reviewed by: imp, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/938

6 months agoUpdate MAINTAINERS for Git
Minsoo Choo [Tue, 26 Dec 2023 17:26:16 +0000 (10:26 -0700)]
Update MAINTAINERS for Git

Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/937

6 months agoUpdate LOCKS for Git
Minsoo Choo [Tue, 26 Dec 2023 17:26:16 +0000 (10:26 -0700)]
Update LOCKS for Git

Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/937

6 months agopax: Add missing 'for' in comment.
Zhan-Wei [Tue, 26 Dec 2023 17:08:58 +0000 (10:08 -0700)]
pax: Add missing 'for' in comment.

Event: Advanced UNIX Programming Course (Fall23) at NTHU.
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/941

6 months agomv: Improve comment
Zhan-Wei [Tue, 26 Dec 2023 17:15:46 +0000 (10:15 -0700)]
mv: Improve comment

Fix typo/grammar error: Use the singlar verb ending on exists.

Event: Advanced UNIX Programming Course (Fall23) at NTHU.
Reviewed by: imp, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/940

6 months agobluetooth: fix comment in bluetooth.device.conf
lherschi [Tue, 26 Dec 2023 17:18:54 +0000 (10:18 -0700)]
bluetooth: fix comment in bluetooth.device.conf

The default for discoverable is 'NO' not 'YES'. This now matches the man
page.

Event: Advanced UNIX Programming Course (Fall'23) at NTHU.
Reviewed by: imp, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/939

6 months agodiff(1): fix a typo
Pin-Yi Kuo [Tue, 26 Dec 2023 17:06:03 +0000 (10:06 -0700)]
diff(1): fix a typo

On the manpage of diff(1), "when" is mistyped to "wen".

Event: Advanced UNIX Programming Course (Fall'23) at NTHU.
Signed-off-by: Pin-Yi Kuo <kuokuoyiyi@gapp.nthu.edu.tw>
Reviewed by: imp, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/943

6 months agodf(1): fix a typo
Pin-Yi Kuo [Tue, 26 Dec 2023 16:37:43 +0000 (09:37 -0700)]
df(1): fix a typo

On the manpage of df(1), "according" is mistyped into "acccording"

Event: Advanced UNIX Programming Course (Fall'23) at NTHU.
Signed-off-by: Pin-Yi Kuo <kuokuoyiyi@gapp.nthu.edu.tw>
Reviewed by: imp, zlei, Mina Galić
Pull Request: https://github.com/freebsd/freebsd-src/pull/944

6 months agobhyve/audio.c: avoid re-calculating the length of dev_name
rilysh [Tue, 26 Dec 2023 16:24:04 +0000 (09:24 -0700)]
bhyve/audio.c: avoid re-calculating the length of dev_name

In the function audio_init(), strlen() is being called two times,
first to get the length of dev_name and second to use in memcpy().
Creating a local variable and keeping the length avoids this
re-calculation.

Signed-off-by: rilysh <nightquick@proton.me>
Reviewed by: imp, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/945

6 months agogvinum(8): Fix a typo
Che-Yu Chang [Tue, 26 Dec 2023 16:05:26 +0000 (09:05 -0700)]
gvinum(8): Fix a typo

On line 354, "go up from" is mistyped as "go up form".

Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/951

6 months agocamcontrol(8): Fix typos
Che-Yu Chang [Tue, 26 Dec 2023 16:07:26 +0000 (09:07 -0700)]
camcontrol(8): Fix typos

On line 748, "bigger than" is mistyped as "bigger then", and on line
765, "more than" is mistyped as "more then".

Event: Advanced UNIX Programming Course (Fall’23) at NTHU.
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/949

6 months agoacpi_cpu: Reduce BUS_MASTER_RLD manipulations
Alexander Motin [Tue, 26 Dec 2023 02:19:28 +0000 (21:19 -0500)]
acpi_cpu: Reduce BUS_MASTER_RLD manipulations

Instead of setting and clearing BUS_MASTER_RLD register on every C3
state enter/exit, set it only once if the system supports C3 state
and we are going to "disable" bus master arbitration while in it.

This is what Linux does for the past 14 years, and for even more time
this register is not implemented in a relevant hardware.  Same time
since this is only a single bit in a bigger register, ACPI has to
do take a global lock and do read-modify-write for it, that is too
expensive, saved only by C3 not entered frequently, but enough to be
seen in idle system CPU profiles.

MFC after: 1 month

6 months agovmm: Fix handling of errors from subyte()
Mark Johnston [Tue, 26 Dec 2023 01:43:51 +0000 (20:43 -0500)]
vmm: Fix handling of errors from subyte()

subyte() returns -1 upon an error, not an errno value.

MFC after: 1 week
Fixes: e17eca327633 ("vmm: Avoid embedding cpuset_t ioctl ABIs")

6 months agocompat_freebsd4: Fix handling of errors from subyte()
Mark Johnston [Tue, 26 Dec 2023 01:43:38 +0000 (20:43 -0500)]
compat_freebsd4: Fix handling of errors from subyte()

Upon failure, subyte() returns -1, not an errno value.

MFC after: 1 week

6 months agoiscsi: Check for copyout errors in iscsi_ioctl_daemon_receive()
Mark Johnston [Tue, 26 Dec 2023 01:43:31 +0000 (20:43 -0500)]
iscsi: Check for copyout errors in iscsi_ioctl_daemon_receive()

Reviewed by: jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43148

6 months agonmount: Ignore errors when copying out an error string
Mark Johnston [Tue, 26 Dec 2023 01:43:21 +0000 (20:43 -0500)]
nmount: Ignore errors when copying out an error string

In general we copy error strings as part of reporting an error from
lower layers, so if the copyout() fails there's nothing to do since we'd
prefer to preserve the original error.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: olce, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43147

6 months agogeom: Report copyout() errors in g_ctl_ioctl_ctl()
Mark Johnston [Tue, 26 Dec 2023 01:43:06 +0000 (20:43 -0500)]
geom: Report copyout() errors in g_ctl_ioctl_ctl()

Despite the name, req->serror is used in some cases to copy non-error
messages to userspace.  So, report errors when copying out so long as
they don't clobber an earlier error.

Reviewed by: mav, imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43146

6 months agogntdev: Handle errors from suword32() in gntdev_alloc_gref()
Mark Johnston [Tue, 26 Dec 2023 01:42:58 +0000 (20:42 -0500)]
gntdev: Handle errors from suword32() in gntdev_alloc_gref()

Try to copy out output values before handling errors, and check that we
did so successfully.  In particular, it doesn't seem sensible to ignore
errors here, otherwise userspace won't have any way to refer to the
allocations.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: royger
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43145

6 months agompr: Handle errors from copyout() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:42:49 +0000 (20:42 -0500)]
mpr: Handle errors from copyout() in ioctl handlers

In preparation for adding a __result_use_check annotation to copyin()
and related functions, start checking for errors from copyout() in
the mpr(4) user command handler.  This should make it easier to catch
bugs.

Reviewed by: imp, asomers
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D43177

6 months agomps: Handle errors from copyout() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:42:33 +0000 (20:42 -0500)]
mps: Handle errors from copyout() in ioctl handlers

In preparation for adding a __result_use_check annotation to copyin()
and related functions, start checking for errors from copyout() in
the mps(4) user command handler.  This should make it easier to catch
bugs.

Reviewed by: imp, asomers
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D43176

6 months agoumtx: Check for errors from suword32()
Mark Johnston [Tue, 26 Dec 2023 01:42:17 +0000 (20:42 -0500)]
umtx: Check for errors from suword32()

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D43144

6 months agothread: Ignore errors when copying out during thr_exit()
Mark Johnston [Tue, 26 Dec 2023 01:42:04 +0000 (20:42 -0500)]
thread: Ignore errors when copying out during thr_exit()

It does not seem reasonable to return to userspace after calling
umtx_thread_exit().

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: olce, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43143

6 months agojail: Ignore errors from copyout() while copying the error string
Mark Johnston [Tue, 26 Dec 2023 01:41:54 +0000 (20:41 -0500)]
jail: Ignore errors from copyout() while copying the error string

Reviewed by: zlei, jamie
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43142

6 months agosendfile: Explicitly ignore errors from copyout()
Mark Johnston [Tue, 26 Dec 2023 01:41:32 +0000 (20:41 -0500)]
sendfile: Explicitly ignore errors from copyout()

There is a documented bug in sendfile.2 which notes that sendfile(2)
does not raise an error if it fails to copy out the number of bytes
written.  Explicitly ignore the error from copyout() calls in
preparation for annotating copyout() with __result_use_check.

Reviewed by: glebius, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43129

6 months agoses: Add error checking for copyout() calls
Mark Johnston [Tue, 26 Dec 2023 01:40:33 +0000 (20:40 -0500)]
ses: Add error checking for copyout() calls

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: mav, imp, asomers
Tested by: asomers
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43130

6 months agopowerpc: Avoid ignoring copyin()'s return value
Mark Johnston [Tue, 26 Dec 2023 01:40:16 +0000 (20:40 -0500)]
powerpc: Avoid ignoring copyin()'s return value

A recent change made it possible for cpu_set_upcall() to return an
error.  Do that here instead of ignoring an error from copyin().

Reviewed by: jhibbits
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43105

6 months agolinux: Check for copyout errors in linux_fixup()
Mark Johnston [Tue, 26 Dec 2023 01:40:05 +0000 (20:40 -0500)]
linux: Check for copyout errors in linux_fixup()

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: olce, dchagin
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43104

6 months agothread: Add a return value to cpu_set_upcall()
Mark Johnston [Tue, 26 Dec 2023 01:39:39 +0000 (20:39 -0500)]
thread: Add a return value to cpu_set_upcall()

Some implementations copy data to userspace, an operation which can in
principle fail.  In preparation for adding a __result_use_check
annotation to copyin() and related functions, let implementations of
cpu_set_upcall() return an error, and check for errors when copying data
to user memory.

Reviewed by: kib, jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43100

6 months agocompat_freebsd4: Check for errors from subyte() in freebsd4_uname()
Mark Johnston [Tue, 26 Dec 2023 01:39:21 +0000 (20:39 -0500)]
compat_freebsd4: Check for errors from subyte() in freebsd4_uname()

This is in preparation for adding a __result_use_check annotation to
copyin() and related functions.

Reviewed by: imp, kib, jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43099

6 months agoocs: Check for copyin errors in the ioctl handler
Mark Johnston [Tue, 26 Dec 2023 01:38:57 +0000 (20:38 -0500)]
ocs: Check for copyin errors in the ioctl handler

If copyin() fails, the driver will blindly proceed with whatever had
been in the uninitialized DMA buffer.  This is not what we want.  Check
for copyin failures.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: ram
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43097

6 months agompi3mr: Check for copyin errors in mpi3mr_map_data_buffer_dma()
Mark Johnston [Tue, 26 Dec 2023 01:38:12 +0000 (20:38 -0500)]
mpi3mr: Check for copyin errors in mpi3mr_map_data_buffer_dma()

A failed copyin will cause the driver to use the contents of
uninitialized buffers instead, which is unlikely to be the behaviour
that we want.  Check for errors.

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43098

6 months agouhid: Check for errors from copyin() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:38:04 +0000 (20:38 -0500)]
uhid: Check for errors from copyin() in ioctl handlers

This is in preparation for annotating copyin() and related functions
with __result_use_check.

Reviewed by: wulf
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43103

6 months agohid: Handle errors from copyin() in ioctl handlers
Mark Johnston [Tue, 26 Dec 2023 01:37:49 +0000 (20:37 -0500)]
hid: Handle errors from copyin() in ioctl handlers

If copyin() fails, the driver will proceed blindly with a zeroed buffer,
which is not what we want.  In preparation for annotating copyin() with
__result_use_check, start checking for errors.

Reviewed by: wulf
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43102

6 months agofreebsd32: Report errors when copying out oldlenp in __sysctl
Mark Johnston [Tue, 26 Dec 2023 01:37:32 +0000 (20:37 -0500)]
freebsd32: Report errors when copying out oldlenp in __sysctl

This matches the native implementation's behaviour.

Reviewed by: kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43101

6 months agoath: Handle errors from copyout() in ath_rate_fetch_node_stats()
Mark Johnston [Tue, 26 Dec 2023 01:35:43 +0000 (20:35 -0500)]
ath: Handle errors from copyout() in ath_rate_fetch_node_stats()

MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43096

6 months agovfs_domount_update(): correct fsidcmp() usage
Andrew Gierth [Sun, 24 Dec 2023 12:04:21 +0000 (14:04 +0200)]
vfs_domount_update(): correct fsidcmp() usage

MFC after: 3 days

6 months agoiommu_gas_remove(): consolidate places where decision is made to keep the entry
Konstantin Belousov [Fri, 22 Dec 2023 22:41:19 +0000 (00:41 +0200)]
iommu_gas_remove(): consolidate places where decision is made to keep the entry

Move all flag checks into iommu_gas_remove_unmap().

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoiommu_gas: make placeholder entry at the start of the GAS zero size
Konstantin Belousov [Fri, 22 Dec 2023 22:19:05 +0000 (00:19 +0200)]
iommu_gas: make placeholder entry at the start of the GAS zero size

same as the placeholder at the end.  This is required to allow GAS to
start at zero, for integration with vmm.

Also, in iommu_gas_remove(), accept placeholders after remove op.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoiommu: add iommu_gas_remove_locked()
Konstantin Belousov [Thu, 14 Dec 2023 02:41:31 +0000 (04:41 +0200)]
iommu: add iommu_gas_remove_locked()

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoIOMMU: add GAS map entry flag IOMMU_MAP_ENTRY_FAKE
Konstantin Belousov [Fri, 22 Dec 2023 22:39:27 +0000 (00:39 +0200)]
IOMMU: add GAS map entry flag IOMMU_MAP_ENTRY_FAKE

to allow to shut down assert in iommu_gas_cmp_entries() when used
against fake entry to search for specific place in the tree.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoiommu_gas: zero fake on-stack map entry used in iommu_gas_remove_clip_left()
Konstantin Belousov [Sun, 24 Dec 2023 00:59:19 +0000 (02:59 +0200)]
iommu_gas: zero fake on-stack map entry used in iommu_gas_remove_clip_left()

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoiommu_gas: print entries flags and domains if an overlap detected
Konstantin Belousov [Sat, 23 Dec 2023 23:34:16 +0000 (01:34 +0200)]
iommu_gas: print entries flags and domains if an overlap detected

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoDMAR: add knob to disable RMRR entries installation into domains
Konstantin Belousov [Sat, 23 Dec 2023 16:57:19 +0000 (18:57 +0200)]
DMAR: add knob to disable RMRR entries installation into domains

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoiommu_gas: add ddb 'show iommu_domain' command
Konstantin Belousov [Sun, 24 Dec 2023 14:52:00 +0000 (16:52 +0200)]
iommu_gas: add ddb 'show iommu_domain' command

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoiommu_gas_match_one(): check for underflow
Konstantin Belousov [Tue, 26 Dec 2023 00:57:00 +0000 (02:57 +0200)]
iommu_gas_match_one(): check for underflow

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agodmar(9): style, fix indent
Konstantin Belousov [Fri, 15 Dec 2023 11:24:44 +0000 (13:24 +0200)]
dmar(9): style, fix indent

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoiommu: remove leftover sys/cdefs.h includes
Konstantin Belousov [Sun, 24 Dec 2023 14:24:05 +0000 (16:24 +0200)]
iommu: remove leftover sys/cdefs.h includes

Sponsored by: The FreeBSD Foundation
MFC after: 1 week

6 months agoMinimize libc++ errno-related header diffs with upstream
Dimitry Andric [Mon, 25 Dec 2023 17:18:31 +0000 (18:18 +0100)]
Minimize libc++ errno-related header diffs with upstream

In commit 88640c0e8b6f5 the new EINTEGRITY errno value was added, and
this caused us to carry a patch for upstream libc++ since that time.
Because it can cause merge conflicts when importing libc++ code from
upstream, I have submitted an upstream pull request to get most of that
patch integrated.

It turns out that we do not need the errno.h part of it at all, since
all supported FreeBSD versions define EOWNERDEAD and ENOTRECOVERABLE,
and therefore the block that juggles with ELAST values is never used in
FreeBSD. At the moment it only applies to older versions of Linux, or
possibly other platforms.

Therefore the only part that needs to stay is the definition of a enum
errc value for EINTEGRITY, and this is made optional upon EINTEGRITY
being defined, to make it suitable for upstreaming.

No functional change is intended.

MFC after: 1 week

6 months agoshare/man/man7/simd.7: document SIMD-enhanced memrchr implementation
Robert Clausecker [Wed, 6 Dec 2023 13:47:03 +0000 (08:47 -0500)]
share/man/man7/simd.7: document SIMD-enhanced memrchr implementation

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785

6 months agolib/libc/amd64/string: add memrchr() scalar, baseline implementation
Robert Clausecker [Wed, 6 Dec 2023 10:05:47 +0000 (05:05 -0500)]
lib/libc/amd64/string: add memrchr() scalar, baseline implementation

The scalar implementation is fairly simplistic and only performs
slightly better than the generic C implementation. It could be
improved by using the same algorithm as for memchr, but it would
have been a lot more complicated.

The baseline implementation is similar to timingsafe_memcmp.  It's
slightly slower than memchr() due to the more complicated main
loop, but I don't think that can be significantly improved.

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785
Differential Revision: https://reviews.freebsd.org/D42925

6 months agolib/libc/tests/string: add memrchr unit tests
Robert Clausecker [Wed, 6 Dec 2023 09:11:40 +0000 (04:11 -0500)]
lib/libc/tests/string: add memrchr unit tests

The "values" test case is specifically crafted to detect the off-by-one
error previous discovered in the scalar strchrnul implementation.

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785
Differential Revision: https://reviews.freebsd.org/D42925

6 months agolib/libc/string: document restrict qualification of memccpy() arguments
Robert Clausecker [Tue, 5 Dec 2023 14:03:28 +0000 (09:03 -0500)]
lib/libc/string: document restrict qualification of memccpy() arguments

POSIX.1-2004 and the upcoming C23 agree that memccpy()'s arguments
are restrict qualified and must not overlap.  In 2002, restrict
qualifiers were added to <string.h>'s declaration of the function.
Make things official and document that the arguments must not
overlap.

See also: 61b60edfd3fff20f884419f8097870c7045315c9
Approved by: kib
MFC after: 1 month
MFC to: stable/14

6 months agolib/libc/amd64/string: implement strncat() by calling strlen(), memccpy()
Robert Clausecker [Mon, 4 Dec 2023 17:32:49 +0000 (12:32 -0500)]
lib/libc/amd64/string: implement strncat() by calling strlen(), memccpy()

This picks up the accelerated implementation of memccpy().

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785
Differential Revision: https://reviews.freebsd.org/D42902

6 months agoshare/man/man7/simd.7: document simd-enhanced memccpy, strncat
Robert Clausecker [Mon, 4 Dec 2023 17:16:50 +0000 (12:16 -0500)]
share/man/man7/simd.7: document simd-enhanced memccpy, strncat

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785
Differential Revision: HTTPS://reviews.freebsd.org/D42902

6 months agolib/libc/amd64/string: add memccpy scalar, baseline implementation
Robert Clausecker [Sat, 2 Dec 2023 12:28:05 +0000 (07:28 -0500)]
lib/libc/amd64/string: add memccpy scalar, baseline implementation

Based on the strlcpy code from D42863, this patch adds a SIMD-enhanced
implementation of memccpy for amd64. A scalar implementation calling
into memchr and memcpy to do the job is provided, too.

Please note that this code does not behave exactly the same as the C
implementation of memccpy for overlapping inputs. However, overlapping
inputs are not allowed for this function by ISO/IEC 9899:1999 and neither
has the C implementation any code to deal with the possibility. It just
proceeds byte-by-byte, which may or may not do the expected thing for
some overlaps. We do not document whether overlapping inputs are
supported in memccpy(3).

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785
Differential Revision: https://reviews.freebsd.org/D42902

6 months agolib/libc/tests/string: add unit tests for memccpy()
Robert Clausecker [Sun, 3 Dec 2023 11:42:17 +0000 (06:42 -0500)]
lib/libc/tests/string: add unit tests for memccpy()

Adapted from the strlcpy() unit tests.

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785

6 months agoshare/man/man7/simd.7: add forgotten aarch64 string functions
Robert Clausecker [Wed, 29 Nov 2023 03:33:18 +0000 (22:33 -0500)]
share/man/man7/simd.7: add forgotten aarch64 string functions

I previously forgot to mention these as they are set up through
contrib/arm-optimized/routines/string.

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785

6 months agoshare/man/man7/simd.7: document scalar/baseline strlcpy, strlcat
Robert Clausecker [Wed, 29 Nov 2023 02:35:45 +0000 (21:35 -0500)]
share/man/man7/simd.7: document scalar/baseline strlcpy, strlcat

Tested by: developers@, exp-run
Approved by: mjg
MFC after: 1 month
MFC to: stable/14
PR: 275785
Differential Revision: https://reviews.freebsd.org/D42863