]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
18 months agonetmap: Correct a comment
Mark Johnston [Mon, 23 Jan 2023 19:42:19 +0000 (14:42 -0500)]
netmap: Correct a comment

Reviewed by: vmaffione
MFC after: 1 week
Sponsored by: Zenarmor
Sponsored by: OPNsense
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38063

(cherry picked from commit 854b2f302dcc73dfef2e4458d382f8149ce9167c)

18 months agonetmap: Fix a queue length check in the generic port rx path
Mark Johnston [Mon, 23 Jan 2023 19:41:55 +0000 (14:41 -0500)]
netmap: Fix a queue length check in the generic port rx path

The check is ok by default, since the default value of
netmap_generic_ringsize is 1024.  But we should check against the
configured "ring" size.

Reviewed by: vmaffione
MFC after: 1 week
Sponsored by: Zenarmor
Sponsored by: OPNsense
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38062

(cherry picked from commit 539437c8281d24450bacded3734276acd9983e90)

18 months agoipsec: Clear pad bytes in PF_KEY messages
Mark Johnston [Mon, 16 Jan 2023 15:46:20 +0000 (10:46 -0500)]
ipsec: Clear pad bytes in PF_KEY messages

Various handlers for SADB messages will allocate a new mbuf and populate
some structures in it.  Some of these structures, such as struct
sadb_supported, contain small reserved fields that are not initialized
and are thus leaked to userspace.

Fix the problem by adding a helper to allocate zeroed mbufs.  This
reduces code duplication and the overhead of zeroing these messages
isn't harmful.

Reviewed by: zlei, melifaro
Reported by: KMSAN
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D38068

(cherry picked from commit 8a9495517b0ad54da9759a7ba2cc0b56f8e7c8f9)

18 months agousr.bin/stat: Fix error message formatting.
Jamie Landeg-Jones [Sun, 29 Jan 2023 22:37:25 +0000 (14:37 -0800)]
usr.bin/stat: Fix error message formatting.

PR: bin/261657

(cherry picked from commit 37399d5bcf67c6d68e30a34ce2df30e0964d46d9)

18 months agonetwork.subr: Fix infinite loop
Cy Schubert [Wed, 14 Dec 2022 21:41:10 +0000 (13:41 -0800)]
network.subr: Fix infinite loop

When setting up carp tunnel, using a password consisting of only the
characters used as hexadecimal characters, i.e. abc-def, there will be
an infinite loop in the shell function ifalias_af_common_handler().
To circumvent this we test for " pass ".

PR: 268378
Reported by: jyoung15@gmail.com
Differential Revision: https://reviews.freebsd.org/D37748

(cherry picked from commit e3e57edf4aac05d041ca55ff2f008c6109ef88d5)

18 months agonetwork.subr: Replace "\ " with "[[:space:]]"
Cy Schubert [Wed, 21 Dec 2022 16:06:02 +0000 (08:06 -0800)]
network.subr: Replace "\ " with "[[:space:]]"

"[[:space:]]" is easier to read than "\ " and is conisitent with
clone_up().

Reported by: eugen
Differential Revision: https://reviews.freebsd.org/D37748

(cherry picked from commit fef0e429f190d396d5b3228166a012e85dd912f2)

18 months agoNote upgrade to sendmail 8.17.1
Gregory Neil Shapiro [Wed, 1 Feb 2023 02:48:05 +0000 (02:48 +0000)]
Note upgrade to sendmail 8.17.1

18 months agoMFC: Note upgrade to sendmail 8.17.1
Gregory Neil Shapiro [Wed, 1 Feb 2023 02:22:39 +0000 (02:22 +0000)]
MFC: Note upgrade to sendmail 8.17.1

(cherry picked from commit 38c2f8fe6207ec50088f9efc36d66776b0608137)

18 months agoMFC: Minor changes to force commit these files so new freebsd*.cf files are
Gregory Neil Shapiro [Tue, 17 Jan 2023 06:49:49 +0000 (06:49 +0000)]
MFC: Minor changes to force commit these files so new freebsd*.cf files are
built to use the new sendmail-8.17.1/cf tree.

(cherry picked from commit 431d2a81d421d4db7a07833b4fd12015cbae5ee7)

18 months agoMFC: Sync with vendor sendmail 8.17.1 cf/cf/submit.mc
Gregory Neil Shapiro [Tue, 17 Jan 2023 06:49:07 +0000 (06:49 +0000)]
MFC: Sync with vendor sendmail 8.17.1 cf/cf/submit.mc

(cherry picked from commit 021562c5020dd63d6b812369a9020b3b8147bfbd)

18 months agoMFC: sendmail 8.17.1 included this fix, though in a different location so
Gregory Neil Shapiro [Sun, 15 Jan 2023 21:25:39 +0000 (21:25 +0000)]
MFC: sendmail 8.17.1 included this fix, though in a different location so
removing the FreeBSD local code in favor of the vendor branch version

(cherry picked from commit f97a19ecb98541455c6c940f4bab2dc7dc425468)

18 months agoMFC: Add -DSTARTTLS CFLAG in order to enable DANE in sendmail builds
Gregory Neil Shapiro [Sun, 15 Jan 2023 21:24:38 +0000 (21:24 +0000)]
MFC: Add -DSTARTTLS CFLAG in order to enable DANE in sendmail builds

(cherry picked from commit 3413ee88c39dbfedfa7d00db536a8e8dc073a562)

18 months agoMFC: Update for new library files in sendmail 8.17.1
Gregory Neil Shapiro [Sun, 15 Jan 2023 21:23:27 +0000 (21:23 +0000)]
MFC: Update for new library files in sendmail 8.17.1

(cherry picked from commit d89513ed20502ddb320474a721d872ef32b31402)

18 months agoMerge commit '28fbd2825d216dafca4d991ad96d05b312f4f9a3'
Gregory Neil Shapiro [Sun, 15 Jan 2023 21:20:22 +0000 (21:20 +0000)]
Merge commit '28fbd2825d216dafca4d991ad96d05b312f4f9a3'

Merge vendor sendmail 8.17.1 into HEAD

(cherry picked from commit 2fb4f839f3fc72ce2bab12f9ba4760f97f73e97f)

18 months agoMakefile.inc1: Print the right PATH for missing install tool error
Jessica Clarke [Sun, 29 Jan 2023 23:45:49 +0000 (23:45 +0000)]
Makefile.inc1: Print the right PATH for missing install tool error

We override PATH for which but then go and print the non-overridden
PATH, which leads to rather confusing messages.

Fixes: 5bb9250e0af4 ("Add necessary Makefile.inc1 infrastructure for building on non-FreeBSD")
(cherry picked from commit 4ebd18cf357af71941675ff3ae7fb3bf56a37e0e)

18 months agoBring our tzcode up to date.
Dag-Erling Smørgrav [Tue, 10 Jan 2023 15:14:27 +0000 (16:14 +0100)]
Bring our tzcode up to date.

* Replay 2010[acflm] which had been merged but not recorded.
* Merge 2010n.
* Reorganize (unsplit) the code to match the upstream layout.
* Merge 2022[cdefg].

MFC after:      1 week
Sponsored by:   Klara, Inc.

(cherry picked from commit bc42155199b5b0b479311e05b07aee7f6f9c5172)

tzcode: Address some compiler warnings.

MFC after: 1 week
Sponsored by: Klara, Inc.

(cherry picked from commit d5c85ac6526dcd0ac25ebdb71969c8c788d5e13b)

tzcode: Move configuration into separate header.

MFC after: 1 week
Sponsored by: Klara, Inc.

(cherry picked from commit 394cf6719a3c665eabe24d96669409e0c5a78076)

tzcode: Remove access() again, cf. 02ba1d993fa9.

Reported by: Coverity (CID 1250126)
MFC after: 1 week
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38035

(cherry picked from commit 3e2e5eebfaa0aebb2790bbde7f35d4c6c52e2596)

tzcode: Avoid memory leak if pthread_setspecific() fails.

