]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
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

6 months agolib/libc/amd64/string: implement strlcat() through strlcpy()
Robert Clausecker [Wed, 29 Nov 2023 02:32:28 +0000 (21:32 -0500)]
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

6 months agolib/libc/amd64/string: add strlcpy scalar, baseline implementation
Robert Clausecker [Sun, 12 Nov 2023 22:47:06 +0000 (17:47 -0500)]
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

6 months agolib/libc/tests/string: add unit test for strlcpy
Robert Clausecker [Thu, 9 Nov 2023 18:08:23 +0000 (13:08 -0500)]
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

6 months agoshare/man/man7/simd.7: document SIMD-enhanced strcat
Robert Clausecker [Tue, 14 Nov 2023 18:26:21 +0000 (13:26 -0500)]
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

6 months agolib/libc/amd64/string/strcat.S: enable use of SIMD
Robert Clausecker [Tue, 14 Nov 2023 18:09:08 +0000 (13:09 -0500)]
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

6 months agoshare/man/man7/simd.7: document simd-enhanced strncpy, stpncpy
Robert Clausecker [Thu, 9 Nov 2023 04:39:11 +0000 (23:39 -0500)]
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

6 months agolib/libc/amd64/string: implement strncpy() by calling stpncpy()
Robert Clausecker [Thu, 9 Nov 2023 04:25:55 +0000 (23:25 -0500)]
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

6 months agolib/libc/amd64/string: add stpncpy scalar, baseline implementation
Robert Clausecker [Mon, 30 Oct 2023 03:15:46 +0000 (23:15 -0400)]
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

6 months agolib/libc/tests/string/stpncpy_test.c: extend for upcoming SSE implementation
Robert Clausecker [Sun, 5 Nov 2023 04:02:00 +0000 (00:02 -0400)]
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

6 months agoshare/man/man7/simd.7: document amd64 SIMD use for strsep()
Robert Clausecker [Tue, 24 Oct 2023 03:57:56 +0000 (23:57 -0400)]
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

6 months agolib/libc/amd64/string: implement strsep() through strcspn()
Robert Clausecker [Tue, 24 Oct 2023 03:52:01 +0000 (23:52 -0400)]
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

6 months agoshare/man/man7/simd.7: document strrchr scalar, baseline implementation
Robert Clausecker [Thu, 12 Oct 2023 22:31:55 +0000 (18:31 -0400)]
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

6 months agolib/libc/amd64/string: add strrchr scalar, baseline implementation
Robert Clausecker [Thu, 12 Oct 2023 05:37:41 +0000 (01:37 -0400)]
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

6 months agoshare/man/man7/simd.7: document strncmp amd64 scalar, baseline implementations
Robert Clausecker [Sun, 8 Oct 2023 02:46:36 +0000 (22:46 -0400)]
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

6 months agolib/libc/amd64/string: add strncmp scalar, baseline implementation
Robert Clausecker [Wed, 27 Sep 2023 22:46:04 +0000 (18:46 -0400)]
lib/libc/amd64/string: add strncmp scalar, baseline implementation

The scalar implementation is fairly straightforward and merely unrolled
four times.  The baseline implementation closely follows D41971 with
appropriate extensions and extra code paths to pay attention to string
length.

Performance is quite good.  We beat both glibc (except for very long
strings, but they likely use AVX which we don't) and Bionic (except for
medium-sized aligned strings, where we are still in the same ballpark).

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

6 months agolib/libc/tests/string: add unit tests for strncmp(3)
Robert Clausecker [Thu, 28 Sep 2023 20:40:20 +0000 (16:40 -0400)]
lib/libc/tests/string: add unit tests for strncmp(3)

These are patterned after the previously added (D41970)
strcmp tests, but are extended to check for various length
conditions.

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

6 months agoshare/man/man7/simd.7: document amd64 SIMD use for strpbrk()
Robert Clausecker [Mon, 25 Sep 2023 21:45:26 +0000 (17:45 -0400)]
share/man/man7/simd.7: document amd64 SIMD use for strpbrk()

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/D41980

6 months agolib/libc/amd64/string: implement strpbrk() through strcspn()
Robert Clausecker [Mon, 25 Sep 2023 21:43:12 +0000 (17:43 -0400)]
lib/libc/amd64/string: implement strpbrk() through strcspn()

This lets us use our optimised strcspn() routine for strpbrk() calls.

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/D41980

