freebsd.git
2 years agozfs: merge openzfs/zfs@b9d98453f
Martin Matuska [Fri, 3 Jun 2022 15:58:39 +0000 (17:58 +0200)]
zfs: merge openzfs/zfs@b9d98453f

Notable upstream pull request merges:
  #12321 Fix inflated quiesce time caused by lwb_tx during zil_commit()
  #13244 zstd early abort
  #13360 Verify BPs as part of spa_load_verify_cb()
  #13452 More speculative prefetcher improvements
  #13466 Expose zpool guids through kstats
  #13476 Refactor Log Size Limit
  #13484 FreeBSD: libspl: Add locking around statfs globals
  #13498 Cancel in-progress rebuilds when we finish removal
  #13499 zed: Take no action on scrub/resilver checksum errors
  #13513 Remove wrong assertion in log spacemap

Obtained from: OpenZFS
OpenZFS commit: b9d98453f9387c413f91d1d9cdb0cba8e04dbd95

2 years agoiwlwifi: add sysctl to dump PCI IDs/ names / firmware-prefixes
Bjoern A. Zeeb [Wed, 18 May 2022 16:05:49 +0000 (16:05 +0000)]
iwlwifi: add sysctl to dump PCI IDs/ names / firmware-prefixes

Add a FreeBSD-specifc SYSCTL_PROC to dump the list of
PCI IDs / name / firmware-prefix which can be post-processed
for man pages (iwlwifi.4 and iwlwififw.4) or the wiki.

The output still yields duplicates depending on by what information
you need so one may wants to filter them out (try not to use sort/uniq).

Sponsored by: The FreeBSD Foundation
MFC after: 3 days

2 years agoiwlwifi: Update man pages with card list
Bjoern A. Zeeb [Tue, 17 May 2022 01:43:15 +0000 (01:43 +0000)]
iwlwifi: Update man pages with card list

Add list of supported names to iwlwifi.4 and an extended list with
PCI IDs and firmware prefix to iwlwififw.4.

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

2 years agolinuxkpi/dmi: don't match exactly on DMI_MATCH
Corvin Köhne [Fri, 3 Jun 2022 14:20:45 +0000 (16:20 +0200)]
linuxkpi/dmi: don't match exactly on DMI_MATCH

Linux has two defines to check dmi data. DMI_MATCH checks if the dmi
string includes substr. DMI_EXACT_MATCH checks if the dmi string exactly
matches substr. Compat layer should have the same behaviour.

The new definition of dmi_strmatch shouldn't break any driver. A driver
would break if it uses the highest bit of the slot field. Nevertheless,
linux uses the same definition and FreeBSD uses dmi_field values as slot
which are lower than 128.

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

2 years agong_ubt(4): Probe USB Bluetooth per USB interface and not per USB device.
Hans Petter Selasky [Fri, 3 Jun 2022 08:22:54 +0000 (10:22 +0200)]
ng_ubt(4): Probe USB Bluetooth per USB interface and not per USB device.

PR: 264416
MFC after: 1 week
Sponsored by: NVIDIA Networking

2 years agotcp: Correctly compute the retransmit length for all 64-bit platforms.
Hans Petter Selasky [Thu, 2 Jun 2022 18:33:21 +0000 (20:33 +0200)]
tcp: Correctly compute the retransmit length for all 64-bit platforms.

When the TCP sequence number subtracted is greater than 2**32 minus
the window size, or 2**31 minus the window size, the use of unsigned
long as an intermediate variable, may result in an incorrect retransmit
length computation on all 64-bit platforms.

While at it create a helper macro to facilitate the computation of
the difference between two TCP sequence numbers.

Differential Revision: https://reviews.freebsd.org/D35388
Reviewed by: rscheff
MFC after: 3 days
Sponsored by: NVIDIA Networking

2 years agohwpmc: Add IDs for few more Intel Atom CPUs.
Alexander Motin [Fri, 3 Jun 2022 02:55:42 +0000 (22:55 -0400)]
hwpmc: Add IDs for few more Intel Atom CPUs.

MFC after: 1 month

2 years agohwpmc: Skip GLOBAL_CTRL updates on stop_pmc().
Alexander Motin [Thu, 2 Jun 2022 22:20:33 +0000 (18:20 -0400)]
hwpmc: Skip GLOBAL_CTRL updates on stop_pmc().

After we wipe PMC configuration, including its local enable bit(s),
we don't really care about its global enable bit.  Global enable bits
now may only be cleared by interrupt handler in case of error (sample
buffer overflow).  Being set is actually a reset default for them.

This saves one WRMSR per process-scope PMC per context switch, that
is clearly visible in profiles.

MFC after: 1 month

2 years agobusdma_iommu: simplify split logic
Doug Moore [Thu, 2 Jun 2022 20:59:57 +0000 (15:59 -0500)]
busdma_iommu: simplify split logic

iommu_bus_dmamap_load_something1 includes code for handling the
possibility of splitting a buffer that is needlessly complex.
Simplify it.

Reviewed by: alc, kib
MFC after: 3 weeks
Tested by: pho (previous revisions)
Differential Revision: https://reviews.freebsd.org/D35232

2 years agoCirrus-CI: update image to FreeBSD 13.1 (latest release)
Ed Maste [Thu, 2 Jun 2022 17:58:09 +0000 (13:58 -0400)]
Cirrus-CI: update image to FreeBSD 13.1 (latest release)

Sponsored by: The FreeBSD Foundation

2 years agolibpmc: Prefer fixed counters in Intel event aliases.
Alexander Motin [Thu, 2 Jun 2022 19:09:38 +0000 (15:09 -0400)]
libpmc: Prefer fixed counters in Intel event aliases.

It is recommended by Intel to use fixed counters when possible to
leave programmable ones for different events.

This fixes `pmc stat`, which tries to count 6 events same time, while
many Intel CPUs have only 4 programmable counters.

MFC after: 1 month

2 years agonfscl: Do not flush when a write delegation is held
Rick Macklem [Thu, 2 Jun 2022 19:11:55 +0000 (12:11 -0700)]
nfscl: Do not flush when a write delegation is held

When a NFSv4 byte range write lock is unlocked, all
data modifications need to be flushed to the server
to satisfy the coherency requirements for byte range
locking.  However, if a write delegation for the
file is held by the client, flushing is not required,
since no other NFSv4 client can have the file NFSv4
Opened.

