]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
15 months agortwn: Fix mismatches in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:33:21 +0000 (12:33 -0800)]
rtwn: Fix mismatches in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37550

(cherry picked from commit 8bc615f5919f027cdf09825764276ab41a38375e)

15 months agoipfilter: Fix mismatch in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:32:38 +0000 (12:32 -0800)]
ipfilter: Fix mismatch in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, cy, emaste
Differential Revision: https://reviews.freebsd.org/D37548

(cherry picked from commit 415ccf51122eab7b55978a1db00b484a06ffc84b)

15 months agoaesni: Remove misleading array bounds for aesni_decryt_ecb.
John Baldwin [Wed, 7 Dec 2022 20:32:19 +0000 (12:32 -0800)]
aesni: Remove misleading array bounds for aesni_decryt_ecb.

All the other functions used pointers for from/to instead of
fixed-size array parameters.  More importantly, this function can
accept pointers to buffers of multiple blocks, not just a single
block.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37547

(cherry picked from commit d256a06fe8bda8120a3e22434c53fdef076001d3)

15 months agomlx5: Fix mismatch in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:32:54 +0000 (12:32 -0800)]
mlx5: Fix mismatch in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: hselasky, imp, emaste (earlier version)
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D37549

(cherry picked from commit 47cc457bd6c16352b47d3fb1288f745482a082af)

15 months agonet80211: Fix mismatches in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:31:53 +0000 (12:31 -0800)]
net80211: Fix mismatches in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste (earlier version)
Differential Revision: https://reviews.freebsd.org/D37546

(cherry picked from commit 1f078120955947c85c54a8c088782ea5e4451eb5)

15 months agosys: Stop enabling -Wnested-externs.
John Baldwin [Wed, 22 Mar 2023 19:35:09 +0000 (12:35 -0700)]
sys: Stop enabling -Wnested-externs.

clang doesn't implement this warning, so violations are only caught by
GCC.  It is also no longer a common practice to use this as it was in
the original BSD code, so the need for the warning is not as important
as when it was used to do cleanups 20 years ago.  A recent commit
(c3179891f897d840f578a5139839fcacb587c96d) triggers this warning on
GCC, but that commit uses nested externs purposefully.

Reviewed by: markj, emaste
Differential Revision: https://reviews.freebsd.org/D39214

(cherry picked from commit 4ffeb3b88ed228e72e13abe1be888c77c6ede95d)

15 months agoocs: Fix mismatch in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:31:33 +0000 (12:31 -0800)]
ocs: Fix mismatch in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37545

(cherry picked from commit fb4a86164dc5ded5b42b7511d3bf48ae11ec891e)

15 months agoocs: Remove unused variable.
John Baldwin [Fri, 8 Apr 2022 00:01:27 +0000 (17:01 -0700)]
ocs: Remove unused variable.

(cherry picked from commit afda855350685d994f3fa5702079ce782563ee8f)

15 months agomalo: Fix mismatch in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:31:16 +0000 (12:31 -0800)]
malo: Fix mismatch in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37544

(cherry picked from commit 8b45e0c180114e1059767d0920ad6e6bfdeb37ce)

15 months agoiwi: Fix mismatch in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:31:01 +0000 (12:31 -0800)]
iwi: Fix mismatch in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37543

(cherry picked from commit f322a6cef0b142bd65c3750139ea1801513b864a)

15 months agoiwi: Remove write-only status variable.
John Baldwin [Wed, 6 Apr 2022 23:45:27 +0000 (16:45 -0700)]
iwi: Remove write-only status variable.

Skip over unused field from asresp frame header.

(cherry picked from commit 99f65e9198c89e96f935986300b8ee3605d1349f)

15 months agoath: Fix mismatches in array bounds.
John Baldwin [Wed, 7 Dec 2022 20:30:42 +0000 (12:30 -0800)]
ath: Fix mismatches in array bounds.

Reported by: GCC -Warray-parameter
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37542

(cherry picked from commit c1ebd4c98fb8feab6931a536390739fc115e1805)

15 months agoDisable -Wzero-length-bounds for the kernel for GCC 12.
John Baldwin [Wed, 21 Dec 2022 18:47:08 +0000 (10:47 -0800)]
Disable -Wzero-length-bounds for the kernel for GCC 12.

The mlx5 driver and some other OFED bits use a somewhat dubious
pattern of:

  struct foo {
      uint64_t arg[0];
      /* Real members of a struct */
  };

The code then treats 'arg' as if it were really a kind of union
such that foo.arg[N] functions similarly to (uint64_t *)foo[N].
This uses of foo.arg[N] then trigger this warning.

No real bugs were found by this warning though, so just turn it off
globally.

Reviewed by: hselasky, kib
Differential Revision: https://reviews.freebsd.org/D37630

(cherry picked from commit 1aa6d44decb33ce3eab0efe5336b75fa2dfa3733)

15 months agoDisable -Wdangling-pointer for the kernel for GCC 12.
John Baldwin [Wed, 21 Dec 2022 18:46:26 +0000 (10:46 -0800)]
Disable -Wdangling-pointer for the kernel for GCC 12.

Some of the warnings raised in the kernel seem to be outright bugs in
the compiler (e.g. the cases in ata_xpt.c and scsi_xpt.c).  Other
cases are not fatal and it didn't seem to find any legitimate bugs in
the kernel.

Differential Revision: https://reviews.freebsd.org/D37629

(cherry picked from commit 2637ed558baacdab7a8cf789dca713bde5843e43)

15 months agoiee80211_hwmp: Don't dereference NULL ni in debug printf.
John Baldwin [Wed, 21 Dec 2022 18:45:45 +0000 (10:45 -0800)]
iee80211_hwmp: Don't dereference NULL ni in debug printf.

In this call to IEEE80211_NOTE, ni is always NULL due to the assignment
a few lines earlier at the start of the function.  If debug traces are
enabled, then this will pass an invalid pointer as the 'mac' pointer to
ieee80211_note_mac.  Use IEEE80211_DPRINTF which doesn't take a 'ni'
argument instead.

Reported by: GCC -Wstringop-overread
Reviewed by: bz, emaste
Differential Revision: https://reviews.freebsd.org/D37626

(cherry picked from commit 95d146592f5ee3fa998496713f28475e65996ff9)

15 months agomrsas: Don't leak a stack pointer value in the softc.
John Baldwin [Wed, 21 Dec 2022 18:45:26 +0000 (10:45 -0800)]
mrsas: Don't leak a stack pointer value in the softc.

mrsas_issue_blocked_cmd stores a pointer to an on-stack variable
in its softc so that the driver can call wakeup() on the correct
pointer.  Once the loop around tsleep() has finished however, the
pointer is no longer needed and any further use would be invalid.
Clear sc->chan to NULL after the loop.

Reported by: GCC -Wdangling-pointer
Differential Revision: https://reviews.freebsd.org/D37628

(cherry picked from commit 9f0c0e6eede6aedb60e12888fc9751c40b364dc9)

15 months agoDisable errors for -Wnonnull for the kernel for GCC 12.
John Baldwin [Wed, 21 Dec 2022 18:46:06 +0000 (10:46 -0800)]
Disable errors for -Wnonnull for the kernel for GCC 12.

The USB code and some other places raise false positives when a NULL
pointer is passed to an inlined function along with a separate length
and the compiler can't determine that the separate length of 0
prevents the use of the NULL pointer.

