HardenedBSD/hardenedbsd d324fc3lib/libbe be.c, sys/amd64/conf HARDENEDBSD

Merge remote-tracking branch 'origin/hardened/current/master' into 
hardened/current/unstable

* origin/hardened/current/master:
  Fix systat's :only command parser for the multiple arguments case
  libbe(3): simplify import, allow replication streams
  HBSD: Remove IEEE80211_AMPDU_AGE config option

HardenedBSD/hardenedbsd 9e9c1a5lib/libbe be.c, usr.bin/systat devs.c

Merge branch 'freebsd/current/master' into hardened/current/master

* freebsd/current/master:
  Fix systat's :only command parser for the multiple arguments case
  libbe(3): simplify import, allow replication streams

HardenedBSD/hardenedbsd 3f4ef84contrib/ipfilter pcap-bpf.h mli_ipl.c

Merge branch 'freebsd/10-stable/master' into hardened/10-stable/master

* freebsd/10-stable/master:
  MFC r343103:
  MFC r343073:

HardenedBSD/hardenedbsd 64f29f2contrib/ipfilter pcap-bpf.h mli_ipl.c, sys/dev/nvme nvme_qpair.c

Merge remote-tracking branch 'origin/hardened/11-stable/master' into 
hardened/11-stable/unstable

* origin/hardened/11-stable/master:
  MFC r343103:
  MFC r343073:
  MFC r342558: Switch from mutexes to atomics in GEOM_DEV I/O path.
  MFC r342546: Add descriptions to NVMe interrupts.
  MFC r342400: Increase MTX_POOL_SLEEP_SIZE from 128 to 1024.

HardenedBSD/hardenedbsd ead5ed9contrib/ipfilter pcap-bpf.h mli_ipl.c, sys/dev/nvme nvme_qpair.c

Merge branch 'freebsd/11-stable/master' into hardened/11-stable/master

* freebsd/11-stable/master:
  MFC r343103:
  MFC r343073:
  MFC r342558: Switch from mutexes to atomics in GEOM_DEV I/O path.
  MFC r342546: Add descriptions to NVMe interrupts.
  MFC r342400: Increase MTX_POOL_SLEEP_SIZE from 128 to 1024.

HardenedBSD/hardenedbsd ffdfae8contrib/ipfilter pcap-bpf.h mli_ipl.c, sys/dev/nvme nvme_sim.c nvme_qpair.c

Merge branch 'freebsd/12-stable/master' into hardened/12-stable/master

* freebsd/12-stable/master:
  MFC r343103:
  MFC r343073:
  MFC r342558: Switch from mutexes to atomics in GEOM_DEV I/O path.
  MFC r342546: Add descriptions to NVMe interrupts.
  Increase MTX_POOL_SLEEP_SIZE from 128 to 1024.
  MFC r342399: Remove CAM SIM lock from NVMe SIM.

HardenedBSD/hardenedbsd 17dd669usr.bin/systat devs.c

Fix systat's :only command parser for the multiple arguments case

According to systat(1) :only option is supposed to accept multiple drives
but the parser for its arguments stops after first entry. Fix the parser
logic to accept multiple drives.

PR:            59220
Reported by:    Andy Farkas <andyf at speednet.com.au>
MFC after:      1 week

HardenedBSD/hardenedbsd 9f21513contrib/ipfilter pcap-bpf.h

MFC r343103:

Remove redundant ipfilter version of pcap-bpf.h. As of r214535 it was
no longer needed.

HardenedBSD/hardenedbsd 793d557contrib/ipfilter pcap-bpf.h

MFC r343103:

Remove redundant ipfilter version of pcap-bpf.h. As of r214535 it was
no longer needed.

HardenedBSD/hardenedbsd fde2c9econtrib/ipfilter pcap-bpf.h

MFC r343103:

Remove redundant ipfilter version of pcap-bpf.h. As of r214535 it was
no longer needed.

HardenedBSD/hardenedbsd 468073acontrib/ipfilter mli_ipl.c

MFC r343073:

Remove an IRIX-only source file.

HardenedBSD/hardenedbsd e83de28contrib/ipfilter mli_ipl.c

MFC r343073:

Remove an IRIX-only source file.

HardenedBSD/hardenedbsd 73c3608contrib/ipfilter mli_ipl.c

MFC r343073:

Remove an IRIX-only source file.

HardenedBSD/hardenedbsd 793efaelib/libbe be.c

libbe(3): simplify import, allow replication streams

Previously, we directly used libzfs_core's lzc_receive to import to a
temporary snapshot, then cloned the snapshot and setup the properties. This
failed when attempting to import replication streams with questionable
error.