Found by inspection as suggested by a similar change
that was done to the Linux NFSv4 client.

2 years agopf: fix more syncookie memory leaks
Franco Fichtner [Thu, 2 Jun 2022 16:27:43 +0000 (18:27 +0200)]
pf: fix more syncookie memory leaks

Allocate memory for packed nvlists in M_NVLIST, as nvlist_pack() does
this as well, and we use the same variable interchangable with the
memory we allocate. When we free it we can end up freeing from the wrong
zone, leaking memory.

Reviewed by: kp
Differential Revision: https://reviews.freebsd.org/D35385

2 years agohwpmc: Bump Intel's IA32_PERFEVTSELx width to 64 bits.
Alexander Motin [Thu, 2 Jun 2022 17:08:55 +0000 (13:08 -0400)]
hwpmc: Bump Intel's IA32_PERFEVTSELx width to 64 bits.

Haswell added there bits 32/33 for TSX, and AlderLake added bit 34
for Adaptive PEBS Record.

MFC after: 1 month

2 years agoUse KERNEL_PANICKED() in more places
Mitchell Horne [Thu, 2 Jun 2022 13:14:41 +0000 (10:14 -0300)]
Use KERNEL_PANICKED() in more places

This is slightly more optimized than checking panicstr directly. For
most of these instances performance doesn't matter, but let's make
KERNEL_PANICKED() the common idiom.

Reviewed by: mjg
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D35373

2 years agoApply llvm fix for possible hangs with CPUTYPE=skylake-avx512
Dimitry Andric [Wed, 1 Jun 2022 21:43:18 +0000 (23:43 +0200)]
Apply llvm fix for possible hangs with CPUTYPE=skylake-avx512

Merge commit e8305c0b8f49 from llvm git (by Simon Pilgrim)

    [X86] combineX86ShuffleChain - don't fold to truncate(concat(V1,V2)) if it was already a PACK op

    Fixes #55050

PR: 264394
Reported by: VVD <vvd@unislabs.com>
MFC after: 3 days

2 years agohwpmc: Make powerpc memory allocation alike to x86.
Alexander Motin [Wed, 1 Jun 2022 18:50:27 +0000 (14:50 -0400)]
hwpmc: Make powerpc memory allocation alike to x86.

It should remove some unneeded pointer dereferences.

MFC after: 1 month

2 years agoApply compiler-rt fix for building with earlier versions of clang
Dimitry Andric [Wed, 1 Jun 2022 18:29:15 +0000 (20:29 +0200)]
Apply compiler-rt fix for building with earlier versions of clang

Merge commit 18efa420da5f from llvm git (by Brooks Davis)

  compiler-rt: Allow build without __c11_atomic_fetch_nand

  Don't build atomic fetch nand libcall functions when the required
  compiler builtin isn't available. Without this compiler-rt can't be
  built with LLVM 13 or earlier.

  Not building the libcall functions isn't optimal, but aligns with the
  usecase in FreeBSD where compiler-rt from LLVM 14 is built with an LLVM
  13 clang and no LLVM 14 clang is built.

  Reviewed By:   efriedma

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

MFC after: 3 days

2 years agoautoconf: AC_MSG_CHECKING consistency
Brian Behlendorf [Tue, 31 May 2022 23:42:49 +0000 (16:42 -0700)]
autoconf: AC_MSG_CHECKING consistency

Make the wording more consistent for the kernel AC_MSG_CHECKING
output (e.g. "checking whether ...".).  Additionally, group some
of the VFS interface checks with the others.  No functional change.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Attila Fülöp <attila@fueloep.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13529

2 years agoLinux 5.19 compat: asm/fpu/internal.h
Brian Behlendorf [Tue, 31 May 2022 23:30:59 +0000 (16:30 -0700)]
Linux 5.19 compat: asm/fpu/internal.h

As of the Linux 5.19 kernel the asm/fpu/internal.h header was
entirely removed.  It has been effectively empty since the 5.16
kernel and provides no required functionality.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Attila Fülöp <attila@fueloep.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13529

2 years agodtrace: add warning for /dev/dtrace/prototype
Christos Margiolis [Wed, 1 Jun 2022 16:58:31 +0000 (12:58 -0400)]
dtrace: add warning for /dev/dtrace/prototype

Let the programmer know that creating a device is not necessary.

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

2 years agoRemove wrong assertion in log spacemap
Alexander Motin [Wed, 1 Jun 2022 16:54:35 +0000 (12:54 -0400)]
Remove wrong assertion in log spacemap

It is typical, but not generally true that if log summary has more
blocks it must also have unflushed metaslabs.  Normally with metaslabs
flushed in order it works, but there are known exceptions, such as
device removal or metaslab being loaded during its flush attempt.

Before 600a02b8844 if spa_flush_metaslabs() hit loading metaslab it
usually stopped (unless memlimit is also exceeded), but now it may
flush more metaslabs, just skipping that particular one.  This
increased chances of assertion to fire when the skipped metaslab is
flushed on next iteration if all other metaslabs in that summary
entry are already flushed out of order.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored-By: iXsystems, Inc.
Closes #13486
Closes #13513

2 years agodtrace: remove /dev/dtrace/fbt
Christos Margiolis [Wed, 1 Jun 2022 16:26:07 +0000 (12:26 -0400)]
dtrace: remove /dev/dtrace/fbt

It is unused.

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

2 years agodtrace: remove /dev/dtrace/profile
Christos Margiolis [Wed, 1 Jun 2022 16:42:35 +0000 (12:42 -0400)]
dtrace: remove /dev/dtrace/profile

It is unused.

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

2 years agodtrace: remove /dev/dtrace/dtmalloc
Christos Margiolis [Wed, 1 Jun 2022 16:39:23 +0000 (12:39 -0400)]
dtrace: remove /dev/dtrace/dtmalloc

It is unused.

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

2 years agogetpagesize(3): add .Xr to sysconf(3)
Ed Maste [Mon, 30 May 2022 19:34:34 +0000 (15:34 -0400)]
getpagesize(3): add .Xr to sysconf(3)

POSIX deprecated getpagesize(3).  The portable way to obtain the page
size is `sysconf(_SC_PAGESIZE)`.

Reviewed by: cperciva (earlier), imp
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35352