Differential Revision: https://reviews.freebsd.org/D37627

(cherry picked from commit 488c498b099e3f48db4048833d2b0d03d7bed3e1)

15 months agoMove NO_WUNUSED_BUT_SET_VARIABLE clang helper to the right place.
John Baldwin [Mon, 14 Mar 2022 21:05:25 +0000 (14:05 -0700)]
Move NO_WUNUSED_BUT_SET_VARIABLE clang helper to the right place.

Reviewed by: imp, dim, emaste
Sponsored by: University of Cambridge, Google, Inc.
Differential Revision: https://reviews.freebsd.org/D34537

(cherry picked from commit 2814ba8ef17aa647fa52092106731bcf76a2392d)

15 months agobhyve: Don't return -ENOMEM from qemu_fwcfg_add_file.
John Baldwin [Wed, 22 Mar 2023 19:34:56 +0000 (12:34 -0700)]
bhyve: Don't return -ENOMEM from qemu_fwcfg_add_file.

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

(cherry picked from commit 7bf44831ca05c67169fd90408b514573ddbbcf9d)

15 months agobhyve: Accept a variable-length string name for qemu_fwcfg_add_file.
John Baldwin [Wed, 22 Mar 2023 19:34:34 +0000 (12:34 -0700)]
bhyve: Accept a variable-length string name for qemu_fwcfg_add_file.

It is illegal (UB?) to pass a shorter array to a function argument
that takes a fixed-length array.  Do a runtime check for names that
are too long via strlen() instead.

Reviewed by: markj
Reported by: GCC -Wstringop-overread
Differential Revision: https://reviews.freebsd.org/D39211

(cherry picked from commit 61482760a0ca198a9310d450133e9ac792b67955)

15 months agoacpica: Quiet a -Wdangling-pointer warning in AcpiUtInitStackPtrTrace.
John Baldwin [Mon, 5 Dec 2022 00:28:59 +0000 (16:28 -0800)]
acpica: Quiet a -Wdangling-pointer warning in AcpiUtInitStackPtrTrace.

This function intentionally saves a pointer to an on-stack variable in
a global as a dubious way of reading the stack pointer.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37535

(cherry picked from commit f4432625edd64df94ce7c2a085f256dbc4d2b215)

15 months agopw: Don't return a pointer to an on-stack buffer from grp_set_passwd.
John Baldwin [Mon, 5 Dec 2022 00:28:22 +0000 (16:28 -0800)]
pw: Don't return a pointer to an on-stack buffer from grp_set_passwd.

Make 'line' static to move it to .bss instead as that pattern is used
elsewhere in pw(8) (e.g. the static buffer in pw_pwcrypt).

Reported by: GCC -Wdangling-pointer
Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37534

(cherry picked from commit 1055bedbed42dc176468b45b4f167a752ed8868f)

15 months agofwcontrol: Disable -Wzero-length-bounds warnings.
John Baldwin [Mon, 5 Dec 2022 00:30:20 +0000 (16:30 -0800)]
fwcontrol: Disable -Wzero-length-bounds warnings.

firewire.h includes zero length arrays in unions that trigger this
warning.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37538

(cherry picked from commit aa9ce62be54fd9a022b770d36fb1e4f24bfcd223)

15 months agobsd.sys.mk: Add NO_WZERO_LENGTH_BOUNDS helper variable.
John Baldwin [Mon, 5 Dec 2022 00:29:55 +0000 (16:29 -0800)]
bsd.sys.mk: Add NO_WZERO_LENGTH_BOUNDS helper variable.

This variable expands to -Wno-zero-length-bounds on GCC 10+.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37537

(cherry picked from commit 9134d9265c54a02257292c32b2144c401a86678f)

15 months agorpcgen: Unindent a line not guarded by if (mtflag).
John Baldwin [Mon, 5 Dec 2022 00:32:03 +0000 (16:32 -0800)]
rpcgen: Unindent a line not guarded by if (mtflag).

mtflag is used to add pthread mutex locking around operations to make
them thread-safe.  Setting the state to _SERVED is not conditional on
locking.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37541

(cherry picked from commit 4fa1e855be60f2c95005edb295fdc36cc163ff6b)

15 months agorpcgen: Don't free() a pointer after realloc().
John Baldwin [Mon, 5 Dec 2022 00:31:35 +0000 (16:31 -0800)]
rpcgen: Don't free() a pointer after realloc().

A successful realloc() already frees the old pointer.

Reported by: GCC -Wuse-after-free
Reviewed by: brooks, imp, emaste
Differential Revision: https://reviews.freebsd.org/D37540

(cherry picked from commit f0b58b190107416e813c5db875034c6cfcede523)

15 months agolibsa: Disable -Wdangling-pointer for zfs.c.
John Baldwin [Mon, 5 Dec 2022 00:27:22 +0000 (16:27 -0800)]
libsa: Disable -Wdangling-pointer for zfs.c.

GCC 12 warns about a dangling pointer to 'objid' in
zfs_bootenv_initial().  However, this appears to be a false positive
as the pointer to 'objid' is only passed to zfs_lookup_dataset() but
not saved anywhere that outlives the lifetime of the
zfs_bootenv_initial() function.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37533

(cherry picked from commit 0163de282e3195a1845f75b486adb3e1e7580199)

15 months agobsd.sys.mk: Add NO_WDANGLING_POINTER helper variable.
John Baldwin [Mon, 5 Dec 2022 00:26:48 +0000 (16:26 -0800)]
bsd.sys.mk: Add NO_WDANGLING_POINTER helper variable.

This variable expands to -Wno-dangling-pointer on GCC 12+.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D37532

(cherry picked from commit ad96424e31a8c8c87fac8077fd4304c6fb133e25)

15 months agoExplicitly set CXXSTD to c++11 for old C++ code using std::auto_ptr<>.
John Baldwin [Wed, 30 Nov 2022 22:56:19 +0000 (14:56 -0800)]
Explicitly set CXXSTD to c++11 for old C++ code using std::auto_ptr<>.

GCC 12 defaults to C++17 which removes (not just deprecates)
std::auto_ptr<>.  Trying to use CXXSTD of c++03 doesn't work with
libc++ headers, but c++11 does.

Reviewed by: brooks, imp, emaste
Differential Revision: https://reviews.freebsd.org/D37531

(cherry picked from commit 42fb28cef42e883d808c9efadd44016563248817)

15 months agolibefivar: Fix a buffer overread.
John Baldwin [Mon, 3 Oct 2022 23:10:44 +0000 (16:10 -0700)]
libefivar: Fix a buffer overread.

DevPathToTextUsbWWID allocates a separate copy of the SerialNumber
string to append a null terminator if the original string is not
null terminated.  However, by using AllocateCopyPool, it tries to
copy 'Length + 1' words from the existing string containing 'Length'
characters into the target string.  Split the copy out to only
copy 'Length' characters instead.

Reviewed by: imp, emaste
Reported by: GCC 12 -Wstringop-overread
Differential Revision: https://reviews.freebsd.org/D36826

(cherry picked from commit d30a1689f5b37e78ea189232a8b94a7011dc0dc8)

15 months agoSilence GCC warnings when using libc++ headers.
John Baldwin [Wed, 30 Nov 2022 22:50:35 +0000 (14:50 -0800)]
Silence GCC warnings when using libc++ headers.