libzfs's zfs_receive is a much better fit here, so we now use it instead
with the destination dataset and let libzfs take care of the dirty details.
be_import is greatly simplified as a result.

Reported by:    Marie Helene Kvello-Aune <freebsd at mhka.no>
MFC after:      1 week
DeltaFile
+7-42lib/libbe/be.c
+7-421 files

HardenedBSD/hardenedbsd 5984292sys/geom geom_dev.c

MFC r342558: Switch from mutexes to atomics in GEOM_DEV I/O path.

Mutexes in I/O path there were used twice per I/O to atomically access
several variables to close and/or destroy the device on last request
completion.  I found the way to fit all required info into one integer,
suitable for atomic operations.  It opened race window on device close,
but addition of timeout to the msleep() there should cover it.

Profiling shows removal of significant spinning time on those mutexes
and IOPS increase from ~600K to >800K to NVMe on 72-core systems.
DeltaFile
+25-22sys/geom/geom_dev.c
+25-221 files

HardenedBSD/hardenedbsd aeaabbbsys/geom geom_dev.c

MFC r342558: Switch from mutexes to atomics in GEOM_DEV I/O path.

Mutexes in I/O path there were used twice per I/O to atomically access
several variables to close and/or destroy the device on last request
completion.  I found the way to fit all required info into one integer,
suitable for atomic operations.  It opened race window on device close,
but addition of timeout to the msleep() there should cover it.

Profiling shows removal of significant spinning time on those mutexes
and IOPS increase from ~600K to >800K to NVMe on 72-core systems.
DeltaFile
+25-22sys/geom/geom_dev.c
+25-221 files

HardenedBSD/hardenedbsd cf04ebasys/dev/nvme nvme_qpair.c

MFC r342546: Add descriptions to NVMe interrupts.

HardenedBSD/hardenedbsd 92d3c48sys/dev/sound/pci/hda hdaa_patches.c hdac.h, sys/net if.c

Merge remote-tracking branch 'origin/hardened/current/master' into 
hardened/current/unstable

* origin/hardened/current/master:
  Add quirk to enable mic and headphones redirection on HP Spectre laptops.
  Rework CASE_IOC_IFGROUPREQ() to require a case before the macro.
  Silence a CI warning regarding the use of strcpy().
  Remove unused *_sysinit_flags() declarations.

HardenedBSD/hardenedbsd 66cf963sys/dev/nvme nvme_qpair.c

MFC r342546: Add descriptions to NVMe interrupts.

HardenedBSD/hardenedbsd 86577e7sys/amd64/conf HARDENEDBSD

HBSD: Remove IEEE80211_AMPDU_AGE config option

FreeBSD commit 8f57d8136c3b3c5be9b77eed6424b85d04a4e0a6 removed the
IEEE80211_AMPDU_AGE kernel config option. Follow the same removal in the
HARDENEDBSD amd64 kernel config.

Signed-off-by:  Shawn Webb <shawn.webb at hardenedbsd.org>
Sponsored-by:   SoldierX

HardenedBSD/hardenedbsd d201a43sys/dev/sound/pci/hda hdaa_patches.c hdac.h, sys/net if.c

Merge branch 'freebsd/current/master' into hardened/current/master

* freebsd/current/master:
  Add quirk to enable mic and headphones redirection on HP Spectre laptops.
  Rework CASE_IOC_IFGROUPREQ() to require a case before the macro.
  Silence a CI warning regarding the use of strcpy().
  Remove unused *_sysinit_flags() declarations.

HardenedBSD/hardenedbsd 739635fsys/kern kern_mtxpool.c

Increase MTX_POOL_SLEEP_SIZE from 128 to 1024.

This value remained unchanged for 15 years, and now this bump reduces
lock spinning in GEOM and BIO layers while doing ~1.6M IOPS to 4 NVMe
on 72-core system from ~25% to ~5% by the cost of additional 28KB RAM.

While there, align struct mtx_pool fields to cache lines.

HardenedBSD/hardenedbsd 4c4ac88sys/kern kern_mtxpool.c

MFC r342400: Increase MTX_POOL_SLEEP_SIZE from 128 to 1024.

This value remained unchanged for 15 years, and now this bump reduces
lock spinning in GEOM and BIO layers while doing ~1.6M IOPS to 4 NVMe
on 72-core system from ~25% to ~5% by the cost of additional 28KB RAM.

While there, align struct mtx_pool fields to cache lines.

HardenedBSD/hardenedbsd 6fd7d2asys/dev/nvme nvme_sim.c