2 years agohwpmc: Remove always zero pc_resync field.
Alexander Motin [Wed, 1 Jun 2022 15:05:50 +0000 (11:05 -0400)]
hwpmc: Remove always zero pc_resync field.

MFC after: 1 month

2 years agostress2: Updated the exclude list and sorted it
Peter Holm [Wed, 1 Jun 2022 08:03:23 +0000 (10:03 +0200)]
stress2: Updated the exclude list and sorted it

2 years agostress2: Added syzkaller reproducers
Peter Holm [Wed, 1 Jun 2022 08:02:08 +0000 (10:02 +0200)]
stress2: Added syzkaller reproducers

2 years agostress2: Added procctl(2) PROC_REAP_KILL regression tests
Peter Holm [Wed, 1 Jun 2022 07:58:28 +0000 (09:58 +0200)]
stress2: Added procctl(2) PROC_REAP_KILL regression tests

2 years agonetinet6: fix panic on kldunload pfsync
Kristof Provost [Tue, 31 May 2022 19:11:14 +0000 (21:11 +0200)]
netinet6: fix panic on kldunload pfsync

Commit d6cd20cc5 ("netinet6: fix ndp proxying") caused us to panic when
unloading pfsync:

Fatal trap 12: page fault while in kernel mode
cpuid = 19; apic id = 38
fault virtual address = 0x20
fault code = supervisor read data, page not present
instruction pointer = 0x20:0xffffffff80dfe7f4
stack pointer         = 0x28:0xfffffe015d4f8ac0
frame pointer         = 0x28:0xfffffe015d4f8ae0
code segment = base 0x0, limit 0xfffff, type 0x1b
= DPL 0, pres 1, long 1, def32 0, gran 1
processor eflags = interrupt enabled, resume, IOPL = 0
current process = 5477 (kldunload)
trap number = 12
panic: page fault
cpuid = 19
time = 1654023100
KDB: stack backtrace:
db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe015d4f8880
vpanic() at vpanic+0x17f/frame 0xfffffe015d4f88d0
panic() at panic+0x43/frame 0xfffffe015d4f8930
trap_fatal() at trap_fatal+0x387/frame 0xfffffe015d4f8990
trap_pfault() at trap_pfault+0xab/frame 0xfffffe015d4f89f0
calltrap() at calltrap+0x8/frame 0xfffffe015d4f89f0
--- trap 0xc, rip = 0xffffffff80dfe7f4, rsp = 0xfffffe015d4f8ac0, rbp = 0xfffffe015d4f8ae0 ---
in6_purge_proxy_ndp() at in6_purge_proxy_ndp+0x14/frame 0xfffffe015d4f8ae0
if_purgeaddrs() at if_purgeaddrs+0x24/frame 0xfffffe015d4f8b90
if_detach_internal() at if_detach_internal+0x1c2/frame 0xfffffe015d4f8bf0
if_detach() at if_detach+0x71/frame 0xfffffe015d4f8c20
pfsync_clone_destroy() at pfsync_clone_destroy+0x1dd/frame 0xfffffe015d4f8c70
if_clone_destroyif() at if_clone_destroyif+0x239/frame 0xfffffe015d4f8cc0
if_clone_detach() at if_clone_detach+0xc8/frame 0xfffffe015d4f8cf0
vnet_pfsync_uninit() at vnet_pfsync_uninit+0xda/frame 0xfffffe015d4f8d10
vnet_deregister_sysuninit() at vnet_deregister_sysuninit+0x85/frame 0xfffffe015d4f8d40
linker_file_sysuninit() at linker_file_sysuninit+0x147/frame 0xfffffe015d4f8d70
linker_file_unload() at linker_file_unload+0x269/frame 0xfffffe015d4f8db0
kern_kldunload() at kern_kldunload+0x18d/frame 0xfffffe015d4f8e00
amd64_syscall() at amd64_syscall+0x12e/frame 0xfffffe015d4f8f30
fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe015d4f8f30
--- syscall (444, FreeBSD ELF64, sys_kldunloadf), rip = 0x1601eab28cba, rsp = 0x1601e9c363f8, rbp = 0x1601e9c36c50 ---