GCC 12 raises warnings about literal operator suffixes not preceded by
'_' in libc++ headers such as <string_view> as it doesn't recognize
libc++ headers being an implementation of the standard.

GCC 12 also warns about clang-specific pragmas in <locale>.

Disabling these warnings globally for all C++ code is not ideal, but
is a better option than patching libc++ headers to ignore these
warnings.

Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D37530

(cherry picked from commit 442295c1fe84b4dc3e4834acdbf4ede75affe3c4)

15 months agoUse __freebsd_kprintf__ with GCC 12+ similar to clang.
John Baldwin [Tue, 22 Nov 2022 16:36:12 +0000 (08:36 -0800)]
Use __freebsd_kprintf__ with GCC 12+ similar to clang.

(cherry picked from commit 5115511ed4941684bc82b8a3c4b95e9a8931b940)

15 months agolibirdma: Drop clang-specific -ferror-limit.
John Baldwin [Mon, 3 Oct 2022 23:10:42 +0000 (16:10 -0700)]
libirdma: Drop clang-specific -ferror-limit.

This could use -fmax-errors on GCC, but tweaking the error limit is
unusual in the tree anyway.  Just remove it.

Reviewed by: erj, imp, emaste
Differential Revision: https://reviews.freebsd.org/D36808

(cherry picked from commit c3a3d1fd6c7007e7088936e14fd9b4944b3a3054)

15 months agoncurses: Backport a few fixes for GCC warnings from version 6.2-20210220.
John Baldwin [Tue, 2 May 2023 23:38:54 +0000 (16:38 -0700)]
ncurses: Backport a few fixes for GCC warnings from version 6.2-20210220.

This is a direct commit to stable/13.

15 months agolibpmc: Use LIB_CXX instead of explicit LDADD to link a C++ library.
John Baldwin [Thu, 23 Mar 2023 16:31:29 +0000 (09:31 -0700)]
libpmc: Use LIB_CXX instead of explicit LDADD to link a C++ library.

This uses the C++ compiler as the linker instead of the C compiler
letting the compiler driver pick the right libraries.  This is a no-op
on main and stable/13 but matters for stable/12 where the current
logic breaks for external GCC since it tries to use a non-existent
libstdc++.

Reviewed by: emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D39197

(cherry picked from commit c6b3f47fedd3f94f74cc4f7c40761b1d0e777f17)

15 months agompr: don't use hardcoded value in debug branch
Mariusz Zaborski [Fri, 21 Apr 2023 07:57:38 +0000 (09:57 +0200)]
mpr: don't use hardcoded value in debug branch

Pointed out by: imp
Sponsored by:   Klara Inc.

(cherry picked from commit 444c6615459efe2b015deb1cffc54fcaa3ea1fca)

15 months agompr: fix copying of event_mask
Mariusz Zaborski [Fri, 21 Apr 2023 07:50:16 +0000 (09:50 +0200)]
mpr: fix copying of event_mask

Before the commit 6cc44223cb6717795afdac4348bbe7e2a968a07d the
field event_mask was fully copied to the EventMasks field.
After this commit the event_mask (uint8_t) is 4 times casted to
EventMask (uint32_t). Because of that 24 bits of each event_mask array
is lost.

This commits brings back simple copying of field, and after words
converting 32 bits field to the requested endian.

I don't think we need more sophisticated method,
as the array is of size 4 (for 32 bits version).

Reviewed by: imp
MFC after: 1 week
Sponsored by: Klara Inc.
Differential Revision: https://reviews.freebsd.org/D39562

(cherry picked from commit ea6597c38c77c7bfaae71259d8636cbb89add6a3)

15 months agoipv6: disable RFC 4620 nodeinfo by default
Ed Maste [Mon, 24 Apr 2023 19:41:45 +0000 (15:41 -0400)]
ipv6: disable RFC 4620 nodeinfo by default

RFC 4620 is an experimental RFC that can be used to request information
about a host, including:

- the fully-qualified or single-component name
- some set of the Responder's IPv6 unicast addresses
- some set of the Responder's IPv4 unicast addresses

This is not something that should be made available by default.

PR: 257709
Submitted by: ruben@verweg.com
Reviewed by: melifaro
Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39778

(cherry picked from commit b73183d1a243d486e3889bd71800e94812f5fa17)

15 months agogeom: use bool for one-bit wide bit-field
Ed Maste [Mon, 17 Apr 2023 18:56:51 +0000 (14:56 -0400)]
geom: use bool for one-bit wide bit-field

A one-bit wide bit-field can take only the values 0 and -1.  Clang 16
introduced a warning that "implicit truncation from 'int' to a one-bit
wide bit-field changes value from 1 to -1".  Fix by using c99 bool.

Reported by: Clang, via dim
Reviewed by: dim
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 00172f341666f2d5535ae6f4630c93593e86a4cb)

15 months agosys/fs: do not report blocks allocated for synthetic file systems
Stefan Eßer [Tue, 25 Apr 2023 07:40:05 +0000 (09:40 +0200)]
sys/fs: do not report blocks allocated for synthetic file systems

The pseudo file systems (devfs, fdescfs, procfs, etc.) report total
and available blocks and inodes despite being synthetic with no
underlying storage device to which those values could be applied.

The current code of these file systems tends to report a fixed number
of total blocks but no free blocks, and in the case of procfs,
libprocfs, linsysfs also no free inodes.

This can be irritating in e.g. the "df" output, since 100% of the
resources seem to be in use, but it can also create warnings in
monitoring tools used for capacity management.

This patch makes these file systems return the same value for the
total and free parameters, leading to 0% in use being displayed by
"df". Since there is no resource that can be exhausted, this appears
to be a sensible result.

Reviewed by: mckusick
Differential Revision: https://reviews.freebsd.org/D39442

(cherry picked from commit 88a795e80c03ff1d960d830ee273589664ab06cc)

15 months agomsdosfs: fix debug print format and parameter
Stefan Eßer [Wed, 8 Mar 2023 16:58:00 +0000 (17:58 +0100)]
msdosfs: fix debug print format and parameter

Building with -DMSDOSFS_DEBUG failed due to a format mismatch and
a variable that has been renamed but not updated in the printf()
parameter list.

(cherry picked from commit 2d8cf575d5778781928699f9b7cfb448bd2f1f8e)

fs/msdosfs: add tracking of free root directory entries

This update implements tallying of free directory entries during
create, delete, or rename operations on FAT12 and FAT16 file systems.

Prior to this change, the total number of root directory entries
was reported as number of inodes, but 0 as the number of free
inodes, causing system health monitoring software to warn about
a suspected disk full issue.

The FAT12 and FAT16 file systems provide a limited number of
root directory entries, e.g. 512 on typical hard disk formats.
The valid range of values is 1 to 65535, but the msdosfs code
will effectively round up "odd" values to the next multiple of 16
(e.g. 513 would allow for 528 root directory entries).

This update implements tracking of directory entries during create,
delete, or rename operations, with initial values determined by
scanning the directory when the file system is mounted.

Total and free directory entries are reported in the f_files and
f_ffree elements of struct statfs, despite differences in semantics
of these values:

- There is no limit on the number of files and directories that can
  be created on a FAT file system. Only the root directory of FAT12
  and FAT16 file systems is limited, any number of files can still be
  created in sub-directories, even when 0 free "inodes" are reported.

