]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
2 years agofetch: make -S argument accept values > 2GB
Stefan Eßer [Sun, 20 Feb 2022 14:24:43 +0000 (15:24 +0100)]
fetch: make -S argument accept values > 2GB

Use strtoll() to parse the argument of the -S option.

FreeBSD has supported 64 bit file offsets for more than 25 years on
all architectures and off_t is a 64 bit integer type for that reason.

While strtol() returns a 64 bit value on 64 LP64 architectures, it
is limit to 32 bit on e.g. i386. The strtoll() function returns a 64
but result on all supported architectures and therefore supports the
possible file lengths and file offsets on 32 bit archtectures.

(cherry picked from commit 32066c96fa00fc19c8355e1956ca5aa9ead37673)

2 years agobin/df: allow -t option to be used together with -l
Stefan Eßer [Thu, 10 Feb 2022 20:09:34 +0000 (21:09 +0100)]
bin/df: allow -t option to be used together with -l

The df command provides a -l option to exclude all non-local file
systems and a -t option with a (positive or negative) list of file
system types to display.

This commit adds support for a combination of -l and -t. If both are
specified, the parameter list of the -t option is applied on top of
the selection of öocal file systems (independently of the order of
the -l and -t options).

E.g., "df -t noprocfs,sysfs -l" will select all local file systems
except those of type procfs and sysfs.

(cherry picked from commit f0fd4a32c4f7ab5eb008ab08a1a13cb20d4b30d2)

2 years agofread.c: fix undefined behavior
Stefan Eßer [Sat, 15 Jan 2022 23:30:04 +0000 (00:30 +0100)]
fread.c: fix undefined behavior

A case of undefined behavior in __fread() has been detected by UBSAN
and reported by Mark Millard:

/usr/main-src/lib/libc/stdio/fread.c:133:10: runtime error: applying
zero offset to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior in
/usr/main-src/lib/libc/stdio/fread.c:133:10

While being benign (the NULL pointer is later passed to memcpy() with
a length argument of 0), this issue causes in the order of 600 Kyua
test cases to fail on systems running a world built with WITH_UBSAN
and WITH_ASAN.

The undefined behavior can be prevented by skipping operations that
have no effect for r == 0. Mark Millard has suggested to only skip
this code segment if fp->_p == NULL, but I have verified that for the
case of r == 0 no further argument checking is performed on the
addresses passed to memcpy() and thus no bugs are hidden from the
sanitizers due to the simpler condition chosen.

(cherry picked from commit 10af8e45a89818754b80315539e167ae49599f17)

2 years agoqsort.c: prevent undefined behavior
Stefan Eßer [Thu, 13 Jan 2022 10:09:38 +0000 (11:09 +0100)]
qsort.c: prevent undefined behavior

Mark Milliard has detected a case of undefined behavior with the LLVM
UBSAN. The mandoc program called qsort with a==NULL and n==0, which is
allowed by the POSIX standard. The qsort() in FreeBSD did not attempt
to perform any accesses using the passed pointer for n==0, but it did
add an offset to the pointer value, which is undefined behavior in
case of a NULL pointer. This operation has no adverse effects on any
achitecture supported by FreeBSD, but could be caught in more strict
environments.

After some discussion in the freebsd-current mail list, it was
concluded that the case of a==NULL and n!=0 should still be caught by
UBSAN (or cause a program abort due to an illegal access) in order to
not hide errors in programs incorrectly invoking qsort().

Only the the case of a==NULL and n==0 should be fixed to not perform
the undefined operation on a NULL pointer.

This commit makes qsort() exit before reaching the point of
potentially undefined behvior for the case n==0, but does not test
the value of a, since the result will not depend on whether this
pointer is NULL or an actual pointer to an array if n==0.

The issue found by Mark Milliard in the whatis command has been
reported to the upstream (OpenBSD) and has already been patched
there.

(cherry picked from commit d106f982a54cd299671ccad58bc456138a22ae7b)

2 years agobitset.9: add description of BIT_ISSET
Doug Moore [Thu, 6 Jan 2022 12:14:18 +0000 (13:14 +0100)]
bitset.9: add description of BIT_ISSET

Extracted from abandoned review https://reviews.freebsd.org/D33701.

(cherry picked from commit 145c65fc5791d1e4a21c7653f68a55cfd1772aac)

cpuset.9: add description of CPU_ISSET

(cherry picked from commit eaf3c3af9c88dc63ea09833397f2bbeded16f553)

2 years agousr.bin/stat: honour locale for "-t %+"
Stefan Eßer [Sat, 30 Oct 2021 07:00:34 +0000 (09:00 +0200)]
usr.bin/stat: honour locale for "-t %+"

The man page states that "-t %+" prints time information in the same
format as date with no format specifier.

This was not the case, the format used was always that of date for the
POSIX locale.

The fix suggested by the reporter leads to output that matches the
documentation.

(cherry picked from commit 20f8331aca892ff812510609b3bc4e747b201197)

2 years agonetstat: Fix typo
Stefan Eßer [Fri, 2 Jul 2021 06:38:42 +0000 (08:38 +0200)]
netstat: Fix typo

Correct spelling of "received packers" to "received packets".

(cherry picked from commit c5b8d7b7c14f72a4ad12e610222642c69374dd4a)

2 years agousr.bin/calendar: do not treat // in text as comment
Stefan Eßer [Mon, 7 Jun 2021 13:46:24 +0000 (15:46 +0200)]
usr.bin/calendar: do not treat // in text as comment

The C++-style comment marker "//" has been added with the rewrite of
the preprocessor features. Since this character sequence occurs in
ULRS, the reminder of the URL was considered a comment and stripped
from the calendar line.

Change parsing of "//" to only start a comment at the begin of a line
or when preceeded by a white-space character.

(cherry picked from commit 35b8fd0b699a20f71d5636069347b243eb336979)

2 years agopowerpc64: fix loader regression
Leandro Lupori [Tue, 21 Sep 2021 20:22:42 +0000 (17:22 -0300)]
powerpc64: fix loader regression

After b4cb3fe0e39a, loader started crashing on PowerPC64, with a
Program Exception (700) error. The problem was that archsw was
used before being initialized, with the new mount feature. This
change fixes the issue by initializing archsw earlier, before
setting currdev, that triggers the mount.

Reviewed by: tsoome
MFC after: 1 month
X-MFC-With: b4cb3fe0e39a
Sponsored by: Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision: https://reviews.freebsd.org/D32027

(cherry picked from commit 680ca739458ba8cba221ea74794c2cd9771c77f8)

2 years agormlock: Micro-optimize read locking
Mark Johnston [Fri, 25 Feb 2022 18:42:51 +0000 (13:42 -0500)]
rmlock: Micro-optimize read locking

Use get_pcpu() instead of an open-coded pcpu_find(td->td_oncpu).  This
eliminates some memory accesses and results in a shorter instruction
sequence.  Note that get_pcpu() didn't exist when rmlocks were added.

Reviewed by: jah, mjg
Sponsored by: The FreeBSD Foundation

(cherry picked from commit c84bb8cd771ce4bed58152e47a32dda470bef23a)

2 years agonfscl: Fix a use after free in nfscl_cleanupkext()
Rick Macklem [Fri, 25 Feb 2022 15:27:03 +0000 (07:27 -0800)]
nfscl: Fix a use after free in nfscl_cleanupkext()

ler@, markj@ reported a use after free in nfscl_cleanupkext().
They also provided two possible causes:
- In nfscl_cleanup_common(), "own" is the owner string
  owp->nfsow_owner.  If we free that particular
  owner structure, than in subsequent comparisons
  "own" will point to freed memory.
- nfscl_cleanup_common() can free more than one owner, so the use
  of LIST_FOREACH_SAFE() in nfscl_cleanupkext() is not sufficient.

I also believe there is a 3rd:
- If nfscl_freeopenowner() or nfscl_freelockowner() is called
  without the NFSCLSTATE mutex held, this could race with
  nfscl_cleanupkext().
  This could happen when the exclusive lock is held
  on the client, such as when delegations are being returned
  or when recovering from NFSERR_EXPIRED.

