Commit graph

288498 commits

Author SHA1 Message Date
Mark Johnston abbc260f74 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
2023-12-25 21:04:00 -05:00
Mark Johnston d0adc2f283 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
2023-12-25 21:04:00 -05:00
Mark Johnston 771501e96f 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
2023-12-25 21:04:00 -05:00
Mark Johnston bdf03b4bcc 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
2023-12-25 21:04:00 -05:00
Mark Johnston 3fde275167 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
2023-12-25 21:04:00 -05:00
Mark Johnston 7b68fb5ab2 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
2023-12-25 21:04:00 -05:00
Mark Johnston 4f35450ce5 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
2023-12-25 21:04:00 -05:00
Mark Johnston a01ff11cb7 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
2023-12-25 21:04:00 -05:00
Mark Johnston 6bfb7306ef 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
2023-12-25 21:04:00 -05:00
Mark Johnston b2caed2f8d 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
2023-12-25 21:04:00 -05:00
Mark Johnston e452fa70d5 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
2023-12-25 21:04:00 -05:00
Mark Johnston 81eb7baa69 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
2023-12-25 21:04:00 -05:00
Mark Johnston 711880597c ath: Handle errors from copyout() in ath_rate_fetch_node_stats()
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D43096
2023-12-25 21:04:00 -05:00
Andrew Gierth 2a1d50fc12 vfs_domount_update(): correct fsidcmp() usage
MFC after:	3 days
2023-12-26 03:35:46 +02:00
Konstantin Belousov c0047e7c35 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
2023-12-26 03:28:23 +02:00
Konstantin Belousov f591287756 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
2023-12-26 03:28:22 +02:00
Konstantin Belousov 273b4de346 iommu: add iommu_gas_remove_locked()
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Konstantin Belousov a59c252903 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
2023-12-26 03:28:22 +02:00
Konstantin Belousov cb1d664b00 iommu_gas: zero fake on-stack map entry used in iommu_gas_remove_clip_left()
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Konstantin Belousov 733da1eb94 iommu_gas: print entries flags and domains if an overlap detected
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Konstantin Belousov 24e38af60a DMAR: add knob to disable RMRR entries installation into domains
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Konstantin Belousov 30ce85ca11 iommu_gas: add ddb 'show iommu_domain' command
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Konstantin Belousov a869643e18 iommu_gas_match_one(): check for underflow
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Konstantin Belousov 7153d5e4bc dmar(9): style, fix indent
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Konstantin Belousov 6afa2333d2 iommu: remove leftover sys/cdefs.h includes
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-12-26 03:28:22 +02:00
Dimitry Andric 1ff41cad71 Minimize libc++ errno-related header diffs with upstream
In commit 88640c0e8b 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
2023-12-25 18:19:12 +01:00
Robert Clausecker fb9c25a91f 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
2023-12-25 15:00:08 +01:00
Robert Clausecker fb197a4f77 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
2023-12-25 15:00:05 +01:00
Robert Clausecker 691ff1832e 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
2023-12-25 14:59:58 +01:00
Robert Clausecker e0d4f419ac 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:	61b60edfd3
Approved by:	kib
MFC after:	1 month
MFC to:		stable/14
2023-12-25 14:59:50 +01:00
Robert Clausecker ea7b13771c 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
2023-12-25 14:59:48 +01:00
Robert Clausecker 5fa0fbf40b 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
2023-12-25 14:59:46 +01:00
Robert Clausecker fc0e38a7a6 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
2023-12-25 14:59:42 +01:00
Robert Clausecker e4b7b0bcbc 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
2023-12-25 14:59:40 +01:00
Robert Clausecker 6fdcb85b1c 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
2023-12-25 14:59:37 +01:00
Robert Clausecker d4a5605d9f 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
2023-12-25 14:59:35 +01:00
Robert Clausecker 2b7b03b7ae lib/libc/amd64/string: implement strlcat() through strlcpy()
This should pick up our optimised memchr(), strlen(), and strlcpy()
when strlcat() is called.

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
2023-12-25 14:59:31 +01:00
Robert Clausecker 74d6cfad54 lib/libc/amd64/string: add strlcpy scalar, baseline implementation
Somewhat similar to stpncpy, but different in that we need to compute
the full source length even if the buffer is shorter than the source.