Reported by: Coverity (CID 10184721018474)
MFC after: 1 week
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38036

(cherry picked from commit 96e68c393f65046c0cf69d29f89efcfee949e5de)

tzcode: Fully initialize structs before use.

Reported by: Coverity (CID 15025421502548)
MFC after: 1 week
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38037

(cherry picked from commit 55572cff58c4208a9e532356a245676b8eed6a3e)

tzcode: Silence warnings.

* Ignore failure to remove our temp file.
* Avoid a minor memory leak in the -D case.

Reported by: Coverity (CID 150253415025351502538)
MFC after: 1 week
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38038

(cherry picked from commit 2aad7570f4e11ac94bb06c44cdc83ad1962fb97e)

depend-cleanup.sh: handle zic moving one level up.

MFC after: 1 week
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D38044

(cherry picked from commit 4a158fc030b5a31efdbad8b30c9a859df553ae3c)

libc: Update mktime(3) / timegm(3) tests.

Sponsored by: Klara, Inc.
Reviewed by: ngie
Differential Revision: https://reviews.freebsd.org/D38177

(cherry picked from commit d8c9f80891872a54d0b21933136644d915096fe3)

zoneinfo: On amd64, include 32-bit data.

While there, drop the unnecessary posixrules option.

Sponsored by: Klara, Inc.
Reviewed by: imp, allanjude
Differential Revision: https://reviews.freebsd.org/D38142

(cherry picked from commit 783c318fd1181d46554c31a5039db10e7f5eef49)

tzcode: Document zic's -D option.

Sponsored by: Klara, Inc.
Reviewed by: allanjude
Differential Revision: https://reviews.freebsd.org/D38141

(cherry picked from commit a7b1b73935f21a3dcd6fc8d86a37b92f0c9ba93f)

zoneinfo: Always produce fat zoneinfo files.

These aren't just needed for compatibility with i386 binaries (which need
the 32-bit section), but potentially also for compatibility with older
binaries on all platforms.

Sponsored by: Klara, Inc.
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D38194

(cherry picked from commit f1021d27f73efb821213a973e1ab9366278c78f1)

Fix cross-build from STABLE or older CURRENT.

Previously, zic and tzsetup were both listed as install tools and basic
bootstrap tools.  Actually, tzsetup is an install tool while zic is a
non-basic bootstrap tool.

Fixes: 783c318fd118
Sponsored by: Klara, Inc.
Reviewed by: jrtc27, emaste
Differential Revision: https://reviews.freebsd.org/D38195

(cherry picked from commit 7a4a520064cb7fbff79560113682d6fe1a1ae9ee)

Makefile.inc1: Restore adding tzsetup to _basic_bootstrap_tools

ITOOLS is only the list of programs to make a copy of during install, it
doesn't cause anything to be bootstrapped. Thus, by removing tzsetup
from _basic_bootstrap_tools, we end up without it on non-FreeBSD, and so
we error out trying to copy it to INSTALLTMP.

Note that _basic_bootstrap_tools is only used for BOOTSTRAP_ALL_TOOLS
(which is why zic was moved away from it). Should tzsetup evolve such
that the host version is insufficient on older FreeBSD it can be moved
to be more like zic, but that seems unnecessary for what is likely to
remain a simple tool.

This partially reverts commit 7a4a520064cb7fbff79560113682d6fe1a1ae9ee.

Fixes: 7a4a520064cb ("Fix cross-build from STABLE or older CURRENT.")
(cherry picked from commit d4fdfd3f9077216e52f38f7364974959c9e43168)

18 months agotzcode: Implement timezone change detection
Edward Tomasz Napierala [Sun, 12 Sep 2021 03:07:26 +0000 (03:07 +0000)]
tzcode: Implement timezone change detection

Implement optional timezone change detection for local time libc
functions.  This is disabled by default; set WITH_DETECT_TZ_CHANGES
to build it.

Reviewed By: imp
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
X-NetApp-PR: #47
Differential Revision: https://reviews.freebsd.org/D30183

(cherry picked from commit ddedf2a11eb20af1ee52cb3da70a57c21904af8f)

tzcode: Fix operation without WITH_DETECT_TZ_CHANGES

Reviewed By: bdrewery, kevans, cy
Reported By: lwhsu, bdrewery
Fixes: ddedf2a11eb
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D31961

(cherry picked from commit 6f43f86bf36dba158355593bab5f81a7f8e2773c)

tzcode: fix tz change detection logic

clock_gettime() returns 0 if it succeeds, so don't capture that into the
fail logic.  With this, WITH_DETECT_TZ_CHANGES successfully detects a
change after 61 seconds.

Reviewed by: imp, trasz
Differential Revision: https://reviews.freebsd.org/D33494

(cherry picked from commit a2c51da6581dbc38c60c9fc41d1b624ff2c8de97)

18 months agopfctl: rule.label is a two-dimensional array
Kristof Provost [Tue, 24 Jan 2023 06:46:46 +0000 (07:46 +0100)]
pfctl: rule.label is a two-dimensional array

Fix checking for a non-empty first string.

PR: 269075
MFC after: 1 week
Reported by: nreilly@blackberry.com

(cherry picked from commit cd80c52cade3e38d273eecec6f9b0a7cba23bcc8)

18 months agogoldfish_rtc: Fix handling a local time RTC
Jessica Clarke [Sun, 14 Aug 2022 18:50:22 +0000 (19:50 +0100)]
goldfish_rtc: Fix handling a local time RTC

The default QEMU config is to have the RTC in UTC. However, if run with
-rtc base=localtime (and wall_cmos_clock is set to match), the driver
fails to account for adjkerntz due to the use of CLOCKF_SETTIME_NO_ADJ.
Copy the same code used by other CLOCKF_SETTIME_NO_ADJ-using drivers
to fix this, namely manually subtracting utc_offset().

Fixes: d63a631e7244 ("Add Goldfish RTC device driver for RISC-V")
MFC after: 1 week

(cherry picked from commit 762dcf10641251c55dda2e6950fef8bb698027ad)

18 months agolibcrypto: Work around strict aliasing violations in bn_nist.c
Jessica Clarke [Mon, 25 Jul 2022 17:17:50 +0000 (18:17 +0100)]
libcrypto: Work around strict aliasing violations in bn_nist.c

This file is full of strict aliasing violations. Previously it was only
optimised in ways that broke the code by CHERI LLVM, but now it appears
that the in-tree LLVM also breaks it for RISC-V, resulting in broken
ECDSA signature validation with error messages like the following:

  root@unmatched:/usr/src # ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key
  /etc/ssh/ssh_host_ecdsa_key is not a key file.
  root@unmatched:/usr/src # git fetch
  fatal: unable to access 'https://git.FreeBSD.org/src.git/': error:1012606B:elliptic curve routines:EC_POINT_set_affine_coordinates:point is not on curve

Reviewed by: dim, jkim
Obtained from: CheriBSD
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D35885

(cherry picked from commit 3b41ae32124ad7b61b2297b2e7f3aa5d76b30c53)

18 months agomips: Fix sendsig for stack layout randomisation
Jessica Clarke [Tue, 31 Jan 2023 01:27:50 +0000 (01:27 +0000)]
mips: Fix sendsig for stack layout randomisation

PS_STRINGS doesn't account for the stack gap, we need to use the new
PROC_PS_STRINGS macro to correctly point at the trampoline.

This is a direct commit to stable/13 as mips no longer exists in main.

Fixes: d247611467e0 ("exec: Introduce the PROC_PS_STRINGS() macro")

18 months agolibc: Fix longjmp/_longjmp(buf, 0) for MIPS
Jessica Clarke [Mon, 30 Jan 2023 23:55:03 +0000 (23:55 +0000)]
libc: Fix longjmp/_longjmp(buf, 0) for MIPS

Like AArch64 and RISC-V in the past, MIPS fails to handle this special
case, and will cause the corresponding setjmp/_setjmp to return 0 rather
than 1. Fix this so the newly-added regression tests pass.