This happens because ifp->if_afdata[AF_INET6] is NULL. Check for this,
just as we already do in a few other places.
See also c139b3c19b52a ("arp/nd: Cope with late calls to
iflladdr_event").

Reviewed by: melifaro
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D35374

2 years agoTwo bug fixes to UFS/FFS superblock integrity checks when reading a superblock.
Kirk McKusick [Wed, 1 Jun 2022 02:55:54 +0000 (19:55 -0700)]
Two bug fixes to UFS/FFS superblock integrity checks when reading a superblock.

Two bugs have been reported with the UFS/FFS superblock integrity
checks that were added in commit 076002f24d35.

The code checked that fs_sblockactualloc was properly set to the
location of the superblock. The fs_sblockactualloc field was an
addition to the superblock in commit dffce2150eea on Jan 26 2018
and used a field that was zero in filesystems created before it
was added. The integrity check had to be expanded to accept the
fs_sblockactualloc field being zero so as not to reject filesystems
created before Jan 26 2018.

The integrity check set an upper bound on the value of fs_maxcontig
based on the maximum transfer size supported by the kernel. It
required that fs->fs_maxcontig <= maxphys / fs->fs_bsize. The kernel
variable maxphys defines the maximum transfer size permitted by the
controllers and/or buffering. The fs_maxcontig parameter controls the
maximum number of blocks that the filesystem will read or write in
a single transfer. It is calculated when the filesystem is created
as maxphys / fs_bsize. The bug appeared in the loader because it
uses a maxphys of 128K even when running on a system that supports
larger values. If the filesystem was built on a system that supports
a larger maxphys (1M is typical) it will have configured fs_maxcontig
for that larger system so would fail the test when run with the smaller
maxphys used by the loader. So we bound the upper allowable limit
for fs_maxconfig to be able to at least work with a 1M maxphys on the
smallest block size filesystem: 1M / 4096 == 256. We then use the
limit for fs_maxcontig as fs_maxcontig <= MAX(256, maxphys / fs_bsize).
There is no harm in allowing the mounting of filesystems that make larger
than maxphys I/O requests because those (mostly 32-bit machines) can
(very slowly) handle I/O requests that exceed maxphys.

Thanks to everyone who helped sort out the problems and the fixes.

Reported by:  Cy Schubert, David Wolfskill
Diagnosis by: Mark Johnston, John Baldwin
Reviewed by:  Warner Losh
Tested by:    Cy Schubert, David Wolfskill
MFC after:    1 month (with 076002f24d35)
Differential Revision: https://reviews.freebsd.org/D35219

2 years agoCorrected parameters for zstd early abort
Rich Ercolani [Tue, 31 May 2022 22:41:33 +0000 (18:41 -0400)]
Corrected parameters for zstd early abort

That'll teach me to try and recall them from the definition.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rich Ercolani <rincebrain@gmail.com>
Closes #13519

2 years agoFix typo in zil_commit() comment block
Allan Jude [Tue, 31 May 2022 22:37:46 +0000 (18:37 -0400)]
Fix typo in zil_commit() comment block

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Allan Jude <allan@klarasystems.com>
Closes #13518

2 years agoLinux 5.18 compat: META
Brian Behlendorf [Tue, 31 May 2022 21:38:00 +0000 (14:38 -0700)]
Linux 5.18 compat: META

Update the META file to reflect compatibility with the 5.18 kernel.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13527

2 years agonetinet6: Fix mbuf leak in NDP
Arseny Smalyuk [Tue, 31 May 2022 20:04:51 +0000 (20:04 +0000)]
netinet6: Fix mbuf leak in NDP

Mbufs leak when manually removing incomplete NDP records with pending packet via ndp -d.
It happens because lltable_drop_entry_queue() rely on `la_numheld`
counter when dropping NDP entries (lles). It turned out NDP code never
increased `la_numheld`, so the actual free never happened.

Fix the issue by introducing unified lltable_append_entry_queue(),
common for both ARP and NDP code, properly addressing packet queue
maintenance.

Reviewed By: melifaro
Differential Revision: https://reviews.freebsd.org/D35365
MFC after: 2 weeks

2 years agopf: fix a race against kif destruction in pf_test{,6}
Mateusz Guzik [Tue, 31 May 2022 20:00:37 +0000 (20:00 +0000)]
pf: fix a race against kif destruction in pf_test{,6}

ifp kif was dereferenced prior to taking the lock and
could have been nullified later.

Reviewed by: kp
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision:

2 years agonfs: skip bootpc when vfs.root.mountfrom is other than nfs
Alfredo Dal'Ava Junior [Tue, 31 May 2022 19:03:43 +0000 (16:03 -0300)]
nfs: skip bootpc when vfs.root.mountfrom is other than nfs

If "vfs.root.mountfrom" is set and the value is something other
than "nfs:*", it means the user doesn't want to mount root via nfs,
there's no reason to continue with bootpc

This fixes the powerpcspe kernel (MPC85XXSPE) that's compiled with
BOOTP_NFSROOT by default and gets stuck on bootpc/dhcp request loop
when no DHCP server is available on the network, even when user
specifies a local disk via "vfs.root.mountfrom" kernel parameter.

Reviewed by: imp
MFC after: 2 weeks
Sponsored by: Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision: https://reviews.freebsd.org/D35098

2 years agoLinux 5.19 compat: zap_flags_t conflict
Brian Behlendorf [Fri, 27 May 2022 22:56:05 +0000 (15:56 -0700)]
Linux 5.19 compat: zap_flags_t conflict

As of the Linux 5.19 kernel an identically named zap_flags_t typedef
is declared in the include/linux/mm_types.h linux header.  Sadly,
the inclusion of this header cannot be easily avoided.  To resolve
the conflict a #define is used to remap the name in the OpenZFS
sources when building against the Linux kernel.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515

2 years agoLinux 5.19 compat: bdev_start_io_acct() / bdev_end_io_acct()
Brian Behlendorf [Fri, 27 May 2022 21:31:03 +0000 (21:31 +0000)]
Linux 5.19 compat: bdev_start_io_acct() / bdev_end_io_acct()

As of the Linux 5.19 kernel the disk_*_io_acct() helper functions
have been replaced by the bdev_*_io_acct() functions.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515

2 years agoLinux 5.19 compat: aops->read_folio()
Brian Behlendorf [Fri, 27 May 2022 20:44:43 +0000 (20:44 +0000)]
Linux 5.19 compat: aops->read_folio()

As of the Linux 5.19 kernel the readpage() address space operation
has been replaced by read_folio().

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515

2 years agoLinux 5.19 compat: blkdev_issue_secure_erase()
Brian Behlendorf [Fri, 27 May 2022 19:40:22 +0000 (19:40 +0000)]
Linux 5.19 compat: blkdev_issue_secure_erase()

Linux 5.19 commit torvalds/linux@44abff2c0 splits the secure
erase functionality from the blkdev_issue_discard() function.
The blkdev_issue_secure_erase() must now be issued to issue
a secure erase.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515

2 years agoLinux 5.19 compat: bdev_max_secure_erase_sectors()
Brian Behlendorf [Fri, 27 May 2022 18:20:04 +0000 (18:20 +0000)]
Linux 5.19 compat: bdev_max_secure_erase_sectors()

Linux 5.19 commit torvalds/linux@44abff2c0 removed the
blk_queue_secure_erase() helper function.  The preferred
interface is to now use the bdev_max_secure_erase_sectors()
function to check for discard support.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515

2 years agoLinux 5.19 compat: bdev_max_discard_sectors()
Brian Behlendorf [Fri, 27 May 2022 17:51:55 +0000 (17:51 +0000)]
Linux 5.19 compat: bdev_max_discard_sectors()

Linux 5.19 commit torvalds/linux@70200574cc removed the
blk_queue_discard() helper function.  The preferred interface
is to now use the bdev_max_discard_sectors() function to check
for discard support.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515

2 years agoLinux 5.18 compat: bio_alloc()
Brian Behlendorf [Fri, 27 May 2022 20:28:51 +0000 (20:28 +0000)]
Linux 5.18 compat: bio_alloc()

As for the Linux 5.18 kernel bio_alloc() expects a block_device struct
as an argument.  This removes the need for the bio_set_dev() compatibility
code for 5.18 and newer kernels.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515

2 years agonfscl: Enable support for the Lookup+Open RPC
Rick Macklem [Tue, 31 May 2022 18:59:39 +0000 (11:59 -0700)]
nfscl: Enable support for the Lookup+Open RPC

Commits 3ad1e1c1ce20 and 57014f21e754 added a Lookup+Open
RPC for NFSv4.1/4.2, which can reduce the RPC count by
10-20% for some loads.  This has now received a fair amount
of testing, so I think it is ok to enable it.

Note that the Lookup+Open RPC is only used when the
"oneopenown" mount option is specified.  As such, this
change won't affect most NFSv4.1/4.2 mounts.

2 years agollvm MIPS target: add missed source file
Dimitry Andric [Tue, 31 May 2022 13:19:55 +0000 (15:19 +0200)]
llvm MIPS target: add missed source file

Otherwise, linking llvm binaries with this target enabled (which is not
the default) will fail with a number of undefined symbol errors:

  ld: error: undefined symbol: llvm::initializeMipsMulMulBugFixPass(llvm::PassRegistry&)
  ld: error: undefined symbol: llvm::createMipsMulMulBugPass()

MFC after: 3 days

2 years agomandoc: workaround lack of macro parsing in list -width
Eric van Gyzen [Tue, 17 May 2022 17:46:59 +0000 (12:46 -0500)]
mandoc: workaround lack of macro parsing in list -width

GNU tools parse macros in the -width argument of lists.  mandoc does not,
so it calculates an excessive width.  This often squeezes the text into
a very narrow column, especially in nested lists.

Implement the easy workaround suggested in the TODO list.  When there is
only one macro, at the beginning of the -width argument, this fixes the
formatting as well as a complete solution.

Reviewed by: bapt
Relnotes: yes
MFC after: 1 week
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D35245

2 years agorc: Fix quoting in the zpoolreguid script
Mark Johnston [Tue, 31 May 2022 14:51:28 +0000 (10:51 -0400)]
rc: Fix quoting in the zpoolreguid script

Reported by: 0mp
Fixes: 227caacc918a ("rc: Add a zpoolreguid rc.d script")
Sponsored by: The FreeBSD Foundation

2 years agolinux(4): Return EINVAL when the clockid has invalid bits are set
Dmitry Chagin [Tue, 31 May 2022 08:46:15 +0000 (11:46 +0300)]
linux(4): Return EINVAL when the clockid has invalid bits are set

Linux forbids PERTHREAD bit set for CLOCKFD clock.

MFC after: 2 weeks

2 years agolinux(4): Return ENOTSUP for unsupported clockid
Dmitry Chagin [Tue, 31 May 2022 08:43:00 +0000 (11:43 +0300)]
linux(4): Return ENOTSUP for unsupported clockid

It's much better from the user perspective to get a sane error code.

MFC after: 2 weeks

2 years agolinprocfs: Add /proc/vm/max_map_count
Dmitry Chagin [Tue, 31 May 2022 08:42:06 +0000 (11:42 +0300)]
linprocfs: Add /proc/vm/max_map_count

On Linux this limits the number of maps per mm struct.
We don't limit mappings, return a suitable large value.

Reviewed by: emaste
Differential revision: https://reviews.freebsd.org/D35351
MFC after: 2 weeks

2 years agolibpmc: Fix INVERT flag mapping for both Intel and AMD.
Alexander Motin [Tue, 31 May 2022 04:02:06 +0000 (00:02 -0400)]
libpmc: Fix INVERT flag mapping for both Intel and AMD.

Looks like somebody's trivial copy/paste bug.

MFC after: 1 month

2 years agosoo_aio_*: use socket buffer mutexes in struct socket directly
Gleb Smirnoff [Tue, 31 May 2022 03:38:34 +0000 (20:38 -0700)]
soo_aio_*: use socket buffer mutexes in struct socket directly

A miss from commit 4328318445a.

2 years agohwpmc: Add basic Intel Alderlake CPUs support.
Alexander Motin [Tue, 31 May 2022 03:17:37 +0000 (23:17 -0400)]
hwpmc: Add basic Intel Alderlake CPUs support.

The PMC subsystem is not designed for non-uniform CPU capabilities
(P/E-cores are different), but at least several working architectural
events like cpu_clk_unhalted.thread_p should be better than nothing.

MFC after: 1 month

2 years agohwpmc: Update Intel's programmable counters restrictions.
Alexander Motin [Tue, 31 May 2022 02:51:00 +0000 (22:51 -0400)]
hwpmc: Update Intel's programmable counters restrictions.

Primarily remove unneeded restrictions from later CPUs.

MFC after: 1 month

2 years agozdiff: avoid non-conformant features
Kyle Evans [Fri, 20 May 2022 20:38:03 +0000 (15:38 -0500)]
zdiff: avoid non-conformant features

`setvar` is a non-conformant feature that looks slightly neater but is
not portable to other /bin/sh implementations.  Making the script
portable is straightforward, so let's do it.

Tests are added to make sure that I didn't break anything major in the
process.

Reviewed by: bapt (previous version), jilles
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35275

2 years agolibpmc: Disable hardcoding of Intel fixed counters.
Alexander Motin [Mon, 30 May 2022 23:58:40 +0000 (19:58 -0400)]
libpmc: Disable hardcoding of Intel fixed counters.

Intel json's now have pretty reasonable fixed counters representation
via event=0 and umask.  Hardcoded values create more confusion than fix.

MFC after: 1 month

2 years agohwpmc: Correct selection of Intel fixed counters.
Alexander Motin [Mon, 30 May 2022 23:46:48 +0000 (19:46 -0400)]
hwpmc: Correct selection of Intel fixed counters.

Intel json's use event=0 to specify fixed counter number via umask.
Alternatively fixed counters have equivalent programmable event/umask.

MFC after: 1 month

2 years agoirdma: fix LINT-NOIP/NOINET/NOINET6 builds
Mitchell Horne [Mon, 30 May 2022 20:47:32 +0000 (17:47 -0300)]
irdma: fix LINT-NOIP/NOINET/NOINET6 builds

This module depends on the presence of both INET and INET6 options in
order to compile.

Reviewed by: erj
Fixes: cdcd52d41e24 ("irdma: Add RDMA driver for Intel(R) Ethernet...")
Differential Revision: https://reviews.freebsd.org/D35343

2 years agoibcore: Fix missing ib_cm_destroy_id() in ib_cm_insert_listen()
Hans Petter Selasky [Mon, 30 May 2022 18:19:33 +0000 (20:19 +0200)]
ibcore: Fix missing ib_cm_destroy_id() in ib_cm_insert_listen()

The algorithm pre-allocates a cm_id since allocation cannot be done while
holding the cm.lock spinlock, however it doesn't free it on one error
path, leading to a memory leak.

Linux commit:
c14dfddbd869bf0c2bafb7ef260c41d9cebbcfec

PR: 264248
MFC after: 1 week
Sponsored by: NVIDIA Networking

2 years agomlx4core: Fix a memory leak when deleting slave's resources
Hans Petter Selasky [Mon, 30 May 2022 18:11:50 +0000 (20:11 +0200)]
mlx4core: Fix a memory leak when deleting slave's resources

mlx4_delete_all_resources_for_slave() in the resource tracker should free
all memory allocated for a slave. While releasing memory of fs_rule,
it misses releasing memory of fs_rule->mirr_mbox.

Linux commit:
461d5f1b59490ce0096dfda45e10038c122a7892

PR: 264249
MFC after: 1 week
Sponsored by: NVIDIA Networking

2 years agolibpmc: jevents: Sync with the latest Linux kernel.
Alexander Motin [Mon, 30 May 2022 18:07:31 +0000 (14:07 -0400)]
libpmc: jevents: Sync with the latest Linux kernel.

commit f4df0dbbe62ee8e4405a57b27ccd54393971c773
Date:   Wed May 25 22:04:10 2022 +0800

MFC after: 1 month

2 years agoRevert "libpmc: jevents: Partial style(9) pass"
Alexander Motin [Mon, 30 May 2022 14:07:31 +0000 (10:07 -0400)]
Revert "libpmc: jevents: Partial style(9) pass"

This file is shared with Linux.  Having local style patches does not
help with updating it.

This reverts commit 3ea691c2612952dc5e6963649ad64312bd6dff4f.

2 years agolinux(4): Properly restore the thread signal mask after signal delivery on i386
Dmitry Chagin [Mon, 30 May 2022 17:03:49 +0000 (20:03 +0300)]
linux(4): Properly restore the thread signal mask after signal delivery on i386

Replace sigframe sf_extramask by native sigset_t and use it to
store/restore the thread signal mask without conversion to/from
Linux signal mask.

Pointy hat to: dchagin
MFC after: 2 weeks

2 years agolinux(4): Prefer sizeof(object) vs sizeof(type)
Dmitry Chagin [Mon, 30 May 2022 17:03:14 +0000 (20:03 +0300)]
linux(4): Prefer sizeof(object) vs sizeof(type)

MFC after: 2 weeks

2 years agolinux(4): Error is not a bool, use proper comparison
Dmitry Chagin [Mon, 30 May 2022 17:00:30 +0000 (20:00 +0300)]
linux(4): Error is not a bool, use proper comparison

MFC afer: 2 weeks

2 years agolinux(4): Use the copyin_sigset() in the remaining places
Dmitry Chagin [Mon, 30 May 2022 16:59:45 +0000 (19:59 +0300)]
linux(4): Use the copyin_sigset() in the remaining places

MFC after: 2 weeks

2 years agolinux(4): Refactor SIGPWR mapping
Dmitry Chagin [Mon, 30 May 2022 16:55:49 +0000 (19:55 +0300)]
linux(4): Refactor SIGPWR mapping

Map Linux RT signals to the native RT signals starting from SIGRTMIN,
and Linux SIGPWR signal map to after the last RT signal.

MFC after: 2 weeks

2 years agolinux(4): Fix the type of a constant in the signal mask macro
Dmitry Chagin [Mon, 30 May 2022 16:53:52 +0000 (19:53 +0300)]
linux(4): Fix the type of a constant in the signal mask macro

Since l_sigset_t is 64-bit unsigned on all Linuxulators, fix the type
of a constant in the signal mask manipulation macro.
The suffix L indicates type long which is 32-bit on i386, therefore,
bitwise operations between a 32-bit constant and 64-bit signal mask
lead to the wrong result.

Pointy hat to: dchagin
MFC after: 2 weeks

2 years agolinux(4): Properly build argument list for the signal handler
Dmitry Chagin [Mon, 30 May 2022 16:53:12 +0000 (19:53 +0300)]
linux(4): Properly build argument list for the signal handler

Provide arguments 2 and 3 if signal handler installed with SA_SIGINFO.

MFC after: 2 weeks

2 years agolinux(4): Microoptimize rt_sendsig(), convert signal mask once
Dmitry Chagin [Mon, 30 May 2022 16:49:45 +0000 (19:49 +0300)]
linux(4): Microoptimize rt_sendsig(), convert signal mask once

On amd64 Linux saves the thread signal mask in both contexts, in the machine
dependent and in the machine independent. Both contexts are user accessible.
Convert the mask once, then copy it.

MFC after: 2 weeks

2 years agolinux(4): Avoid direct manipulation of td_sigmask
Dmitry Chagin [Mon, 30 May 2022 16:48:20 +0000 (19:48 +0300)]
linux(4): Avoid direct manipulation of td_sigmask

Use kern_sigprocmask() instead of direct manipulation of td_sigmask
to reschedule newly blocked signals.

MFC after: 2 weeks

2 years agolinux(4): Reduce duplication between MD parts of the Linuxulator
Dmitry Chagin [Mon, 30 May 2022 16:47:26 +0000 (19:47 +0300)]
linux(4): Reduce duplication between MD parts of the Linuxulator

Move sigprocmask actions defines under compat/linux,
they are identical across all Linux architectures.

MFC after: 2 weeks

2 years agosockbuf: retain backward compatibility with userland after d59bc188d652
Alexander V. Chernikov [Mon, 30 May 2022 14:56:25 +0000 (14:56 +0000)]
sockbuf: retain backward compatibility with userland after d59bc188d652

Add spare fields to xsockbuf in place of sb_mcnt / sb_ccnt to avoid
 rebuilding userland binaries like sockstat(1).

Reviewed by: glebius

2 years agosrc.conf.5: Regenerate
Mark Johnston [Mon, 30 May 2022 14:53:13 +0000 (10:53 -0400)]
src.conf.5: Regenerate

2 years agosrc.conf.5: Update the WITHOUT_ZFS description
Mark Johnston [Mon, 30 May 2022 14:45:57 +0000 (10:45 -0400)]
src.conf.5: Update the WITHOUT_ZFS description

... to take into account programs and libraries which might implement
some ZFS-specific features without being exclusive to ZFS.

Reviewed by: emaste
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35337

2 years agorc: Add a zpoolreguid rc.d script
Mark Johnston [Mon, 30 May 2022 14:43:44 +0000 (10:43 -0400)]
rc: Add a zpoolreguid rc.d script

If one boots up multiple copies of a template VM image containing a
zpool, the pool GUIDs will be identical, making it impossible to, e.g.,
share datasets between them.

This diff introduces a simple workaround for the problem: one can use
the script to, upon first boot, assign a new GUID to one or more zpools.
This will be useful when building ZFS-based VM images from release(7).

Reviewed by: mav, allanjude, asomers
Reviewed by: Pau Amma (docs)
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D35336

2 years agogitignore: Ignore compile_commands.events.json
Mark Johnston [Sun, 29 May 2022 17:32:24 +0000 (13:32 -0400)]
gitignore: Ignore compile_commands.events.json

This is a temporary file that appears when a build is wrapped using
devel/bear.

MFC after: 1 week

2 years agopkgbase: Move pw to the runtime package
Doug Rabson [Mon, 30 May 2022 13:22:08 +0000 (14:22 +0100)]
pkgbase: Move pw to the runtime package

This allows building a container image with enough functionality for
downloading and installing packages without having to include the
utilities package.

Reviewed by: manu
MFC after:   2 weeks

2 years agopf: make sure the rule tree is allocated in DIOCCHANGERULE
Mateusz Guzik [Fri, 27 May 2022 22:15:34 +0000 (00:15 +0200)]
pf: make sure the rule tree is allocated in DIOCCHANGERULE

Original patch by: peter
Sponsored by: Rubicon Communications, LLC ("Netgate")

2 years agohwpmc: Use hardware PMCs freezing on PMI on Intel v2+.
Alexander Motin [Mon, 30 May 2022 13:07:30 +0000 (09:07 -0400)]
hwpmc: Use hardware PMCs freezing on PMI on Intel v2+.

Since version 2 Intel CPUs can freeze PMCs when intering PMI to reduce
PMI effects on collected statistics.  Since version 4 hardware supports
"streamlined" mechanism, not requiring IA_GLOBAL_CTRL MSR access.

MFC after: 1 month

2 years agolib/libgssapi: Trailing whitespace cleanup
Cy Schubert [Fri, 27 May 2022 20:48:23 +0000 (13:48 -0700)]
lib/libgssapi: Trailing whitespace cleanup

Clean up trailing whitespace (trailing spaces and trailing tabs).

MFC after: 1 week

2 years agosockstat: be more verbose when reporting kernel/userland size mismatch.
Alexander V. Chernikov [Mon, 30 May 2022 10:54:53 +0000 (10:54 +0000)]
sockstat: be more verbose when reporting kernel/userland size mismatch.

MFC after: 2 weeks

2 years agonetinet6: fix ndp proxying
KUROSAWA Takahiro [Mon, 30 May 2022 07:51:15 +0000 (07:51 +0000)]
netinet6: fix ndp proxying

We could insert proxy NDP entries by the ndp command, but the host
with proxy ndp entries had not responded to Neighbor Solicitations.
Change the following points for proxy NDP to work as expected:
* join solicited-node multicast addresses for proxy NDP entries
  in order to receive Neighbor Solicitations.
* look up proxy NDP entries not on the routing table but on the
  link-level address table when receiving Neighbor Solicitations.

Reviewed By: melifaro
Differential Revision: https://reviews.freebsd.org/D35307
MFC after: 2 weeks

2 years agolltable: introduce the llt_post_resolved callback
KUROSAWA Takahiro [Mon, 30 May 2022 07:38:54 +0000 (07:38 +0000)]
lltable: introduce the llt_post_resolved callback

In order to decrease ifdef INET/INET6s in the lltable implementation,
introduce the llt_post_resolved callback and implement protocol-dependent
code in the protocol-dependent part.

Reviewed By: melifaro
Differential Revision: https://reviews.freebsd.org/D35322
MFC after: 2 weeks

2 years agolltable: use sa_family_t instead of int for lltable.llt_af
KUROSAWA Takahiro [Mon, 30 May 2022 07:36:52 +0000 (07:36 +0000)]
lltable: use sa_family_t instead of int for lltable.llt_af

Reviewed By: melifaro, #network
Differential Revision: https://reviews.freebsd.org/D35323
MFC after: 2 weeks

2 years agox86/mp: don't create empty cpu groups
Corvin Köhne [Mon, 30 May 2022 09:19:14 +0000 (11:19 +0200)]
x86/mp: don't create empty cpu groups

When some APICs are disabled by tunables, some cpu groups could end up
empty. An empty cpu group causes the system to panic because not all
functions handle them correctly. Additionally, it's wasted time to
handle and inspect empty cpu groups. Therefore, just don't create them.

Reviewed by: kib, avg, cem
Sponsored by: Beckhoff Automation GmbH & Co. KG
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D24927

2 years agovmm: add tunable to trap WBINVD
Corvin Köhne [Mon, 30 May 2022 08:02:52 +0000 (10:02 +0200)]
vmm: add tunable to trap WBINVD

x86 is cache coherent. However, there are special cases where cache
coherency isn't ensured (e.g. when switching the caching mode). In these
cases, WBINVD can be used. WBINVD writes all cache lines back into main
memory and invalidates the whole cache.

Due to the invalidation of the whole cache, WBINVD is a very heavy
instruction and degrades the performance on all cores. So, we should
minimize the use of WBINVD as much as possible.

In a virtual environment, the WBINVD call is mostly useless. The guest
isn't able to break cache coherency because he can't switch the physical
cache mode. When using pci passthrough WBINVD might be useful.

Nevertheless, trapping and ignoring WBINVD is an unsafe operation. For
that reason, we implement it as tunable.

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

2 years agobhyve: use bhyve_config for SMBIOS strings
Corvin Köhne [Mon, 30 May 2022 08:01:36 +0000 (10:01 +0200)]
bhyve: use bhyve_config for SMBIOS strings

Some software uses SMBIOS entries to identify the system on which it's
running. In order to make it possible to use such software inside a VM,
SMBIOS entries should be configurable. Therefore, bhyve_config can be
used. While only a few SMBIOS entries might be of interest, it makes
sense that all SMBIOS entries are configurable. This way all SMBIOS
tables are build the same way and there's no special handling for some
tables.

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

2 years agosctp: improve handling of listen() call
Michael Tuexen [Sun, 29 May 2022 18:40:30 +0000 (20:40 +0200)]
sctp: improve handling of listen() call

Fail the listen() call for 1-to-1 style sockets when the SCTP
association has been shutdown or aborted.

Reported by: syzbot+6c484f116b9dc88f7db1@syzkaller.appspotmail.com
MFC after: 3 days

2 years agohwpmc: Add Intel Core register defines up to version 5.
Alexander Motin [Sun, 29 May 2022 02:11:59 +0000 (22:11 -0400)]
hwpmc: Add Intel Core register defines up to version 5.

MFC after: 1 month

2 years agonfsstat: Add an entry to output NFSPROC_APPENDWRITE count
Rick Macklem [Sat, 28 May 2022 23:27:02 +0000 (16:27 -0700)]
nfsstat: Add an entry to output NFSPROC_APPENDWRITE count

Commit 5218d82c81f9 added a new NFSv4.1/4.2 procedure called
AppendWrite that uses a Verify to avoid a separate Getattr RPC
for the common case where the client knows the correct file
size for O_APPEND writes.

This patch modifies nfsstat so that it displays a count of
these new RPCs for the "-E -c" option.

2 years agomount_nfs: Only create a mounttab file entry is nmount(2) succeeds
Rick Macklem [Sat, 28 May 2022 22:48:40 +0000 (15:48 -0700)]
mount_nfs: Only create a mounttab file entry is nmount(2) succeeds

mount_nfs creates entries in the mounttab file and umount removes
them.  Entries in the mounttab file ae used by rpc.umntall to
notify the NFS server that NFSv3 entries need to be removed when
they have not been removed by umount.

Without this patch, an enty will be created in the mounttab file,
even if the nmount(2) syscall fails for the mount.  This patch
modifies the code so that the mounttab entry is only created
after nmount(2) succeeds.

This change only affects NFSv3 and only affects how showmount
displays NFSv3 mounts.

MFC after: 2 weeks

2 years agoApply clang fix for assertion failure building putty 0.77 on i386
Dimitry Andric [Sat, 28 May 2022 21:26:37 +0000 (23:26 +0200)]
Apply clang fix for assertion failure building putty 0.77 on i386

Merge commit 45084eab5e63 from llvm git (by Arthur Eubanks):

  [clang] Fix some clang->llvm type cache invalidation issues

  Take the following as an example

    struct z {
      z (*p)();
    };

    z f();

  When we attempt to get the LLVM type of f, we recurse into z. z itself
  has a function pointer with the same type as f. Given the recursion,
  Clang simply treats z::p as a pointer to an empty struct `{}*`. The
  LLVM type of f is as expected. So we have two different potential
  LLVM types for a given Clang type. If we store one of those into the
  cache, when we access the cache with a different context (e.g. we
  are/aren't recursing on z) we may get an incorrect result. There is some
  attempt to clear the cache in these cases, but it doesn't seem to handle
  all cases.

  This change makes it so we only use the cache when we are not in any
  sort of function context, i.e. `noRecordsBeingLaidOut() &&
  FunctionsBeingProcessed.empty()`, which are the cases where we may
  decide to choose a different LLVM type for a given Clang type. LLVM
  types for builtin types are never recursive so they're always ok.

  This allows us to clear the type cache less often (as seen with the
  removal of one of the calls to `TypeCache.clear()`). We
  still need to clear it when we use a placeholder type then replace it
  later with the final type and other dependent types need to be
  recalculated.

  I've added a check that the cached type matches what we compute. It
  triggered in this test case without the fix. It's currently not
  check-clang clean so it's not on by default for something like expensive
  checks builds.

  This change uncovered another issue where the LLVM types for an argument
  and its local temporary don't match. For example in type-cache-3, when
  expanding z::dc's argument into a temporary alloca, we ConvertType() the
  type of z::p which is `void ({}*)*`, which doesn't match the alloca GEP
  type of `{}*`.

  No noticeable compile time changes:
  https://llvm-compile-time-tracker.com/compare.php?from=3918dd6b8acf8c5886b9921138312d1c638b2937&to=50bdec9836ed40e38ece0657f3058e730adffc4c&stat=instructions

  Fixes #53465.

  Reviewed By: rnk

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

PR: 264318
Reported by: mandree
MFC after: 3 days

2 years agolinux(4): Handle multiple mbufs in a control message chain in recvmsg
Dmitry Chagin [Sat, 28 May 2022 20:48:45 +0000 (23:48 +0300)]
linux(4): Handle multiple mbufs in a control message chain in recvmsg

PR: 230274
MFC after: 2 weeks

2 years agolinux(4): Ratelimit message about unupported cmsg
Dmitry Chagin [Sat, 28 May 2022 20:48:16 +0000 (23:48 +0300)]
linux(4): Ratelimit message about unupported cmsg

MFC after: 2 weeks

2 years agolinux(4): Handle IP_ORIGDSTADDR socket option for IPPROTO_IP protocol level
Dmitry Chagin [Sat, 28 May 2022 20:47:40 +0000 (23:47 +0300)]
linux(4): Handle IP_ORIGDSTADDR socket option for IPPROTO_IP protocol level

MFC after: 2 weeks

2 years agolinux(4): Add LINUX_RATELIMIT_MSG_OPT2 for future use
Dmitry Chagin [Sat, 28 May 2022 20:47:23 +0000 (23:47 +0300)]
linux(4): Add LINUX_RATELIMIT_MSG_OPT2 for future use

MFC after: 2 weeks

2 years agolinux(4): Overwrite SO_TIMESTAMP counterpart
Dmitry Chagin [Sat, 28 May 2022 20:46:38 +0000 (23:46 +0300)]
linux(4): Overwrite SO_TIMESTAMP counterpart

A socket cannot mix SO_TIMESTAMP and SO_TIMESTAMPNS: the two modes
are mutually exclusive.

MFC after: 2 weeks