MFC r342399: Remove CAM SIM lock from NVMe SIM.

CAM does not require SIM lock since FreeBSD 10.4, and NVMe code never
required it at all, using per-queue locks instead.  This formally allows
parallel request submission in CAM mode as much as single per-device and
per-queue locks of CAM allow.

HardenedBSD/hardenedbsd ab7e565lib/libc/string strcat.3 strcpy.3

Merge branch 'freebsd/10-stable/master' into hardened/10-stable/master

* freebsd/10-stable/master:
  MFC: 325765 (imp) Add notes about overlapping copies.

HardenedBSD/hardenedbsd 01c4a98lib/libc/string strcpy.3 strcat.3, sys/dev/amdsmn amdsmn.c

Merge remote-tracking branch 'origin/hardened/11-stable/master' into 
hardened/11-stable/unstable

* origin/hardened/11-stable/master:
  MFC: 325765 (imp) Add notes about overlapping copies.
  MFC r342977 (by cem): amdtemp(4): Add support for Family 15h, Model >=60h
  MFC r340426 (by cem): amdtemp(4): Fix temperature reporting on AMD 2990WX
  MFC r340425 (by cem): amdsmn(4)/amdtemp(4): Attach to Ryzen 2 hostbridges

HardenedBSD/hardenedbsd 125a22flib/libc/string strcat.3 strcpy.3, sys/dev/amdsmn amdsmn.c

Merge branch 'freebsd/11-stable/master' into hardened/11-stable/master

* freebsd/11-stable/master:
  MFC: 325765 (imp) Add notes about overlapping copies.
  MFC r342977 (by cem): amdtemp(4): Add support for Family 15h, Model >=60h
  MFC r340426 (by cem): amdtemp(4): Fix temperature reporting on AMD 2990WX
  MFC r340425 (by cem): amdsmn(4)/amdtemp(4): Attach to Ryzen 2 hostbridges

HardenedBSD/hardenedbsd b652608sys/dev/amdsmn amdsmn.c, sys/dev/amdtemp amdtemp.c

Merge branch 'freebsd/12-stable/master' into hardened/12-stable/master

* freebsd/12-stable/master:
  MFC r342977 (by cem): amdtemp(4): Add support for Family 15h, Model >=60h
  MFC r341095:

HardenedBSD/hardenedbsd a2ed312sys/dev/sound/pci/hda hdaa_patches.c hdac.h

Add quirk to enable mic and headphones redirection on HP Spectre laptops.

Tested on HP AF006UR.

MFC after:      2 weeks

HardenedBSD/hardenedbsd 583875blib/libc/string strcat.3 strcpy.3

MFC: 325765 (imp) Add notes about overlapping copies.

Add notes to each of these that specifically state that results are
undefined if the strings overlap. In the case of memcpy, we document
the overlapping behavior on FreeBSD (pre-existing). For str*, it is
left unspecified, however, since the default (and x86) implementations
do not handle overlapping strings properly.

PR: 223653
Approved by:    phk (mentor)

HardenedBSD/hardenedbsd 7260b9elib/libc/string strcat.3 strcpy.3

MFC: 325765 (imp) Add notes about overlapping copies.

Add notes to each of these that specifically state that results are
undefined if the strings overlap. In the case of memcpy, we document
the overlapping behavior on FreeBSD (pre-existing). For str*, it is
left unspecified, however, since the default (and x86) implementations
do not handle overlapping strings properly.

PR: 223653
Approved by:    phk (mentor)

HardenedBSD/hardenedbsd a5c195dsys/dev/amdsmn amdsmn.c, sys/dev/amdtemp amdtemp.c

MFC r342977 (by cem): amdtemp(4): Add support for Family 15h, Model >=60h

Family 15h is a bit of an oddball.  Early models used the same temperature
register and spec (mostly[1]) as earlier CPU families.

Model 60h-6Fh and 70-7Fh use something more like Family 17h's Service
Management Network, communicating with it in a similar fashion.  To support
them, add support for their version of SMU indirection to amdsmn(4) and use
it in amdtemp(4) on these models.

While here, clarify some of the deviceid macros in amdtemp(4) that were
added with arbitrary, incorrect family numbers, and remove ones that were
not used.  Additionally, clarify intent and condition of heterogenous
multi-socket system detection.

[1]: 15h adds the "adjust range by -49°C if a certain condition is met,"
which previous families did not have.

Reported by:    D. C. <tjoard AT gmail.com>
PR:             234657
Tested by:      D. C. <tjoard AT gmail.com>

HardenedBSD/hardenedbsd 27e3ea8sys/dev/amdtemp amdtemp.c