This is a direct commit to stable/13 as mips no longer exists in main.

Reviewed by: arichardson, jhb
Differential Revision: https://reviews.freebsd.org/D29363

18 months agolibc: Fix longjmp/_longjmp(buf, 0) for AArch64 and RISC-V
Jessica Clarke [Mon, 9 Jan 2023 18:34:43 +0000 (18:34 +0000)]
libc: Fix longjmp/_longjmp(buf, 0) for AArch64 and RISC-V

These architectures fail to handle this special case, and will cause the
corresponding setjmp/_setjmp to return 0 rather than 1. Fix this and add
regression tests (also committed upstream).

PR: 268684
Reviewed by: arichardson, jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D29363

(cherry picked from commit 9fb118bebced1452a46756a13be0161021b10905)

18 months agoMakefile: Avoid sanitizing PATH on non-FreeBSD systems
Jake Freeland [Thu, 19 Jan 2023 22:24:44 +0000 (22:24 +0000)]
Makefile: Avoid sanitizing PATH on non-FreeBSD systems

Allow the build process to find host binaries during the host-symlinks target when
cross-building on non-FreeBSD systems. Whilst most non-FreeBSD systems have all
the needed tools in /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin (the final
path added by host-symlinks itself), Homebrew for macOS on Arm defaults to
/opt/homebrew/bin, other more niche systems may also deviate and users may
expect tools in a customised PATH to be picked up, unlike on FreeBSD where we
want to ensure everything comes from base. In particular, (un)xz are needed
from Homebrew on macOS, and thus cannot be found on Arm without this.

Note that non-FreeBSD builds enforce BUILD_WITH_STRICT_TMPPATH, and so the
actual main build steps will still use a sanitised PATH.

Reviewed by: jrtc27, arichardson
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D37991

(cherry picked from commit 16fbf0191243e7c9dff6615b1424b5d39186b36c)

18 months agostrfmon(3): Match the return type
Jose Luis Duran [Tue, 8 Nov 2022 20:16:49 +0000 (17:16 -0300)]
strfmon(3): Match the return type

(cherry picked from commit f5924ad8fde4d5e9c233b821cb6097c6a46740b5)

18 months agostrfmon(3): Wording improvements
Jose Luis Duran [Tue, 8 Nov 2022 20:53:17 +0000 (17:53 -0300)]
strfmon(3): Wording improvements

(cherry picked from commit 59cc636d94a6c9b28147304fa59351224f801e92)

18 months agostrfmon(3): Add an EXAMPLES section
Jose Luis Duran [Tue, 8 Nov 2022 20:36:57 +0000 (17:36 -0300)]
strfmon(3): Add an EXAMPLES section

(cherry picked from commit cdd9d92dade61a6b5c37b758e9533a076bb5a2de)

18 months agolibcxx: add comment explaining why umtx is only used for 64bits
Konstantin Belousov [Tue, 24 Jan 2023 15:36:24 +0000 (17:36 +0200)]
libcxx: add comment explaining why umtx is only used for 64bits

(cherry picked from commit 4c4a29267cbdd05471322e03bfd5eff8eb68e750)

18 months agolibcxx: use __SIZEOF_LONG__ == 8 instead of __LP64__
Konstantin Belousov [Tue, 24 Jan 2023 10:03:45 +0000 (12:03 +0200)]
libcxx: use __SIZEOF_LONG__ == 8 instead of __LP64__

For MFC, 64bit mips is excluded from the new mode of wait/wake, because
it uses 32bit __cxx_contention_t, as noted by jrtc27.

(cherry picked from commit 25b18d8935a5ee933d5465f5db41ad58c26590f9)

18 months agolibcxx: Implement atomic::wait/notify using _umtx_op(2) for 64bit arches
Konstantin Belousov [Fri, 20 Jan 2023 02:57:26 +0000 (04:57 +0200)]
libcxx: Implement atomic::wait/notify using _umtx_op(2) for 64bit arches

(cherry picked from commit 9c996882b0ed279ca314d995f2eb1d538b94e3f8)

18 months agofreebsd32: Make sendmsg match native ABI for unpadded final control message
Jessica Clarke [Thu, 15 Sep 2022 16:16:22 +0000 (17:16 +0100)]
freebsd32: Make sendmsg match native ABI for unpadded final control message

The API says that CMSG_SPACE should be used for msg_controllen, but in
practice the native ABI allows you to only use CMSG_LEN for the final
(typically only) control message, and real-world software does this,
including Wayland. For freebsd32, this is in practice mostly harmless,
since control messages are generally used to carry file descriptors,
which are already 4 bytes in size and thus no padding is needed, but
they can carry other quantities that may not result in an aligned
length. This was discovered after CheriBSD's freebsd64 equivalent was
updated to match the freebsd32 implementation, as that uses 8 byte
alignment which does break the file descriptor use case, and thus
Wayland.

This used to be addressed by aligning buflen before the first iteration,
but that allowed unwanted invalid inputs and was lost in 1b1428dcc82b,
with no safer equivalent put in its place.

Reviewed by: brooks, kib, markj
Obtained from: CheriBSD
Fixes: 1b1428dcc82b ("Fix a TOCTOU vulnerability in freebsd32_copyin_control().")
Differential Revision: https://reviews.freebsd.org/D36554

(cherry picked from commit 7b673a2c73d0577e2c006aeb110295a522b98135)

18 months agofreebsd32_sendmsg: fix control message ABI
Brooks Davis [Wed, 24 Aug 2022 17:34:39 +0000 (18:34 +0100)]
freebsd32_sendmsg: fix control message ABI

When a freebsd32 caller uses all or most allowed space for control
messages (MCLBYTES == 2K) then the message may no longer fit when
the messages are padded for 64-bit alignment.  Historically we've just
shrugged and said there is no ABI guarantee.  We ran into this on
CheriBSD where a capsicumized 64-bit nm would fail when called with more
than 64 files.

Fix this by not gratutiously capping size of mbuf data we'll allocate
to MCLBYTES and let m_get2 allocate up to MJUMPAGESIZE (4K or larger).
Instead of hard-coding a length check, let m_get2 do it and check for a
NULL return.

Reviewed by: markj, jhb, emaste
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D36322

(cherry picked from commit c46697b9cb97a14f61ac0a58758aab081b9e48c5)

18 months agokvmclock: Fix initialization when EARLY_AP_STARTUP is not defined
Mark Johnston [Fri, 13 Jan 2023 15:01:00 +0000 (10:01 -0500)]
kvmclock: Fix initialization when EARLY_AP_STARTUP is not defined

To attach to the hypervisor, kvmclock needs to write a per-CPU MSR.
When EARLY_AP_STARTUP is not defined, device attach happens too early:
APs are not yet spun up, so smp_rendezvous only runs the callback on the
local CPU.  As a result, the timecounter only gets initialized on the
BSP, and then timekeeping is broken on SMP systems.

Implement handling for !EARLY_AP_STARTUP kernels: keep track of the CPU
on which device attach ran, and then use a SI_SUB_SMP SYSINIT to
register the rest of the CPUs with the hypervisor.

Reported by: Shrikanth R Kamath <kshrikanth@juniper.net>
Reviewed by: kib, jhb (earlier versions)
Sponsored by: Klara, Inc.
Sponsored by: Juniper Networks, Inc.
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D37705

(cherry picked from commit 568f552b0410f4f72db9ce710f7803acca23f79f)

18 months agoAdd kf_file_nlink field to kf_file and populate it
Jiajie Chen [Mon, 23 Jan 2023 16:36:59 +0000 (00:36 +0800)]
Add kf_file_nlink field to kf_file and populate it

This will allow user-space programs (e.g. lsof) to locate deleted files
whose nlink equals zero. Prior to this commit, programs has to use
stat(kf_path) to get nlink, but that will fail if the file is deleted.

[mjg: s/fail/file in the commit message]

Reviewed by: mjg
Differential Revision:  https://reviews.freebsd.org/D38169