- A single file can require 1 to 21 directory entries, depending on
  the character set, structure, and length of the name. The DOS 8.3
  style file name takes up 1 entry, and if the name does not comply
  with the syntax of a DOS 8.3 file name, 1 additional entry is used
  for each 13 characters of the file name. Since all these entries
  have to be contiguous, it is possible that a file or directory with
  a long name can not be created, despite a sufficient total number of
  free directory entries.

- Renaming a file can require more directory entries than currently
  allocated to store its long name, which may prevent an in-place
  update of the name if more entries are needed. This may cause a
  rename operation to fail if no contiguous range of free entries for
  the new name can be found.

- The volume label is stored in a directory entry. An empty FAT file
  system with a volume label will therefore show 1 used "inode" in
  df.

- The perceentage of free inodes shown in df or monitoring tools does
  only represent the state of the root directory of a FAT12 or FAT16
  file system. Neither does a reported value of 0% free inodes does
  prevent files from being created in sub-directories, nor does a
  value of 50% free inodes guarantee that even a single file with
  a "long" name can be created in the root directory (if every other
  directory entry is occupied and there are no 2 contiguous entries).

The statfs(2) and df(1) man pages have been updated with a notice
regarding the possibly different semantics of values reported as
total and free inodes for non-Unix file systems.

PR: 270053
Reported by: Ben Woods <woodsb02@freebsd.org>
Approved by: mckusick
Differential Revision: https://reviews.freebsd.org/D38987

(cherry picked from commit c33db74b5323480fba7adef58e8aa88f6091d134)

fs/msdosfs: Fix potential panic and size calculations

Some combinations of FAT12 file system parameters could cause a kernel
panic due to an unmapped access if the size of the FAT was larger than
the CPU page size. The reason is that FAT12 uses 3 bytes to store
2 FAT pointers, leading to partial FAT pointers at the end of buffers
of a size that is not a multiple of 3.

With a typical page size of 4 KB, this caused the FAT entry at byte
offsets 4095 and 4096 to cross the page boundary, with only the first
page mapped. This was fixed by adjusting the mapping to always cover
both bytes of each FAT entry.

Testing revealed 2 other inconsistencies that are fixed by this commit:

1) The calculation of the size of the data area did not take into
   account the fact that the first two data block numbers are reserved
   and that the data area starts with block 2. This could cause a
   FAT12 file system created with the maximum supported number of
   blocks to be incorrectly identified as FAT16.

2) The root directory does not take up space in the data area of a
   FAT12 or FAT16 file system, since it is placed into a reserved
   area outside of that data area. This commits makes stat() report
   the logical size of the root directory, but with 0 blocks allocated
   from the data area.

PR: 270587
Reviewed by: mckusick
Differential Revision: https://reviews.freebsd.org/D39386

(cherry picked from commit 0728695c63efda298feccefb3615c23cb6682929)

15 months agovn_open_vnode(): fix locking around VOP_CLOSE() on advisory lock error
Olivier Certner [Mon, 24 Apr 2023 09:36:09 +0000 (11:36 +0200)]
vn_open_vnode(): fix locking around VOP_CLOSE() on advisory lock error

(cherry picked from commit 6a5e61401502288ec10629beb28be048c1cce34a)

15 months agolookup(): ensure that openat("/", "..", O_RESOLVE_BENEATH) fails
Konstantin Belousov [Sun, 23 Apr 2023 23:21:42 +0000 (02:21 +0300)]
lookup(): ensure that openat("/", "..", O_RESOLVE_BENEATH) fails

PR: 269780

(cherry picked from commit a718431c30a57226bc7c1a9181fc84bab00641a1)

15 months agosqlite3: Vendor import of sqlite3 3.41.2
Cy Schubert [Mon, 17 Apr 2023 16:02:41 +0000 (09:02 -0700)]
sqlite3: Vendor import of sqlite3 3.41.2

Release notes at https://www.sqlite.org/releaselog/3_41_2.html.

Obtained from:  https://www.sqlite.org/2023/sqlite-autoconf-3410200.tar.gz

Merge commit '853a43f7c79218855a6e45a25a00b942972e3fa1'

(cherry picked from commit e7e621f94d9073d620a4d15f13952f1d40685ece)

15 months agomlx4: purge EOL release compatibility
Elliott Mitchell [Thu, 23 Jun 2022 00:53:47 +0000 (17:53 -0700)]
mlx4: purge EOL release compatibility

Remove FreeBSD 10 support code.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/603
Differential Revision: https://reviews.freebsd.org/D35560

(cherry picked from commit 026babd427e6511e53478814ce0aa1cc3f7a9988)

15 months agolibc: Add missing object size check to qsort_s(3)
Hans Petter Selasky [Wed, 19 Apr 2023 10:22:11 +0000 (12:22 +0200)]
libc: Add missing object size check to qsort_s(3)

When sorting, both the C11 standard (ISO/IEC 9899:2011, K.3.6.3.2) and
the ISO/IEC JTC1 SC22 WG14 N1172 standard, does not define objects of
zero size as undefined behaviour. However Microsoft's cpp-docs does.

Add proper checks for this. Found while working on bsort(3).

Reviewed by: kib@ and emaste@
Sponsored by: NVIDIA Networking
Differential Revision: https://reviews.freebsd.org/D39687

(cherry picked from commit 27bb0d337c0d82a1a4f310315840236eb239963c)

15 months agolibc: Sorting is not needed when there are less than two elements
Hans Petter Selasky [Wed, 19 Apr 2023 10:18:56 +0000 (12:18 +0200)]
libc: Sorting is not needed when there are less than two elements

If there are less than two elements avoid executing the first
sorting loop. No functional change intended.

Reviewed by: kib@
Sponsored by: NVIDIA Networking
Differential Revision: https://reviews.freebsd.org/D39691

(cherry picked from commit ecb2ce3a51e9b09a57cd42262fc798ae089c0758)

15 months agomlx5: Remove unused debugfs node pointers.
Hans Petter Selasky [Tue, 18 Apr 2023 11:40:22 +0000 (13:40 +0200)]
mlx5: Remove unused debugfs node pointers.

No functional change intended.

Sponsored by: NVIDIA Networking

(cherry picked from commit 80b4ef6d10544d30b6cfeddca12ae28d81816201)

15 months agomlx5: Don't give zero number of pages to the firmware.
Hans Petter Selasky [Tue, 18 Apr 2023 11:22:41 +0000 (13:22 +0200)]
mlx5: Don't give zero number of pages to the firmware.

Can happen when using virtual mlx5_core<N> functions, VFs.

Sponsored by: NVIDIA Networking

(cherry picked from commit 95bf70a4bf7982091bb59200bc2db2cb5cd840d7)

15 months agomlx5: Implement mlx5_core_modify_cq_by_mask().
Hans Petter Selasky [Tue, 18 Apr 2023 11:21:28 +0000 (13:21 +0200)]
mlx5: Implement mlx5_core_modify_cq_by_mask().

Implement one CQ modify function supporting all firmware versions,
instead of having more variants of CQ modify.

Sponsored by: NVIDIA Networking

(cherry picked from commit 273bfac08ff838786c8b48bc7d3d7180b5f6a3be)

15 months agomlx5: Make MLX5_COMP_EQ_SIZE tunable.
Hans Petter Selasky [Tue, 18 Apr 2023 11:11:02 +0000 (13:11 +0200)]
mlx5: Make MLX5_COMP_EQ_SIZE tunable.

When using hardware pacing, this value can be increased, because more SQ's
means more EQ events aswell. Make it tunable, hw.mlx5.comp_eq_size .