strlcat is implemented as a simple wrapper around strlcpy.  The scalar
implementation of strlcpy just calls into strlen() and memcpy() to do
the job.

Perf-wise we're very close to stpncpy.  The code is slightly slower as
it needs to carry on with finding the source string length even if the
buffer ends before the string.

Sponsored by:	The FreeBSD Foundation
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
2023-12-25 14:56:05 +01:00
Robert Clausecker f7098b8659 lib/libc/tests/string: add unit test for strlcpy
A straightforward derivation from the stpncpy unit test.

Sponsored by:	The FreeBSD Foundation
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
2023-12-25 14:56:02 +01:00
Robert Clausecker c983825a77 share/man/man7/simd.7: document SIMD-enhanced strcat
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42600
2023-12-25 14:55:59 +01:00
Robert Clausecker aff9143a24 lib/libc/amd64/string/strcat.S: enable use of SIMD
strcat has a bespoke scalar assembly implementation we
inherited from NetBSD.  While it performs well, it is
better to call into our SIMD implementations if any SIMD
features are available at all.  So do that and implement
strcat() by calling into strlen() and strcpy() if these
are available.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Reviison: https://reviews.freebsd.org/D42600
2023-12-25 14:55:53 +01:00
Robert Clausecker 75a9e22506 share/man/man7/simd.7: document simd-enhanced strncpy, stpncpy
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42519
2023-12-25 14:55:50 +01:00
Robert Clausecker e19d46c808 lib/libc/amd64/string: implement strncpy() by calling stpncpy()
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42519
2023-12-25 14:55:48 +01:00
Robert Clausecker 90253d49db lib/libc/amd64/string: add stpncpy scalar, baseline implementation
This was surprisingly annoying to get right, despite being such a simple
function.  A scalar implementation is also provided, it just calls into
our optimised memchr(), memcpy(), and memset() routines to carry out its
job.

I'm quite happy with the performance.  glibc only beats us for very long
strings, likely due to the use of AVX-512.  The scalar implementation
just calls into our optimised memchr(), memcpy(), and memset() routines,
so it has a high overhead to begin with but then performs ok for the
amount of effort that went into it.  Still beats the old C code, except
for very short strings.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D42519
2023-12-25 14:55:42 +01:00
Robert Clausecker 6fa9e7d873 lib/libc/tests/string/stpncpy_test.c: extend for upcoming SSE implementation
This adds additional unit tests validating the function for
All possible alignment offsets of source and destination.

Also extend the test to allow testing of an external stpncpy
implementation, which greatly simplifies the development of
custom implementations.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42519
2023-12-25 14:55:37 +01:00
Robert Clausecker 75cb202698 share/man/man7/simd.7: document amd64 SIMD use for strsep()
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D42346
2023-12-25 14:55:34 +01:00
Robert Clausecker fd2ecd91ae lib/libc/amd64/string: implement strsep() through strcspn()
The strsep() function is basically strcspn() with extra steps.
On amd64, we now have an optimised implementation of strcspn(),
so instead of implementing the inner loop manually, just call
into the optimised routine.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42346
2023-12-25 14:55:30 +01:00
Robert Clausecker dd1c2e887c share/man/man7/simd.7: document strrchr scalar, baseline implementation
Also mention missing rindex() entry, which is provided through
strrchr().

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42217
2023-12-25 14:55:26 +01:00
Robert Clausecker 2ed514a220 lib/libc/amd64/string: add strrchr scalar, baseline implementation
The baseline implementation is very straightforward, while the scalar
implementation suffers from register pressure and the need to use SWAR
techniques similar to those used for strchr().

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42217
2023-12-25 14:55:22 +01:00
Robert Clausecker f5edd8450e share/man/man7/simd.7: document strncmp amd64 scalar, baseline implementations
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42122
2023-12-25 14:55:18 +01:00