6 months agoshare/man/man7/simd.7: document new amd64 baseline strcmp()
Robert Clausecker [Mon, 25 Sep 2023 06:18:06 +0000 (02:18 -0400)]
share/man/man7/simd.7: document new amd64 baseline strcmp()

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/D41971

6 months agolib/libc/amd64/string/strcmp.S: add baseline implementation
Robert Clausecker [Sat, 16 Sep 2023 05:29:39 +0000 (01:29 -0400)]
lib/libc/amd64/string/strcmp.S: add baseline implementation

This is the most complicated one so far.  The basic idea is to process
the bulk of the string in aligned blocks of 16 bytes such that one
string runs ahead and the other runs behind.  The string that runs ahead
is checked for NUL bytes, the one that runs behind is compared with the
corresponding chunk of the string that runs ahead.  This trades an extra
load per iteration for the very complicated block-reassembly needed in
the other implementations (bionic, glibc).  On the flip side, we need
two code paths depending on the relative alignment of the two buffers.

The initial part of the string is compared directly if it is known not
to cross a page boundary.  Otherwise, a complex slow path to avoid
crossing into unmapped memory commences.

Performance-wise we beat bionic for misaligned strings (i.e. the strings
do not share an alignment offset) and reach comparable performance for
aligned strings.  glibc is a bit better as it has a special kernel for
AVX-512, where this stuff is a bit easier to do.

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/D41971

6 months agoig4: Actively use FIFO thresholds
Alexander Motin [Sun, 24 Dec 2023 23:18:11 +0000 (18:18 -0500)]
ig4: Actively use FIFO thresholds

Before every wait for FIFO interrupt set how much data/space do we
want to see there.  Previous code was not using it for receive, as
result aggregating interrupts only within processing latency.  The
new code needs only one interrupt per transfer per FIFO length.

On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this
reduces the interrupt rate per device down to 2 per sample or 16-20
per second when idle and 120-160 per second when actively touched.

MFC after: 1 month

6 months agoLinuxKPI: Constify src parameter of bitmap_copy
Vladimir Kondratyev [Sun, 24 Dec 2023 12:48:06 +0000 (15:48 +0300)]
LinuxKPI: Constify src parameter of bitmap_copy

in bitmap_from_arr32() to fix build on 32 bit archs.

Sponsored by: Serenity Cyber Security, LLC
Fixes: 5ae2e6f913fa ("LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()")
MFC after: 1 week

6 months agoLinuxKPI: Define ioread64() in linux/io.h only on 64 bit archs.
Vladimir Kondratyev [Sun, 24 Dec 2023 12:48:06 +0000 (15:48 +0300)]
LinuxKPI: Define ioread64() in linux/io.h only on 64 bit archs.

32 bit archs includes nonatomic version from linux/io-64-nonatomic-*.h

Sponsored by:   Serenity Cyber Security, LLC
Fixes: dcfc983373c3 ("LinuxKPI: Implement ioread64()")
MFC after:      1 week

6 months agoLinuxKPI: Do not use explicit context in FPU sections on powerpc64
Vladimir Kondratyev [Sun, 24 Dec 2023 12:48:06 +0000 (15:48 +0300)]
LinuxKPI: Do not use explicit context in FPU sections on powerpc64

It is not supported yet.

Sponsored by: Serenity Cyber Security, LLC
Fixes: 5a3bd281672b ("LinuxKPI: Add explicit software context to FPU sections")
MFC after: 1 week

6 months agoBump __FreeBSD_version after LinuxKPI changes.
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:01 +0000 (11:20 +0300)]
Bump __FreeBSD_version after LinuxKPI changes.

Sponsored by: Serenity Cyber Security, LLC

6 months agoLinuxKPI: Add explicit software context to FPU sections
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:01 +0000 (11:20 +0300)]
LinuxKPI: Add explicit software context to FPU sections

Amdgpu driver does a lot of memory allocations in FPU-protected sections
of code for certain display cores, e.g. for DCN30. This does not work
currently on FreeBSD as its malloc function can not be run within a
critical section. Allocate memory for FPU context to overcome such
restriction.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu (previous version), markj
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42822

6 months agoLinuxKPI: Add acpi_dev_present() function.
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add acpi_dev_present() function.

acpi_dev_present detects that a given ACPI device is present based on
Hardware ID, Unique ID and Hardware Revision of the device.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42823