(cherry picked from commit dec7db49602df75119f6b57d32f1eb58e0040abc)

18 months agonetpfil tests: improve pfsync_defer.py
Kajetan Staszkiewicz [Fri, 20 Jan 2023 09:43:02 +0000 (10:43 +0100)]
netpfil tests: improve pfsync_defer.py

Return different exit code depending on which failure was encountered.
The pfsync test expect a very particular failure, not just any.

MFC after: 1 week
Sponsored by: InnoGames GmbH
Differential Revision: https://reviews.freebsd.org/D38123

(cherry picked from commit 06012728beff45e94d58410eae7cda2ea980ef77)

18 months agonetpfil tests: improve pft_ping.py
Kajetan Staszkiewicz [Sat, 21 Jan 2023 02:44:52 +0000 (03:44 +0100)]
netpfil tests: improve pft_ping.py

Multiple improvements to pft_ping.py:

* Automatically use IPv6 when IPv6 addresses are used, --ip6 is not needed.
* Building of ping requests and parsing of ping replies is done layer by
  layer. This way most arguments are available both for IPv6 and IPv4,
  for ICMP and TCP.
* Use argument groups for improved readability.
* Change ToS and TTL argument name to TC and HL to reflect the modern
  IPv6 nomenclature. The argument still set related IPv4 header fields
  properly.
* Instead of sniffing for the very specific case of duplicated packets,
  allow for sniffing on multiple interfaces.
* Report which sniffer has failed by setting bits of error code.
* Raise meaningful exceptions when irrecoverable errors happen.
* Make IPv4 fragmentation flags configurable.
* Make IPv6 HL / IPv4 TTL configurable.
* Make TCP MSS configurable.
* Make TCP sequence number configurable.
* Make ICMP payload size configurable.
* Add debug output.
* Move command line argument parsing out of network functions.
* Make the code somehow PEP-8 compliant.

MFC after: 1 week
Sponsored by: InnoGames GmbH
Differential Revision: https://reviews.freebsd.org/D38122

(cherry picked from commit f57218e469a7b1ab40521ea75ebfd45b493851ca)

18 months agonetpfil tests: improve sniffer.py
Kajetan Staszkiewicz [Fri, 20 Jan 2023 01:40:34 +0000 (02:40 +0100)]
netpfil tests: improve sniffer.py

Multiple improvements to sniffer.py:

* Remove ambiguity of configuring recvif, it must be now explicitly specified.
* Don't catch exceptions around creating the sniffer, let it properly
  fail and display the whole stack trace.
* Count correct packets so that duplicates can be found.

MFC after: 1 week
Sponsored by: InnoGames GmbH
Differential Revision: https://reviews.freebsd.org/D38120

(cherry picked from commit a39dedeb31052ec74b0cd394d56f8d7cc8534645)

18 months agonfsserver: Fix handling of SP4_NONE
Rick Macklem [Sun, 15 Jan 2023 22:07:40 +0000 (14:07 -0800)]
nfsserver: Fix handling of SP4_NONE

For NFSv4.1/4.2, when the client specifies SP4_NONE for
state protection in the ExchangeID operation arguments,
the server MUST allow the state management operations for
any user credentials.  (I misread the RFC and thought that
SP4_NONE meant "at the server's discression" and not MUST
be allowed.)

This means that the "sec=XXX" field of the "V4:" exports(5)
line only applies to NFSv4.0.

This patch fixes the server to always allow state management
operations for SP4_NONE, which is the only state management
option currently supported. (I have patches that add support
for SP4_MACH_CRED to the server. These will be in a future commit.)

In practice, this bug does not seem to have caused
interoperability problems.

(cherry picked from commit 5a0050e68a54353af53ac28df90854797ebbef16)

18 months agogrep: properly switch EOL indicator with -z
Kyle Evans [Wed, 4 Jan 2023 05:21:10 +0000 (23:21 -0600)]
grep: properly switch EOL indicator with -z

-z is supposed to use only the NUL byte as EOL, but we were
inadvertently using both newline and NUL due to REG_NEWLINE in cflags.

The odds of anyone relying on this bsdgrep-specific bug are quite low,
so let's just fix it.  At least one port in the wild has been reported
to expect the intended behavior.

Reported by: Hill Ma <maahiuzeon@gmail.com>
Triaged by: the self-proclaimed peanut gallery on Discord

(cherry picked from commit e898a3af97f97f74c0fb22032bbd163f7cc92a05)

18 months agopf tests: test fast port re-use with syncookies
Kristof Provost [Sat, 31 Dec 2022 18:23:15 +0000 (19:23 +0100)]
pf tests: test fast port re-use with syncookies

When a src/dst ip/port tuple is re-used before the pf state fully
expires we clean up the state and create a new one, unless syncookies
are enabled.

Test this, by running two back-to-back nc sessions, with a fixed source
port. Move the interface and IP to a different (vnet) jail, to trick the
network stack into letting us do this.

MFC after:      2 weeks
Event:          Aberdeen hackathon 2022
Differential Revision:  https://reviews.freebsd.org/D36886

(cherry picked from commit dc698b2cd59ebc08b05a261dbba8ee5707450d28)

18 months agopf: fix syncookies in conjunction with tcp fast port reuse
Kristof Provost [Sat, 31 Dec 2022 14:59:10 +0000 (15:59 +0100)]
pf: fix syncookies in conjunction with tcp fast port reuse

Basic scenario: we have a closed connection (In TCPS_FIN_WAIT_2), and
get a new connection (i.e. SYN) re-using the tuple.

Without syncookies we look at the SYN, and completely unlink the old,
closed state on the SYN.
With syncookies we send a generated SYN|ACK back, and drop the SYN,
never looking at the state table.

So when the ACK (i.e. the third step in the three way handshake for
connection setup) turns up, we’ve not actually removed the old state, so
we find it, and don’t do the syncookie dance, or allow the new
connection to get set up.

Explicitly check for this in pf_test_state_tcp(). If we find a state in
TCPS_FIN_WAIT_2 and the syncookie is valid we delete the existing state
so we can set up the new state.
Note that when we verify the syncookie in pf_test_state_tcp() we don't
decrement the number of half-open connections to avoid an incorrect
double decrement.

MFC after:      2 weeks
Differential Revision:  https://reviews.freebsd.org/D37919

(cherry picked from commit 9c041b450d5e604c3e35b5799b60a2c53795feef)

18 months agopf: fix panic on deferred packets
Kristof Provost [Fri, 13 Jan 2023 03:34:20 +0000 (04:34 +0100)]
pf: fix panic on deferred packets

The pfsync_defer_tmo() callout needs to set the correct vnet before it
can transmit packets. It used the rcvif in the mbuf to get this vnet,
but that doesn't work for locally originated traffic. In that case the
rcvif pointer is NULL, and the dereference leads to a panic.

Instead use the sc_sync_if, which is always set (if pfsync is enabled,
at least).

PR: 268246
MFC after: 2 weeks

(cherry picked from commit fd02192c3acaefeb62db11e0c10ab36240b79ba2)

18 months ago13.2: update stable/13 to -PRERELEASE to start the release cycle
Colin Percival [Sat, 28 Jan 2023 00:59:24 +0000 (16:59 -0800)]
13.2: update stable/13 to -PRERELEASE to start the release cycle

Approved by: re (implicit)
Sponsored by: https://www.patreon.com/cperciva

18 months agocal: don't print terminal control characters unless stdout is a TTY
Alan Somers [Fri, 13 Jan 2023 20:19:03 +0000 (13:19 -0700)]
cal: don't print terminal control characters unless stdout is a TTY

A similar change was made in svn r223931, but it was incomplete, working
only when the utility was invoked as "ncal".  Fix the same issue when
invoking as "cal".

PR: 268936
Reported by: Ray Bellis <ray@bellis.me.uk>
Sponsored by: Axcient
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D38045

(cherry picked from commit 92e978439f0c3139775ad96d412959f5a74b17b6)