MFC r340426 (by cem): amdtemp(4): Fix temperature reporting on AMD 2990WX

Update the AMD family 17h temperature reporting based on AMD Tech Doc 56255
OSRR, section 4.2.1.

For CPUS w/CUR_TEMP_RANGE_SEL set, scale the reported temperature into the
range -49..206; i.e., subtract 49°C.

Submitted by:   gallatin@
Reported by:    bcran@

HardenedBSD/hardenedbsd 5e40741sys/dev/amdsmn amdsmn.c, sys/dev/amdtemp amdtemp.c

MFC r340425 (by cem): amdsmn(4)/amdtemp(4): Attach to Ryzen 2 hostbridges

As reported, tested, and patch supplied by Johannes.

There may be future work to do to support multiple sensors, but for now, any
sensor at all is a strict improvement for Ryzen 2 systems.

PR:             228480
Submitted by:   Johannes Lundberg <johalun0 AT gmail.com> (earlier version)
Reported by:    deischen@, Johannes, and numerous others

HardenedBSD/hardenedbsd 8a46c2csys/dev/amdsmn amdsmn.c, sys/dev/amdtemp amdtemp.c

MFC r342977 (by cem): amdtemp(4): Add support for Family 15h, Model >=60h

Family 15h is a bit of an oddball.  Early models used the same temperature
register and spec (mostly[1]) as earlier CPU families.

Model 60h-6Fh and 70-7Fh use something more like Family 17h's Service
Management Network, communicating with it in a similar fashion.  To support
them, add support for their version of SMU indirection to amdsmn(4) and use
it in amdtemp(4) on these models.

While here, clarify some of the deviceid macros in amdtemp(4) that were
added with arbitrary, incorrect family numbers, and remove ones that were
not used.  Additionally, clarify intent and condition of heterogenous
multi-socket system detection.

[1]: 15h adds the "adjust range by -49°C if a certain condition is met,"
which previous families did not have.

Reported by:    D. C. <tjoard AT gmail.com>
PR:             234657
Tested by:      D. C. <tjoard AT gmail.com>

HardenedBSD/hardenedbsd c3be065sys/net if.c

Rework CASE_IOC_IFGROUPREQ() to require a case before the macro.

This is more compatible with formatting tools and looks more normal.

Reported by:    jhb (on a different review)
Sponsored by:   DARPA, AFRL
Differential Revision:  https://reviews.freebsd.org/D18442
DeltaFile
+6-6sys/net/if.c
+6-61 files

HardenedBSD/hardenedbsd 29cda35sys/net iflib.c iflib_private.h

MFC r341095:

  Use busdma unconditionally in iflib

  - Remove the complex mechanism to choose between using busdma
  and raw pmap_kextract at runtime.   The reduced complexity makes
  the code easier to read and maintain.

  - Fix a bug in the small packet receive path where clusters were
  repeatedly mapped but never unmapped. We now store the cluster's
  bus address and avoid re-mapping the cluster each time a small
  packet is received.

  This patch fixes bugs I've seen where ixl(4) will not even
  respond to ping without seeing DMAR faults.

  I see a small improvement (14%) on packet forwarding tests using
  a Haswell based Xeon E5-2697 v3.  Olivier sees a small
  regression (-3% to -6%) with lower end hardware.

Reviewed by:    mmacy
Sponsored by:   Netflix, Inc
Differential Revision:  https://reviews.freebsd.org/D17901

HardenedBSD/hardenedbsd e1fb642usr.sbin/kbdmap kbdmap.c

Silence a CI warning regarding the use of strcpy().

While this is a false positive (a sufficiently large buffer has been
allocated in the line above), the use of strdup() simplifies and clarifies
the code.

MFC after:      2 weeks

HardenedBSD/hardenedbsd bb4c46dsys/sys rwlock.h rmlock.h

Remove unused *_sysinit_flags() declarations.

Submitted by:   Sebastian Huber <sebastian.huber at embedded-brains.de>
MFC after:      3 days

HardenedBSD/hardenedbsd 0a5aee3sbin/pfctl pfctl_altq.c pfctl_parser.c, sys/compat/ndis kern_windrv.c

Merge remote-tracking branch 'origin/hardened/current/master' into 
hardened/current/unstable

* origin/hardened/current/master:
  Add missing dependency to vmxnet3 Makefile and clean it up a bit otherwise.
  [ndis] Fix unregistered use of FPU by NDIS in kernel on amd64
  pf tests: Check size validation in DIOCGETSRCNODES
  Remove unused function gsc_destroy()
  pf: Validate psn_len in DIOCGETSRCNODES
  iwn(4): drop i_seq field initialization for A-MPDU frames.
  onvert vmx(4) to being an iflib driver.
  Fix various resource leaks that can occur in the error paths of iflib_device_register() 