This patch fixes them as follows:
1 - Copy the owner string to a local variable before the
    nfscl_cleanup_common() call.
2 - Modify nfscl_cleanup_common() so that it will never free more
    than the first matching element.  Normally there should only
    be one element in each list with a matching open/lock owner
    anyhow (but there might be a bug that results in a duplicate).
    This should guarantee that the FOREACH_SAFE loops in
    nfscl_cleanupkext() are adequate.
3 - Acquire the NFSCLSTATE mutex in nfscl_freeopenowner()
    and nfscl_freelockowner(), if it is not already held.
    This serializes all of these calls with the ones done in
    nfscl_cleanup_common().

(cherry picked from commit 1cedb4ea1a790f976ec6211c938dfaa23874b497)

2 years agodwc: Support phy mode MII
Emmanuel Vadot [Tue, 22 Feb 2022 08:58:36 +0000 (09:58 +0100)]
dwc: Support phy mode MII

Some board use dwc phy in MII mode, so do not fail to attach if this is
the case.
Only rockchip code uses the phy mode to program some custom syscon register.

PR: 260848
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG

(cherry picked from commit da6252a6a099e6253207b69960e6762ce3cca0f8)

2 years agodwc: Release resources when attach fails
Emmanuel Vadot [Tue, 22 Feb 2022 08:53:11 +0000 (09:53 +0100)]
dwc: Release resources when attach fails

PR: 259282
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 30f16ad460e2f9631484d04f067d80ee578473bc)

2 years agossh: correct configure option name
Ed Maste [Tue, 1 Mar 2022 14:35:46 +0000 (09:35 -0500)]
ssh: correct configure option name

The option is security-key-builtin not security-key-internal.  There is
no change to the generated config.h because the option defaults off
anyway.

MFC after: 3 days
Fixes: 87152f340549 ("ssh: disble internal security key...")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit f1421a8972a2c8babfacfd1270258492579e0208)

2 years agonetinet: simplify RSS ifdef statements
Franco Fichtner [Tue, 8 Feb 2022 02:22:03 +0000 (19:22 -0700)]
netinet: simplify RSS ifdef statements

Approved by: transport (rrs)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D31583

(cherry picked from commit 47ded797ce9620f055f005e9dccfcd03613b1804)

2 years agousb(4): Automagically apply all quirks for USB mass storage devices.
Hans Petter Selasky [Mon, 21 Feb 2022 08:24:28 +0000 (09:24 +0100)]
usb(4): Automagically apply all quirks for USB mass storage devices.

Currently there are five quirks the USB stack tries to automagically detect:
- UQ_MSC_NO_PREVENT_ALLOW
- UQ_MSC_NO_SYNC_CACHE
- UQ_MSC_NO_TEST_UNIT_READY
- UQ_MSC_NO_GETMAXLUN
- UQ_MSC_NO_START_STOP

If any of the quirks above are set, no further quirks will be probed.

If any of the USB mass storage tests fail, the USB device is
re-enumerated as a last resort to clear any error states from the
device. Then the USB stack will try to probe and attach the umass<N>
device passing the detected quirks.

While at it give more details in dmesg about what is going on.

Tested by: several
Submitted by: Idwer Vollering <vidwer_fbsdbugs@gmail.com>
Differential Revision: https://reviews.freebsd.org/D30919
Sponsored by: NVIDIA Networking

(cherry picked from commit 7520b88860d7a79432e12ffcc47056844518bb62)

2 years agomlx5ib: Add support for NDR link speed.
Hans Petter Selasky [Mon, 21 Feb 2022 08:25:29 +0000 (09:25 +0100)]
mlx5ib: Add support for NDR link speed.

The IBTA specification has new speed - NDR. That speed supports signaling
rate of 100Gb. mlx5 IB driver translates link modes reported by ConnectX
device to IB speed and width. Added translation of new 100Gb, 200Gb and
400Gb link modes to NDR IB type and width of x1, x2 or x4 respectively.

Linux commits:
f946e45f59ef01ff54ffb3b1eba3a8e7915e7326

Sponsored by: NVIDIA Networking

(cherry picked from commit 91c8ffd7e60fa7f017731cd234c01b7cddc05272)

2 years agoibcore: Add support for NDR link speed.
Hans Petter Selasky [Mon, 21 Feb 2022 08:25:10 +0000 (09:25 +0100)]
ibcore: Add support for NDR link speed.

Add new IBTA speed NDR, supporting signaling rate of 100Gb.

Linux commit:
c7adf7717301558e8852949d8e3dc3748d1a4a97

Sponsored by: NVIDIA Networking

(cherry picked from commit 1aa593b90ca96acb0d996daef9739ec98538f0db)

2 years agomlx5core: Add PCI IDs for ConnectX-8.
Hans Petter Selasky [Mon, 21 Feb 2022 08:25:45 +0000 (09:25 +0100)]
mlx5core: Add PCI IDs for ConnectX-8.

Sponsored by: NVIDIA Networking

(cherry picked from commit eb16e362d6cb96fab733d94fa01b7a1c84ccb436)

2 years agomlx5core: Add PCI IDs for ConnectX-7.
Hans Petter Selasky [Mon, 21 Feb 2022 08:25:23 +0000 (09:25 +0100)]
mlx5core: Add PCI IDs for ConnectX-7.

Linux commits:
505a7f5478062c6cd11e22022d9f1bf64cd8eab3
dd8595eabeb486d41ad9994e6cece36e0e25e313

Sponsored by: NVIDIA Networking

(cherry picked from commit ea8aacc523e8ac43e035097233774f30b1d33653)

2 years agovfs_unregister: fix error handling
Marvin Ma [Fri, 25 Feb 2022 15:34:33 +0000 (09:34 -0600)]
vfs_unregister: fix error handling

Due to misplaced braces, an error from vfs_uninit() in the VFCF_SBDRY
case was ignored.

Reported by: Anton Rang <rang@acm.org>
Reviewed by: Anton Rang <rang@acm.org>, markj
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D34375

(cherry picked from commit 1517b8d5a7f58897200497811de1b18809c07d3e)

2 years agommap map_at_zero test: handle W^X
Arka Sharma [Fri, 18 Feb 2022 15:34:15 +0000 (09:34 -0600)]
mmap map_at_zero test: handle W^X

Use kern.elfXX.allow_wx to decide whether to map W+X or W-only memory.

Future work could expand this test to add an "allow_wx" axis to the
test matrix, but I would argue that a separate test should be written,
since that's orthogonal to map_at_zero.

MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 766c2466ff465b3c7c1a46be729b42a6da47de03)

2 years agoatrtc: reads Century field from FADT table
Austin Zhang [Thu, 13 Jan 2022 17:13:25 +0000 (11:13 -0600)]
atrtc: reads Century field from FADT table

The ACPI spec describes the FADT->Century field as:

    The RTC CMOS RAM index to the century of data value (hundred and
    thousand year decimals).  If this field contains a zero, then the
    RTC centenary feature is not supported.  If this field has a non-zero
    value, then this field contains an index into RTC RAM space that
    OSPM can use to program the centenary field.

Use this field to decide whether to program the CENTURY register
of the CMOS RTC device.

Reviewed by: akumar3@isilon.com, dab, vangyzen
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D33667

MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit e1ef6c0ef256f797d629b9490db3f0034b28ae43)

2 years agoddb: do not assume that ffs is mounted with softdep
Keith Owens [Wed, 25 Aug 2021 01:59:31 +0000 (20:59 -0500)]
ddb: do not assume that ffs is mounted with softdep

Avoid a panic when debugging with "show ffs" in ddb.

Reviewed By: kib, markj, mckusick
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D31622

(cherry picked from commit 3b29c8b4bdb0e396d7bb5d0760f11d7fa4208c84)

2 years agoipmi: support getting address from EFI
Yinlong Lu [Thu, 29 Apr 2021 10:04:36 +0000 (05:04 -0500)]
ipmi: support getting address from EFI