6 months agoLinuxKPI: Add pcie_capability_clear_and_set_word() function
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add pcie_capability_clear_and_set_word() function

It does a Read-Modify-Write operation using clear and set bitmasks on
PCI Express Capability Register at pos. As certain PCI Express
Capability Registers are accessed concurrently in RMW fashion, hence
require locking which is handled transparently to the caller.

Sponsored by: Serenity CyberSecurity, LLC
Reviewed by: manu, bz
MFC after: 1 week
MFC TODO: Move pcie_cap_lock to bottom to preserve KBI compatibility
Differential Revision: https://reviews.freebsd.org/D42821

6 months agoLinuxKPI: Add x86_vendor field to struct cpuinfo_x86
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add x86_vendor field to struct cpuinfo_x86

and initialize it at linuxkpi module load.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42820

6 months agoLinuxKPI: Add linux/apple-gmux.h
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add linux/apple-gmux.h

Sponsored by: Serenity Cyber Security, LLC
Obtained from: OpenBSD
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42819

6 months agoLinuxKPI: Rename linux_list_add to __list_add() in linux/list.h
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Rename linux_list_add to __list_add() in linux/list.h

to match Linux

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42818

6 months agoLinuxKPI: Add linux/ioport.h header
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add linux/ioport.h header

Sponsored by: Serenity Cyber Security, LLC
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42817

6 months agoLinuxKPI: Add get_random_u64() function
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add get_random_u64() function

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42816

6 months agoLinuxKPI: Add linux/dynamic_debug.h header
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add linux/dynamic_debug.h header

Sponsored by: Serenity Cyber Security, LLC
Obtained from: OpenBSD
Reviewed by: manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42815

6 months agoLinuxKPI: Add acpi_video_backlight_use_native()
Vladimir Kondratyev [Sun, 24 Dec 2023 08:20:00 +0000 (11:20 +0300)]
LinuxKPI: Add acpi_video_backlight_use_native()

We assume that backlight (in Linux term) is always "native".

Also stub acpi_video_register_backlight()

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42814

6 months agoLinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()

and bitmap_shift_right() functions to linux/bitmap.h

They perform calculation of two bitmaps intersection,
copying the contents of u32 array of bits to bitmap and
logical right shifting of the bits in a bitmap.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42812

6 months agoLinuxKPI: Add cancel_work() function.
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add cancel_work() function.

Cancel a work not waiting for it to finish.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42811

6 months agoLinuxKPI: Add write_seqcount_invalidate() and seqprop_sequence()
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add write_seqcount_invalidate() and seqprop_sequence()

functions to linux/seqlock.h

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42810

6 months agoLinuxKPI: Chase for new "name" argument of register_shrinker()
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Chase for new "name" argument of register_shrinker()

Linux uses it only if SHRINKER_DEBUG config option is enabled. Ignore it.

Sponsored by: Serenity Cyber Security, LLC
Reviewers: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42809

6 months agoLinuxKPI: Add ida_alloc_min()
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add ida_alloc_min()

ida_alloc_min() allocates an unused ID. between min and INT_MAX.

While here allow end parameter of ida_simple_get() be larger than
INT_MAX. Linux caps the value to INT_MAX.

Sponsored by: Serenity Cyber Security, LLC
Reviewers: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42806

6 months agoLinuxKPI: Add IOMEM_ERR_PTR() to linux/io.h
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add IOMEM_ERR_PTR() to linux/io.h

The function creates an error pointer.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42805

6 months agoLinuxKPI: Add ktime_get_raw_fast_ns() to linux/ktime.h
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add ktime_get_raw_fast_ns() to linux/ktime.h

It is implemented like ktime_get_raw_ns() function but uses less
precise getnanouptime() call.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42804

6 months agoLinuxKPI: Add xa_(un)lock_irq to linux/xarray.h
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add xa_(un)lock_irq to linux/xarray.h

On FreeBSD they are equal to non-irq version.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42803

6 months agoLinuxKPI: Add asm/hypervisor.h header
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:59 +0000 (11:19 +0300)]
LinuxKPI: Add asm/hypervisor.h header

Sponsored by: Serenity Cyber Security, LLC
Obtained from: OpenBSD
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42802

6 months agoLinuxKPI: Implement ioread64()
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Implement ioread64()

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42801