Sponsored by: NVIDIA Networking

(cherry picked from commit 3bb3e4768ff854b88ba0a7d129edad49f15d7ce3)

15 months agomlx5: Fix duplicate free of default flow rule in error case.
Hans Petter Selasky [Tue, 18 Apr 2023 11:17:38 +0000 (13:17 +0200)]
mlx5: Fix duplicate free of default flow rule in error case.

Sponsored by: NVIDIA Networking

(cherry picked from commit 2f7e9a8a21367393b613f0f150d49009fa74dd5c)

15 months agomlx5: Make mlx5_del_flow_rule() NULL safe.
Hans Petter Selasky [Tue, 18 Apr 2023 11:16:16 +0000 (13:16 +0200)]
mlx5: Make mlx5_del_flow_rule() NULL safe.

This change factors out repeated NULL checks.

No functional change intended.

Sponsored by: NVIDIA Networking

(cherry picked from commit b0b87d9151456e71fd6a14736e132d67114db4aa)

15 months agomlx5en(4): Don't wait for receive queue to fill up with mbufs during open channels.
Hans Petter Selasky [Tue, 18 Apr 2023 11:42:17 +0000 (13:42 +0200)]
mlx5en(4): Don't wait for receive queue to fill up with mbufs during open channels.

Failure to get mbufs may be transient.
Don't permanently fail to open the channels due to lack of mbufs.
This also makes modifying channel parameters faster.

Sponsored by: NVIDIA Networking

(cherry picked from commit 1943c40cd655b7259b9b21849f328362c97a2657)

15 months agomlx5en(4): Explain why CQE zipping is off.
Hans Petter Selasky [Tue, 18 Apr 2023 11:12:32 +0000 (13:12 +0200)]
mlx5en(4): Explain why CQE zipping is off.

Sponsored by: NVIDIA Networking

(cherry picked from commit 6bd4bb9bdbadb76c5502c7972df9f525b909e2f5)

15 months agomlx5: Implement diagostic counters as sysctl(8) nodes.
Hans Petter Selasky [Tue, 18 Apr 2023 11:38:59 +0000 (13:38 +0200)]
mlx5: Implement diagostic counters as sysctl(8) nodes.

Sponsored by: NVIDIA Networking

(cherry picked from commit aa7bbdabde890676d54a22eeec3af9b7681d19b7)

15 months agoImplement an API for sending a zero-length-packet. The purpose of such a
Hans Petter Selasky [Tue, 6 Jul 2021 10:29:57 +0000 (12:29 +0200)]
Implement an API for sending a zero-length-packet. The purpose of such a
USB packet is to toggle the binary packet counter for USB 1.0/2.0 protocols,
without sending any data, so that the first packet sent after opening
a USB BULK endpoint doesn't get lost. This is for devices not supporting
the USB standard defined clear-stall handling.

Tested by: jmg
Sponsored by: NVIDIA Networking

(cherry picked from commit f83f5d58394db57576bbed6dc7531997cabeb102)
(cherry picked from commit ec97e9ca1fa543a4a803e84706564d41cd492065)

15 months agousb: tiny formatting nit
Warner Losh [Thu, 11 Mar 2021 15:23:32 +0000 (08:23 -0700)]
usb: tiny formatting nit

Format 300 baud like all the others here. No functional change.

(cherry picked from commit 1645a4ae645fa9b9e3571b7512caa92e73b20635)

15 months agoulpt(4): Add support for Epson TM-U220B.
Hans Petter Selasky [Sat, 2 Apr 2022 00:27:48 +0000 (02:27 +0200)]
ulpt(4): Add support for Epson TM-U220B.

Submitted by: Archimedes Gaviola <archimedes.gaviola@gmail.com>
Sponsored by: NVIDIA Networking

(cherry picked from commit 88162f7abd61206c98432f2c0de869a59be13854)

15 months agoMake sure the uftdi(4) driver doesn't start a USB transfer when being cancelled.
Hans Petter Selasky [Wed, 18 Aug 2021 09:41:49 +0000 (11:41 +0200)]
Make sure the uftdi(4) driver doesn't start a USB transfer when being cancelled.

Sponsored by: NVIDIA Networking

(cherry picked from commit 8a46f021c2408c82375a1f5127efb7ac6b78596e)

15 months agowsp: Add sysctl tunable for Z-Axis inversion
Vladimir Kondratyev [Mon, 8 Feb 2021 21:26:42 +0000 (00:26 +0300)]
wsp: Add sysctl tunable for Z-Axis inversion

This adds a new sysctl to Wellspring Touchpad driver for controlling
Z-Axis (2-finger vertical scroll) direction "hw.usb.wsp.z_invert".

Submitted by: James Wright <james.wright_AT_digital-chaos_DOT_com>
Reviewed by: wulf
PR: 253321
Differential revision: https://reviews.freebsd.org/D28521

(cherry picked from commit d8c6d4c7321d4c969216bda8f792b45ed00afd64)

15 months agoxhci: Rework 64-byte context support to avoid pointer abuse
Jessica Clarke [Sun, 24 Oct 2021 18:48:46 +0000 (19:48 +0100)]
xhci: Rework 64-byte context support to avoid pointer abuse

Currently, to support 64-byte contexts, xhci_ctx_[gs]et_le(32|64) take a
pointer to the field within a 32-byte context and, if 64-byte contexts
are in use, compute where the 64-byte context field is and use that
instead by deriving a pointer from the 32-byte field pointer. This is
done by exploiting a combination of 64-byte contexts being the same
layout as their 32-byte counterparts, just with 32 bytes of padding at
the end, and that all individual contexts are either in a device
context or an input context which itself is page-aligned. By masking out
the low 4 bits (which is the offset of the field within the 32-byte
contxt) of the offset within the page, the offset of the invididual
context within the containing device/input context can be determined,
which is itself 32 times the number of preceding contexts. Thus, adding
this value to the pointer again gets 64 times the number of preceding
contexts plus the field offset, which gives the offset of the 64-byte
context plus the field offset, which is the address of the field in the
64-byte context.

However, this involves a fair amount of lying to the compiler when
constructing these intermediate pointers, and is rather difficult to
reason about. In particular, this is problematic for CHERI, where we
compile the kernel with subobject bounds enabled; that is, unless
annotated to opt out (e.g. for C struct inheritance reasons where you
need to be able to downcast, or containerof idioms), a pointer to a
member of a struct is a capability whose bounds only cover that field,
and any attempt to dereference outside those bounds will fault,
protecting against intra-object buffer overflows. Thus the pointer given
to xhci_ctx_[gs]et_le(32|64) is a capability whose bounds only cover the
field in the 32-byte context, and computing the pointer to the 64-byte
context field takes the address out of bounds, resulting in a fault when
later dereferenced.

This can be cleaned up by using a different abstraction. Instead of
doing the 32-byte to 64-byte conversion on access to the field, we can
do the conversion when getting a pointer to the context itself, and
define proper 64-byte versions of contexts in order to let the compiler
do all the necessary arithmetic rather than do it manually ourselves.
This provides a cleaner implementation, works for CHERI and may even be
slightly more performant as it avoids the need to mess with masking
pointers (which cannot in the general case be optimised by compilers to
be reused across accesses to different fields within the same context,
since it does not know that the contexts are over-aligned compared with
the C ABI requirements).

Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D32554