The original implementation only supports getting the address from legacy
BIOS (by searching for the SMBIOS_SIG pattern in a fixed address space).

Try to get the SMBIOS table from EFI through efirt (EFI Runtime Services)
firstly.  Continue to search in the legacy BIOS if a NULL address is
returned from EFI.

By this way the ipmi function supports both legacy BIOS and UEFI systems.

Reviewed by: dab, vangyzen
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D30007

(cherry picked from commit ee8b757a949a9575c7355ea01f0475e0c526b9e5)

2 years agoipmi,smbios: move smbios_walk_table to smbios.h
Greg V [Wed, 7 Apr 2021 20:05:49 +0000 (15:05 -0500)]
ipmi,smbios: move smbios_walk_table to smbios.h

This function will be used for exposing DMI info as sysctls in the
smbios module (in an upcoming review).

While here, add __packed to the structs.

Reviewed by: dab
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29270

(cherry picked from commit f689cb23b2782d0d0f586bcfabbad68f728ed1df)

2 years agosmbios: support getting address from EFI
Greg V [Wed, 7 Apr 2021 19:46:29 +0000 (14:46 -0500)]
smbios: support getting address from EFI

On some systems (e.g. Lenovo ThinkPad X240, Apple MacBookPro12,1)
the SMBIOS entry point is not found in the <0xFFFFF space.

Follow the SMBIOS spec and use the EFI Configuration Table for
locating the entry point on EFI systems.

Reviewed by: rpokala, dab
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29276

(cherry picked from commit a29bff7a5216bd5f4a76228788e7eacf235004de)

2 years agosmbios: Move smbios driver out from x86 machdep code
Allan Jude [Tue, 23 Feb 2021 21:14:18 +0000 (21:14 +0000)]
smbios: Move smbios driver out from x86 machdep code

Add it to the x86 GENERIC and MINIMAL kernels

Sponsored by: Ampere Computing LLC
Submitted by: Klara Inc.
Reviewed by: rpokala
Differential Revision: https://reviews.freebsd.org/D28738

(cherry picked from commit d0673fe160b04f8162f380926d455dfb966f08fb)

2 years agofuse: Fix build on 32-bit architectures
Jessica Clarke [Thu, 3 Mar 2022 03:22:30 +0000 (03:22 +0000)]
fuse: Fix build on 32-bit architectures

MFC 3d721de049be ("Fix NFS exports of FUSE file systems for big
directories") missed a case of a uint64_t from HEAD that should be a
u_long in 13 due to KPI differences. Specifically, HEAD has b214fcceacad
("Change VOP_READDIR's cookies argument to a **uint64_t"), but stable/13
does not.

This is a direct commit to stable/13.

2 years agotime_t is pathological: use %j + cast to print it.
Warner Losh [Fri, 1 Oct 2021 18:14:35 +0000 (12:14 -0600)]
time_t is pathological: use %j + cast to print it.

Sponsored by: Netflix

(cherry picked from commit 4aed5c3c9d1d78986d3feba3f128187c59fb2dfe)

2 years ago[skip ci] fusefs: delete a stray comment from 91972cfcddf
Alan Somers [Sat, 12 Feb 2022 16:27:56 +0000 (09:27 -0700)]
[skip ci] fusefs: delete a stray comment from 91972cfcddf

(cherry picked from commit 0b6a34acda4245215df29be35e4ef4bba995ec91)

2 years agoFix NFS exports of FUSE file systems for big directories
Alan Somers [Sun, 2 Jan 2022 17:18:47 +0000 (10:18 -0700)]
Fix NFS exports of FUSE file systems for big directories

The FUSE protocol does not require that a directory entry's d_off field
outlive the lifetime of its directory's file handle.  Since the NFS
server must reopen the directory on every VOP_READDIR call, that means
it can't pass uio->uio_offset down to the FUSE server.  Instead, it must
read the directory from 0 each time.  It may need to issue multiple
FUSE_READDIR operations until it finds the d_off field that it's looking
for.  That was the intention behind SVN r348209 and r297887, but a logic
bug prevented subsequent FUSE_READDIR operations from ever being issued,
rendering large directories incompletely browseable.

Reviewed by: rmacklem

(cherry picked from commit d088dc76e1a62ecb6c05bd2b14ee48a9f9a7e2bd)

fusefs: optimize NFS readdir for FUSE_NO_OPENDIR_SUPPORT

In its lowest common denominator, FUSE does not require that a directory
entry's d_off field is valid outside of the lifetime of the directory's
FUSE file handle.  But since NFS is stateless, it must reopen the
directory on every call to VOP_READDIR.  That means reading the
directory all the way from the first entry.  Not only does this create
an O(n^2) condition for large directories, but it can also result in
incorrect behavior if either:

* The file system _does_ change the d_off field for the last directory
  entry previously seen by NFS, or
* The file system deletes the last directory entry previously seen by
  NFS.

Handily, for file systems that set FUSE_NO_OPENDIR_SUPPORT d_off is
guaranteed to be valid for the lifetime of the directory entry, there is
no need to read the directory from the start.

Reviewed by: rmacklem

(cherry picked from commit 4a6526d84a56f398732bff491e63aa42f796a27d)

fusefs: require FUSE_NO_OPENDIR_SUPPORT for NFS exporting

FUSE file systems that do not set FUSE_NO_OPENDIR_SUPPORT do not
guarantee that d_off will be valid after closing and reopening a
directory.  That conflicts with NFS's statelessness, that results in
unresolvable bugs when NFS reads large directories, if:

* The file system _does_ change the d_off field for the last directory
  entry previously returned by VOP_READDIR, or
* The file system deletes the last directory entry previously seen by
  NFS.

Rather than doing a poor job of exporting such file systems, it's better
just to refuse.

Even though this is technically a breaking change, 13.0-RELEASE's
NFS-FUSE support was bad enough that an MFC should be allowed.

Reviewed by: rmacklem
Differential Revision: https://reviews.freebsd.org/D33726

(cherry picked from commit 00134a07898fa807b8a1fcb2596f0e3644143f69)

fusefs: fix the build without INVARIANTS after 00134a07898

MFC with: 00134a07898fa807b8a1fcb2596f0e3644143f69
Reported by: se

(cherry picked from commit 18ed2ce77a254f365a4687d6afe8eeba2aad2e13)

2 years agoMFC posixshm: Add a -j option to posixshmcontrol ls, to specify a jail
Jamie Gritton [Sun, 27 Feb 2022 01:45:28 +0000 (17:45 -0800)]
MFC posixshm: Add a -j option to posixshmcontrol ls, to specify a jail

PR: 257556
Reported by: grembo@

(cherry picked from commit be7cf3f4b8c2818155f5a4a83c64c9ef6a60a320)

2 years agoposixshm: Allow jails to use kern.ipc.posix_shm_list
Jamie Gritton [Thu, 24 Feb 2022 17:30:49 +0000 (09:30 -0800)]
posixshm: Allow jails to use kern.ipc.posix_shm_list

PR: 257554
Reported by: grembo@

(cherry picked from commit d7c4ea7d728e7480477eaedf79fac84e7d1aefde)

2 years agopowerpc: Fix syntax atomic.h
Li-Wen Hsu [Fri, 14 Jan 2022 11:11:22 +0000 (19:11 +0800)]
powerpc: Fix syntax atomic.h

Fixes: b5d227b0b27 powerpc: Add atomic_testand_{set,clear}_{int,long}
(cherry picked from commit 62b4e25f058b9820c8bf61e4664aa82428b0303b)

2 years agopowerpc/atomic: Fix atomic_testand_*_long on powerpc64
Justin Hibbits [Thu, 3 Feb 2022 23:20:36 +0000 (17:20 -0600)]
powerpc/atomic: Fix atomic_testand_*_long on powerpc64

After b5d227b0 FreeBSD was panicking on boot with "Duplicate free" in
UMA.  Analyzing the asm, the '1' mask was treated as an integer, rather
than a long, causing 'slw' (shift left word) to be used for the shifting
instruction, not 'sld' (shift left double).  This means the upper bits
of the bitfield were not getting used, resulting in corruption of the
bitfield.

While fixing this, the 'and' check of the mask does not need to be
recorded, so don't record (drop the '.').

(cherry picked from commit aa4736459ee2d314dc90ae9cbb4ad9c1cf48d796)

2 years agopowerpc: Add atomic_testand_{set,clear}_{int,long}
Justin Hibbits [Fri, 14 Jan 2022 03:46:29 +0000 (21:46 -0600)]
powerpc: Add atomic_testand_{set,clear}_{int,long}

Add machine-optimized implementations for the following:
* atomic_testandset_int
* atomic_testandclear_int
* atomic_testandset_long
* atomic_testandclear_long

This fixes the build with ISA_206_ATOMICS enabled.
Add the associated atomic_testandset_32, atomic_testandclear_32, so
that ice(4) can potentially build.

(cherry picked from commit b5d227b0b27adbb7b4db9f8f27a14df342344c50)

2 years agocxgbe(4): Changes to the fatal error handler.
Navdeep Parhar [Fri, 4 Feb 2022 21:16:35 +0000 (13:16 -0800)]
cxgbe(4): Changes to the fatal error handler.

* New error_flags that can be used from the error ithread and elsewhere
  without a synch_op.
* Stop the adapter immediately in t4_fatal_err but defer most of the
  rest of the handling to a task.  The task is allowed to sleep, unlike
  the ithread.  Remove async_event_task as it is no longer needed.
* Dump the devlog, CIMLA, and PCIE_FW exactly once on any fatal error
  involving the firmware or the CIM block.  While here, dump some
  additional info (see dump_cim_regs) for these errors.
* If both reset_on_fatal_err and panic_on_fatal_err are set then attempt
  a reset first and do not panic the system if it is successful.

Sponsored by: Chelsio Communications

(cherry picked from commit e9e7bc8250548fc6f91e2b3b9c30a865c5edfb60)

2 years agoApply lld fixes for internal errors building perl on 32-bit PowerPC
Dimitry Andric [Sun, 27 Feb 2022 12:53:19 +0000 (13:53 +0100)]
Apply lld fixes for internal errors building perl on 32-bit PowerPC

Merge commit f457863ae345 from llvm git (by Fangrui Song):

  [ELF] Support REL-format R_AARCH64_NONE relocation

  -fprofile-use=/-fprofile-sample-use= compiles may produce REL-format
  .rel.llvm.call-graph-profile even if the prevailing format is RELA on AArch64.
  Add R_AARCH64_NONE to getImplicitAddend to fix this linker error:

  ```
  ld.lld: error: internal linker error: cannot read addend for relocation R_AARCH64_NONE
  PLEASE submit a bug report to https://crbug.com and run tools/clang/scripts/process_crashreports.py (only works inside Google) which will upload a report and include the crash backtrace.
  ```

Merge commit 53fc5d9b9a01 from llvm git (by Fangrui Song):

  [ELF] Support R_PPC_NONE/R_PPC64_NONE in getImplicitAddend

  Similar to f457863ae345d2635026501f5383e0e625869639

Merge commit 767e64fc11d7 from llvm git (by Fangrui Song):

  [ELF] Support some absolute/PC-relative relocation types for REL format

  ctfconvert seems to use REL-format `.rel.SUNW_dof` for 32-bit architectures.
  ```
  Binary file usr/ports/lang/perl5.32/work/perl-5.32.1/dtrace_mini.o matches
  [alfredo.junior@dell-a ~/tmp/llvm-bug]$ readelf -r dtrace_mini.o

  Relocation section (.rel.SUNW_dof):
  r_offset r_info   r_type              st_value st_name
  00000184 0000281a R_PPC_REL32         00000000 $dtrace1772974259.Perl_dtrace_probe_load
  ```

  Support R_PPC_REL32 to fix `ld.lld: error: drti.c:(.SUNW_dof+0x4E4): internal linker error: cannot read addend for relocation R_PPC_REL32`.
  While here, add some common relocation types for AArch64, PPC, and PPC64.
  We perform minimum tests.

  Reviewed By: adalava, arichardson

  Differential Revision: https://reviews.llvm.org/D120535

Requested by: alfredo
MFC after: 3 days

(cherry picked from commit 298c3e8d6b6405cbea13a7a1a1fbc1ad5a45c378)

2 years agogzip: fix error handling in unxz
Eric van Gyzen [Thu, 24 Feb 2022 23:00:52 +0000 (17:00 -0600)]
gzip: fix error handling in unxz

The result of fstat() was not checked.  Furthermore, there was a
redundant check of st.st_size.  Fix both.

Reported by:    Coverity
MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 58135fbd8b68228678eb0ce38566aaf7ab1aad94)