18 months agoSwitch wg(4) to the new if_clone KPI
Alan Somers [Sun, 18 Dec 2022 20:12:02 +0000 (13:12 -0700)]
Switch wg(4) to the new if_clone KPI

Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D37740

(cherry picked from commit eb3f9a7aece9473d678adddcf6aefe6c1eec0ac4)

18 months agofsx: more consistent debug output with -[RWU]
Alan Somers [Sat, 7 Jan 2023 04:49:28 +0000 (21:49 -0700)]
fsx: more consistent debug output with -[RWU]

(cherry picked from commit da303f5fd4ee8582cf76712212dd0b711d7d9dac)

18 months agofsx: bounds check the inputs
Alan Somers [Sat, 7 Jan 2023 01:54:23 +0000 (18:54 -0700)]
fsx: bounds check the inputs

In particular, don't allow the user to specify a file size that can't be
expressed as an int, since fsx's random-number generator only has a 32
bit range.

(cherry picked from commit 3f8ca7a22ed917a3e3a4ad78538d9f468d6d3bd8)

18 months agoping(8): man page cleanup
Jose Luis Duran [Sun, 20 Nov 2022 02:56:49 +0000 (23:56 -0300)]
ping(8): man page cleanup

* Appease mandoc -T lint and igor

* Use example.com for documentation

* Update the IPv4 TTL section.
  Update the IPv4 TTL section specifically for FreeBSD.
  FreeBSD changed the default TTL to 64 in
  5639e86bdd7ea151958776264bf5a67e60a54d68.  NetBSD and OpenBSD still
  use 255.  Remove some references of extinct operating systems.

Reviewed by: gbe (manpages), asomers
Pull Request: https://github.com/freebsd/freebsd-src/pull/630

(cherry picked from commit 8eb4df948711166a438f4111f7069a412d1456bd)

18 months agoAdd test cases for ping with IP options in the response
Alan Somers [Sat, 29 Oct 2022 22:03:41 +0000 (16:03 -0600)]
Add test cases for ping with IP options in the response

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

(cherry picked from commit e35cfc606a299ef40767e708362529c370f767f5)

18 months agoimprovements to cap_sysctl.3
Alan Somers [Thu, 1 Dec 2022 16:49:57 +0000 (09:49 -0700)]
improvements to cap_sysctl.3

* Correct some function prototypes which were documented with the wrong
  pointer type.
* Clarify return values and requirements for freeing the limit handle.

[skip ci]

Sponsored by: Axcient
Reviewed by: oshogbo
Differential Revision: https://reviews.freebsd.org/D37586

(cherry picked from commit 6c93a2d0bc37f0c912e402f3f94c3c01350dca26)

18 months agoloader: md: Use default func for fmtdev and parsedev
Emmanuel Vadot [Fri, 27 Jan 2023 06:34:02 +0000 (07:34 +0100)]
loader: md: Use default func for fmtdev and parsedev

The default function are enough for md so use them instead of the
disks ones that doesn't work for it anymore.

Reviewed by: imp
Sponsored by: Beckhoff Automation GmbH & Co. KG
MFC after: now
Differential Revision: https://reviews.freebsd.org/D38218

(cherry picked from commit 04afa8cc370e6bb7302b6fe09c8d27a606fe414e)

18 months agoAllow any user to read the NFS stats, for example with nfsstat(1).
Alan Somers [Thu, 1 Dec 2022 21:08:01 +0000 (14:08 -0700)]
Allow any user to read the NFS stats, for example with nfsstat(1).

This was originally allowed by 3cea29603d3 (2011).  But it got broken by
693957f8861 (2016) and apparently nobody noticed.

Sponsored by: Axcient
Reviewed by: rmacklem, ken
Differential Revision: https://reviews.freebsd.org/D37589

(cherry picked from commit d2ce00e9a6176014bbeb792dd9959ef1e60d787e)

18 months agodocument first appearance of fhlink et al
Alan Somers [Wed, 30 Nov 2022 17:23:22 +0000 (10:23 -0700)]
document first appearance of fhlink et al

[skip ci]

Sponsored by: Axcient
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D37575

(cherry picked from commit 34120c0c5234a56945f9a732b05a8d8b97492916)

18 months agoena: Update driver version to v2.6.2
Arthur Kiyanovski [Tue, 13 Dec 2022 16:58:25 +0000 (16:58 +0000)]
ena: Update driver version to v2.6.2

Bug Fixes:
* Remove timer service re-arm on ena_restore_device failure.
* Re-Enable per-packet missing tx completion print

Minor Changes:
* Switch driver owners from Semihalf to Amazon in man file.

MFC after: 2 weeks
Sponsored by: Amazon, Inc.
Pull Request: https://github.com/freebsd/freebsd-src/pull/637

(cherry picked from commit e5de1d8dad25308f3a332f9386e05b851a36c507)

18 months agoena: Switch driver owners from semihalf to amazon in man file
Arthur Kiyanovski [Tue, 13 Dec 2022 12:34:08 +0000 (12:34 +0000)]
ena: Switch driver owners from semihalf to amazon in man file

1. Update ena.4 manual file to include amazon owner emails.
2. State that the driver is developed by amazon but leave
that it was originally written by Semihalf, similarly to other
drivers in the /share/man/ directory of the FreeBSD source code.
3. Advance year in copyright notice to 2022.

MFC after: 2 weeks
Sponsored by: Amazon, Inc.

(cherry picked from commit fb47286c38a5315bdd93389b0547b8ccccdc7327)

18 months agoena: Remove timer service re-arm on ena_restore_device failure
David Arinzon [Sun, 4 Dec 2022 10:37:32 +0000 (12:37 +0200)]
ena: Remove timer service re-arm on ena_restore_device failure

In case the reset sequence fails (ena_destroy_device() followed by
ena_restore_device() calls) during ena_restore_device(), the driver
resources are being freed. After the clean-up, the timer service is
re-armed in order to try and re-initialize the driver state.
But, such an attempt would fail given that the resources are freed.
Moreover, this would actually cause either the system to fail or a
panic.
When the driver fails in ena_restore_device() procedure, the only
recovery is either unloading and loading the driver or instance
reboot.

This change removes the timer service re-arm in case of failure
in ena_restore_device().

MFC after: 2 weeks
Sponsored by: Amazon, Inc.
Fixes: 78554d0c707c ("ena: start timer service on attach")
(cherry picked from commit c4a85b8d684d3db9dc4d3d01d966130e21390529)

18 months agoena: Re-Enable per-packet missing tx completion print
Arthur Kiyanovski [Mon, 19 Dec 2022 13:56:44 +0000 (13:56 +0000)]
ena: Re-Enable per-packet missing tx completion print

Commit [1] first added the ena_tx_buffer.print_once member,
so that a message about a missing tx completion is printed only
once per packet (and not every second when the watchdog runs).
In this commit print_once is initialized to true, and is set back
to false after detecting a missing tx completion and printing
a warning about it to dmesg.

Commit [2] incorrectly reverses the values assigned to print_once.
The variable is initialized to be true but is checked to be false
when a missing tx completion is detected. This is never true, and
therefore the warning print for each missing tx completion is never
printed since this commit.

Commit [3] added time passed since last TX cleanup to the missing
tx completions per-packet print. However, due to the issue in commit
[2], this time is never printed.

This commit reverses back the values assigned to ena_tx_buffer.print_once
erroneously by commit [2], bringing back to life the missing tx
completion per-packet print.

Also add a space after "." in the missing tx completion print.

[1] - 9b8d05b8ac78 ("Add support for Amazon Elastic Network Adapter (ENA) NIC")
[2] - 74dba3ad7851 ("Split function checking for missing TX completion in ENA driver")
[3] - d8aba82b5ca7 ("ena: Store ticks of last Tx cleanup")

Fixes: 74dba3ad7851 ("Split function checking for missing TX completion in ENA driver")
Fixes: d8aba82b5ca7 ("ena: Store ticks of last Tx cleanup")
MFC after: 2 weeks
Sponsored by: Amazon, Inc.