(cherry picked from commit 29863d1effe20da3cc75ae10bd52d96edafe9e59)

15 months agoUSB: adjust the Generic XHCI ACPI probe return value
Bjoern A. Zeeb [Fri, 1 Oct 2021 13:37:01 +0000 (13:37 +0000)]
USB: adjust the Generic XHCI ACPI probe return value

Change the probe return value from BUS_PROBE_DEFAULT to BUS_PROBE_GENERIC
given this is the "generic" attach method.  This allows individual
drivers using XHCI generic but needing their own intialisation to
gain priority for attaching over the generic implementation.

Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D32257

(cherry picked from commit 76f3b8cb640536de2c370cc2bd60382bbc35cf5d)

15 months agoGet clocks for Rockchip RK3568.
Søren Schmidt [Tue, 20 Dec 2022 08:53:58 +0000 (08:53 +0000)]
Get clocks for Rockchip RK3568.

(cherry picked from commit 1d8c07b7ab7bc123ec62e97176beffef4052eba8)

15 months agobcm5974(4): add Magic Trackpad 2 (USB only) support
Val Packett [Tue, 25 Apr 2023 09:20:53 +0000 (12:20 +0300)]
bcm5974(4): add Magic Trackpad 2 (USB only) support

The MT2 uses a compact report format, but otherwise is similar in many
ways to the internal trackpads, it even uses the same mode switching
commands.

Reviewed by: wulf
Differential revision: https://reviews.freebsd.org/D34437

(cherry picked from commit ef8397c28e981e0115d435aabcf57cee7ea5f5ee)

15 months agoif_mos: Remove set but unused variable.
John Baldwin [Mon, 10 Apr 2023 17:35:48 +0000 (10:35 -0700)]
if_mos: Remove set but unused variable.

Reviewed by: hselasky
Reported by: GCC
Differential Revision: https://reviews.freebsd.org/D39356

(cherry picked from commit 5328efb3d0a54df20779d82319c3eebd49aa2993)

15 months agousb(4): Separate the fast path and the slow path to avoid races and use-after-free...
Hans Petter Selasky [Fri, 31 Mar 2023 17:14:18 +0000 (19:14 +0200)]
usb(4): Separate the fast path and the slow path to avoid races and use-after-free for the USB FS interface.

Bad behaving user-space USB applicatoins may crash the kernel by issuing
USB FS related ioctl(2)'s out of their expected order. By default
the USB FS ioctl(2) interface is only available to the
administrator, root, and driver applications like webcamd(8) needs
to be hijacked in order for this to happen.

The issue is the fast-path code does not always see updates made
by the slow-path code, and may then work on freed memory.

This is easily fixed by using an EPOCH(9) type of synchronization
mechanism. A SX(9) lock will be used as a substitute for EPOCH(9),
due to the need for sleepability. In addition most calls going into
the fast-path originate from a single user-space process and the
need for multi-thread performance is not present.

Differential Revision: https://reviews.freebsd.org/D39373
Reviewed by: markj@
Reported by: C Turt <ecturt@gmail.com>
admbugs: 994
Sponsored by: NVIDIA Networking

(cherry picked from commit 9b077d72bcc313baea2b9283afc7f568739eaadc)

15 months agousb(4): Code refactoring as a pre-step for adding missing synchronization mechanism.
Hans Petter Selasky [Tue, 4 Apr 2023 15:15:38 +0000 (17:15 +0200)]
usb(4): Code refactoring as a pre-step for adding missing synchronization mechanism.

Move code in switch cases into own functions to make later changes easier to track.

No functional change, except for removing a superfluous break statement when
range checking USB_FS_MAX_FRAMES, in the USB_FS_OPEN case.
It should not have been there at all.

Suggested by: emaste@
Sponsored by: NVIDIA Networking

(cherry picked from commit 03a2e432d5cc2eedb9304faea2b19051c84caecf)

15 months agousb: dwc3: add <sys/mutex.h>
Joerg Wunsch [Wed, 8 Mar 2023 19:59:29 +0000 (20:59 +0100)]
usb: dwc3: add <sys/mutex.h>

Commit 5e54bb1ea9e90 added USB_BUS_LOCK/USB_BUS_UNLOCK. They, in
consequence, require mutexes so <sys/mutex.h> is needed.

(cherry picked from commit 175a584e501e19c90fd2241c505d1797de603a5c)

15 months agousb: dwc3: implement hw.usb.xhci.use_polling
Kyle Evans [Tue, 28 Feb 2023 01:59:43 +0000 (19:59 -0600)]
usb: dwc3: implement hw.usb.xhci.use_polling

Polling is currently only implemented in the xhci pci attachment.
Adding it to dwc3 doesn't make it much uglier, and supporting it can be
useful for confirming that hardware's otherwise functional when
interrupts are apparently not firing.

Reviewed by: manu
Differential Revision: https://reviews.freebsd.org/D38816

(cherry picked from commit 5e54bb1ea9e904075225dc96641c2ede3fc3273c)

15 months agowmt: purge EOL release compatibility
Elliott Mitchell [Thu, 23 Jun 2022 00:53:47 +0000 (17:53 -0700)]
wmt: purge EOL release compatibility

Remove FreeBSD 11 support

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/603
Differential Revision: https://reviews.freebsd.org/D35560

(cherry picked from commit 5fa183351459996cfb86f8621de1a0e1bf985d67)

15 months agousb: purge EOL release compatibility
Elliott Mitchell [Thu, 23 Jun 2022 00:53:47 +0000 (17:53 -0700)]
usb: purge EOL release compatibility

Remove conditionsals for FreeBSD 6, 7, 8 and 9 compatibility.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/603
Differential Revision: https://reviews.freebsd.org/D35560

(cherry picked from commit 336fbb23def7a6b3dc44ce5c76bbc07a701c0a69)

15 months agoxhci(4): Make sure allocated bandwidth is freed in hardware by unconfiguring endpoint.
Cheng, Huiming [Thu, 15 Dec 2022 22:30:11 +0000 (23:30 +0100)]
xhci(4): Make sure allocated bandwidth is freed in hardware by unconfiguring endpoint.

Sponsored by: NVIDIA Networking

(cherry picked from commit 8685d7b5cb759b4f688dea93dbe1c38f9e833e4e)

15 months agousb(4): Call optional endpoint_uninit() when changing configuration or alternate...
Hans Petter Selasky [Thu, 15 Dec 2022 22:32:47 +0000 (23:32 +0100)]
usb(4): Call optional endpoint_uninit() when changing configuration or alternate setting.

Sponsored by: NVIDIA Networking

(cherry picked from commit e4611d26265fb9e3bd2a345cf4776863f49a2587)

15 months agoUSB id of yet another Lenovo USB-C ethernet dongle.
Poul-Henning Kamp [Sun, 28 Aug 2022 17:21:38 +0000 (17:21 +0000)]
USB id of yet another Lenovo USB-C ethernet dongle.

(cherry picked from commit 31937f7e843da8be685557d513fc1af58079eda3)

15 months agouath(4): Fix incorrect byte-swapping and a buffer length check.
Hans Petter Selasky [Sat, 30 Apr 2022 09:21:54 +0000 (11:21 +0200)]
uath(4): Fix incorrect byte-swapping and a buffer length check.

PR: 263638
Reported by: Jeff Gibbons <jgibbons@protogate.com>
Sponsored by: NVIDIA Networking