2 years agoefivar: handle error when reading --fromfile
Eric van Gyzen [Wed, 23 Feb 2022 18:15:34 +0000 (12:15 -0600)]
efivar: handle error when reading --fromfile

The result of read() was stored in an unsigned variable, so the
test for a negative value would never work.

While I'm here, print a better error message for an empty file,
omitting the misleading errno message.

Reported by: Coverity
MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit d0f4e583bff67e2bdd816549c460da6daa3f67b1)

2 years agoefivar: use bool for booleans
Warner Losh [Fri, 9 Apr 2021 22:35:50 +0000 (16:35 -0600)]
efivar: use bool for booleans

Rather than int flags we ++, use booleans for all command line args.
No functional change intended.

Reviewed by: markj@
Sponsored by: Netflix, Inc
Differential Revision: https://reviews.freebsd.org/D29621

(cherry picked from commit 066b096d13a150e802c7142602d821c0b494487b)

2 years agoefivar: Attempt to fix setting/printing/deleting EFI vars with '-' in their name
Warner Losh [Fri, 9 Apr 2021 22:35:17 +0000 (16:35 -0600)]
efivar: Attempt to fix setting/printing/deleting EFI vars with '-' in their name

Due to how we're parsing UUIDs, we were disallowing setting, printing or
deleting any UEFI variable with a '-' in it when you attempted to do that
operation with the exact name (wildcard reporting was unaffected). Fix the
parser to loop over all the dashes in the name and only give up when all
possible matches are exhausted.

Reviewed by: markj@
Sponsored by: Netflix, Inc
Differential Revision: https://reviews.freebsd.org/D29620

(cherry picked from commit 0292a5c95f14b1ad3df39ee71c51cc830864a3aa)

2 years agoefivar: Add --quiet to not report errors
Warner Losh [Fri, 9 Apr 2021 22:35:08 +0000 (16:35 -0600)]
efivar: Add --quiet to not report errors

Add -q/--quiet flag to the command line. With it, errors are not reported at
all. Instead nothing is printed and the exit code is non-zero.

Reviewed by: markj
Sponsored by: Netflix, Inc
Differential Revision: https://reviews.freebsd.org/D29619

(cherry picked from commit 3c0dcbfc8501155af2c5461de10fd01c615524a0)

2 years agortsold: fix memory leak in script execution
Eric van Gyzen [Wed, 23 Feb 2022 16:49:12 +0000 (10:49 -0600)]
rtsold: fix memory leak in script execution

Since commit 04e9edb54428, rtsold has leaked the memory for the
argument vector of every script it runs.

Reported by: Coverity
Reviewed by: markj
Fixes: 04e9edb5442826a14616157962361ff81e4a38fe
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D34355

(cherry picked from commit 331b84b5db11b17d1bb0cdbce986efb587a1e5ee)

2 years agortsold: Use correct error in llflags_get()
Eric van Gyzen [Wed, 23 Feb 2022 16:29:53 +0000 (10:29 -0600)]
rtsold: Use correct error in llflags_get()

Set errno to EINVAL if the name overflows the buffer, as was done
before commit ecce515d54bc.

Reviewed by: dab, markj
Fixes: ecce515d54bcea54fea03f731aad646c87761d22
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D34354

(cherry picked from commit a2a8efb4f6c15ad0880167cb22452e50aaacf52f)