6 months agoLinuxKPI: Add linux/iosys-map.h header
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Add linux/iosys-map.h header

Sponsored by: Serenity Cyber Security, LLC
Obtained from: OpenBSD
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42799

6 months agoLinuxKPI: Add some header pollution and dummy headers
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Add some header pollution and dummy headers

required by recent drm-kmod to be succesfully compiled.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
Obtained from: OpenBSD (partially)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42798

6 months agoLinuxKPI: Add xen/xen.h header
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Add xen/xen.h header

It contains proxy-implementation of xen_initial_domain() and
xen_pv_domain() required by latest drm-kmod.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42797

6 months agoLinuxKPI: Split linux/container_of.h off from linux/kernel.h
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Split linux/container_of.h off from linux/kernel.h

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after:      1 week
Differential Revision: https://reviews.freebsd.org/D42796

6 months agoLinuxKPI: Add static_assert() macro
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Add static_assert() macro

And move it along BUILD_BUG family in to
linux/build_bug.h to match Linux.

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42800

6 months agoLinuxKPI: Implement dev_dbg_once() macro
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Implement dev_dbg_once() macro

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42795

6 months agoLinuxKPI: Add str_on_off and other helpers to linux/string_helpers.h
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Add str_on_off and other helpers to linux/string_helpers.h

Sponsored by: Serenity Cyber Security, LLC
Reviewed by: manu, bz, imp (previous version)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42794

6 months agoLinuxKPI: Add video/vga.h header
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:58 +0000 (11:19 +0300)]
LinuxKPI: Add video/vga.h header

Sponsored by: Serenity Cyber Security, LLC
Obtained from: OpenBSD
Reviewed by: manu, bz
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42793

6 months agoLinuxKPI: Remove sys/rman.h include from LKPI headers.
Vladimir Kondratyev [Sun, 24 Dec 2023 08:19:57 +0000 (11:19 +0300)]
LinuxKPI: Remove sys/rman.h include from LKPI headers.

sys/rman.h defines `resource` structure which conflicts with the Linux
structure of the same name. To fix that remove reference to sys/rman.h
from linux/pci.h and move resource management code to linux_pci.c.
Update consumers which were depending on linux/pci.h pollution.

No functional changes intended.

Sponsored by: Serenity Cyber Security, LLC
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42792

6 months agovm_page.h: tweak page-busied assertion macros
Jason A. Harmening [Sun, 24 Dec 2023 05:20:13 +0000 (23:20 -0600)]
vm_page.h: tweak page-busied assertion macros

Fix incorrect macro name and include the value of curthread in the
panic message where relevant.

6 months agoAvoid waiting on physical allocations that can't possibly be satisfied
Jason A. Harmening [Mon, 20 Nov 2023 23:23:58 +0000 (17:23 -0600)]
Avoid waiting on physical allocations that can't possibly be satisfied

- Change vm_page_reclaim_contig[_domain] to return an errno instead
  of a boolean.  0 indicates a successful reclaim, ENOMEM indicates
  lack of available memory to reclaim, with any other error (currently
  only ERANGE) indicating that reclamation is impossible for the
  specified address range.  Change all callers to only follow
  up with vm_page_wait* in the ENOMEM case.

- Introduce vm_domainset_iter_ignore(), which marks the specified
  domain as unavailable for further use by the iterator.  Use this
  function to ignore domains that can't possibly satisfy a physical
  allocation request.  Since WAITOK allocations run the iterators
  repeatedly, this avoids the possibility of infinitely spinning
  in domain iteration if no available domain can satisfy the
  allocation request.

PR: 274252
Reported by: kevans
Tested by: kevans
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D42706

6 months agoacpi_lid: Remove duplicate events
Alexander Motin [Sun, 24 Dec 2023 02:33:51 +0000 (21:33 -0500)]
acpi_lid: Remove duplicate events

Remove extra acpi_UserNotify() call per event.  Filter duplicate
notifications received from ACPI without actual status change.

Without this on my Dell XPS 13 9310 I saw 4 devd events for either
open or close, now only one.

MFC after: 1 month

6 months agoiichid(4): Restore/increase sampling rate
Alexander Motin [Sun, 24 Dec 2023 00:10:49 +0000 (19:10 -0500)]
iichid(4): Restore/increase sampling rate

My previous commit by reducing precision reduced the sampling rate
from 60Hz to 40Hz on idle system.  Return it back to 60-80Hz range,
that should be good for mouse smoothness on 60Hz displays.