(cherry picked from commit 6eb6aeef7e670bddc9cd52aaf32765a9ea85eee3)

15 months agousb: Respect NO_INQUIRY quirk during device enumeration
Kornel Duleba [Tue, 26 Apr 2022 12:07:21 +0000 (14:07 +0200)]
usb: Respect NO_INQUIRY quirk during device enumeration

Both usb_iface_is_cdrom and usb_msc_auto_quirk functions use SCSI INQUIRY
command to probe various properties of usb mass storage devices.
The problem here is that some very broken devices don't like this command.
Check if UQ_MSC_NO_INQUIRY quirk is set and skip cdrom and quirk
autodetection in that case.

Sponsored by: Stormshield
Obtained from: Semihalf
Reviewed by: hps, wma
Differential Revision: https://reviews.freebsd.org/D35075

(cherry picked from commit 3ee943868c74ce917820fe9ddbcfeab338704d90)

15 months agouhid_snes: Remove USB_ST_TRANSFERRED handling for the status request.
John Baldwin [Mon, 18 Apr 2022 19:27:48 +0000 (12:27 -0700)]
uhid_snes: Remove USB_ST_TRANSFERRED handling for the status request.

The result of the request computed in new_status was never returned to
the caller leaving new_status as a set-but-unused variable.  Removing
new_status leaves sc->previous_status as a write-only variable.
Removing sc->previous_status leaves current_status as a write-only
variable, so it collapses down to removing the entire
USB_ST_TRANSFERRED case.

Arguably, all of the support for UHID_SNES_STATUS_DT_RD should be
removed as it doesn't return anything to the caller.  If the request
should be fixed instead then this commit should be reverted and
new_status should be returned to whoever submitted the request.

Differential Revision: https://reviews.freebsd.org/D34840

(cherry picked from commit 540ac338d5575131d134d2c033f31b5d6d576c68)

15 months agolibusb: remove use of COMPAT_32BIT
Brooks Davis [Fri, 17 Dec 2021 21:28:14 +0000 (21:28 +0000)]
libusb: remove use of COMPAT_32BIT

This codepath used uint64_t's in place of pointers in structs and
arrays to allow 32-bit code to use 64-bit version of ioctls.  Now
that we support 32-bit compat natively this is no longer needed.

Reviewed by: hselasky, jrtc27 (prior version)

(cherry picked from commit 8010f4ad21b6120e929bda4eed27696e63514677)

15 months agousb: remove COMPAT_32BIT ifdefs
Brooks Davis [Fri, 17 Dec 2021 21:28:14 +0000 (21:28 +0000)]
usb: remove COMPAT_32BIT ifdefs

Now that we have proper 32-bit compat support, remove COMPAT_32BIT
ifdefs to allow 32-bit code to use the 64-bit layout of USB ioctl
structs and struct usb_fs_endpoint.

This includes the removal of redundant alignment directives that had
no effect in practice.

Reviewed by: hselasky, jrtc27 (prior version)

(cherry picked from commit ea972feea2d2589ee1317a19eeada0598332defa)

15 months agousb: add 32-bit compat for FIFOs
Brooks Davis [Fri, 17 Dec 2021 21:28:14 +0000 (21:28 +0000)]
usb: add 32-bit compat for FIFOs

Unlike most 32-bit compatability code, this isn't just a simple thunk
in the ioctl code.  An ioctl (USB_FS_INIT) is used to install a
pointer to an array of usb_fs_endpoint structs which are then used
by the ugen fifo code.  These struct contains an array of pointers
which requires translation.  We change the interfaces around
struct usb_fs_endpoint as follows:
 - We store the size of struct usb_fs_endpoint in struct usb_fifo
   in the USB_FS_INIT handler so we know the ABI of the userspace
   array.
 - APIs to manipulate userspace struct usb_fs_endpoint objects now
   take a struct usb_fifo and an index rather than a pointer to
   the object.  This allows most code to remain oblivious to the
   different struct usb_fs_endpoint sizes.
 - Add ugen_fs_copyin() which copies the struct usb_fs_endpoint
   from userspace, thunking it to the native size if required.
 - Uses of struct usb_fs_endpoint's ppBuffer member are now
   via ugen_fs_getbuffer() which produces a native pointer.
 - Updates to userspace are now handled by ugen_fs_update().

For clarity, single, fixed-sized members now are accessed with
fueword/suword rather than copyin/copyout.

Reviewed by: hselasky, jrtc27 (prior version)

(cherry picked from commit 0ec590d24e415dd36e38648630a0b963412ad87e)
(cherry picked from commit 8b60419b798ae9049988c529e6af3f313a5cce55)

15 months agolibusb(3): Implement libusb_init_context() and the needed structures and definitions.
Hans Petter Selasky [Thu, 26 Jan 2023 12:56:51 +0000 (13:56 +0100)]
libusb(3): Implement libusb_init_context() and the needed structures and definitions.

Differential Revision: https://reviews.freebsd.org/D38212
Sponsored by: NVIDIA Networking

(cherry picked from commit 4c6bcffd04f9d0b6cb57af0ffcc9be3098fe950c)

15 months agoSkip Pass 5 in fsck_ffs(8) when corrupt cylinder groups remain unfixed.
Kirk McKusick [Tue, 18 Apr 2023 23:10:49 +0000 (16:10 -0700)]
Skip Pass 5 in fsck_ffs(8) when corrupt cylinder groups remain unfixed.

Sponsored by: FreeBSD Foundation

(cherry picked from commit da86e7a20dc4a4b17e8d9e7630ed9b675cf71702)

15 months agoBug fixes for fsck_ffs(8).
Kirk McKusick [Tue, 18 Apr 2023 06:03:30 +0000 (23:03 -0700)]
Bug fixes for fsck_ffs(8).

Sponsored by: Netflix

(cherry picked from commit 18746531a881356ed24b6ef2fdc9e50707642163)

15 months agoAdd `chdb' command to fsdb(8) to set direct block numbers.
Kirk McKusick [Tue, 18 Apr 2023 05:42:32 +0000 (22:42 -0700)]
Add `chdb' command to fsdb(8) to set direct block numbers.

(cherry picked from commit 7636973c68f15419a71bc8e4253b2fbae3258025)

15 months agoImprovement in UFS/FFS directory placement when doing mkdir(2).
Kirk McKusick [Thu, 30 Mar 2023 04:09:39 +0000 (21:09 -0700)]
Improvement in UFS/FFS directory placement when doing mkdir(2).

Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39246

(cherry picked from commit fe5e6e2cc5d6f2e4121eccdb3a8ceba646aef2c9)

15 months agoal_eth: make function definitions consistent with declarations
Dimitry Andric [Sat, 22 Apr 2023 11:45:57 +0000 (13:45 +0200)]
al_eth: make function definitions consistent with declarations

The declarations for al_eth_lm_retimer_ds25_signal_detect() and
al_eth_lm_retimer_ds25_cdr_lock() say that these functions return
'al_bool', but the definitions actually return 'boolean_t'.

Make the definitions match the declarations.

Reviewed by: jhb, emaste
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D39759

(cherry picked from commit 9ea31d78f00d23612f3ab44d83265f8039f487af)

15 months agoUse bool for one-bit wide bit-fields
Dimitry Andric [Tue, 25 Apr 2023 17:18:58 +0000 (19:18 +0200)]
Use bool for one-bit wide bit-fields