2 years agosendfile_test: fix copy-paste bug
Eric van Gyzen [Thu, 24 Feb 2022 22:53:03 +0000 (16:53 -0600)]
sendfile_test: fix copy-paste bug

Require the newly opened file descriptor to be good, instead of
re-requiring the one that was required three lines earlier.
Thankfully, opening /dev/null is really unlikely to fail.

Reported by: Coverity
MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit a8fea07c3053293f35e00b9073b33ff6f1d9a067)

2 years agoelfdump: handle small files more gracefully
Eric van Gyzen [Thu, 17 Feb 2022 15:53:48 +0000 (09:53 -0600)]
elfdump: handle small files more gracefully

elfdump -E on an empty file would complain "Invalid argument" because
it tried to mmap zero bytes.  With the -E flag, elfdump should
simply exit non-zero.  For tiny files, the code would reference off
the end of the mapped region.

Ensure the file is large enough to contain an ELF header before mapping it.

MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 86e5e10daf54da7df358a06033f3a3bd8c852a08)

2 years agoIntegrate contrib/file/tests with kyua/atf
Eric van Gyzen [Wed, 16 Feb 2022 15:50:43 +0000 (09:50 -0600)]
Integrate contrib/file/tests with kyua/atf

This could be done better by making each test a separate ATF test case.
This exercise is left for the reader.

Reviewed by: delphij (earlier version)
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D34303

(cherry picked from commit 1581ec9a4502c1f0e4f0ce290190864abf946d6f)

2 years agonewfs_msdos: connect the ATF test from NetBSD
Eric van Gyzen [Mon, 31 Jan 2022 20:43:04 +0000 (14:43 -0600)]
newfs_msdos: connect the ATF test from NetBSD

NetBSD has an ATF test for newfs_msdos.  Connect it to the build.
Adapt it for FreeBSD.  This would have caught the bug fixed by my
previous commit.

Reviewed by: delphij, emaste
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D34116

(cherry picked from commit 4e71258227d6a0d7ae5adadb0f3672bfce2bc906)

2 years agoAllow downstream projects to easily add private and internal libs
Eric van Gyzen [Fri, 14 Jan 2022 14:12:57 +0000 (08:12 -0600)]
Allow downstream projects to easily add private and internal libs

Allow projects based on the FreeBSD tree to append to _PRIVATELIBS
and _INTERNALLIBS by simply maintaining their own lists of
LOCAL_PRIVATELIBS and LOCAL_INTERNALLIBS, respectively.

Reviewed by: bdrewery
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D33901

(cherry picked from commit d7f944a0460531cfb3ec9ae7d4bfd9dc29481ab8)

2 years agosem_clockwait_np test: fix usage of ATF API
Eric van Gyzen [Fri, 1 Oct 2021 11:25:48 +0000 (06:25 -0500)]
sem_clockwait_np test: fix usage of ATF API

ATF_REQUIRE_ERRNO requires the given errno iff the given expression is
true.  These test cases used it incorrectly, potentially allowing
sem_clockwait_np to succeed when it was expected to fail.  Use separate
ATF calls to require failure and the expected errno.

MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 35e4527e88d3843cccf2f15a32b1fa041a01d693)

2 years agosem test: move sem_clockwait_np tests into individual cases
Eric van Gyzen [Fri, 1 Oct 2021 11:24:27 +0000 (06:24 -0500)]
sem test: move sem_clockwait_np tests into individual cases

Move these tests into individual test cases for all the usual reasons.
No functional change intended.

MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 2334abfd01ba92dfa6a7ab6f2c4cc45fa64ffd3c)

2 years agosem_clockwait_np test: relax time constraint on VMs
Eric van Gyzen [Fri, 1 Oct 2021 10:37:17 +0000 (05:37 -0500)]
sem_clockwait_np test: relax time constraint on VMs

In a guest on a busy hypervisor, the time remaining after an
interrupted sleep could be much lower than other environments.
Relax the lower bound on VMs.

MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 31466594cd09d1413dbd8cab516fafc3557c2200)

2 years agoFix lockstat:::thread-spin dtrace probe with LOCK_PROFILING
Eric van Gyzen [Mon, 2 Aug 2021 18:54:57 +0000 (13:54 -0500)]
Fix lockstat:::thread-spin dtrace probe with LOCK_PROFILING

The spinning start time is missing from the calculation due to a
misplaced #endif.  Return the #endif where it's supposed to be.

Submitted by: Alexander Alexeev <aalexeev@isilon.com>
Reviewed by: bdrewery, mjg
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D31384

(cherry picked from commit 428624130abfc225b479a09a3060d0939569b1ea)

2 years agoaio_md_test: label the md
Eric van Gyzen [Fri, 23 Jul 2021 13:57:44 +0000 (08:57 -0500)]
aio_md_test: label the md

Add a label to md devices created by this test.  The next time this
test leaks md devices, finding the culprit will be much easier.

Thanks to: sobomax, for adding labels in r322969
MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 9666cda9764a1d19cbf967940508dc6d2020cbfb)

2 years agoaio_md_test: NUL-terminate result of readlink
Eric van Gyzen [Fri, 23 Jul 2021 13:49:55 +0000 (08:49 -0500)]
aio_md_test: NUL-terminate result of readlink

readlink does not NUL-terminate the output buffer.  This led to spurious
failures to destroy the md device because the unit number was garbage.
NUL-terminate the output buffer.

Reported by: ASLR
MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit ea0e1b19f232331bffa75a0a64a6859c40f1cc4d)

2 years agoaio_md_test: fix cleanup
Eric van Gyzen [Fri, 23 Jul 2021 13:24:52 +0000 (08:24 -0500)]
aio_md_test: fix cleanup

ATF cleanup functions cannot use functions such as ATF_REQUIRE
and atf_tc_fail.  These functions assert that a test case is
currently running, which is not true during cleanup, so the
process aborts.  Change the cleanup function to simply print
to stderr and return.

MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit c6f92e64b6140f9e095b41687ff09ff973c28e14)

2 years agolibprocstat kstack: fix race with thread creation
Eric van Gyzen [Thu, 27 May 2021 16:33:22 +0000 (11:33 -0500)]
libprocstat kstack: fix race with thread creation

When collecting kernel stacks for a target process, if the process
adds a thread between the two calls to sysctl, ignore the additional
threads.  Previously, procstat would print only a useless error
message.  Now, it prints a consistent snapshot of the stacks.
We know that snapshot is already stale, but it could still be stale
even with a more complex fix to reallocate and retry, so such a fix
is hardly worth the effort.

Reported by: Daniel.Mitchell@emc.com
MFC after: 1 week
Sponsored by: Dell EMC Isilon

(cherry picked from commit 427f12f150e875c40acb84f292a80bfa0b90a1a2)

2 years agoWait longer for a previous IPI to be sent
Eric van Gyzen [Mon, 26 Apr 2021 15:01:17 +0000 (10:01 -0500)]
Wait longer for a previous IPI to be sent

When sending an IPI, if a previous IPI is still pending delivery,
native_lapic_ipi_vectored() waits for the previous IPI to be sent.
We've seen a few inexplicable panics with the current timeout of 50 ms.
Increase the timeout to 1 second and make it tunable.

No hardware specification mentions a timeout in this case; I checked
the Intel SDM, Intel MP spec, and Intel x2APIC spec.  Linux and illumos
wait forever.  In Linux, see __default_send_IPI_shortcut() in
arch/x86/kernel/apic/ipi.c.  In illumos, see apic_send_ipi() in
usr/src/uts/i86pc/io/pcplusmp/apic_common.c.  However, misbehaving hardware
could hang the system if we wait forever.

Reviewed by: mav kib
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29942

(cherry picked from commit 2f32a971b7f936170b4d61318238e6cf89f198b5)

2 years agouefisign: handle empty sections
Eric van Gyzen [Tue, 6 Apr 2021 14:42:20 +0000 (09:42 -0500)]
uefisign: handle empty sections

loader.efi has an empty set_Xfic section.  Handle it correctly.