(cherry picked from commit f01b2cd98e93ef5ac3698b97bbaa45ac9c50fe5d)

18 months agoena: Remove write only variables
Warner Losh [Wed, 6 Apr 2022 01:58:03 +0000 (19:58 -0600)]
ena: Remove write only variables

Sponsored by: Netflix

(cherry picked from commit 094b2a2379c1c92f134fac22be78517c71470ca6)

18 months agoena: Remove unused variable.
John Baldwin [Wed, 6 Apr 2022 23:45:28 +0000 (16:45 -0700)]
ena: Remove unused variable.

(cherry picked from commit 4dab99b936920cf0c8f3fcf63754985906714a40)

18 months agoena: Remove unused devclass argument to DRIVER_MODULE.
John Baldwin [Mon, 9 May 2022 19:22:01 +0000 (12:22 -0700)]
ena: Remove unused devclass argument to DRIVER_MODULE.

(cherry picked from commit 1dc1476cac52a65c6a25e786f90ccc7529b6a7de)

18 months agoipfw: Add missing 'va' code point name
Jose Luis Duran [Fri, 13 Jan 2023 20:19:34 +0000 (20:19 +0000)]
ipfw: Add missing 'va' code point name

Per RFC 5865, add the 'va' (VOICE-ADMIT, 101100) symbolic name.

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

(cherry picked from commit bdd60b224fa461a5849f60575afdb458613f4ccd)

18 months agonetlink: add netlink to GENERIC@amd64
Alexander V. Chernikov [Fri, 13 Jan 2023 10:11:26 +0000 (10:11 +0000)]
netlink: add netlink to GENERIC@amd64

Netlink is a communication protocol defined in RFC 3549. It is async,
TLV-based protocol, providing 1-1 and 1-many communications between kernel
and userland. Netlink is currently used in Linux kernel to modify, read and
subscribe for nearly all networking states. Interface state, addresses, routes,
firewall, rules, fibs, etc, are controlled via Netlink.

Netlink support was added in D36002. It has got a number of improvements and
first customers since then:
* net/bird2 got netlink support, enabling route multipath in FreeBSD
* netlink-based devd notifications are being worked on ( D37574 ).
* linux(4) fully supports and depends on Netlink

Enabling Netlink in GENERIC targets two goals.
The first one is to provide stability for the third-party userland applications,
so they can rely on the fact that netlink always exists since 14.0 and potentially 13.2.
Loadable module makes life of the app delepers harder. For example, `net/bird2` can be
either build with netlink or rtsock support, but not both.

The second goal is to enable gradual conversion of the base userland tools
to use netlink(4) interfaces. Converting tools like netstat (D36529), route,
ifconfig one-by-one simplifies testing and addressing the feedback.
Othewise, switching all base to use netlink at once may be too big of a leap.

This change targets amd64, the other architectures will follow soon.

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

(cherry picked from commit 692e19cf519578176d51d4c1001b01b1f355c1de)

18 months agobhyve: Mark pci_de_vinput as const.
John Baldwin [Thu, 26 Jan 2023 22:31:57 +0000 (14:31 -0800)]
bhyve: Mark pci_de_vinput as const.

I missed this in the prior fixup commit that added static.

Fixes: 03851ae8cd4d bhyve: Mark pci_de_vinput as static.

18 months agobhyveload: open guest boot disk image O_RDWR
Robert Wing [Mon, 5 Dec 2022 17:22:45 +0000 (08:22 -0900)]
bhyveload: open guest boot disk image O_RDWR

When a boot environment has been booted via the bootonce feature,
userboot clears the bootonce value from an nvlist but fails to write the
updated nvlist back to disk.

The failure occurs because bhyveload opens the guest boot disk image
O_RDONLY, fix this by opening it O_RDWR.

Reviewed by: imp, markj, jhb
Differential Revision: https://reviews.freebsd.org/D37274

(cherry picked from commit 5a023bd2a53a7279b126ae6bf949560c6342b57a)

18 months agobhyve: Fix a buffer overread in the PCI hda device model.
John Baldwin [Fri, 20 Jan 2023 17:58:38 +0000 (09:58 -0800)]
bhyve: Fix a buffer overread in the PCI hda device model.

The sc->codecs array contains HDA_CODEC_MAX (15) entries.  The
guest-supplied cad field in the verb provided to hda_send_command is a
4-bit field that was used as an index into sc->codecs without any
bounds checking.  The highest value (15) would overflow the array.

Other uses of sc->codecs in the device model used sc->codecs_no to
determine which array indices have been initialized, so use a similar
check to reject requests for uninitialized or invalid cad indices in
hda_send_command.

PR: 264582
Reported by: Robert Morris <rtm@lcs.mit.edu>
Reviewed by: corvink, markj, emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D38128

(cherry picked from commit cf57f20edcf9c75f0f9f1ac1c44729184970b9d9)

18 months agobhyve: Fix a global buffer overread in the PCI hda device model.
John Baldwin [Fri, 20 Jan 2023 17:57:45 +0000 (09:57 -0800)]
bhyve: Fix a global buffer overread in the PCI hda device model.

hda_write did not validate the relative register offset before using
it as an index into the hda_set_reg_table array to lookup a function
pointer to execute after updating the register's value.

PR: 264435
Reported by: Robert Morris <rtm@lcs.mit.edu>
Reviewed by: corvink, markj, emaste
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D38127

(cherry picked from commit bfe8e339eb77910c2eb739b45aaa936148b33897)

18 months agobhyve: Remove vmctx argument from PCI device model methods.
John Baldwin [Thu, 19 Jan 2023 18:30:18 +0000 (10:30 -0800)]
bhyve: Remove vmctx argument from PCI device model methods.

Most of these arguments were unused.  Device models which do need
access to the vmctx in one of these methods can obtain it from the
pi_vmctx member of the pci_devinst argument instead.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D38096

(cherry picked from commit 6a284cacb1e56a81dff7f5c34bbbd7ed1a0b6cb1)

18 months agobhyve: Fix a mismerge in the PCI passthrough device model.
John Baldwin [Thu, 26 Jan 2023 22:24:55 +0000 (14:24 -0800)]
bhyve: Fix a mismerge in the PCI passthrough device model.

This block of code was removed in stable/13 commit 7ea16192a01e.  It
was accidentally re-added in commit aa5eea98b99c (probably due to
resolving a conflict during the merge).

This is a direct commit to stable/13.

18 months agobhyve: Avoid triggering false -Wfree-nonheap-object warnings.
John Baldwin [Thu, 19 Jan 2023 18:21:50 +0000 (10:21 -0800)]
bhyve: Avoid triggering false -Wfree-nonheap-object warnings.

XHCI port and slot numbers are 1-based rather than 0-based.  To handle
this, bhyve was subtracting one item from the pointers saved in the
softc so that index 1 accessed index 0 of the allocated array.

However, this is UB and confused GCC 12.  The compiler noticed that
the calls to free() were using an offset and emitted a warning.
Rather than storing UB pointers in the softc, push the decrement
operation into the existing macros that wrap accesses to the relevant
arrays.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D36829

(cherry picked from commit b36b14beda4ff7ecbb906ada756141f76fcb81aa)

18 months agobhyve: Simplify spinup_ap_realmode slightly.
John Baldwin [Wed, 21 Dec 2022 18:33:34 +0000 (10:33 -0800)]
bhyve: Simplify spinup_ap_realmode slightly.

There is no reason to modify the passed in rip variable.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37647

(cherry picked from commit e53fcff1848bb5acafc3dc38cfeb34724d9b0b96)

18 months agobhyve: Tidy vCPU pthread startup.
John Baldwin [Wed, 21 Dec 2022 18:33:18 +0000 (10:33 -0800)]
bhyve: Tidy vCPU pthread startup.

Set the thread affinity in fbsdrun_start_thread next to where the
thread name is set.  This keeps all the pthread initialization
operations at the start of a thread in one place.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37646