MFC after: 1 months

6 months agoig4: Fix FIFO depths detection
Alexander Motin [Sun, 24 Dec 2023 00:02:49 +0000 (19:02 -0500)]
ig4: Fix FIFO depths detection

At least on my Tiger Lake-LP queue depth detection failed before the
ig4iic_set_config() call, resulting in no FIFO use.  Moving it after
solves the problem, getting proper 64 bytes size.

On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this
by few times reduces context switch rate in the driver, and probably
also improves the I2C bus utilization.

MFC after: 1 month

6 months agoiicbb: Fix pause_sbt() arguments order
Alexander Motin [Sat, 23 Dec 2023 23:52:17 +0000 (18:52 -0500)]
iicbb: Fix pause_sbt() arguments order

It should make pause interval less strict.

While there, add cpu_spinwait() into a tight spin wait loop to burn
less power and let other SMT thread work more.

MFC after: 1 month

6 months agomlx4(5): fix driver initialization
Yuji Hagiwara [Sat, 23 Dec 2023 20:53:02 +0000 (22:53 +0200)]
mlx4(5): fix driver initialization

After netlinkification, ether_ifattach() requires ifmedia_init() to be
done before it.

PR: 275897
MFC after: 1 week

6 months agonewsyslog(8): Add option to globally override compression method.
Xin LI [Sat, 23 Dec 2023 06:46:33 +0000 (22:46 -0800)]
newsyslog(8): Add option to globally override compression method.

Historically, newsyslog compressed rotated log files to save disk space.
This was useful in the early days. However, with modern file systems like
ZFS offering native compression, and with the availability of larger hard
drives, the benefits of additional compression have become less significant.
This is particularly true considering the inconvenience of decompressing
log files when searching for specific patterns.

Additionally, the original implementation of compression methods was not
future-proof.  As a result, we have redefined the J, X, Y, Z flags to
signify "treat the file as compressible" rather than "compress the file
with that specific method."

A new command-line option, -c, has been introduced to allow overriding
these settings in a more future-proof way. The available choices are:

 * none  - do not compress, regardless of flag.
 * legacy  - historical behavior: J=bzip2, X=xz, Y=zstd, Z=gzip.
 * bzip2, xz, zstd, gzip - apply the specified compression method.

Currently, the default is set to 'legacy' to preserve historical behavior.
However, our intention is to change this default to 'none' in FreeBSD 15.0.

Additionally, this update changes the default settings for zstd to use
multithreading and long-range options, better aligning with its intended
use.

Inspired by D42961 .

Reviewed by: debdrup (earlier version, mdoc(7))
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D43165

6 months agoiichid(4): Improve idle sampling hysteresis
Alexander Motin [Sat, 23 Dec 2023 03:50:52 +0000 (22:50 -0500)]
iichid(4): Improve idle sampling hysteresis

In sampling mode some devices return same data indefinitely even if
there is nothing to report.  Previous idle hysteresis implementation
activated only when device returned no data, so some devices ended up
polled at fast rate all the time.  This new implementation compares
each new report with the previous, and, if they are identical, after
reaching threshold also drop sampling rate to slow.

On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this
reduces idle power consumption by ~0.5W by reducing number of context
switches in the driver from ~4000 to ~700 per second when not touched.

MFC after: 1 month

6 months agocontrib/tzdata: import tzdata 2023d
Philip Paeps [Sat, 23 Dec 2023 01:51:01 +0000 (09:51 +0800)]
contrib/tzdata: import tzdata 2023d

Changes: https://github.com/eggert/tz/blob/2023d/NEWS

MFC after: 1 day

6 months agoImport tzdata 2023d
Philip Paeps [Sat, 23 Dec 2023 01:34:58 +0000 (09:34 +0800)]
Import tzdata 2023d

6 months agoRELNOTES: Add an entry for commit 7c5146da1286
Rick Macklem [Fri, 22 Dec 2023 20:25:19 +0000 (12:25 -0800)]
RELNOTES: Add an entry for commit 7c5146da1286

6 months agomountd: Update exports.5 for commit 7c5146da1286
Rick Macklem [Fri, 22 Dec 2023 20:17:36 +0000 (12:17 -0800)]
mountd: Update exports.5 for commit 7c5146da1286