```
Sections:
Idx Name          Size      VMA               LMA               File off  Algn
[...]
3 set_Xcom      00000168  00000000000d4000  00000000000d4000  000d0e00  2**2
      CONTENTS, ALLOC, LOAD, DATA
4 set_Xfic      00000000  00000000000d4168  00000000000d4168  00000000  2**2
      ALLOC, LOAD, DATA
5 .sdata        00000448  00000000000d5000  00000000000d5000  000d1000  2**2
      CONTENTS, ALLOC, LOAD, DATA
[...]
```

Reviewed by: trasz, dab
Reported by: andy.y.liu@dell.com
Tested by: andy.y.liu@dell.com
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29606

(cherry picked from commit 12db51d20823a5e3b9e5f8a2ea73156fe1cbfc28)

2 years agouefisign: fix handling of errors from child proc
Eric van Gyzen [Tue, 6 Apr 2021 14:36:52 +0000 (09:36 -0500)]
uefisign: fix handling of errors from child proc

Close the unused pipe file descriptors so the parent will notice if
the child exits prematurely.  Previously, the parent would block
forever on a read from the pipe.

    $ uefisign -c foo.cert -k foo.key -o loader.efi loader.efi.unsigned
    uefisign: section points inside the headers
    load: 0.06  cmd: uefisign 4502 [piperd] 7.25r 0.00u 0.00s 0% 5968k
    ... _sleep+0x1be pipe_read+0x3d6 kern_readv+0x8c sys_read+0x83 ...

Reviewed by: trasz
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29605

(cherry picked from commit 9e6158d274829249322efb3767e6ac2e690cc4a9)

2 years agocxgbe(4): Fix build warning for LINT-NOIP.
Navdeep Parhar [Mon, 10 Jan 2022 20:32:39 +0000 (12:32 -0800)]
cxgbe(4): Fix build warning for LINT-NOIP.

MFC after: 1 week
Sponsored by: Chelsio Communications

(cherry picked from commit 94e6b3fee1e5f1ae52741c367c4a3f93a0c0708d)

2 years agocxgbe(4): Fix "set but not used [-Wunused-but-set-variable]" warnings.
Navdeep Parhar [Wed, 5 Jan 2022 20:23:06 +0000 (12:23 -0800)]
cxgbe(4): Fix "set but not used [-Wunused-but-set-variable]" warnings.

Sponsored by: Chelsio Communications

(cherry picked from commit 39d5cbdc1b783e2f199349a7a20b6d7c58e180a0)

2 years agolibctf: Use const ctf_file_t references in string lookup routines
Mark Johnston [Wed, 23 Feb 2022 23:37:40 +0000 (18:37 -0500)]
libctf: Use const ctf_file_t references in string lookup routines

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 45c23c2608ec3e34b5c7ce18eca91a46419e363c)

2 years agofbt: Remove handling for CTFv1
Mark Johnston [Wed, 23 Feb 2022 14:58:35 +0000 (09:58 -0500)]
fbt: Remove handling for CTFv1

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 2997ab002e0c3430aff00c8b6f6b0c44c6707bd7)

2 years agolibctf: Remove checks for CTFv1
Mark Johnston [Wed, 23 Feb 2022 14:57:41 +0000 (09:57 -0500)]
libctf: Remove checks for CTFv1

Per commit 7db423d69273 ("libctf: Rip out CTFv1 support") this support
is obsolete.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 565518046c9e721ea6ff608d44f1e89d344e5e02)

2 years agolibdtrace: Add a missing newline to an error message
Mark Johnston [Wed, 23 Feb 2022 16:31:51 +0000 (11:31 -0500)]
libdtrace: Add a missing newline to an error message

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 1ef441f69933dd3246c9b563c0c8f328e474b359)

2 years agomps/mpr: Add missing newlines in error messages.
Alexander Motin [Tue, 22 Feb 2022 20:06:48 +0000 (15:06 -0500)]
mps/mpr: Add missing newlines in error messages.

MFC after: 1 week

(cherry picked from commit 074bed4f486b4fa54e4d9bd2fccfad3cce732ba1)

2 years agoriscv: Fix another race in pmap_pinit()
Mark Johnston [Tue, 22 Feb 2022 14:26:33 +0000 (09:26 -0500)]
riscv: Fix another race in pmap_pinit()

Commit c862d5f2a789 ("riscv: Fix a race in pmap_pinit()") did not really
fix the race.  Alan writes,

 Suppose that N entries in the L1 tables are in use, and we are in the
 middle of the memcpy().  Specifically, we have read the zero-filled
 (N+1)st entry from the kernel L1 table.  Then, we are preempted.  Now,
 another core/thread does pmap_growkernel(), which fills the (N+1)st
 entry.  Finally, we return to the original core/thread, and overwrite
 the valid entry with the zero that we earlier read.

Try to fix the race properly, by copying kernel L1 entries while holding
the allpmaps lock.  To avoid doing unnecessary work while holding this
global lock, copy only the entries that we expect to be valid.

Fixes: c862d5f2a789 ("riscv: Fix a race in pmap_pinit()")
Reported by: alc, jrtc27
Reviewed by: alc
Sponsored by: The FreeBSD Foundation

(cherry picked from commit d5c0a7b6d3923d2a6967810d0aa3e148a39351c1)

2 years agoriscv: Fix a race in pmap_pinit()
Mark Johnston [Tue, 8 Feb 2022 18:15:54 +0000 (13:15 -0500)]
riscv: Fix a race in pmap_pinit()

All pmaps share the top half of the address space.  With 3-level page
tables, the top-level kernel map entries are not static: they might
change if the kernel map is extended (via pmap_growkernel()) or a 1GB
mapping in the direct map is demoted (not implemented yet).  Thus the
riscv pmap maintains the allpmaps list to synchronize updates to
top-level entries.

When a pmap is created, it is inserted into this list after copying
top-level entries from the kernel pmap.  The copying is done without
holding the allpmaps lock, and it is possible for pmap_pinit() to race
with kernel map updates.  In particular, if a thread is modifying L1
entries, and a concurrent pmap_pinit() copies the old version of the
entries, it might not receive the update.

Fix the problem by copying the kernel map entries after inserting the
pmap into the list.  This ensures that the nascent pmap always receives
updates, though pmap_distribute_l1() may race with the page copy.

Reviewed by: mhorne, jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit c862d5f2a789925efe70fc64247caa5148e98a54)

2 years agoreadelf: add Arm address mask note type NT_ARM_ADDR_MASK
Ed Maste [Tue, 22 Feb 2022 17:40:39 +0000 (12:40 -0500)]
readelf: add Arm address mask note type NT_ARM_ADDR_MASK

Reviewed by: andrew
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34346

(cherry picked from commit 817e68d8e64a4949a8b390b302738d45107aee49)

2 years agosrc.libnames.mk: add a comment explaining libssp_nonshared
Ed Maste [Tue, 22 Feb 2022 21:22:03 +0000 (16:22 -0500)]
src.libnames.mk: add a comment explaining libssp_nonshared

libssp_nonshared is a special case for (only) i386 and power*.  Add a
comment explaining why, based on the original commit message that added
it.

MFC after: 1 week
Fixes: 0f61170882cb ("libssp_nonshared: use only on i386 and ppc")
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 9aa786cbb50e997739f31094dc8d45260f19c63c)

2 years agobridge: Don't share broadcast packets
Kristof Provost [Sat, 19 Feb 2022 15:34:31 +0000 (16:34 +0100)]
bridge: Don't share broadcast packets

if_bridge duplicates broadcast packets with m_copypacket(), which
creates shared packets. In certain circumstances these packets can be
processed by udp_usrreq.c:udp_input() first, which modifies the mbuf as
part of the checksum verification. That may lead to incorrect packets
being transmitted.

Use m_dup() to create independent mbufs instead.

Reported by: Richard Russo <toast@ruka.org>
Reviewed by: donner, afedorov
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D34319

(cherry picked from commit 36637dd19dba79088e53c6f2aa026415eae9f8f0)