(cherry picked from commit 7224a96a55d512e00f390d4477e0fb0a163d7528)

18 months agobhyve: Don't access vcpumap[vcpu] directly in parse_cpuset().
John Baldwin [Wed, 21 Dec 2022 18:33:04 +0000 (10:33 -0800)]
bhyve: Don't access vcpumap[vcpu] directly in parse_cpuset().

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37645

(cherry picked from commit 8487443792ce67fce21ae32470d6d8c217e93368)

18 months agobhyve: Allocate struct vm_exit on the stack in vm_loop.
John Baldwin [Wed, 21 Dec 2022 18:32:45 +0000 (10:32 -0800)]
bhyve: Allocate struct vm_exit on the stack in vm_loop.

The global vmexit[] array is no longer needed to smuggle the rip
value from fbsdrun_addcpu() to vm_loop().

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37644

(cherry picked from commit a20c00c60e1c022f77a7bc638f29d3d6d9456953)

18 months agobhyve: Remove some no-op code for setting RIP.
John Baldwin [Wed, 21 Dec 2022 18:32:24 +0000 (10:32 -0800)]
bhyve: Remove some no-op code for setting RIP.

fbsdrun_addcpu() read the current vCPU's RIP register from the kernel
via vm_get_register() to pass along through some layers to vm_loop()
which then set the register via vm_set_register().  However, this is
just always setting the value back to itself.

Reviewed by: corvink
Differential Revision: https://reviews.freebsd.org/D37643

(cherry picked from commit ceb0d0b0f184d72f31ebdaa4edc752aed78a5807)

18 months agobhyve: Simplify setting vCPU capabilities.
John Baldwin [Wed, 21 Dec 2022 18:31:16 +0000 (10:31 -0800)]
bhyve: Simplify setting vCPU capabilities.

- Enable VM_CAP_IPI_EXIT in fbsdrun_set_capabilities along with other
  capabilities enabled on all vCPUs.

- Don't call fbsdrun_set_capabilities a second time on the BSP in
  spinup_vcpu.

- To preserve previous behavior, don't unconditionally enable
  unrestricted guest mode on the BSP (this unbreaks single-vCPU guests
  on Nehalem systems, though supporting such setups is of dubious
  value).  Other places that enbale UG on the BSP are careful to check
  the result of the operation and fail if it is not available.

- Don't set any capabilities in spinup_ap().  These are now all
  redundant with earlier settings from spinup_vcpu().

- While here, axe a stale comment from fbsdrun_addcpu().  This
  function is now always called from the main thread for all vCPUs.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37642

(cherry picked from commit 461663ddbad02a4a5135673d545695b1a9f25ed0)

18 months agobhyve: Remove unused return value from spinup_ap.
John Baldwin [Wed, 21 Dec 2022 18:31:02 +0000 (10:31 -0800)]
bhyve: Remove unused return value from spinup_ap.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37641

(cherry picked from commit e7d5d2d1876afb429c6e1b4453bdd6d165bc5a68)

18 months agobhyve: Remove handler for VM_EXITCODE_SPINUP_AP.
John Baldwin [Wed, 21 Dec 2022 18:30:45 +0000 (10:30 -0800)]
bhyve: Remove handler for VM_EXITCODE_SPINUP_AP.

Since commit 0bda8d3e9f7a, bhyve always enables VM_EXITCODE_IPI exits
instead, so this handler is no longer used.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37640

(cherry picked from commit 007d9ca5dd953c009cf976b49e2568444a16a473)

18 months agobhyve: Remove the unused vcpu argument from all of the I/O port handlers.
John Baldwin [Fri, 9 Dec 2022 18:35:44 +0000 (10:35 -0800)]
bhyve: Remove the unused vcpu argument from all of the I/O port handlers.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37653

(cherry picked from commit 08b05de1e21a7f3720eb618613276e3f3ab665f3)

18 months agobhyve: Remove unused vcpu argument from PCI read/write methods.
John Baldwin [Fri, 9 Dec 2022 18:35:28 +0000 (10:35 -0800)]
bhyve: Remove unused vcpu argument from PCI read/write methods.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37652

(cherry picked from commit 78c2cd83eccac0ebd23ebd15df77ee33a5781a6e)

18 months agobhyve: Pass a vCPU ID of 0 to vm_setup_pptdev_msi*.
John Baldwin [Fri, 9 Dec 2022 18:28:11 +0000 (10:28 -0800)]
bhyve: Pass a vCPU ID of 0 to vm_setup_pptdev_msi*.

These ioctls are not vCPU-specific and the ioctl now ignores the vCPU
ID.  0 is used instead of -1 to provide limited forwards
compatibility.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37651

(cherry picked from commit 0857e5555d77357e34ea6d70b28ead6335e41d33)

18 months agobhyve: Remove unused argument from pci_nvme_handle_doorbell.
John Baldwin [Fri, 9 Dec 2022 18:27:36 +0000 (10:27 -0800)]
bhyve: Remove unused argument from pci_nvme_handle_doorbell.

Reviewed by: corvink, chuck, markj
Differential Revision: https://reviews.freebsd.org/D37650

(cherry picked from commit 34781da505fd06fc7cdf18e6e0c0eb187391d2c7)

18 months agoRELNOTES: Document lifting the hard limit on guest vCPUs in bhyve.
John Baldwin [Thu, 26 Jan 2023 22:15:08 +0000 (14:15 -0800)]
RELNOTES: Document lifting the hard limit on guest vCPUs in bhyve.

18 months agovmm: Free vCPUs when destroying them.
John Baldwin [Fri, 9 Dec 2022 18:27:05 +0000 (10:27 -0800)]
vmm: Free vCPUs when destroying them.

Reported by: andrew
Reviewed by: corvink, andrew, markj
Differential Revision: https://reviews.freebsd.org/D37649

(cherry picked from commit af3b48e101986fb0840739f8c4bb3195e78008b1)

18 months agovmm: Avoid infinite loop in vcpu_lock_all error case.
John Baldwin [Fri, 9 Dec 2022 18:26:49 +0000 (10:26 -0800)]
vmm: Avoid infinite loop in vcpu_lock_all error case.

Reported by: Coverity (CIDs 1501060,1501071)
Reviewed by: corvink, markj, emaste
Differential Revision: https://reviews.freebsd.org/D37648

(cherry picked from commit d212d6ebb4ea3b3e9c3964c1a6d3f41817e437e1)

18 months agovmm: Don't lock a vCPU for VM_PPTDEV_MSI[X].
John Baldwin [Fri, 9 Dec 2022 18:26:23 +0000 (10:26 -0800)]
vmm: Don't lock a vCPU for VM_PPTDEV_MSI[X].

These are manipulating state in a ppt(4) device none of which is
vCPU-specific.  Mark the vcpu fields in the relevant ioctl structures
as unused, but don't remove them for now.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37639

(cherry picked from commit 91980db1beecd52e34a1550a247e374cfcc746a2)

18 months agovmm: VM_GET/SET_KERNEMU_DEV should run with the vCPU locked.
John Baldwin [Fri, 9 Dec 2022 18:25:30 +0000 (10:25 -0800)]
vmm: VM_GET/SET_KERNEMU_DEV should run with the vCPU locked.

Reviewed by: corvink, kib, markj
Differential Revision: https://reviews.freebsd.org/D37638

(cherry picked from commit 62be9ffd82fb1a03db5e04d32ab75550f1f4f2c7)

18 months agovmm: Remove stale comment for vm_rendezvous.
John Baldwin [Wed, 30 Nov 2022 21:06:46 +0000 (13:06 -0800)]
vmm: Remove stale comment for vm_rendezvous.

Support for rendezvous outside of a vcpu context (vcpuid of -1) was
removed in commit 949f0f47a4e7, and the vm, vcpuid argument pair was
replaced by a single struct vcpu pointer in commit d8be3d523dd5.

Reported by: andrew