Commit 7c5146da1286 modified mountd so that it uses
strunvis(3) to decode directory names in exports lines.
This allows special characters, such as blanks, to be
encoded in the directory names.

This patch updates the exports.5 man page for this change.

This is a content change.

Reviewed by: karels, pauamma_gundo.com (manpages)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42163

6 months agonfscl: Fix handling of a copyout() error reply
Rick Macklem [Fri, 22 Dec 2023 20:11:22 +0000 (12:11 -0800)]
nfscl: Fix handling of a copyout() error reply

If vfs.nfs.nfs_directio_enable is set non-zero (the default is
zero) and a file on an NFS mount is read after being opened
with O_DIRECT | O_ RDONLY, a call to nfsm_mbufuio() calls
copyout() without checking for an error return.
If copyout() returns EFAULT, this would not work correctly.

Only the call path
 VOP_READ()->ncl_readrpc()->nfsrpc_read()->nfsrpc_readrpc()
will do this and the error return for EFAULT will
be returned back to VOP_READ().

This patch adds the error check to nfsm_mbufuio().

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

6 months agovm_iommu_map()/unmap(): stop transiently wiring already wired pages
Konstantin Belousov [Thu, 21 Dec 2023 00:12:37 +0000 (02:12 +0200)]
vm_iommu_map()/unmap(): stop transiently wiring already wired pages

Namely, switch from vm_fault_quick_hold() to pmap_extract() KPI to
translate gpa to hpa. Assert that the looked up hpa belongs to the wired
page, as it should be for the VM which is configured for pass-throu
(this is theoretically a restriction that could be removed on newer
DMARs).

Noted by: alc
Reviewed by: alc, jhb, markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D43140

6 months agovmm_iommu_modify(): split vm_iommu_map()/unmap() into separate functions
Konstantin Belousov [Thu, 21 Dec 2023 00:00:33 +0000 (02:00 +0200)]
vmm_iommu_modify(): split vm_iommu_map()/unmap() into separate functions

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

6 months agopf: mark netlink commands as requiring NETINET_PF privileges
Kristof Provost [Fri, 22 Dec 2023 16:40:52 +0000 (17:40 +0100)]
pf: mark netlink commands as requiring NETINET_PF privileges

Sponsored by: Rubicon Communications, LLC ("Netgate")

6 months agokldxref: Appease a Coverity warning
John Baldwin [Fri, 22 Dec 2023 15:49:40 +0000 (07:49 -0800)]
kldxref: Appease a Coverity warning

While parsing .dynamic, nsym is set when parsing the symbol table from
.dynsym.  That parsing also sets ef->ef_symtab to a non-NULL value.
The value of nsym isn't validated until after a check for
ef->ef_symtab being NULL, so nsym always has a valid value when it is
read.  However, that chain of events is a bit much for static analysis
to follow, so initialize nsym to 0 before parsing sections to quiet
the warning.

Reported by: Coverity Scan
CID: 1532339
Sponsored by: DARPA

6 months agokldxref: Simplify handling of ELF object files
John Baldwin [Fri, 22 Dec 2023 15:49:18 +0000 (07:49 -0800)]
kldxref: Simplify handling of ELF object files

Unlike the backend for ELF DSOs, the object file backend allocated an
aligned chunk of memory and read all of the in-memory sections from
the file into this memory even though most of the file contents were
never used.  Instead, just track a set of virtual addresses (based at
0) that each loaded section would be loaded at and only read the
necessary bits from the backing file when needed.

Reviewed by: imp
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D43126

6 months agokldxref: Simplify elf_read_raw_data
John Baldwin [Fri, 22 Dec 2023 15:49:03 +0000 (07:49 -0800)]
kldxref: Simplify elf_read_raw_data

Use pread as a valid offset is always passed now.  Originally the DSO
code read the .hash section in two separate requests and relied on the
implicit offset for the second read, but now the hash table is fetched
in a single call.

Reviewed by: imp
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D43125

6 months agokldxref: Tidy error handling for invalid addresses
John Baldwin [Fri, 22 Dec 2023 15:48:47 +0000 (07:48 -0800)]
kldxref: Tidy error handling for invalid addresses

- Don't print an offset value that's always zero.

- ef_get_offset can't return -1.

Reviewed by: imp
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D43124

6 months agobhyve.8: fix -k description
Konstantin Belousov [Thu, 21 Dec 2023 23:58:55 +0000 (01:58 +0200)]
bhyve.8: fix -k description