2 years agonetinet: allow UDP tunnels to be removed
Kristof Provost [Tue, 15 Feb 2022 10:49:39 +0000 (11:49 +0100)]
netinet: allow UDP tunnels to be removed

udp_set_kernel_tunneling() rejects new callbacks if one is already set.
Allow callbacks to be cleared. The use case for this is OpenVPN DCO,
where the socket is opened by userspace and then adopted by the kernel
to run the tunnel. If the DCO interface is removed but userspace does
not close the socket (something the kernel cannot prevent) the installed
callbacks could be called with an invalidated context.

Allow new functions to be set, but only if they're NULL (i.e. allow the
callback functions to be cleared).

Reviewed by: tuexen
MFC after: 3 weeks
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D34288

(cherry picked from commit 995cba5a0c9659e623b910429222ac2831a2ecca)

2 years agopf tests: Test per-anchor tables
Kristof Provost [Thu, 17 Feb 2022 13:13:50 +0000 (14:13 +0100)]
pf tests: Test per-anchor tables

MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 7d3fc84b2d3eb18b675200dbf7732ef41eb79fe2)

2 years agopf tests: remove a stray 'set -x'
Kristof Provost [Thu, 17 Feb 2022 12:40:41 +0000 (13:40 +0100)]
pf tests: remove a stray 'set -x'

'set -x' is very useful when debugging tests, but does not need to be
left in.

MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 7f55a9b490cc792491eebb50e46680b8eb2153ee)

2 years agovm_pageout: Print a more accurate message to the console before an OOM kill
Mark Johnston [Fri, 14 Jan 2022 20:03:53 +0000 (15:03 -0500)]
vm_pageout: Print a more accurate message to the console before an OOM kill

Previously we'd always print "out of swap space."  This can be
misleading, as there are other reasons an OOM kill can be triggered.  In
particular, it's entirely possible to trigger an OOM kill on a system
with plenty of free swap space.

Reviewed by: kib
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 4a864f624a7097f1d032a0350ac70fa6c371179e)

2 years agortld.1: Fix misplaced text
John F. Carr [Fri, 25 Feb 2022 16:09:03 +0000 (11:09 -0500)]
rtld.1: Fix misplaced text

PR: 262194
Fixes: f90218886fc8 ("rtld: introduce PRELOAD_FDS")

(cherry picked from commit 6c799530d8dc91d4e5c390274b8a27231f369a56)

2 years agocxgbe(4): Fix illegal hardware access in cxgbe_refresh_stats.
Navdeep Parhar [Sat, 12 Feb 2022 00:58:46 +0000 (16:58 -0800)]
cxgbe(4): Fix illegal hardware access in cxgbe_refresh_stats.

cxgbe_refresh_stats takes into account VI_SKIP_STATS but not
VI_INIT_DONE when deciding whether to read the hardware stats.  But
before this change VI_SKIP_STATS was set only for VIs with VI_INIT_DONE.
That meant that cxgbe_refresh_stats always accessed the hardware for
uninitialized VIs, and this is a problem if the adapter is suspended or
in the middle of a reset.

Fix this by setting VI_SKIP_STATS on all VIs during suspend.  While
here, ignore VI_INIT_DONE in vi_refresh_stats too to be consistent with
cxgbe_refresh_stats.

Sponsored by: Chelsio Communications

(cherry picked from commit 08c7dc7fd4735b85e9696d0439af6cc98b23b25d)

2 years agocxgbe(4): Avoid unsafe hardware access in the ifmedia ioctls.
Navdeep Parhar [Fri, 11 Feb 2022 23:37:17 +0000 (15:37 -0800)]
cxgbe(4): Avoid unsafe hardware access in the ifmedia ioctls.

The hardware is unavailable when the device is suspended or in the
middle of a reset.

Sponsored by: Chelsio Communications

(cherry picked from commit 39a36707bd33b86a115651678028baeb616c8365)

2 years agocxgbe(4): Fix bad races between sysctl and driver detach.
Navdeep Parhar [Thu, 13 Jan 2022 22:21:49 +0000 (14:21 -0800)]
cxgbe(4): Fix bad races between sysctl and driver detach.

The default sysctl context setup by newbus for a device is eventually
freed by device_sysctl_fini, which runs after the device driver's detach
routine.  sysctl nodes associated with this context must not use any
resources (like driver locks, hardware access, counters, etc.) that are
released by driver detach.

There are a lot of sysctl nodes like this in cxgbe(4) and the fix is to
hang them off a context that is explicitly freed by the driver before it
releases any resource that might be used by a sysctl.

This fixes panics when running "sysctl dev.t6nex dev.cc" in a tight loop
and loading/unloading the driver in parallel.

Reported by: Suhas Lokesha
Sponsored by: Chelsio Communications

(cherry picked from commit a727d9531afbd58e304acc27e3717031e78bff90)

2 years agocxgbe(4): Fix regression in previous attempt to fix FEC selection.
Navdeep Parhar [Mon, 10 Jan 2022 21:54:06 +0000 (13:54 -0800)]
cxgbe(4): Fix regression in previous attempt to fix FEC selection.

Sponsored by: Chelsio Communications

(cherry picked from commit d0ff9b029c7175e20c801126be127db7c651b02e)

2 years agocxgbe(4): Do not ignore the return value of ifmedia_ioctl.
Navdeep Parhar [Mon, 10 Jan 2022 21:01:51 +0000 (13:01 -0800)]
cxgbe(4): Do not ignore the return value of ifmedia_ioctl.

This ensures that the driver reports an error instead of failing
silently when an invalid media is requested.

Reported by: Suhas Lokesha @ Chelsio
Sponsored by: Chelsio Communications

(cherry picked from commit cdd7fe04cb803d49a2fb6389be70f4378ae3ca3b)

2 years agocxgbe(4): Do not request an FEC that is invalid for the requested speed.
Navdeep Parhar [Wed, 5 Jan 2022 18:45:06 +0000 (10:45 -0800)]
cxgbe(4): Do not request an FEC that is invalid for the requested speed.

This eliminates error messages like this from the driver when running at
50Gbps with 100G cables:
[3726] cc0: l1cfg failed: 71
[4407] cc0: l1cfg failed: 71

Note that link comes up anyway with or without this change.

Reported by: Suhas Lokesha @ Chelsio
Sponsored by: Chelsio Communications

(cherry picked from commit f3c2987f2f5c91f0801fa8bbf9e1bc09d91aeb46)

2 years agocxgbe(4): Update firmwares to 1.26.6.0.
Navdeep Parhar [Mon, 3 Jan 2022 22:35:45 +0000 (14:35 -0800)]
cxgbe(4): Update firmwares to 1.26.6.0.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CHANGES
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Version : 1.26.6.0
Date    : 01/03/2022
================================================================================

Fixes
-----
BASE:
- Fixed one module eeprom read failure.
- Fixed an issue with speed selection when 40G and 25G are advertised and
  supported.
- Fixed a random traffic hang when T5 receives invalid ets BW in dcbx
  messages from a switch.
- Fixed very long link up time with few switches.
================================================================================

Obtained from: Chelsio Communications
Sponsored by: Chelsio Communications

(cherry picked from commit 3b76242433e5651bce0c89ce98af450c0cd02ad1)

2 years agocxgbe(4): Fix stats collection for ports with port_id != tx_chan
Navdeep Parhar [Mon, 3 Jan 2022 21:31:46 +0000 (13:31 -0800)]
cxgbe(4): Fix stats collection for ports with port_id != tx_chan

This fixes a driver panic during stats collection when a port's id does
not match its tx channel.  The bug affected only the T580 card running
with a non-default VPD.

Reported by: Suhas Lokesha @ Chelsio
Sponsored by: Chelsio Communications

(cherry picked from commit bbab9ab5796028e6ef9d765bfd307936bde14e89)

2 years agocxgbe(4): Fix panic on driver detach after a partially failed attach.
Navdeep Parhar [Wed, 29 Dec 2021 00:46:09 +0000 (16:46 -0800)]
cxgbe(4): Fix panic on driver detach after a partially failed attach.