(cherry picked from commit 1f6db5d6b5de5e0cafcdb141a988120b0faea049)

18 months agovmm: Fix build w/o KDTRACE_HOOKS.
Dmitry Chagin [Sun, 20 Nov 2022 15:00:55 +0000 (18:00 +0300)]
vmm: Fix build w/o KDTRACE_HOOKS.

Reviewed by: imp
Differential revision: https://reviews.freebsd.org/D37446

(cherry picked from commit 2ee1a18d51ed68ee34df7dcfd05f6cfc16110202)

18 months agovmm: Fix non-INVARIANTS build
Cy Schubert [Fri, 18 Nov 2022 21:20:13 +0000 (13:20 -0800)]
vmm: Fix non-INVARIANTS build

Reported by: O. Hartmann <freebsd@walstatt-de.de>
Reviewed by: jhb
Fixes: 58eefc67a1cf
Differential Revision: https://reviews.freebsd.org/D37444

(cherry picked from commit d487cba33d777efb9f6f7d7967ad2eaa629bcb90)

18 months agovmm: Trim some pointless #ifdef KTR.
John Baldwin [Fri, 18 Nov 2022 18:06:20 +0000 (10:06 -0800)]
vmm: Trim some pointless #ifdef KTR.

Reported by: markj
Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37272

(cherry picked from commit 49fd5115a9b244c599e068977324e8f6a9993066)

18 months agovmm: Convert VM_MAXCPU into a loader tunable hw.vmm.maxcpu.
John Baldwin [Fri, 18 Nov 2022 18:06:08 +0000 (10:06 -0800)]
vmm: Convert VM_MAXCPU into a loader tunable hw.vmm.maxcpu.

The default is now the number of physical CPUs in the system rather
than 16.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37175

(cherry picked from commit ee98f99d7a68b284a669fefb969cbfc31df2d0ab)

18 months agovmm: Allocate vCPUs on first use of a vCPU.
John Baldwin [Fri, 18 Nov 2022 18:05:35 +0000 (10:05 -0800)]
vmm: Allocate vCPUs on first use of a vCPU.

Convert the vcpu[] array in struct vm to an array of pointers and
allocate vCPUs on first use.  This avoids always allocating VM_MAXCPU
vCPUs for each VM, but instead only allocates the vCPUs in use.  A new
per-VM sx lock is added to serialize attempts to allocate vCPUs on
first use.  However, a given vCPU is never freed while the VM is
active, so the pointer is read via an unlocked read first to avoid the
need for the lock in the common case once the vCPU has been created.

Some ioctls need to lock all vCPUs.  To prevent races with ioctls that
want to allocate a new vCPU, these ioctls also lock the sx lock that
protects vCPU creation.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37174

(cherry picked from commit 98568a005a193ce2c37702a8377ddd10c570e452)

18 months agovmm: don't lock a mtx in the icr_low write handler
Corvin Köhne [Mon, 21 Nov 2022 14:00:04 +0000 (15:00 +0100)]
vmm: don't lock a mtx in the icr_low write handler

x2apic accesses are handled by a wrmsr exit. This handler is called in a
critical section. So, we can't lock a mtx in the icr_low handler.

Reported by: kp, pho
Tested by: kp, pho
Approved by: manu (mentor)
Fixes: c0f35dbf19c3c8825bd2b321d8efd582807d1940 vmm: Use a cpuset_t for vCPUs waiting for STARTUP IPIs.
MFC after: 1 week
MFC with: c0f35dbf19c3c8825bd2b321d8efd582807d1940
Sponsored by: Beckhoff Automation GmbH & Co. KG
Differential Revision: https://reviews.freebsd.org/D37452

(cherry picked from commit 7c326ab5bb9aced8dcbc2465ac1c9ff8df2ba46b)

18 months agovmm: Use a cpuset_t for vCPUs waiting for STARTUP IPIs.
John Baldwin [Fri, 18 Nov 2022 18:05:10 +0000 (10:05 -0800)]
vmm: Use a cpuset_t for vCPUs waiting for STARTUP IPIs.

Retire the boot_state member of struct vlapic and instead use a cpuset
in the VM to track vCPUs waiting for STARTUP IPIs.  INIT IPIs add
vCPUs to this set, and STARTUP IPIs remove vCPUs from the set.
STARTUP IPIs are only reported to userland for vCPUs that were removed
from the set.

In particular, this permits a subsequent change to allocate vCPUs on
demand when the vCPU may not be allocated until after a STARTUP IPI is
reported to userland.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37173

(cherry picked from commit c0f35dbf19c3c8825bd2b321d8efd582807d1940)

18 months agovmm devmem_mmap_single: Bump object reference under memsegs lock.
John Baldwin [Fri, 18 Nov 2022 18:04:58 +0000 (10:04 -0800)]
vmm devmem_mmap_single: Bump object reference under memsegs lock.

Reported by: markj
Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37273

(cherry picked from commit 223de44c93659457e05036dec25b0af610a773a6)

18 months agovmm: take exclusive mem_segs_lock in vm_cleanup()
Robert Wing [Fri, 20 Jan 2023 11:10:53 +0000 (11:10 +0000)]
vmm: take exclusive mem_segs_lock in vm_cleanup()

The consumers of vm_cleanup() are vm_reinit() and vm_destroy().

The vm_reinit() call path is, here vmmdev_ioctl() takes mem_segs_lock:
    vmmdev_ioctl()
    vm_reinit()
    vm_cleanup(destroy=false)

The call path for vm_destroy() is (mem_segs_lock not taken):
    sysctl_vmm_destroy()
    vmmdev_destroy()
    vm_destroy()
    vm_cleanup(destroy=true)

Fix this by taking mem_segs_lock in vm_cleanup() when destroy == true.

Reviewed by: corvink, markj, jhb
Fixes: 67b69e76e8ee ("vmm: Use an sx lock to protect the memory map.")
Differential Revision: https://reviews.freebsd.org/D38071

(cherry picked from commit c668e8173a8fc047b54a5c51b0fe4637e87836b6)

18 months agovmm: take exclusive mem_segs_lock when (un)assigning ppt dev
Robert Wing [Fri, 20 Jan 2023 10:03:59 +0000 (10:03 +0000)]
vmm: take exclusive mem_segs_lock when (un)assigning ppt dev

PR:             268744
Reported by:    mmatalka@gmail.com
Reviewed by: corvink, markj, jhb
Fixes: 67b69e76e8ee ("vmm: Use an sx lock to protect the memory map.")
Differential Revision: https://reviews.freebsd.org/D37962

(cherry picked from commit ccf32a68f821c5c724fb9a5b4b9576925122292f)

18 months agovmm: Use an sx lock to protect the memory map.
John Baldwin [Fri, 18 Nov 2022 18:04:37 +0000 (10:04 -0800)]
vmm: Use an sx lock to protect the memory map.

Previously bhyve obtained a "read lock" on the memory map for ioctls
needing to read the map by locking the last vCPU.  This is now
replaced by a new per-VM sx lock.  Modifying the map requires
exclusively locking the sx lock as well as locking all existing vCPUs.
Reading the map requires either locking one vCPU or the sx lock.

This permits safely modifying or querying the memory map while some
vCPUs do not exist which will be true in a future commit.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37172

(cherry picked from commit 67b69e76e8eecfd204f6de636d622a1d681c8d7e)

18 months agovmm: Destroy mutexes.
John Baldwin [Fri, 18 Nov 2022 18:04:30 +0000 (10:04 -0800)]
vmm: Destroy mutexes.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37171

(cherry picked from commit 08ebb360764729632e1f6bc4e3f434abdd708204)

18 months agovmm stat: Add a special nelems constant for arrays sized by vCPU count.
John Baldwin [Fri, 18 Nov 2022 18:04:23 +0000 (10:04 -0800)]
vmm stat: Add a special nelems constant for arrays sized by vCPU count.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37170

(cherry picked from commit d5118d0fc4599f69116ec8de59052606e36e6306)