and iflib_pseudo_register().
  Reduce pf.conf parsing cost for configs that define N queues from O(N^2) to O(N)

HardenedBSD/hardenedbsd 008749fsbin/pfctl pfctl_altq.c pfctl_parser.c, sys/compat/ndis kern_windrv.c

Merge branch 'freebsd/current/master' into hardened/current/master

* freebsd/current/master:
  Add missing dependency to vmxnet3 Makefile and clean it up a bit otherwise.
  [ndis] Fix unregistered use of FPU by NDIS in kernel on amd64
  pf tests: Check size validation in DIOCGETSRCNODES
  Remove unused function gsc_destroy()
  pf: Validate psn_len in DIOCGETSRCNODES
  iwn(4): drop i_seq field initialization for A-MPDU frames.
  onvert vmx(4) to being an iflib driver.
  Fix various resource leaks that can occur in the error paths of iflib_device_register() 
and iflib_pseudo_register().
  Reduce pf.conf parsing cost for configs that define N queues from O(N^2) to O(N)

HardenedBSD/hardenedbsd 535f292sys/compat/linux linux_socket.c, sys/dev/oce oce_if.c oce_mbox.c

Merge remote-tracking branch 'origin/hardened/11-stable/master' into 
hardened/11-stable/unstable

* origin/hardened/11-stable/master:
  MFC r342856: Added support for the SIOCGI2C ioctl.
  MFC r342864: Specify the correct option level when emulating SO_PEERCRED.
  MFC r343041

HardenedBSD/hardenedbsd 53242b6sys/compat/linux linux_socket.c, sys/dev/oce oce_if.c oce_mbox.c

Merge branch 'freebsd/11-stable/master' into hardened/11-stable/master

* freebsd/11-stable/master:
  MFC r342856: Added support for the SIOCGI2C ioctl.
  MFC r342864: Specify the correct option level when emulating SO_PEERCRED.
  MFC r343041

HardenedBSD/hardenedbsd bbf6811sys/compat/linux linux_socket.c, sys/dev/oce oce_if.c oce_mbox.c

Merge branch 'freebsd/12-stable/master' into hardened/12-stable/master

* freebsd/12-stable/master:
  MFC r342856: Added support for the SIOCGI2C ioctl.
  MFC r342864: Specify the correct option level when emulating SO_PEERCRED.
  MFC r343041

HardenedBSD/hardenedbsd 2657db5sys/modules/vmware/vmxnet3 Makefile

Add missing dependency to vmxnet3 Makefile and clean it up a bit otherwise.

MFC after:      1 week

HardenedBSD/hardenedbsd 7b249absys/dev/oce oce_if.c oce_mbox.c

MFC r342856: Added support for the SIOCGI2C ioctl.

Submitted by:   Ram Kishore Vegesna <ram.vegesna at broadcom.com>
Obtained from:  Broadcom

HardenedBSD/hardenedbsd 1e7b6eesys/dev/oce oce_if.c oce_mbox.c

MFC r342856: Added support for the SIOCGI2C ioctl.

Submitted by:   Ram Kishore Vegesna <ram.vegesna at broadcom.com>
Obtained from:  Broadcom

HardenedBSD/hardenedbsd f59c762sys/compat/ndis kern_windrv.c pe_var.h

[ndis] Fix unregistered use of FPU by NDIS in kernel on amd64

amd64 miniport drivers are allowed to use FPU which triggers "Unregistered use
of FPU in kernel" panic.

Wrap all variants of MSCALL with fpu_kern_enter/fpu_kern_leave.  To reduce
amount of allocations/deallocations done via
fpu_kern_alloc_ctx/fpu_kern_free_ctx maintain cache of fpu_kern_ctx elements.

Based on the patch by Paul B Mahol

PR:            165622
Submitted by:   Vlad Movchan <vladislav.movchan at gmail.com>
MFC after:      1 month

HardenedBSD/hardenedbsd bb8bc10tests/sys/netpfil/pf/ioctl validation.c

pf tests: Check size validation in DIOCGETSRCNODES

Ensure that invalid sizes for DIOCGETSRCNODES do not cause panics.

MFC after:       1 week

HardenedBSD/hardenedbsd da5a978sbin/pfctl pfctl_altq.c

Remove unused function gsc_destroy()

gsc_destroy() is no longer needed as of r343287.

MFC after:      1 week