sge->ctrlq is not always allocated during attach (eg. if firmware
initialization fails) and detach should be able to deal with this.

Sponsored by: Chelsio Communications

(cherry picked from commit b99651c52fa52cdef5688859e0bc7f3fb2085a2f)

2 years agocxgbe(4): Update firmwares to 1.26.4.0
Navdeep Parhar [Thu, 9 Dec 2021 19:10:48 +0000 (11:10 -0800)]
cxgbe(4): Update firmwares to 1.26.4.0

(Rest is from the README that came with the firmware)

Version : 1.26.4.0
Date    : 12/02/2021

Fixes
-----

BASE:
- Fixed error on setting 25G speed on 100G copper with multiple FEC set in
  firmware commands.
- Handle link of unknown optics modules by enabling module tx unconditionally.
- Fixed link not coming up for 25G CRS phys. Firmware incorrectly tried to
  bring up the link in RS-FEC but as per IEEE spec, it must be BASER FEC.
- Fixed an issue where firmware doesn't automatically retry next FEC if driver
  asks to bring up the link using RS-FEC and link doesn't come up.

Obtained from: Chelsio Communications
Sponsored by: Chelsio Communications

(cherry picked from commit 357ba2cf17bf2a201ada5c54822e4f92ff2df296)

2 years agocxgbe(4): Change the way t4_shutdown_adapter brings the link(s) down.
Navdeep Parhar [Mon, 15 Nov 2021 18:55:04 +0000 (10:55 -0800)]
cxgbe(4): Change the way t4_shutdown_adapter brings the link(s) down.

Modify the GPIO pins only on the Base-T cards and even there drive all
of them low instead of putting them in hi-z state.  For the rest (this
is the common case), directly power off the PLLs of the high speed
serdes.  This is the simplest method that does not involve or conflict
with the firmware but still works with all T4-T6 cards regardless of
what's plugged into the port.

This fixes a problem where the peer wouldn't always see a link down if
it is connected to the device using a -CR4 copper cable.

Sponsored by: Chelsio Communications

(cherry picked from commit a8eacf9329e2984f9c950fb5ef6447be4676007a)

2 years agocxgbe(4): Keep link configuration compatible with really old firmwares.
Navdeep Parhar [Thu, 11 Nov 2021 00:10:41 +0000 (16:10 -0800)]
cxgbe(4): Keep link configuration compatible with really old firmwares.

Sponsored by: Chelsio Communications

(cherry picked from commit 8e76bae0b72e53da80c48ba138b1cfd712724df4)

2 years agocxgbe(4): internal knob for flexible control over FEC selection.
Navdeep Parhar [Wed, 10 Nov 2021 19:38:54 +0000 (11:38 -0800)]
cxgbe(4): internal knob for flexible control over FEC selection.

Recent firmwares have support for autonomous FEC selection and a "force"
knob to let the driver control this behavior (or not) in a fine grained
manner. This change adds a driver knob so that all the different ways of
configuring the link FEC can be exercised. Note that this controls the
internal driver/firmware interaction for link configuration and is not
meant for general use.

Sponsored by: Chelsio Communications

(cherry picked from commit 448bcd01dc5edcbbf23975588f131e13cd09778f)

2 years agocxgbe(4): separate sysctls for user-requested and in-use FEC.
Navdeep Parhar [Wed, 10 Nov 2021 18:54:53 +0000 (10:54 -0800)]
cxgbe(4): separate sysctls for user-requested and in-use FEC.

Recent firmwares have more leeway in FEC selection and there is a need
to track the FECs requested by the driver separately from the FEC in use
on the link. The existing dev.<port>.<inst>.fec sysctl can read both but
its behavior depends on the link state and it is sometimes hard to find
out what was requested when the link is up.

Split the fec sysctl into two (requested_fec and link_fec) to get access
to both pieces of information regardless of the link state.

Sponsored by: Chelsio Communications

(cherry picked from commit f6a2e1100fa09742aa29d8e51fd6181fb5c171bb)

2 years agocxgbe(4): sysctl to track the last L1_CFG32 requested by the driver.
Navdeep Parhar [Wed, 3 Nov 2021 18:00:44 +0000 (11:00 -0700)]
cxgbe(4): sysctl to track the last L1_CFG32 requested by the driver.

dev.<port>.<inst>.rcaps

 # sysctl dev.cc | grep rcaps
 dev.cc.1.rcaps: 581107776
 dev.cc.0.rcaps: 582156414

Sponsored by: Chelsio Communications

(cherry picked from commit d99b1d83b9e9ae2c47ffbd71a7c2a261d9eae2dd)

2 years agofsck_ffs: don't try to write in read-only mode
Chuck Silvers [Tue, 29 Jun 2021 21:29:15 +0000 (14:29 -0700)]
fsck_ffs: don't try to write in read-only mode

(cherry picked from commit ed1a156b038dee0e7a02c2935186ad5d8f4c36c1)

Sponsored by: Netflix

2 years agoiwlwifi: update firmware
Bjoern A. Zeeb [Thu, 24 Feb 2022 21:40:20 +0000 (21:40 +0000)]
iwlwifi: update firmware

Update to the latest firmware based on
linux-firmware at c53073d4e1485ac9f7cb065db466793c495aead7
and update firmware module Makefiles accordingly.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 062103fc93c308dec65a183c51dc7f53b8c76e6d)

2 years agoiwlwifi: enhance debug information
Bjoern A. Zeeb [Thu, 24 Feb 2022 21:38:27 +0000 (21:38 +0000)]
iwlwifi: enhance debug information

Add a string of the debug type to the output of the debug message so it
is easier to search for specific events in a trace with lots of debugging
on.  While here remove superflous ().

Sponsored by: The FreeBSD Foundation

(cherry picked from commit 51152e5e6150746ad5514f169c8fd1d04b010b35)

2 years agoiwlwifi: update from iwlwifi-next
Bjoern A. Zeeb [Thu, 24 Feb 2022 21:34:13 +0000 (21:34 +0000)]
iwlwifi: update from iwlwifi-next

Import new code from iwlwifi-next at cb0a1fb7fd86b0062692b5056ca8552906509512
(matching tag: iwlwifi-next-for-kalle-2022-02-18).

Also add files not previously imported because we are not yet compiling
them to ease updating and having them when needed.

This adds MEI (Management Engine) support upstream which we cannot import
(currently GPL-only) so we have stub functions for the missing bits.

This also reduces the diff to upstream.  Changes submitted to avoid
problems with const and  with void * arithmetics were merged.

In the module build Makefile disable CONFIG_IWLWIFI_OPMODE_MODULAR
as we are building iwlwifi as a single module.

Sponsored by:   The FreeBSD Foundation

(cherry picked from commit d9836fb4b9380e2ed1c38455fb31a3832b452671)

2 years agoLinuxKPI: update 802.11 headers
Bjoern A. Zeeb [Tue, 22 Feb 2022 22:57:31 +0000 (22:57 +0000)]
LinuxKPI: update 802.11 headers

Add new defines, struct members, and (stub) functions needed for an
updated iwlwifi.  Most of the defines are for rfkill or HE.

Pull in a case statement from the upcoming iwlwifi update to
not break the build.

Sponsored by: The FreeBSD Foundation

(cherry picked from commit d875aa1587ce7d1651cabe395ed991f2384795cd)
(cherry picked from commit 9ad210c15933e5a49c51fba134e77d84cfdba94f)

2 years agoLinuxKPI: change DECLARE_FLEX_ARRAY()
Bjoern A. Zeeb [Tue, 22 Feb 2022 22:48:08 +0000 (22:48 +0000)]
LinuxKPI: change DECLARE_FLEX_ARRAY()

DECLARE_FLEX_ARRAY can be used inside a structure.  On FreeBSD due to
-Wgnu-variable-sized-type-not-at-end this yields an error.  Use [0]
instead of [] to overcome this.

Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D34350

(cherry picked from commit fab601c5b76a1183c1849222667481fdde948ef9)