Apparently 19eaa01beaba6 inserted -K description in the middle of -k.

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Differential revision: https://reviews.freebsd.org/D43164

6 months agobhyve.8: add missed dot
Konstantin Belousov [Thu, 21 Dec 2023 23:54:39 +0000 (01:54 +0200)]
bhyve.8: add missed dot

Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Differential revision: https://reviews.freebsd.org/D43164

6 months agodevd: Don't install autofs.conf with WITHOUT_AUTOFS
Tijl Coosemans [Fri, 22 Dec 2023 14:14:55 +0000 (15:14 +0100)]
devd: Don't install autofs.conf with WITHOUT_AUTOFS

6 months agotcp: allow userspace use of tcp header flags accessor functions
Richard Scheffenegger [Thu, 21 Dec 2023 23:47:36 +0000 (00:47 +0100)]
tcp: allow userspace use of tcp header flags accessor functions

Provide accessor functions to all 12 possible TCP header
flags for userspace too.

Reviewed By:           zlei
MFC after:             2 weeks
Sponsored by:          Netapp, Inc.
Differential Revision: https://reviews.freebsd.org/D43152

6 months agoseq(1): Put separator only between the elements.
Pawel Jakub Dawidek [Tue, 19 Dec 2023 02:39:57 +0000 (18:39 -0800)]
seq(1): Put separator only between the elements.

- Using non-default ('\n') separator will produce an output with the
  separator at the end of the output, eg.

% echo "[$(seq -s ' ' 0 2)]"
[0 1 2 ]

- The output should always be followed by a new line character. Currently:

% seq -s ' ' 0 2
0 1 2 %

This change makes seq(1) to behave the same way Linux seq(1):

% echo "[$(seq -s ' ' 0 2)]"
[0 1 2]

% seq -s ' ' 0 2
0 1 2
%

Approved by: oshogbo
Differential Revision: https://reviews.freebsd.org/D43094

6 months agoregex: mixed sets are misidentified as singletons
Bill Sommerfeld [Thu, 21 Dec 2023 03:46:14 +0000 (10:46 +0700)]
regex: mixed sets are misidentified as singletons

Fix "singleton" function used by regcomp() to turn character set matches
into exact character matches if a character set has exactly one
element.

The underlying cset representation is complex; most critically it
records"small" characters (codepoint less than either 128
or 256 depending on locale) in a bit vector, and "wide" characters in
a secondary array.

Unfortunately the "singleton" function uses to identify singleton sets
treated a cset as a singleton if either the "small" or the "wide" sets
had exactly one element (it would then ignore the other set).

The easiest way to demonstrate this bug:

$ export LANG=C.UTF-8
$ echo 'a' | grep '[abà]'

It should match (and print "a") but instead it doesn't match because the
single accented character in the set is misinterpreted as a singleton.

Reviewed by: kevans, yuripv
Obtained from: illumos
Differential Revision: https://reviews.freebsd.org/D43149

6 months agoLinuxKPI: reduce impact of large MAXCPU
Bjoern A. Zeeb [Mon, 23 Oct 2023 23:14:35 +0000 (23:14 +0000)]
LinuxKPI: reduce impact of large MAXCPU

Start scaling arrays dynamically instead of using MAXCPU, resulting in
extra allocations on startup but reducing the overall memory footprint.
For the static single CPU mask we provide two versions to further save
memory depending on a low or high CPU count system.  The threshold to
switch is currently at 128 CPUs on 64bit platforms.
More detailed comments on the implementations can be found in the code.

If I am not wrong on a MAXCPU=65536 system the memory footprint should
roughly go down from 512M to 1.5M for the static single CPU mask.

Submitted by: olce (most of this final version)
Sponsored by: The FreeBSD Foundation
PR: 274316
Differential Revision: https://reviews.freebsd.org/D42345

6 months agonet80211: adjust more VHT structures/fields
Bjoern A. Zeeb [Sat, 2 Dec 2023 20:40:51 +0000 (20:40 +0000)]
net80211: adjust more VHT structures/fields

Replace ieee80211_ie_vhtcap with ieee80211_vht_cap and
ieee80211_ie_vht_operation with ieee80211_vht_operation.
The "ie" version has the two bytes type/length at the beginning which
we did not actually use as such (the one place doing did just as unused
extra work).