A signed one-bit wide bit-field can take only the values 0 and -1. Clang
16 introduced a warning that "implicit truncation from 'int' to a
one-bit wide bit-field changes value from 1 to -1". Fix the warnings by
using C99 bool.

Reported by: Clang 16
Reviewed by: emaste, jhb
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D39705

(cherry picked from commit bab8274c090942cf96c44bc001307b9bffac9d7e)

15 months agopowerpc: fix a few pmap related functions to return correct types
Dimitry Andric [Sun, 23 Apr 2023 13:22:44 +0000 (15:22 +0200)]
powerpc: fix a few pmap related functions to return correct types

While experimenting with changing boolean_t to another type, I noticed
that several powerpc pmap related functions returned the wrong type:
boolean_t instead of int.

Fix several declarations and definitions to match the actual pmap
function types: pmap_dev_direct_mapped_t and pmap_ts_referenced_t.

MFC after: 3 days

(cherry picked from commit d142601887524fc595ed0f5e6a69419727222f0a)

15 months agokcsan: add __tsan_mem(cpy|move|set) aliases for clang >= 16
Dimitry Andric [Sun, 23 Apr 2023 18:11:34 +0000 (20:11 +0200)]
kcsan: add __tsan_mem(cpy|move|set) aliases for clang >= 16

Summary:
After https://github.com/llvm/llvm-project/commit/b4257d3bf58c ("[tsan]
Replace mem intrinsics with calls to interceptors") intrinsic calls to
memcpy, memmove or memset will directly call sanitizer interceptors,
e.g. __tsan_memcpy, __tsan_memmove or __tsan_memset.

Building GENERIC-KCSAN with clang >= 16 would thus result in link errors
similar to:

  ld: error: undefined symbol: __tsan_memcpy
  >>> referenced by cam_compat.c:150 (/usr/src/sys/cam/cam_compat.c:150)
  >>>               cam_compat.o:(cam_compat_handle_0x17)
  >>> referenced by cam_compat.c:151 (/usr/src/sys/cam/cam_compat.c:151)
  >>>               cam_compat.o:(cam_compat_handle_0x17)
  >>> referenced by cam_compat.c:152 (/usr/src/sys/cam/cam_compat.c:152)
  >>>               cam_compat.o:(cam_compat_handle_0x17)
  >>> referenced 1692 more times

Similar to subr_msan.c, add aliases from the existing kcsan_* versions
of these functions to __tsan_* names.

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

(cherry picked from commit 42162fb2fe30c0881e7e4d2143ddcfee3e1dd752)

15 months agoInclude bsd.linker.mk to get LINKER_TYPE and VERSION in rescue
Dimitry Andric [Mon, 17 Apr 2023 17:43:29 +0000 (19:43 +0200)]
Include bsd.linker.mk to get LINKER_TYPE and VERSION in rescue

To be able to use these make variables, you also have to include
bsd.linker.mk, apparently.

Fixes: 458f4722bf97
MFC after: 1 week

(cherry picked from commit 653e8c11f43dc6448b8560eb1f6679de2c47e1ed)

15 months agoSuppress lld 16 errors about undefined symbols in version maps
Dimitry Andric [Mon, 17 Apr 2023 16:00:20 +0000 (18:00 +0200)]
Suppress lld 16 errors about undefined symbols in version maps

lld >= 16 turned on --no-undefined-version by default, which results in
errors whenever symbols are mentioned in version maps, but are not
actually defined in the binary.

Since we have quite a few instances of symbols that are defined or not,
depending on various compile-time settings, suppress this lld check for
the time being.

MFC after: 1 week

(cherry picked from commit 2ba84b4bcdd6012e8cfbf8a0d060a4438623a638)

15 months agoSuppress lld 16 errors about multiply defined symbols in rescue
Dimitry Andric [Mon, 17 Apr 2023 16:25:30 +0000 (18:25 +0200)]
Suppress lld 16 errors about multiply defined symbols in rescue

lld >= 16 became more strict about multiply defined symbols. Since there
are many of those in crunchgen'd programs, turn off the check when
linking the rescue binary.

MFC after: 1 week

(cherry picked from commit 458f4722bf974c7fa7961952fcaee146f5a97708)

15 months agobhyve: remove redundant variable
Vitaliy Gusev [Wed, 1 Mar 2023 07:45:46 +0000 (07:45 +0000)]
bhyve: remove redundant variable

Reviewed by:    corvink,markj
Sponsored by:   vStack
Differential Revision: https://reviews.freebsd.org/D38836

15 months agobhyve: add QEMU_FWCFG_INDEX_MAX_CPUS item
Corvin Köhne [Tue, 21 Jun 2022 08:35:40 +0000 (10:35 +0200)]
bhyve: add QEMU_FWCFG_INDEX_MAX_CPUS item

Requested-by: coreboot
Reviewed by: <If someone else reviewed your modification.>
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D39315

(cherry picked from commit 305edaa47918a559de46a5d72060644009f1875c)

15 months agobhyve: add hook for PCI header of passthru devices
Corvin Köhne [Tue, 7 Sep 2021 11:42:25 +0000 (13:42 +0200)]
bhyve: add hook for PCI header of passthru devices

Most register of the PCI header are either constant values or require
emulation anyway. The command and status register are the only exception which
require hardware access. So, we're adding an emulation handler for all
other register.

As this emulation handler will be reused by some future features like
GPU passthrough, we directly export it.

Reviewed by: markj
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D33010

(cherry picked from commit b6e67875a3e5bc706fe37565e464c61fe7833846)

15 months agobhyve: define array to protect passthru regs
Corvin Köhne [Fri, 19 Mar 2021 12:48:34 +0000 (13:48 +0100)]
bhyve: define array to protect passthru regs

GPU passthrough requires a special handling of some PCI config register.
Therefore, we need a flexible approach for implementing it. Adding an
array of handler meets this condition.

Start by using the default handler for all accesses to the PCI config
space. In upcoming commits, we can start to split the default handler
into several handler for each register that requires emulation.

Reviewed by: markj
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D39291

(cherry picked from commit 931bb7bf1c8f90f3303b5291e4868c587f9364e7)

15 months agobhyve: save softc of ACPI devices
Corvin Köhne [Fri, 22 Jul 2022 08:15:28 +0000 (10:15 +0200)]
bhyve: save softc of ACPI devices

This will be useful for writing device specific ACPI tables or DSDT
methods.

Reviewed by: markj
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D39322

(cherry picked from commit 158adced65f844682d26e1e64f247de94212f135)

15 months agobhyve: allow device specific DSDT entries
Corvin Köhne [Fri, 22 Jul 2022 08:11:14 +0000 (10:11 +0200)]
bhyve: allow device specific DSDT entries

This feature will be used by future commits to implement a device
specific method (_DSM) for TPM devices.

Reviewed by: markj
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D39321

(cherry picked from commit e976464a50aceebf97fb3cc6b94058111fc40de1)

15 months agobhyve: check for errors when writing device specific DSDT entries
Corvin Köhne [Wed, 5 Apr 2023 06:45:22 +0000 (08:45 +0200)]
bhyve: check for errors when writing device specific DSDT entries

At the moment, this function can't fail. This behaviour will change in
the future. In preparation to that, convert the return type to int in
order to be able to check for errors.

Reviewed by: markj
MFC after: 1 week
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D39422

(cherry picked from commit ab34ea4711b1001c416dc286380e54c118ff0c49)