Using the non-"ie" versions allows us to re-use them on shared code.
Using an enum helps us to not accidentally get unsuppored or unhandled
values tough we cannot use it in the struct as we need to ensure the
field width.

ieee80211_vht_operation is guarded by _KERNEL/WANT_NET80211.  While the
header is supposed to be exported to user land historically, software
such as wpa bring their own structure definitions.  For in-tree usage
it is only ifconfig which really cares (at least for now).

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: adrian (earlier), cc
Differential Revision: https://reviews.freebsd.org/D42901

6 months agonet80211: improve logging about state transitions lost
Bjoern A. Zeeb [Sun, 12 Nov 2023 23:51:14 +0000 (23:51 +0000)]
net80211: improve logging about state transitions lost

It is possible that we call ieee80211_new_state_locked() again before
a previous task finished to completion (not run yet or unlocked in
between) since 5efea30f039c4 (and follow-up).
In either case we would overwrite the new state and argument in the vap.

While most drivers somehow deal with that (or not), LinuxKPI 802.11 compat
code has KASSERTs to keep net80211, LinuxKPI and driver/firmware state in
sync and they may trigger due to a missing transition or more likely a
changed ni/lsta.

Enhance the wlandebug +state logging for these cases so they
are easier to debug.

While here remove the unconditional logging to the message buffer;
it has been here for a good decade but not helped to actually identify
and sort the problem.

Sponsored by:   The FreeBSD Foundation
MFC after: 3 days
Reviewed by: cc
Differential Revision: https://reviews.freebsd.org/D42560

6 months agofind: Add a warning about -delete.
Dag-Erling Smørgrav [Thu, 21 Dec 2023 23:41:05 +0000 (00:41 +0100)]
find: Add a warning about -delete.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: pauamma_gundo.com
Differential Revision: https://reviews.freebsd.org/D43162

6 months agoSilence VLA extension warnings in fusefs tests
Dimitry Andric [Thu, 21 Dec 2023 22:41:57 +0000 (23:41 +0100)]
Silence VLA extension warnings in fusefs tests

Building tests/sys/fs/fusefs with clang 18 results the following
warning:

  tests/sys/fs/fusefs/cache.cc:145:14: error: variable length arrays in C++ are a Clang extension [-Werror,-Wvla-cxx-extension]
    145 |         uint8_t buf[bufsize];
        |                     ^~~~~~~

Because we do not particularly care that this is a clang extension,
suppress the warning.

MFC after: 3 days

6 months agoSilence snprintf truncation warnings in printf_test examples
Dimitry Andric [Thu, 21 Dec 2023 22:39:15 +0000 (23:39 +0100)]
Silence snprintf truncation warnings in printf_test examples

Building share/examples/tests with clang 18 results in a few warnings
like:

  share/examples/tests/tests/plain/printf_test.c:67:6: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 17 [-Werror,-Wformat-truncation]
     67 |         if (snprintf(buffer, sizeof(buffer), "0123456789abcdef") != 16)
        |             ^

Since these tests are meant as an example of testing snprintf overflow,
suppress the warnings.

MFC after: 3 days

6 months agoFix snprintf truncation in telnet
Dimitry Andric [Thu, 21 Dec 2023 22:35:17 +0000 (23:35 +0100)]
Fix snprintf truncation in telnet

Building telnet with clang 18 results in the following warning:

  contrib/telnet/telnet/telnet.c:231:5: error: 'snprintf' will always be truncated; specified size is 10, but format string expands to at least 11 [-Werror,-Wformat-truncation]
    231 |     snprintf(temp2, sizeof(temp2), "%c%c%c%c....%c%c", IAC, SB, TELOPT_COMPORT,
|     ^

The temp2 buffer is 10 chars, while the format string also consists of
10 chars. Therefore, snprintf(3) will truncate the last character, 'SE'
(end sub negotation) in this case.

Bump the buffer to 11 chars to avoid truncation.

MFC after: 3 days

6 months agoRevert "power*/SYS.h: implement _SYSCALL_BODY() macro"
Brooks Davis [Thu, 21 Dec 2023 21:36:12 +0000 (21:36 +0000)]
Revert "power*/SYS.h: implement _SYSCALL_BODY() macro"

bapt reports build errors on powerpc/powerpc so this is the most likely
culprit.

This reverts commit e88e1272792e41cbf0a5af1f5f0a858afece0475.