Commit graph

19871 commits

Author SHA1 Message Date
Mark Johnston d934517627 bhyve: Remove some unneeded includes of segments.h
They are not needed and are specific to x86.  No functional change
intended.

MFC after:	1 week
Sponsored by:	Innovate UK

(cherry picked from commit 6d1dfc8741)
2023-06-26 15:52:08 -04:00
Poul-Henning Kamp c6d3829c09 freebsd-update: Mention 13.2-RELEASE in usage.
(cherry picked from commit e0e5bf4d62)
2023-06-21 08:52:32 -04:00
Dag-Erling Smørgrav 9feaa109e4 local-unbound-setup: Disable the libc subscriber.
This is the correct way to prevent resolvconf from updating resolv.conf.

Reviewed by:	cy
Differential Revision:	https://reviews.freebsd.org/D39262

(cherry picked from commit 9b20ab1e1e)
2023-06-14 14:40:39 +02:00
Rick Macklem 4eee1fcdfc nfsuserd: Improve failure message when running in a jail
If a jail is not correctly configured to run nfsd(8)
in the jail, nfsuserd(8) cannot run.
This patch improves the failure message for this case.

(cherry picked from commit a94018e200)
2023-06-11 18:23:37 -07:00
Rick Macklem 4deff63c5d gssd: Improve failure message when running in a jail
If a jail is not correctly configured to run nfsd(8)
in the jail, gssd(8) cannot run.
This patch improves the failure message for this case.

(cherry picked from commit 697727110b)
2023-06-11 13:07:55 -07:00
Mitchell Horne e6246bd85a pmcstat: augment an error message
It also applies to the -t argument.

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

(cherry picked from commit bf66159342)
2023-06-09 15:14:59 -03:00
Mitchell Horne e456727fcc pmccontrol: drop Pentium 4 special case
This is dead code; we no longer support Pentium hardware in libpmc or
hwpmc.

MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 8bd4459560)
2023-06-09 15:14:58 -03:00
Cy Schubert 5d3fa3d71c ntp: import ntp-4.2.8p17
Fixes two small bugs including one regression.

Merge commit 'ab1f1aa8333369a83ff284848fc3fc2e52d5f29f'

(cherry picked from commit e6bfd18d21)

ntp: Fix build

Two files used to obtain time from reference clocks did not include
ntp_types.h resulting in an undefined NONEMPTY_TRANSLATION_UNIT.

Fixes:		e6bfd18d21

(cherry picked from commit 82aa1470c9)
2023-06-09 06:35:55 -07:00
Chuck Silvers 89bd147dbf ffs: restore backward compatibility of newfs and makefs with older binaries
The previous change to CGSIZE had the unintended side-effect of allowing
newfs and makefs to create file systems that would fail validation when
examined by older commands and kernels, by allowing newfs/makefs to pack
slightly more blocks into a CG than those older binaries think is valid.
Fix this by having newfs/makefs artificially restrict the number of blocks
in a CG to the slightly smaller value that those older binaries will accept.
The validation code will continue to accept the slightly larger value
that the current newfs/makefs (before this change) could create.

Fixes:		0a6e34e950
Reviewed by:	mckusick
MFC after:	3 days
Sponsored by:	Netflix

(cherry picked from commit d464a7698d)
2023-06-04 04:00:22 -07:00
Cy Schubert b916516fdd ntp: Update version string
Chase a466cc5537, updating the version string in the local config.h.

Reported by:	 Trond Endrestol <Trond.Endrestol@ximalas.info>
Fixes:		a466cc5537

(cherry picked from commit 4d78061377)
2023-06-01 15:18:21 -07:00
Cy Schubert 91ae4636fb ntp: import ntp-4.2.8p16
Security:       NtpBUg3767, NtpBug3808, NtpBug3807 (CVE-2023-26555)

(cherry picked from commit a466cc5537)
2023-06-01 08:06:46 -07:00
Kirk McKusick 4a3834e31f Fix size differences between architectures of the UFS/FFS CGSIZE macro value.
Reported-by:  Tijl Coosemans
Tested-by:    Tijl Coosemans and Peter Holm
Sponsored-by: The FreeBSD Foundation

(cherry picked from commit 0a6e34e950)
2023-05-26 14:25:50 -07:00
Rick Macklem 8d92ebe2fa nfsd.c: Log a more meaningful failure message
For the cases where the nfsd(8) daemon is already running or
has failed to start within a prison due to an incorrect prison
configuration, the failure message logged is:
  Can't read stable storage file: operation not permitted

This patch replaces the above with more meaningful messages.
It depends on commit 10dff9da97 to differentiate between the
above two cases, however even without this commit, the messages
should be an improvement.

(cherry picked from commit fe5c211ba8)
2023-05-23 19:15:01 -07:00
Rick Macklem e11c3ae65e mountd.8: Update for mountd running in jails
Mountd can now be run in an appropriately
configured vnet jail.

This man page update adds some information
for this case.

This is a content change.

(cherry picked from commit 9432e798fc)
2023-05-22 11:31:50 -07:00
Rick Macklem 12d9715002 nfsd.8: Update for nfsd running in jails
Nfsd can now be run in an appropriately
configured vnet jail.

This man page update adds some information
for this case.

This is a content change.

(cherry picked from commit a1254dcaa8)
2023-05-22 11:29:25 -07:00
Rick Macklem e608f0713d jail.8: Update the allow.nfsd section
This patch updates the information for "allow.nfsd"
and adds configuration information.

This is a content change.

(cherry picked from commit c0f94fee0b)
2023-05-22 11:27:45 -07:00
Rick Macklem ffcdd031d7 jail.8: Update the man page for allow.nfsd
Commit bba7a2e896 added "allow.nfsd" to optionally allow
mountd/nfsd to be run inside a vnet prison when the kernel
is built with "options VNET_NFSD".

This patch updates the man page for this change.

This is a content change.

(cherry picked from commit d4b4f3b9c3)
2023-05-22 11:26:03 -07:00
Baptiste Daroussin 4399248d87 pkg(7): now that we do use libmd, use it completly
Use SHA256_Fd and SHA256_Data instead of home made equivalent.
wrap those functions into hash.c to avoid header collition between
openssl and libmd

Suggested by:	kevans

(cherry picked from commit e5dd5bfa55)
2023-05-19 10:16:51 +02:00
Baptiste Daroussin 7bc2192380 pkg(7): use libmd for sha256 instead of openssl
OpenSSL 3.0 has deprecated the sha256 api, let's use libmd which has the
same API instead.

In order to avoid the collision in definitions (sha256.h cannot be
included in the same file as a file where openssl headers has been
included) let's move the sha256 related code in its own file

PR:		270023
Reported by:	ngie

(cherry picked from commit b2654064c2)
2023-05-19 10:16:51 +02:00
pbuff 732f13ad32 pw: The pw_checkname function has added ';' checking.
The pw_checkname function forgot to include a ';'
when checking usernames, causing shell commands
to be executed when a username with a ';' is deleted.

PR:		271427
MFC After:	3 days

(cherry picked from commit e0155c6989)
2023-05-19 10:10:09 +02:00
Michael Osipov e31fbe0dff periodic: Use locale-agnostic (ISO 8601) timestamp format
Instead of reyling on locale-sensitive output which can be mangled when e-mailed
use consistently ISO 8601 format which contains the same information as '-T'.

PR:		271240
MFC After:	3 days

(cherry picked from commit d2b4753f06)
2023-05-19 10:10:08 +02:00
Baptiste Daroussin c1150a6379 pw: do not call system()
Calling system makes pw(8) spawn a shell, which can then be abused.

MFC After:	3 days

(cherry picked from commit ef7d0eb948)
2023-05-19 10:08:15 +02:00
Colin Percival 866e5c6b3c freebsd-update: Fix merging already-updated files
When performing an "upgrade" (moving between FreeBSD releases, as
opposed to "update" which merely applies security/errata updates
to the installed release) FreeBSD Update:

1. Generates a list of "files needing to be merged", namely those
files which don't match the version installed in the "old" release
and have paths matching the MergeChanges configuration directive
(by default, /boot/device.hints and everything under /etc/).

and later on,

2. Compares the currently-installed files to the versions in the
"new" release, removing index entries for files which "don't need
to be updated because they're not changing".

Unfortunately if a file falls into both of these categories -- that
is to say, if a file in /etc/ is the same as the version in the new
release and not the same as the version in the old release -- the
resulting "merge" step saw that the file was no longer listed as
being part of the new release, resulting in the file being deleted.

For the first 18 years of FreeBSD Update's existence, this never
happened, since $FreeBSD$ tags resulted in "new release" files
always being different from any files systems would already have
installed.

This commit fixes this behaviour by only placing a file into the
"files needing to be merged" list if it does not match the version
in the old release *or* the version in the new release.

Reported by:	des
Reviewed by:	delphij (earlier version), des, emaste
MFC after:	7 days
X-EN-Candidate:	yes
Differential Revision:	https://reviews.freebsd.org/D39973

(cherry picked from commit c55b7e5226)
2023-05-16 14:34:10 -07:00
Mina Galic 3f39a2a839 ntpd: Support IPv6-only hosts
0.pool.* returns only IPv4 addresses.
2.pool.* returns both, IPv6 and IPv4 addresses.

conservatively extend our IPv4 only pool configuration by adding a
second pool, which also returns IPv6 addresses.

PR:			270536
Reported by:		Lapo Luchini <lapo@lapo.it>
Pull Request:		https://github.com/freebsd/freebsd-src/pull/731
Differential Revision:	https://reviews.freebsd.org/D39954

(cherry picked from commit fff1551c03)
2023-05-08 10:33:24 -07:00
Corvin Köhne 03d8264dca
bhyve: pass E820 table to guest
E820 table will be used to report valid RAM ranges and reserve special
memory areas like graphics memory for GPU passthrough.

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

(cherry picked from commit 16f23f7543)
2023-05-08 10:21:32 +02:00
Corvin Köhne f1b5ce0d1d
bhyve: add E820 dump function
For debugging purposes it is helpful to dump the E820 table.

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

(cherry picked from commit a8a8e9af57)
2023-05-08 10:21:32 +02:00
Corvin Köhne 0f8a17795d
bhyve: add allocation function to E820
This function makes it easy to allocate new E820 entries. It will be
used to allocate graphics memory for Intel integrated graphic devices.

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

(cherry picked from commit 5597f56487)
2023-05-08 10:21:31 +02:00
Corvin Köhne 951ca31bf6
bhyve: add common memory holes to E820 table
The VGA and the ROM memory ranges can't be used as system memory. For
that reason, remove them from the E820 table.

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

(cherry picked from commit 059af92a30)
2023-05-08 10:21:31 +02:00
Corvin Köhne 694f2c9d35
bhyve: add basic E820 implementation
There are some use cases where bhyve has to prepare some special memory
regions. E.g. GPU passthrough for Intel integrated graphic devices needs
to reserve some memory for the graphic device. So, bhyve has to inform
the guest about those memory regions. This information can be passed by
the qemu fwcfg interface. As qemu creates an E820 table, we can reuse
the existing fwcfg item "etc/e820".

This commit is the first one of a series. It only adds a basic
implementation for the creation of the E820 table. Some subsequent
commits will add more items to the E820 table and register it as fwcfg
item.

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

(cherry picked from commit 9180daa1e3)
2023-05-08 10:21:30 +02:00
Corvin Köhne a02d136df0
bhyve: make use of qemus acpi table loader
Add all acpi tables to qemus acpi table loader. This passes the acpi
tables by fwcfg to the guest.

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

(cherry picked from commit 7959d80d99)
2023-05-08 10:21:30 +02:00
Corvin Köhne d71c3dd112
bhyve: add helper struct for qemus acpi table loader
The hypervisor is aware of all system properties. For the guest bios
it's hard and complex to detect all system properties. For that reason,
it would be better if the hypervisor creates acpi tables instead of the
guest. Therefore, the hypervisor has to send the acpi tables to the
guest. At the moment, bhyve just copies the acpi tables into the guest
memory. This approach has some restrictions. You have to keep sure that
the guest doesn't overwrite them accidentally. Additionally, the size of
acpi tables is limited.

Providing a plain copy of all acpi tables by fwcfg isn't possible. Acpi
tables have to point to each other. So, if the guest copies the acpi
tables into memory by it's own, it has to patch the tables. Due to
different layouts for different acpi tables, there's no generic way to
do that.  For that reason, qemu created a table loader interface. It
contains commands for the guest for loading specific blobs into guest
memory and patching those blobs.

This commit adds a qemu_loader class which handles the creation of qemu
loader commands. At the moment, the WRITE_POINTER command isn't
implement. It won't be required by bhyve's acpi table generation yet.

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

(cherry picked from commit f565b4d630)
2023-05-08 10:21:29 +02:00
John Baldwin f894317873 bhyve: Don't return -ENOMEM from qemu_fwcfg_add_file.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D39212

(cherry picked from commit 7bf44831ca)
2023-05-02 17:07:05 -07:00
John Baldwin 2c63333240 bhyve: Accept a variable-length string name for qemu_fwcfg_add_file.
It is illegal (UB?) to pass a shorter array to a function argument
that takes a fixed-length array.  Do a runtime check for names that
are too long via strlen() instead.

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

(cherry picked from commit 61482760a0)
2023-05-02 17:06:52 -07:00
John Baldwin 0218596e92 acpica: Quiet a -Wdangling-pointer warning in AcpiUtInitStackPtrTrace.
This function intentionally saves a pointer to an on-stack variable in
a global as a dubious way of reading the stack pointer.

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

(cherry picked from commit f4432625ed)
2023-05-02 17:05:54 -07:00
John Baldwin 50367e285d pw: Don't return a pointer to an on-stack buffer from grp_set_passwd.
Make 'line' static to move it to .bss instead as that pattern is used
elsewhere in pw(8) (e.g. the static buffer in pw_pwcrypt).

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

(cherry picked from commit 1055bedbed)
2023-05-02 17:05:05 -07:00
John Baldwin 0345952b9e fwcontrol: Disable -Wzero-length-bounds warnings.
firewire.h includes zero length arrays in unions that trigger this
warning.

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

(cherry picked from commit aa9ce62be5)
2023-05-02 17:04:46 -07:00
Vitaliy Gusev b8cca0cdc0
bhyve: remove redundant variable
Reviewed by:    corvink,markj
Sponsored by:   vStack
Differential Revision: https://reviews.freebsd.org/D38836
2023-04-28 14:01:23 +02:00
Corvin Köhne 82622189fe
bhyve: add QEMU_FWCFG_INDEX_MAX_CPUS item
Requested-by:		coreboot
Reviewed by:		<If someone else reviewed your modification.>
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D39315

(cherry picked from commit 305edaa479)
2023-04-28 09:28:34 +02:00
Corvin Köhne 0ad27bd40b
bhyve: add hook for PCI header of passthru devices
Most register of the PCI header are either constant values or require
emulation anyway. The command and status register are the only exception which
require hardware access. So, we're adding an emulation handler for all
other register.

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

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

(cherry picked from commit b6e67875a3)
2023-04-28 09:28:34 +02:00
Corvin Köhne 847adbb116
bhyve: define array to protect passthru regs
GPU passthrough requires a special handling of some PCI config register.
Therefore, we need a flexible approach for implementing it. Adding an
array of handler meets this condition.

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

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

(cherry picked from commit 931bb7bf1c)
2023-04-28 09:28:34 +02:00
Corvin Köhne 9c8a0c311a
bhyve: save softc of ACPI devices
This will be useful for writing device specific ACPI tables or DSDT
methods.

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

(cherry picked from commit 158adced65)
2023-04-28 09:28:34 +02:00
Corvin Köhne 1c7053169d
bhyve: allow device specific DSDT entries
This feature will be used by future commits to implement a device
specific method (_DSM) for TPM devices.

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

(cherry picked from commit e976464a50)
2023-04-28 09:28:34 +02:00
Corvin Köhne fbf9519ab9
bhyve: check for errors when writing device specific DSDT entries
At the moment, this function can't fail. This behaviour will change in
the future. In preparation to that, convert the return type to int in
order to be able to check for errors.

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

(cherry picked from commit ab34ea4711)
2023-04-28 09:28:33 +02:00
Corvin Köhne 76f744cf2d
bhyve: allow building device specific ACPI tables
Some ACPI devices require a device specific acpi table. E.g. a TPM2
device requires a TPM2 table. Use the acpi_device_emul struct to define
such a device specific table.

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

(cherry picked from commit 0926566f6f)
2023-04-28 09:28:33 +02:00
Corvin Köhne 3f7acfe073
bhyve: introduce acpi_device_emul struct
It'll be easier to add new properties to the ACPI device emulation if we
have a struct which holds all device specific properties. In some future
commits the acpi_device_emul struct will be expanded to include some
device specific functions to build ACPI tables.

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

(cherry picked from commit acd0088c44)
2023-04-28 09:28:32 +02:00
Corvin Köhne d4cae9c5e6
bhyve: add config option to modify LPC IDs
The Intel GOP driver checks the LPC IDs to detect the platform it's
running on. The GOP driver only works on the platforms it's written for.
Maybe other Intel driver have the same behaviour. For that reason, we
should use the LPC IDs of the FreeBSD host for GPU passthrough to work
properly.

We don't know if setting different LPC IDs have any side effect.
Therefore, don't use the host LPC IDs by default on Intel system. Give
the user the opportunity to modify the LPC IDs.

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

(cherry picked from commit f4ceaff56d)

bhyve: fix spelling mistake of pcireg option

The option is spelled "pcireg" not "pcir".

MFC after:		1 week
Fixes:			f4ceaff56d
Sponsored by:		Beckhoff Automation GmbH & Co. KG

(cherry picked from commit c98d13fbf9)

bhyve: scan PCI device functions to find host LPC

At least on some AMD devices the host LPC bridge could be located as
seperate function of another PCI device.

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

(cherry picked from commit d3e03d235e)

bhyve: do not exit if LPC finds no host selector

The host selector is only required when the user likes to use the same
LPC device IDs as the physical LPC device. This is an uncommon use case.
For that reason, it makes no sense to exit when we don't find the host
selector.

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

(cherry picked from commit 0d29d750b9)
2023-04-28 09:28:13 +02:00
Ed Maste 0001406ae2 makefs: set cd9660 Rock Ridge timestamps for . and ..
DOT and DOTDOT entries have special handling, and previously only Rock
Ridge PX (POSIX attributes) entries were attached.  Add TF (timestamp)
entries as well.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39662

(cherry picked from commit dd9059b3e9)
2023-04-27 12:45:37 -04:00
Ed Maste d74a8305b0 makefs: call brelse from bread
This matches NetBSD and rationalizes makefs with the kernel API.

This reverts commit 370e009188.

Reviewed by:	mckusick
Sponsored by:	The FreeBSD Foundation
Obtained from:	NetBSD 0a62dad69f62, 0c4125e1a19f, cb6a5a3575fd
Differential Revision:	https://reviews.freebsd.org/D39070

(cherry picked from commit e5551216d8)
2023-04-27 12:45:37 -04:00
Ed Maste 775defbe0c makefs: use unsigned and %u for rock_ridge_move_count
For diff reduction against NetBSD's makefs.  Based on NetBSD git mirror
commit 00991aee8248.

With this change our makefs cd9660 support should be in sync up to
NetBSD commit bdae6c9dc792 ("makefs(8): Nix trailing whitespace.").

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 10854bf517)
2023-04-21 17:19:48 -04:00
Ed Maste 6dda38e5ca makefs: remove unused variable
Reported by:	Clang
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 79ead08497)
2023-04-21 17:19:48 -04:00
Ed Maste 5fbe15bc21 makefs: remove unused cd9660 options
Makefs defined "follow-symlinks" and "help" options, but they did
nothing.  Remove them.

Obtained from:	OpenBSD a8f1645688c2
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c753f49f70)
2023-04-21 17:18:24 -04:00
Michael Tuexen d7339c4267 trpt: fix several bugs and add deprecation notice
This patch fixes several bugs releated to trpt including
* the computation of the TCP payload bytes, in particular when
  TCP options are present or IPv4 is used.
* the logging of incoming and outgoing packets.
* the logging of timers, in particular add support for logging of
  the delayed ack timer.
Also add a deprecation note, since support for this utility has been
removed from the main branch. Therefore, this is a direct commit to
stable/13.

Reviewed by:		cc, glebius, rrs
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D39436
2023-04-21 00:09:40 +02:00
Ed Maste 72ef847c17 makefs: use %s and __func__ in printf messages
For diff reduction against NetBSD.

Obtained from:	NetBSD 0c4125e1a19f
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit af7624ed31)
2023-04-14 08:10:38 -04:00
Ed Maste 496478c1dc makefs: set the validation entry system type
Obtained from:	NetBSD c3cb4dcc9c43
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 22db5e5d03)
2023-04-14 08:10:38 -04:00
Ed Maste c821bafd9c makefs: use size_t or ssize_t where appropriate
Obtained from:	NetBSD af7bc97830ac

(cherry picked from commit 1d1ffa2efd)
2023-04-14 08:10:38 -04:00
Ed Maste 066d6824fc makefs: simplify filename conversion handling
Obtained from:	OpenBSD 4095a2e01d18
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c02e6ca7c2)
2023-04-14 08:10:38 -04:00
Ed Maste 511e83ab14 makefs: remove some unused cd9660 types and defines
Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit d73acb32d3)
2023-04-14 08:10:38 -04:00
Ed Maste 1a38a53924 makefs: avoid uninitialized memory in root directory date
Move date setting into cd9660_populate_iso_dir_record so there is no
path that leaves it unset.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39258

(cherry picked from commit 7bc4ccf3ae)
2023-04-14 08:10:37 -04:00
Ed Maste 6787081641 makefs: remove CD9660MAXPATH #define
It was used only in constructing the host path that contains file
content, which is not related to anything CD9660-specific.  PATH_MAX is
the appropriate limit.  See OpenBSD commit 299d8950f319.

Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 2f11df6337)
2023-04-14 08:10:37 -04:00
Ed Maste ac8ec8c7cc makefs: improve some cd9660 error messages
Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c6ed8694ac)
2023-04-14 08:10:37 -04:00
Ed Maste 4311c5b3db makefs: #define Apple Partition bits
NetBSD defines these in sys/bootblock.h, which we don't have.  Add local
defintions in cd9660_eltorito.c (as OpenBSD did) to reduce diffs between
the three makefs implementations.

Obtained from:	OpenBSD
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f0bef3d20e)
2023-04-14 08:10:37 -04:00
Ed Maste 8c22a34e9a makefs: correct "filname" typo
Obtained from:	NetBSD cd9660.c r1.58

(cherry picked from commit efe6a1574e)
2023-04-14 08:10:37 -04:00
Ed Maste 3dff748720 makefs: Whitespace cleanup to sync with NetBSD
(cherry picked from commit 52c68e1625)
2023-04-14 08:10:37 -04:00
Ed Maste 57f6ba0e38 makefs: remove vestigial '?' cases from top-level getopt(3) loop
getopt(3) returns '?' when it encounters a flag not present in the in
the optstring or if a flag is missing its option argument.  We can
handle this case with the "default" failure case with no loss of
legibility.

Obtained from:	OpenBSD makefs.c 1.22

(cherry picked from commit cc4adc4c4e)
2023-04-14 08:10:36 -04:00
Ed Maste 5f31bbc5fa makefs: do not pass mode to open() call lacking O_CREAT
Obtained from:	OpenBSD ffs.c 1.35

(cherry picked from commit 45e405603b)
2023-04-14 08:10:36 -04:00
Ed Maste a025a94c50 makefs: spelling
Obtained from:	OpenBSD msdosfs_fat.c 1.7

(cherry picked from commit 1fb7d2cf99)
2023-04-14 08:10:36 -04:00
Christos Margiolis 18eb15bd8a makefs(8): do not print comma after the last super-block
Reviewed by:	markj, emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39430

(cherry picked from commit f21faa67ab)
2023-04-12 10:18:37 -04:00
Corvin Köhne b0efaef285
bhyve: add QEMU_FWCFG_INDEX_NB_CPUS item
Requested-by:		OVMF (qemu)
Reviewed by:		markj
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D39316

(cherry picked from commit e46be58cca)

bhyve: add missing include to qemu_fwcfg.c

Fixes:			e46be58cca ("bhyve: add QEMU_FWCFG_INDEX_NB_CPUS item")
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 76fa62b523)
2023-04-11 09:29:54 +02:00
Stefan Eßer 1412836cbd kbdcontrol.c: make pre-Unicode compatibility conditional
Support for the full range of Unicode character codes has been added
to the main keymap back in 2009, with compatibility shims added in
2011 (to support an older kbdcontrol command on a new kernel during
an upgrade from FreeBSD-8 to FreeBSD-9).

Unicode support for accented characters that are reached via dead key
combinations has been added just recently, again with compatibility
shims to allow all combinations of old/new kernel and old/new
kbdcontrol command to load and display the keymaps including the dead
key table. (But full Unicode in the dead key table requires both a new
kernel and kbdcontrol command.)

This commit makes the compatibility shims depend on the respective
compatibility ioctls (OGIO_KEYMAP, OPIO_KEYMAP, OGIO_DEADKEYMAP, and
OPIO_DEADKEYMAP) being defined in sys/kbio.h. This is true for all of
them in 13-STABLE, none in 12-STABLE (as of now), and will become
optional due to a follow-up commit to sys/kbio.h in -CURRENT.

This commit is the only part of review D38465 that should be merged
back to 12-STABLE and 13-STABLE.

(cherry picked from commit b4eab621f2)
2023-04-10 23:31:24 +02:00
Ed Maste 3a52cc4445 makefs: emit NM records for all directory entries
We previously attempted to emit Rock Ridge NM records only when the name
represented by the Rock Ridge extensions would actually differ. We would
omit the record for an all-upper-case directory name, however Linux (and
perhaps other operating systems) map names with no NM record to
lowercase.

This affected only directories, as file names have an implicit ";1"
version number appended and thus always differ.  To solve, just emit NM
records for all entries other than DOT and DOTDOT .

We could continue to omit the NM record for directories that would avoid
mapping (for example, one named 1234.567) but this does not seem worth
the complexity.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net
Reviewed by:	kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39258

(cherry picked from commit 978013a094)
2023-04-10 09:37:40 -04:00
Ed Maste b957461353 makefs: correct El Torito bood record
The boot catalog pointer is a DWord, but we previously populated it via
cd9660_bothendian_dword which overwrote four unused bytes following it.
See El Torito 1.0 (1995) Figure 7 for details.

PR:		203531, 203646
Reported by:	Coverity Scan
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	kevans
CID:		977470
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39231

(cherry picked from commit 9f2a525360)
2023-04-10 09:37:40 -04:00
Ed Maste 62f8e14192 makefs: correct iso9660 Rock Ridge NM values
These are not actually used by makefs (yet), but ought to match the
spec.

See RRIP 4.1.4 Description of the "NM" System Use Entry for details.

PR:		203531
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit c3ec19359e)
2023-04-10 09:37:40 -04:00
Ed Maste a79601b07a makefs: correct iso9660 Rock Ridge TF timestamps
The bit definitions for the TF_* timestamp bits (TF_MODIFY, etc.) were
incorrect, and timestamps were written in the wrong order.

See RRIP 4.1.6 Description of the "TF" System Use Entry for details.

PR:		203531
Reported by:	Thomas Schmitt <scdbackup@gmx.net>
Reviewed by:	jrtc27, kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39221

(cherry picked from commit c65c969bd5)
2023-04-10 09:37:40 -04:00
Kyle Evans 535fc5f75e daemon: reformat longopts
Use a single tab instead of eight spaces, these aren't line
continuations.

(cherry picked from commit b84aaf143c)
2023-04-09 17:49:52 -05:00
Ihor Antonov 81f89a76e8 daemon: decouple init logic from main loop
main() func contained both initialization and main loop logic.
This made certain operations like restarting problematic and
required dirty hacks in form of goto jumps.

This commit moves the main loop logic into daemon_eventloop(),
cleans up main, and makes restart logic clear: daemon_mainloop()
is run in a loop with a restart condition checked at the end.

Reviewed by:	kevans

(cherry picked from commit 4c41f4a0d6)
2023-04-09 17:49:52 -05:00
Ihor Antonov 7ad1bebb0f daemon: move signal setup into a function
No functional change intended.

Reviewed by:	kevans

(cherry picked from commit 9ee1faeeba)
2023-04-09 17:49:52 -05:00
Kyle Evans 2a69943c7b daemon: kill off some stray blank lines
Overlooked in review; mea culpa.

Reported by:	jrtc27

(cherry picked from commit 6b49a630f4)
2023-04-09 17:49:51 -05:00
Ihor Antonov 980ad64271 daemon: remove unnecessary memset in daemon_state_init()
(cherry picked from commit 8117ea0a41)
2023-04-09 17:49:51 -05:00
Ihor Antonov edc3bffde2 daemon: repace goto exit with daemon_terminate()
Start breaking down big main()
Remove goto exit label and replace it with a function that does cleanup.

Comment re-worded by kevans@.

(cherry picked from commit cf6356fd47)
2023-04-09 17:49:51 -05:00
Ihor Antonov 7362081fad daemon: move variables into struct daemon_state
The fact that most of the daemon's state is stored on the stack
of the main() makes it hard to split the logic smaller chunks.
Which in turn leads to huge main func that does a a lot of things.
struct log_params existed because some variables need to be passed
into other functions together.

This change renames struct log_params into daemon_state
and moves the rest of the variables into it. This is a necessary
preparation step for further refactroing.

Reviewed by: imp

(cherry picked from commit 298a392ec3)
2023-04-09 17:49:51 -05:00
Mateusz Guzik bda1244f01 sendmail: silence K&R warns
Sponsored by:	Rubicon Communications, LLC ("Netgate")

(cherry picked from commit 95a2b4d172)
2023-04-09 16:56:45 +02:00
Corvin Köhne e6bb702fce
bhyve: return EEXIST when adding a fwcfg item twice
Reviewed by:		rew
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D39338

(cherry picked from commit e37edc91b6)
2023-04-06 08:06:23 +02:00
Corvin Köhne 2a33e252a7
bhyve: remove unnecessary const qualifier in acpi_device.h
Those const qualifier declare that the function doesn't change the
values internally. It makes no sense to add them in the header file.

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

(cherry picked from commit 4046899086)
2023-04-06 08:06:23 +02:00
Corvin Köhne ab64356b1c
bhyve: make use of helper to read PCI IDs from bhyve config
For compatibilty reasons, the old config values are still supported.

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

(cherry picked from commit b72e06b13e)
2023-04-05 12:00:39 +02:00
Corvin Köhne ee3a7907bb
bhyve: add helper to read PCI IDs from bhyve config
Changing the PCI IDs is valuable in some situations. The Intel GOP
driver requires that some PCI IDs of the LPC bridge are aligned with the
physical values of the host LPC bridge. Another use case are oracles
virtio driver. They require different subvendor ID than the default one.
For that reason, create a helper which makes it easy to read PCI IDs
from bhyve config. Additionally, this helper ensures that all emulation
devices are using the same config keys.

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

(cherry picked from commit ffaed739a8)
2023-04-05 12:00:39 +02:00
Gordon Bergling f7174106ef rarpd(8): Fix a typo in a source code comment
- s/combinataion/combination/

Obtained from:	NetBSD

(cherry picked from commit 107597fbd4)
2023-03-30 08:30:52 +02:00
Mark Johnston 3b6598f874 bhyve: Sleep briefly in the VMEXIT_DEBUG handler
As of commit 0bda8d3e9f ("vmm: permit some IPIs to be handled by
userspace") and commit 9cc9abf409 ("bhyve: create all vcpus on
startup"), we have a misbehaviour where AP vCPU threads spin until they
receive a SIPI.  In particular, since they are "suspended", they simply
call the VMEXIT_DEBUG handler in a loop, but the handler is a no-op by
default.

This is tricky to fix since the gdb stub isn't aware of whether a given
vCPU is supposed to be running.  For 13.2's sake, introduce a simple
workaround wherein the VMEXIT_DEBUG handler sleeps for a short period.
This ensures that host CPU usage remains sane when VMs are starting
without penalizing users of VMEXIT_DEBUG too much.

Reviewed by:	corvink, jhb
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D39174

(cherry picked from commit ef0ac973db)
2023-03-27 08:50:12 -04:00
Corvin Köhne d468d5dd19
bhyve: add cmdline option to enable qemu's fwcfg
Let the user decide if he wants to use bhyve's fwctl or qemu's fwcfg. He
can set the interface by adding a fwcfg option to bootrom:

-l bootrom,<path/to/rom>,fwcfg=bhyve
-l bootrom,<path/to/rom>,fwcfg=qemu

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

(cherry picked from commit d85147f3d6)
2023-03-27 08:32:59 +02:00
Corvin Köhne 35bdc8b79e
bhyve: add helper for adding fwcfg files
Fwcfg items without a fixed index are reported by the file_dir. They
have an index of 0x20 and above. This helper simplifies the addition of
such fwcfg items. It selects a new free index, assigns it to the fwcfg
items and creates an proper entry in the file_dir.

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

(cherry picked from commit 6f9ebb3d0f)
2023-03-27 08:32:59 +02:00
John Baldwin f31f677c1d makefs: Ignore some sign comparison warnings from GCC.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D37470

(cherry picked from commit abb9a940bb)
2023-03-22 08:22:07 -07:00
Ed Maste a16159aa2e makefs: do not call brelse if bread returns an error
If bread returns an error there is no bp to brelse.  One of these
changes was taken from NetBSD commit 0a62dad69f62 ("This works well
enough to populate..."), the rest were found by looking for the same
pattern.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39069

(cherry picked from commit bc33c99234)
2023-03-21 11:58:40 -04:00
Ihor Antonov 799d67ec40 daemon: set supervise_enabled during argument processing
Now when supervsion mode has it's own variable there is really no
reason to set it separately from the rest of the variables. Move
initialization of supervise_enabled var to the argument processing
switch loop, where it belongs.

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672

(cherry picked from commit f907027b49)
2023-03-17 16:01:03 -05:00
Ihor Antonov ec3a7d2828 daemon: decouple restart variable
The 'restart' variable was responsible for enablement of restart
behavior and for restart delay. While it may seem convenient it
leads to cluttering the exit/restart logic

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672

(cherry picked from commit e781739084)
2023-03-17 16:01:03 -05:00
Ihor Antonov 3f0b048a24 daemon: add braces to while loop
Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672

(cherry picked from commit d6c398d882)
2023-03-17 16:01:03 -05:00
Ihor Antonov bc9d2ee0a7 daemon: simplify if/else chain
Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672

(cherry picked from commit cd1e6e70d0)
2023-03-17 16:01:02 -05:00
Ihor Antonov bb2e206cae daemon: change type of listen_child() to C99 bool
Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672

(cherry picked from commit bc43a9a715)
2023-03-17 16:01:02 -05:00
Ihor Antonov 204306b053 daemon: flatten and simplify fork() logic
Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672

(cherry picked from commit 75f61ca920)
2023-03-17 16:01:02 -05:00
Ihor Antonov 05578dd521 daemon: style changes
This is not a functional change.
- Clean up whitespace (spaces where there should be tabs)
- Break up lines that are longer than 80

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672

(cherry picked from commit 39ea4280e4)
2023-03-17 16:01:02 -05:00
Ihor Antonov 8eb1e5dd77 daemon: more human-friendly variable names
Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 129ec8f480)
2023-03-17 16:01:02 -05:00
Ihor Antonov d8b8a0316e daemon: move syslog facility and syslog tag into log_params
Since struct log_params already contains logging-related
varaiables, including syslog-related, move remaining
syslog-related variables into struct log_params as well

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 6f0636728b)
2023-03-17 16:01:02 -05:00
Ihor Antonov b71a65870f daemon: deduplicate log_params varaibles
While we're here, sort log_params by size.

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit e70444c622)
2023-03-17 16:01:02 -05:00
Ihor Antonov 5e46ebc5d0 daemon: make log_reopen variable a bool
Following style(9) and C99 recommendation use bool instead of
int for boolean operations.

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 97022e90c3)
2023-03-17 16:01:02 -05:00
Ihor Antonov d394c80f49 daemon: make dosyslog variable a bool and give it a better name
Following style(9) and C99 recommendation use bool instead of
int for boolean operations. Also give the variable a more descriptive
name that follows boolean naming convention.

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit f2f9d31d9f)
2023-03-17 16:01:01 -05:00
Ihor Antonov 6f71a68456 daemon: add supervision_enabled var
explicitly name a bunch of boolean checks that enable
supervison mode and improve comments

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 203df05b69)
2023-03-17 16:01:01 -05:00
Ihor Antonov 52f302f136 daemon: initialize struct sigaction at declaration site
This improves readability by uncluttering the code

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 259ed21d21)
2023-03-17 16:01:01 -05:00
Ihor Antonov 93871c6cff daemon: fix double init of pid variable
Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 91b921c7d4)
2023-03-17 16:01:01 -05:00
Ihor Antonov cc123f0dba daemon: initialize mask_orig with sigemptyset()
consolidation of variable declarations and initializations in previous
commit allowed me to detect that one of the signal masks is not properly
initialized with sigemptyset (as man 3 sigsetops demands)

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 84866cefdf)
2023-03-17 16:01:01 -05:00
Ihor Antonov d24c97ebfb daemon: consolidate variable declarations and initializaions
- improve readability by breaking apart single-line multi-variable declarations
- initialize simple variables at declaration site
- move other top-level variable initializations closer declarations
  to avoid potential UB and unclutter the use-site.

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit e745dc2287)
2023-03-17 16:01:01 -05:00
Ihor Antonov 488cf4bb6f daemon: use braces with 'if' consistently
Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669

(cherry picked from commit 6b4ef4b16a)
2023-03-17 16:01:01 -05:00
Ihor Antonov 282e4cf32d daemon: add long_opts
Long options improve readability of scripts, makes code comprehension
easier.  This patch adds long options while preserving the existing CLI
interface.

Also --help/-h option is added.

Reviewed by:	allanjude, pauamma (both earlier versions), kevans
Differential Revision:	https://reviews.freebsd.org/D38244

(cherry picked from commit 0a402ad2e6)
2023-03-17 16:01:01 -05:00
Vitaliy Gusev 4e10f8056b
bhyvectl: don't permit using --suspend and --checkpoint at same time
When using the --suspend and --checkpoint parameter, bhyvectl will
produce two checkpoint images and the exits. This is slightly ambiguous.
So, permit only one of theses parameters at the same time.

Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38887

(cherry picked from commit 062f2818c1)
2023-03-17 11:26:35 +01:00
Vitaliy Gusev c8ec366fd7
bhyve: init checkput before caph_enter
init_checkpoint_thread binds to a socket. Bhyve isn't allowed to do that
after caph_enter.

Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38857

(cherry picked from commit 9a9a248964)
2023-03-17 11:26:35 +01:00
Vitaliy Gusev 6efb053bea
bhyve: exit with EX_OSERR if init checkpoint or restore time failed
Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38872

(cherry picked from commit d213429e42)
2023-03-17 11:26:35 +01:00
Vitaliy Gusev 2193f12bf8
bhyve: add cap limits for ipc socket
Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38856

(cherry picked from commit 577ddca908)
2023-03-17 11:26:35 +01:00
Vitaliy Gusev c8b5f34731
bhyve: don't flush readonly device at blockif_pause
Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38855

(cherry picked from commit 5c0a031259)
2023-03-17 11:26:34 +01:00
Vitaliy Gusev f63fd20a9a
bhyvectl: don't leak nvlist in send_message
Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38900

(cherry picked from commit 942525ab47)
2023-03-17 11:26:34 +01:00
Vitaliy Gusev d2da92306a
bhyvectl: correct socket_fd closing in send_message
Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38889

(cherry picked from commit b64ba24264)
2023-03-17 11:26:33 +01:00
Vitaliy Gusev 38b37099bb
bhyvectl: do not return garbage from send_message
err is used uninitialized in some cases.

Reviewed by:		corvink, markj
MFC after:		1 week
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38886

(cherry picked from commit 89fe7b98fe)
2023-03-17 11:26:33 +01:00
Vitaliy Gusev f6a333f855
bhyve: fix resume for vms with guest_ncpus > 1
This error occurs because vm->vcpu[1] has not been allocated yet when
vm_snapshot_vm() is called.

To fix this, move spinup_vcpu() before restore code.

Reviewed by:		corvink, markj
MFC after:		2 weeks
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38477

(cherry picked from commit 9ff3e8b7f0)
2023-03-17 11:26:33 +01:00
Vitaliy Gusev 38acc80a5b
bhyve: fix restore of kernel structs
vmx_snapshot() and svm_snapshot() do not save any data and error occurs at
resume:

Restoring kernel structs...
vm_restore_kern_struct: Kernel struct size was 0 for: vmx
Failed to restore kernel structs.

Reviewed by:		corvink, markj
Fixes:			39ec056e6d ("vmm: Rework snapshotting of CPU-specific per-vCPU data.")
MFC after:		2 weeks
Sponsored by:		vStack
Differential Revision:	https://reviews.freebsd.org/D38476

(cherry picked from commit 8104fc31a2)
2023-03-17 11:26:33 +01:00
Corvin Köhne 0229691960
bhyve: add common fwcfg items
Qemu defines some common fwcfg items. We don't need to support all of
them. Only a subset needs to be present for fwcfg to work properly.

- signature
  The signature is used by the guest to check if qemu's fwcfg is
  available or not.
- id
  The id is used by the guest to check which features are supported by
  the fwcfg implementation of the hypervisor.
- file_dir
  The file dir reports all fwcfg items which don't have a fixed index.
  These are mostly user defined fwcfg items.

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

(cherry picked from commit 34f804e547)
2023-03-17 11:26:32 +01:00
Corvin Köhne 1adfb2e834
bhyve: add helper to add fwcfg items
This helper makes it easier to add multiple fwcfg items. You can pass an
index and some data to the helper. The helper adds these information to
the fwcfg emulation so that the guest reads the given data on the
specified index.

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

(cherry picked from commit 3ef46195ac)
2023-03-17 11:26:32 +01:00
Alan Somers bd66219c6d sesutil: don't malloc in a tight loop
Reported by:	mav
Sponsored by:	Axcient
Reviwed by:	mav
Differential Revision: https://reviews.freebsd.org/D38473

(cherry picked from commit 4bd4e4b45e)
2023-03-15 16:35:49 -06:00
Warner Losh aa1e6a4f4c makefs: make msdos creation go fast
Add missing brelse(bp). Without it the cache grows and we have a n^2
lookup.  I'm not entirely sure why we read the block before we write it
back out, since the only side effect of that is to allocate memory,
clear the memory, read it in from disk, throw it away with the contents
of the file being written out. We likely should just do a getblk() here
instead, but even with all that, this takes the time it takes to create
a 150MB msdos fs image down from 5 minutes to 30 seconds.

Old: 317.663u 0.685s 5:18.34 100.0%	198+360k 0+19io 1009pf+0w
New: 7.330u 23.841s 0:31.17 100.0%	198+360k 0+250522io 4pf+0w

See code review for how we got this. tl;dr: netbsd move brelse
into bwrite and we picked up msdos code after that, but not the
move. That change should be picked up later.

Sponsored by:		Netflix
Reviewed by:		emaste
MFC After:		1 day (13.2 is coming fast)
Differential Revision:	https://reviews.freebsd.org/D39025

(cherry picked from commit 370e009188)
2023-03-14 09:47:46 -06:00
Mark Johnston 25766cfd83 bhyvectl: Address compiler warnings and bump WARNS
Avoid unaligned accesses in cpu_vendor_intel() and address a few other
nits.  No functional change intended.

Reviewed by:	corvink, rew, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38839

(cherry picked from commit 3f5d875a27)
2023-03-13 11:53:16 -04:00
Mark Johnston cc7b54d6ec bhyveload: Address compiler warnings and bump WARNS
Mostly sprinkle __unused.  Also duplicate strings passed to addenv() so
that constant string literals can be passed.  No functional change
intended.

Reviewed by:	corvink, rew, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38840

(cherry picked from commit ad43dd69ce)
2023-03-13 11:53:16 -04:00
Ed Maste b562307b70 freebsd-update: use grep -E instead of egrep
GNU egrep emits a warning that it is obsolescent and suggests grep -E
instead.  Switch to grep -E in case we end up invoking GNU (e)grep (and
for consistency with other invocations in this file).

Reported by:	Steffen Nurpmeso
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e27ded83c7)
2023-03-05 19:30:57 -05:00
Ed Maste ab53efd142 mergemaster: add deprecation notice to man page
PR:		252417
Reviewed by:	bapt, gjb, kevans (all earlier)
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23327

(cherry picked from commit 398b12691b)
2023-03-05 19:30:57 -05:00
Ed Maste 24fe8a5183 freebsd-update: avoid effects of user's environment on grep
A user had GREP_OPTIONS containing --color=always, which broke grep use
in freebsd-update.  Unset this environment variable.

PR:		255990
Reviewed by:	kevans
Approved by:	re (cperciva, expedited MFC)
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e093c61b2d)
2023-03-02 13:30:54 -05:00
Ed Maste c7e3703352 freebsd-update: re-edit files if merge conflict markers remain
freebsd-update will open ${EDITOR} if conflicts occur while merging
updates to config files.  Inform the user if they've left conflict
markers behind, and go back to editing the file.

PR:		185546
PR:		229689
Reviewed by:	delphij
Approved by:	re (cperciva, expedited MFC)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37703

(cherry picked from commit ceb5f28ba5)
2023-03-02 13:29:57 -05:00
Corvin Köhne 3c12bcba78
bhyve: add emulation for qemu's fwcfg data port
The data port returns the data of the fwcfg item.

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

(cherry picked from commit b11081dca7)
2023-02-28 11:04:37 +01:00
Corvin Köhne bd8366500e
bhyve: add emulation for the qemu fwcfg selector port
The selector port is used to select the desired fwcfg item.

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

(cherry picked from commit 151d8131a8)
2023-02-28 11:04:36 +01:00
Corvin Köhne 0232125972
bhyve: add basic qemu fwcfg implementation
qemu's fwcfg and bhyve's fwctl are both used to configure ovmf. qemu's
fwcfg is much more powerfull than bhyve's fwctl. For that reason, add
support for qemu's fwcfg.

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

(cherry picked from commit 9b99de77f1)
2023-02-28 11:04:35 +01:00
Corvin Köhne 2c1cbd0836
bhyve: maintain a list of acpi devices
The list is used to generate the dsdt entry for every acpi device.

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

(cherry picked from commit fbd045021d)
2023-02-28 11:04:34 +01:00
Corvin Köhne 6726130d68
bhyve: add helper func to write a dsdt entry
The guest will check the dsdt to detect acpi devices. Therefore, add a
helper function to create such a dsdt entry for an acpi device.

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

(cherry picked from commit 682a522d61)
2023-02-28 11:04:34 +01:00
Corvin Köhne eb8931d77c
bhyve: add helper func to add acpi resources
These helper function can be used to assign acpi resources to an
acpi_device.

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

(cherry picked from commit 13a1df5b85)
2023-02-28 11:04:33 +01:00
Corvin Köhne b5d47fa9a5
bhyve: add helper struct for acpi device handling
To simplify the handling of different acpi devices like qemu fwcfg or a
tpm, add a helper struct. It will handle the reporting of acpi
resources.

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

(cherry picked from commit 1231f047c3)
2023-02-28 11:04:26 +01:00
Dimitry Andric 0196b09444 Update leap-seconds to latest leap-seconds.3676924800 (expires 2023-12-28)
Obtained from:	ftp://ftp.boulder.nist.gov/pub/time/leap-seconds.3676924800
MFC after:	3 days

(cherry picked from commit df2fbbfa71)
2023-02-27 10:21:16 +01:00
Warner Losh 8ab17c6dd1 efibootmgr: Add --efidev (-u) to discover UEFI's device path to a dev or file
"efibootmgr --efidev unix-path" will return the UEFI device-path to the
file or device specified by unix-path. It's useful for debugging, but
may also be useful for scripting.

Sponsored by:		Netflix
Reviewed by:		corvink, manu
Differential Revision:	https://reviews.freebsd.org/D38617

(cherry picked from commit 9a79152994)
2023-02-18 17:46:57 -07:00
Alan Somers c16a901eac sesutil: plug memory leaks
Sponsored by:	Axcient
Reviewed by:	bapt
Differential Revision: https://reviews.freebsd.org/D33955

(cherry picked from commit 09f29b03dd)
2023-02-15 17:32:00 -07:00
Juraj Lutter e0c3f2a1e2 unbound: Fix config file path
Commit 1838dec318 changed the
config file path to /usr/local/etc/unbound/unbound.conf which
is wrong for unbound in base.

Reported by:	Ihor Antonov <ihor_AT_antonovs_family>
Reviewed by:	zlei
Approved by:	zlei
Differential Revision: https://reviews.freebsd.org/D38106

Fixes:          1838dec318

(cherry picked from commit 1d577bedba)
2023-02-14 10:32:39 -08:00
Cy Schubert 9f9f2a1270 unbound: Fix config.h
FreeBSD src does not support HAVE_DECL_EVSIGNAL_ASSIGN. While reviewing
the new config.h after regenerating it, this definition was not removed.

Updating config.h is a manual process of configuring the port and
copying/merging the generated config.h into src. This definition was
missed and not removed (#undef'd).

Fixes:		1838dec318

(cherry picked from commit 06b93ef8cd)
2023-02-14 10:32:39 -08:00
Cy Schubert 26ba9518ff unbound: Vendor import 1.17.1
Release notes at
    https://www.nlnetlabs.nl/news/2023/Jan/12/unbound-1.17.1-released/.

Merge commit '7699e1386a16236002b26107ffd2dcbde375e197' into main

(cherry picked from commit 1838dec318)
2023-02-14 10:32:39 -08:00
Tijl Coosemans 412d15f726 local-unbound-setup: Use default root certificates
Don't force /etc/ssl/cert.pem.  It does not exist by default, only if
security/ca_root_nss is installed.  Just use the default OpenSSL search
locations which are /etc/ssl/cert.pem and /etc/ssl/certs/.

The tls-system-cert option was added in Unbound 1.16.0.

Reviewed by:	zlei
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D38243

(cherry picked from commit 8932f7ce17)
2023-02-13 11:52:20 +01:00
Stefan Eßer 6693d527a4 usr.sbin/kbdcontrol.c: Add backwards compatibility functions
This commit allows a kbdcontrol binary built with a version of kbio.h
that supports Unicode characters in dead key maps to load and display
keymaps including the dead key tables on a kernel built with a
previous version of kbio.h (that only supported 8 bit characters in
the dead key map).

This commit is meant as a temporary compatibility shim that will be
reverted when it can be assumed that all relevant systems have been
upgraded to a kernel that uses the updated kbio.h.

MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D38388

(cherry picked from commit b92f8e5c0d)
2023-02-09 22:36:09 +01:00
Xin LI d07eb716f3 etcupdate: Chase test case after pwd_mkdb(8) no longer copies comments.
(cherry picked from commit 4bbf45cf56)
2023-02-03 16:26:24 -08:00
Andre Albsmeier 3e95573311 pwd_mkdb(8): Don't copy comments from /etc/master.passwd to /etc/passwd.
The intention of /etc/passwd was to support legacy applications that are
not yet converted to use modern API like getpwent(3). Comments are not
defined in the legacy format, so copying them could break these
applications. Plus, it could leak sensitive information (e.g. encrypted
form of password of an user that was commented out instead of deleted
or disabled).

PR:		bin/144652
(cherry picked from commit 0deb25bd9d)
2023-02-03 16:25:54 -08:00
Emmanuel Vadot ee4bb682f1 pkgbase: Put devmatch in its own package
devmatch is useful on standalone machine but not on jails.
Put devinfo(8) and libdevinfo there too.

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

(cherry picked from commit e7a5a60ed5)
2023-02-02 10:32:56 +01:00
Emmanuel Vadot 01db7f820e pkgbase: Put ufs related tools and lib in their own package
It's not really useful in a jail or in a mdroot or even if a users
wants to do a full zfs machine.

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

(cherry picked from commit a7ffc94849)
2023-02-02 10:32:55 +01:00
Emmanuel Vadot 33fea630f2 pkgbase: Put accounting utilities in the acct package
(cherry picked from commit 0c6b2a9179)
2023-02-02 10:32:54 +01:00
Navdeep Parhar dde4103a46 pciconf(8): Decode ACS extended capability.
Sponsored by:	Chelsio Communications
Reviewed by:	kib@
Differential Revision:	https://reviews.freebsd.org/D37271

(cherry picked from commit 118cfb829f)
2023-02-01 23:21:59 -08:00
Navdeep Parhar 5d57964698 cxgbetool: remove unnecessary vertical whitespace.
No functional change.

(cherry picked from commit f6cc21e8e1)
2023-02-01 23:16:38 -08:00
Navdeep Parhar 1af49ac2e4 cxgbetool(8): User interface to round-robin queue selection via COP.
Queue "roundrobin" in a COP rule means the driver should select queues
for new tids in a round-robin manner.

Reviewed by:	jhb@
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D34922

(cherry picked from commit 811a82d53a)
2023-02-01 23:14:24 -08:00
Michael Tuexen 301bff9bdd ppp: improve MSS clamping
ppp supports MSS clamping for TCP/IPv4. This patch
* improves MSS clamping for TCP/IPv4 by using the MSS as specified
  in RFC 6691.
* adds support for MSS clamping for TCP/IPv6.

Reported by:		Timo Voelker
Reviewed by:		thj
Differential Revision:	https://reviews.freebsd.org/D37624

(cherry picked from commit cef3c4e0ba)
2023-02-02 01:03:50 +01:00
Michael Tuexen 0c38bb448c traceroute6: fix capabilities for the rcv socket
On the receive socket, recvmsg() and poll()/select() is called.
Therefore, CAP_EVENT is needed in addition to CAP_RECV.

While there, check the socket for readbility before calling recvmsg().

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

(cherry picked from commit 8ff4fc03e6)
2023-02-02 00:49:35 +01:00
Dag-Erling Smørgrav 93cc70bf9c 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 bc42155199)

tzcode: Address some compiler warnings.

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

(cherry picked from commit d5c85ac652)

tzcode: Move configuration into separate header.

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

(cherry picked from commit 394cf6719a)

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

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

(cherry picked from commit 3e2e5eebfa)

tzcode: Avoid memory leak if pthread_setspecific() fails.

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

(cherry picked from commit 96e68c393f)

tzcode: Fully initialize structs before use.

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

(cherry picked from commit 55572cff58)

tzcode: Silence warnings.

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

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

(cherry picked from commit 2aad7570f4)

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 4a158fc030)

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 d8c9f80891)

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 783c318fd1)

tzcode: Document zic's -D option.

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

(cherry picked from commit a7b1b73935)

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 f1021d27f7)

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:		783c318fd1
Sponsored by:	Klara, Inc.
Reviewed by:	jrtc27, emaste
Differential Revision:	https://reviews.freebsd.org/D38195

(cherry picked from commit 7a4a520064)

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 7a4a520064.

Fixes:	7a4a520064 ("Fix cross-build from STABLE or older CURRENT.")
(cherry picked from commit d4fdfd3f90)
2023-01-31 10:44:19 +01:00
John Baldwin df8c42f5ad bhyve: Mark pci_de_vinput as const.
I missed this in the prior fixup commit that added static.

Fixes:		03851ae8cd bhyve: Mark pci_de_vinput as static.
2023-01-26 14:31:57 -08:00
Robert Wing b0bd185dc3 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 5a023bd2a5)
2023-01-26 14:29:36 -08:00
John Baldwin abdc47cd69 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 cf57f20edc)
2023-01-26 14:29:06 -08:00
John Baldwin f31dc54dee 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 bfe8e339eb)
2023-01-26 14:28:56 -08:00
John Baldwin 3917791527 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 6a284cacb1)
2023-01-26 14:28:38 -08:00
John Baldwin 2ae9f7a453 bhyve: Fix a mismerge in the PCI passthrough device model.
This block of code was removed in stable/13 commit 7ea16192a0.  It
was accidentally re-added in commit aa5eea98b9 (probably due to
resolving a conflict during the merge).

This is a direct commit to stable/13.
2023-01-26 14:24:55 -08:00
John Baldwin 411ea77fed 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 b36b14beda)
2023-01-26 14:18:44 -08:00
John Baldwin 622e092eec 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 e53fcff184)
2023-01-26 14:18:27 -08:00
John Baldwin 3dcdb83c85 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 7224a96a55)
2023-01-26 14:18:20 -08:00
John Baldwin bec53b3650 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 8487443792)
2023-01-26 14:18:10 -08:00
John Baldwin 41badad786 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 a20c00c60e)
2023-01-26 14:18:00 -08:00
John Baldwin ec1ecab8c3 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 ceb0d0b0f1)
2023-01-26 14:17:52 -08:00
John Baldwin e57a5e80e9 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 461663ddba)
2023-01-26 14:17:43 -08:00
John Baldwin 05a92ae657 bhyve: Remove unused return value from spinup_ap.
Reviewed by:	corvink, markj
Differential Revision:	https://reviews.freebsd.org/D37641

(cherry picked from commit e7d5d2d187)
2023-01-26 14:17:28 -08:00
John Baldwin cd49fdbdec bhyve: Remove handler for VM_EXITCODE_SPINUP_AP.
Since commit 0bda8d3e9f, 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 007d9ca5dd)
2023-01-26 14:17:20 -08:00
John Baldwin 8dbc7c17ae 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 08b05de1e2)
2023-01-26 14:17:11 -08:00
John Baldwin ce259e6688 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 78c2cd83ec)
2023-01-26 14:16:46 -08:00
John Baldwin 8506352dd5 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 0857e5555d)
2023-01-26 14:16:35 -08:00
John Baldwin 477ca9b8ef 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 34781da505)
2023-01-26 14:16:14 -08:00
John Baldwin d829b4ef46 bhyve: Remove unused vm and vcpu arguments from vm_copy routines.
The arguments identifying the VM and vCPU are only needed for
vm_copy_setup.

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

(cherry picked from commit 2b4fe856f4)
2023-01-26 13:47:06 -08:00
John Baldwin 225443828e bhyve: Avoid passing a possible garbage pointer to free().
All of the error paths in pci_vtcon_sock_add free the sock pointer.
However, sock is not initialized until part way through the function.
An early error would pass stack garbage to free().

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

(cherry picked from commit bc92880072)
2023-01-26 12:24:14 -08:00
John Baldwin cee3658128 bhyve: Appease warning about a potentially unaligned pointer.
When initializing the device model for a PCI pass through device that
uses MSI-X, bhyve reads the MSI-X capability from the real device to
save a copy in the emulated PCI config space.  It also saves a copy in
a local struct msixcap on the stack.  Since struct msixcap is packed,
GCC complains that casting a pointer to the struct to a uint32_t
pointer may result in an unaligned pointer.

This path is not performance critical, so to appease the compiler,
simply change the pointer to a char * and use memcpy to copy the 4
bytes read in each iteration of the loop.

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

(cherry picked from commit 32b21dd271)
2023-01-26 12:24:09 -08:00
John Baldwin f995c129a5 bhyve: Fix sign compare warnings in the NVMe device model.
Reviewed by:	corvink
Differential Revision:	https://reviews.freebsd.org/D37489

(cherry picked from commit 15cebe3d63)
2023-01-26 12:24:04 -08:00
John Baldwin eb8d8798a0 bhyve: Avoid unlikely truncation of the blockif ident strings.
The ident string for NVMe and VirtIO block deivces do not contain the
bus, and the various fields can potentially use up to three characters
when printed as unsigned values (full range of uint8_t) even if not
likely in practice.

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

(cherry picked from commit 5d805962ca)
2023-01-26 12:23:58 -08:00
John Baldwin 697b7cf361 bhyve: Clear lid to 0 for internal device errors for NVMe AENs.
Reported by:	GCC
Reviewed by:	corvink, chuck, imp, markj
Differential Revision:	https://reviews.freebsd.org/D37487

(cherry picked from commit 47d6116239)
2023-01-26 12:23:52 -08:00
John Baldwin 3b70055000 bhyve: Don't leak uninitialized bits in NVMe completion statuses.
In some cases, some bits in the 16-bit status word were never
initialized.

Reported by:	GCC
Reviewed by:	corvink, chuck, markj
Differential Revision:	https://reviews.freebsd.org/D37486

(cherry picked from commit 1d9e8a9e60)
2023-01-26 12:23:47 -08:00
John Baldwin a4d4176aae bhyve: Fix sign compare warnings in the e1000 device model.
Adding a bare constant to a uint16_t promotes to a signed int which
triggers these warnings.  Changing the constant to be explicitly
unsigned instead promotes the expression to unsigned int.

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

(cherry picked from commit e7cd5ffff8)
2023-01-26 12:23:42 -08:00
John Baldwin 50c272dd2e bhyve basl: Use GCC pragmas.
These work with both clang and GCC.

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

(cherry picked from commit 0acf696151)
2023-01-26 12:23:37 -08:00
Mark Johnston 1348ad12a9 bhyve: Enable the default compiler warnings
Disable -Wcast-align for now since we have many instances of that
warning (I fixed some but not most of them) and platforms on which bhyve
runs don't particularly care about unaligned accesses.

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

(cherry picked from commit 71ebd11738)
2023-01-26 12:23:02 -08:00
John Baldwin 03851ae8cd bhyve: Mark pci_de_vinput as static.
Originally in main this was fixed in commit 37045dfa89.  However,
when that commit was merged to stable/13 in commit 976ed044fb,
pci_virtio_input was not yet merged to stable/13.  This is a direct
commit to complete the earlier MFC.
2023-01-26 12:22:43 -08:00
Mark Johnston 79135b4788 bhyve: Let BASL compile with raised warnings
- Make basl_dump() as unused.
- Avoid arithmetic on a void pointer.
- Avoid a signed/unsigned comparison with
  BASL_TABLE_CHECKSUM_LEN_FULL_TABLE.
- Ignore warnings about unused parameters from stuff pulled in by
  acpi.h.  In particular, any prototype wrapped by
  ACPI_DBG_DEPENDENT_RETURN_VOID() will raise such parameters unless
  ACPI_DEBUG_OUTPUT is defined.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D37397

(cherry picked from commit c127c61efa)
2023-01-26 12:07:12 -08:00
Mark Johnston c8a6e51a4f bhyve: Avoid using a packed struct for xhci port registers
I believe the __packed annotation is there only because
pci_xhci_portregs_read() is treating the register set as an array of
uint32_t.  clang warns about taking the address of portregs->portsc
because it is a packed member and thus might not have expected
alignment.

Fix the problem by simply selecting the field to read with a switch
statement.  This mimics pci_xhci_portregs_write().  While here, switch
to using some symbolic constants.

There is a small semantic change here in that pci_xhci_portregs_read()
would silently truncate unaligned offsets.  For consistency with
pci_xhci_portregs_write(), which does not do that, return all ones for
unaligned reads instead.

MFC after:	2 weeks
Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D37408

(cherry picked from commit 0705b7f4e6)
2023-01-26 12:06:39 -08:00
Mark Johnston e449800f0a bhyve: Fix a typo in a comment
Reported by:	Mikaël Urankar <mikael.urankar@mailo.fr>
Fixes:	719e307f80 ("bhyve: Cast away const when fetching a config nvlist")

(cherry picked from commit 84b0b7ea4c)
2023-01-26 11:43:31 -08:00
Mark Johnston b728765f88 bhyve: Address warnings about potential unaligned accesses in fwctl.c
This silences some warning about potential unaligned accesses.  No
functional change intended.

MFC after:	1 week
Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D37288

(cherry picked from commit f64f343809)
2023-01-26 11:43:26 -08:00
Warner Losh 1f1b376361 bhyve: Implement MSR_MISC_FEATURES_ENABLES
Linux reads MISC_FEATURES_ENABLES to manage the CPUID faulting feature
(undocumented in the Intel SDM, but documented in 323850-004 (Intel
Virtualization Technology FlexMigration Application Note). Since bhyve
doesn't emulate this feature, we always return 0. Neither does bhyve
support the MONITOR/MWAIT fault bit also in this MSR (which is
documented in the sdm), so always return 0.

Sponsored by:		Netflix
Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D36602

(cherry picked from commit 1d21f64149)
2023-01-26 11:43:20 -08:00
Mark Johnston a7fd3f511f bhyve: Remove an unused parameter from pci_nvme_append_iov_req()
No functional change intended.

MFC after:	1 week
Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D37116

(cherry picked from commit ae71263c66)
2023-01-26 11:43:15 -08:00
Mark Johnston 04601ccc95 bhyve: Address signed/unsigned comparison warnings in the AHCI model
No functional change intended.

MFC after:	1 week

(cherry picked from commit f0553616cf)
2023-01-26 11:43:10 -08:00
Mark Johnston a48715b58c bhyve: Address some signed/unsigned comparison warnings
MFC after:	1 week

(cherry picked from commit ed72168431)
2023-01-26 11:43:04 -08:00
Mark Johnston f233e95e8a bhyve: Address signed/unsigned comparison warnings in the e1000 model
No functional change intended.

MFC after:	1 week

(cherry picked from commit cea34d0705)
2023-01-26 11:42:59 -08:00
Mark Johnston c369cdd696 bhyve: Address warnings in blockif_proc()
- Use unsigned types for all arithmetic.  Use a new signed variable for
  holding the return value of pread() and pwrite().
- Handle short I/O from pwrite().

MFC after:	1 week

(cherry picked from commit 46f5c82896)
2023-01-26 11:42:43 -08:00
Mark Johnston dc1d08705b bhyve: Drop a bogus const qualifier
No functional change intended.

MFC after:	1 week

(cherry picked from commit eefd863cba)
2023-01-26 11:31:46 -08:00
Mark Johnston 131a87a327 bhyve: Put the prototype for vmexit_task_switch() in a header
No functional change intended.

MFC after:	1 week

(cherry picked from commit f703dc0ef0)
2023-01-26 11:31:41 -08:00
Mark Johnston ea53f4fe7b bhyve: Annotate an unused function as such
No functional change intended.

MFC after:	1 week

(cherry picked from commit eb805f4e0f)
2023-01-26 11:31:36 -08:00
Mark Johnston 1aa0ccf6f2 bhyve: USB device model structures can be qualified with "static"
No functional change intended.

MFC after:	1 week

(cherry picked from commit cd49c066a3)
2023-01-26 11:31:30 -08:00
Mark Johnston 826a7bf961 bhyve: Fix some warnings in the snapshot code
- Qualify unexported symbols with "static".
- Drop some unnecessary and incorrect casts.
- Avoid arithmetic on void pointers.
- Avoid signed/unsigned comparisons in loops which use nitems() as a
  bound.

No functional change intended.

MFC after:	1 week

(cherry picked from commit c9faf69874)
2023-01-26 11:31:17 -08:00
Mark Johnston ba7eee41ff bhyve: Put the prototype for vga_render() in a header
No functional change intended.

MFC after:	1 week

(cherry picked from commit 84633b9d52)
2023-01-26 11:31:11 -08:00
Mark Johnston 986e3ea0ab bhyve: Use the proper type for string literals
No functional change intended.

MFC after:	1 week

(cherry picked from commit 7039bdd535)
2023-01-26 11:31:06 -08:00
Mark Johnston ed9798bff0 bhyve: Avoid arithmetic on void pointers
No functional change intended.

MFC after:	1 week

(cherry picked from commit 63898728b5)
2023-01-26 11:31:00 -08:00
Mark Johnston fa466e70b3 bhyve: Address some warnings in bhyverun.c
- Annotate unused parameters as such.
- Avoid shadowing the global "vmexit".

No functional change intended.

MFC after:	1 week

(cherry picked from commit 4a1c23a708)
2023-01-26 11:30:55 -08:00
Mark Johnston 1934d1a738 bhyve: Make hda_ops function tables const
No functional change intended.

MFC after:	1 week

(cherry picked from commit 489392feb7)
2023-01-26 11:30:50 -08:00
Mark Johnston e696777efa bhyve: Annotate unused function parameters
MFC after:	1 week

(cherry picked from commit 98d920d9cf)
2023-01-26 11:30:45 -08:00
Mark Johnston a9cbcdd96f bhyve: Use designated initializers for virtio_consts tables
This is easier to read and addresses some compiler warnings.

One might expect these tables to be read-only but it seems that the
snapshot/restore code may modify them.

MFC after:	2 weeks

(cherry picked from commit 6cb261620d)
2023-01-26 11:30:39 -08:00
Mark Johnston 542eea73db bhyve: Address some warnings in bhyverun.c
- Add const and __unused qualifiers where appropriate.
- Localize some global variables.
- Consistently spell vmexit state as "vme" in vmexit handlers, to avoid
  shadowing the global vm_exit state array.
- Similarly, avoid shadowing "optarg".

MFC after:	2 weeks

(cherry picked from commit 65b8109b4e)
2023-01-26 11:30:16 -08:00
Chuck Tuffli 6c708e91f4 bhyve nvme: Fix Controller init error cases
Fuzzing of bhyve uncovered an assertion failure in the NVMe emulation.
Investigation uncovered several corner cases the code did not handle.
This change handles several Controller initialization errors, including
 - bad AQ sizes
 - bad AQ vm_map_gpa
 - doorbell writes prior to RDY
 - doorbell writes to uninitialized queue
 - CSTS.RDY if CFS set

PR:		256317,256319,256320,256322
Reported by:	Cheolwoo Myung <cwmyung@snu.ac.kr>
Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D35453

(cherry picked from commit d7d1becad4)
2023-01-26 11:29:51 -08:00
Vitaliy Gusev b22b31b380 bhyve: Snapshot impovements for 'blockif' backend
When pausing a block I/O device model as part of suspending a VM, wait
for all active block I/O requests to finish before saving snapshot
data.  This avoids having to save information about in-flight requests
both in the block_if layer and in storage device models.

For the AHCI device model, the queues are now guaranteed to be idle
when taking a snapshot, so remove the code to save queue state and
rely on the initial state in a resumed VM having all queues already
idle.

This will also simplify adding NVMe snapshot support in the future.

Reviewed by:	jhb
Sponsored by:	vStack
Differential Revision: https://reviews.freebsd.org/D26267

(cherry picked from commit cd9618bdb2)
2023-01-26 11:29:17 -08:00
Vitaliy Gusev 2c86bac0a8 bhyve: Enable suspend/resume support for virtio-blk.
Reviewed by:	jhb
Sponsored by:	vStack
Differential Revision: https://reviews.freebsd.org/D26267

(cherry picked from commit a85bbbea91)
2023-01-26 11:29:11 -08:00
James Mintram 0e81a14657 bhyve: Report an error for invalid UUIDs.
Reviewed by:	rgrimes, grehan, jhb
Differential Revision:	https://reviews.freebsd.org/D30050

(cherry picked from commit e16b709e2d)
2023-01-26 11:28:56 -08:00
Yan Ka Chiu 5fdcc90fb0 bhyve: Fix virtio-console legacy configuration parsing
virtio-console is currently missing .pe_legacy_config, which prevents any
portN configuration from being parsed, and therefore no sockets will be
created.

Reviewed by:	khng
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D35142

(cherry picked from commit 3cdfaefa4b)
2023-01-26 11:23:54 -08:00
Christian Weisgerber f2bd360bf5 man pages: Fix typo
s/the the/the/

Approved by:	ygy (doc)

(cherry picked from commit 81d1214e8a)
2023-01-26 11:23:09 -08:00
Andy Fiddaman b0e5369098 bhyve: missing mutex initializations
Explicitly initialize the mutex that a PCI virtio module passes back to
virtio.

It so happens that these mutexes were being initialized regardless, no
functional change intended.

Reviewed by:    chuck, jhb
Differential Revision:  https://reviews.freebsd.org/D34372

(cherry picked from commit f6f357efb1)
2023-01-26 11:22:48 -08:00
Andy Fiddaman 62bed9d49e bhyve: plug memory leak in topology_parse()
Reviewed by:    jhb, rew
Differential Revision:  https://reviews.freebsd.org/D34301

(cherry picked from commit ad3da82996)
2023-01-26 11:21:46 -08:00
Mark Johnston 3737a0cdcb bhyve: Fix getaddrinfo() error handling
- Use errx() since errno will not be set.
- Print the message returned by gai_strerror().

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 927aa5fefd)
2023-01-26 11:21:32 -08:00
Toomas Soome 1cc76bb620 bhyve: clean up trailing whitespaces
Clean up trailing whitespaces. No functional changes.

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

(cherry picked from commit c2fa905cf6)
2023-01-26 11:18:04 -08:00
Mateusz Piotrowski a6346d2f3e bhyve.8: Fix markup of the -G flag
(cherry picked from commit 775f6f4595)
2023-01-26 11:12:53 -08:00
Ka Ho Ng a1ef42f1cf bhyve: Fix pci device node key in bhyve_config.5
PCI device node key in the manual page is wrong. It should be
pci.bus.slot.function.

MFC after:	3 days

(cherry picked from commit e31cc1d526)
2023-01-26 11:12:44 -08:00
Mariusz Zaborski aa5f7a9152 bhyve: change a default address from ANY to localhost
Discussed with:     grehan, jhb

(cherry picked from commit 3a92927bb6)
2023-01-26 11:12:26 -08:00
Robert Crowston 7e8e5b8b80 bhyve: enhance debug info for memory range clash
Explain what the two clashing regions are.

Reivewed by:		grehan, jhb
Differential Revision:	https://reviews.freebsd.org/D29696
Pull Request:		https://github.com/freebsd/freebsd-src/pull/463

(cherry picked from commit efec757b20)
2023-01-26 11:11:36 -08:00
Filipe da Silva Santos fc3a180c17 bhyve: Fix build when BHYVE_SNAPSHOT is set
Fixes:		9cc9abf409 ("bhyve: create all vcpus on startup")
Sponsored by:	Beckhoff Automation GmbH & Co. KG
X-MFC-With:	9cc9abf409

(cherry picked from commit 10c6af3441)
2023-01-26 10:52:30 -08:00
Robert Wing 10e30f7d8f bhyve/snapshot: ..back to SOCK_STREAM
Now that nvlist_send()/nvlist_recv() are being used, ditch the datagram
socket.

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

(cherry picked from commit 690b7ea081)
2023-01-26 10:50:42 -08:00
Robert Wing 0c10a22550 bhyve: use linker set for ipc commands
Reviewed by:	markj, jhb
Differential Revision:	https://reviews.freebsd.org/D34760

(cherry picked from commit c79331a42c)
2023-01-26 10:49:41 -08:00
Robert Wing 20c0629a3b bhyve: sweep MAX_VMNAME
MAX_VMNAME is no longer used.

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

(cherry picked from commit 3ebe110934)
2023-01-26 10:49:01 -08:00
Robert Wing 4b905478ff bhyve/snapshot: limit snapshot filename to NAME_MAX
NAME_MAX is a better fit since strcat_extension() constructs the
filename of the snapshot file.

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

(cherry picked from commit 961e6a12ef)
2023-01-26 10:48:54 -08:00
Robert Wing 51b1d34820 libvmm: constify vm_get_name()
Allows callers of vm_get_name() to retrieve the vm name without having
to allocate a buffer.

While in the vicinity, do minor cleanup in vm_snapshot_basic_metadata().

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

(cherry picked from commit 3efc45f34e)
2023-01-26 10:48:47 -08:00
Robert Wing a714800283 bhyvectl: drop vm_get_name()
Grab the vm name from bhyvectl's --vm flag instead.

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

(cherry picked from commit ee0ebaa420)
2023-01-26 10:48:24 -08:00
Robert Wing 395c0adb2a bhyve/snapshot: use a string for cmd element in the nvlist
The nvlist for a checkpoint request will now look like:

    { cmd="checkpoint", suspend="true/false", filename="afilename" }

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

(cherry picked from commit 4379c1da56)
2023-01-26 10:47:33 -08:00
Robert Wing bc740a76c3 bhyve/snapshot: switch to nvlist for snapshot requests
Switch to using an nvlist with nvlist_send()/nvlist_recv() to
communicate from bhyvectl(8) to bhyve(8).

The idea is that a bhyve process receives a command with with a set of
arguments. The nvlist here is structured to reflect that premise.

For example, to snapshot the vm, the expected nvlist looks like:

    { cmd=START_CHECKPOINT, filename="filename" }

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

(cherry picked from commit edfb339d38)
2023-01-26 10:47:26 -08:00
Robert Wing 1b85302234 bhyve/snapshot: fix pthread_create() error check
pthread_create() returns 0 on success or an error number on failure.

Reviewed by:	khng, markj
Differential Revision:	https://reviews.freebsd.org/D33930

(cherry picked from commit 51fbd894dd)
2023-01-26 10:46:49 -08:00
Robert Wing 89698430bf bhyve/snapshot: split up mutex/cond initialization from socket creation
Move initialization of the mutex/condition variables required by the
save/restore feature to their own function.

The unix domain socket that facilitates communication between bhyvectl
and bhyve doesn't rely on these variables in order to be functional.

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

(cherry picked from commit fdbc86cf79)
2023-01-26 10:46:15 -08:00
Robert Wing 3c17cf307b bhyve/snapshot: provide a way to send other messages/data to bhyve
This is a step towards sending messages (other than suspend/checkpoint)
from bhyvectl to bhyve.

Introduce a new struct, ipc_message - this struct stores the type of
message and a union containing message specific structures for the type
of message being sent.

Reviewed by:    grehan
Differential Revision: https://reviews.freebsd.org/D30221

(cherry picked from commit d4870e3a72)
2023-01-26 10:46:07 -08:00
Robert Wing e96f9fa135 bhyve/snapshot: use SOCK_DGRAM instead of SOCK_STREAM
The save/restore feature uses a unix domain socket to send messages
from bhyvectl(8) to a bhyve(8) process. A datagram socket will suffice
for this.

An added benefit of using a datagram socket is simplified code. For
bhyve, the listen/accept calls are dropped; and for bhyvectl, the
connect() call is dropped.

EPRINTLN handles raw mode for bhyve(8), use it to print error messages.

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

(cherry picked from commit 38dfb0626f)
2023-01-26 10:46:01 -08:00
Robert Wing bcf297e86e bhyve/snapshot: rename and bump size of MAX_SNAPSHOT_VMNAME
MAX_SNAPSHOT_VMNAME is a macro used to set the size of a character
buffer that stores a filename or the path to a file - this file is used
by the save/restore feature.

Since the file doesn't have anything to do with a vm name, rename
MAX_SNAPSHOT_VMNAME to MAX_SNAPSHOT_FILENAME. Bump the size to PATH_MAX
while here.

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

(cherry picked from commit d656ce199d)
2023-01-26 10:45:54 -08:00
Robert Wing 2ba5f95607 bhyvectl: reduce code duplication
Combine send_start_checkpoint() and send_start_suspend() into a
single function named snapshot_request().

snapshot_request() is equivalent to send_start_checkpoint() and
send_start_suspend() except that it takes an additional argument. The
additional argument, enum ipc_opcode, is used to determine the type of
snapshot request being performed. Also, switch to using strlcpy instead
of strncpy.

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

(cherry picked from commit da9713917e)
2023-01-26 10:45:40 -08:00
Robert Wing adad7dde32 bhyve/snapshot: rename checkpoint_opcodes to be more generic
Generalize the naming here since the domain socket that uses these codes
might be used for purposes other than the save/restore feature.

- rename checkpoint_opcodes to ipc_opcode

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

(cherry picked from commit b7fd9c4e5e)
2023-01-26 10:41:45 -08:00
Robert Wing 89c376406b bhyve/snapshot: drop mkdir when creating the unix domain socket
Add /var/run/bhyve/ to BSD.var.dist so we don't have to call mkdir when
creating the unix domain socket for a given bhyve vm.

The path to the unix domain socket for a bhyve vm will now be
/var/run/bhyve/vmname instead of /var/run/bhyve/checkpoint/vmname

Move BHYVE_RUN_DIR from snapshot.c to snapshot.h so it can be shared
to bhyvectl(8).

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

(cherry picked from commit 5ce2d4a1c2)
2023-01-26 10:40:37 -08:00
Robert Wing 4fc5b31e2f libvmm: clean up vmmapi.h
struct checkpoint_op, enum checkpoint_opcodes, and
MAX_SNAPSHOT_VMNAME are not vmm specific, move them out of the vmmapi
header.

They are used for the save/restore functionality that bhyve(8)
provides and are better suited in usr.sbin/bhyve/snapshot.h

Since bhyvectl(8) requires these, the Makefile for bhyvectl has been
modified to include usr.sbin/bhyve/snapshot.h

Reviewed by:    kevans, grehan
Differential Revision:  https://reviews.freebsd.org/D28410

(cherry picked from commit 4f4065e0a2)
2023-01-26 10:37:19 -08:00
Jessica Clarke 3622fe1620 ufs: Rework shortlink handling to avoid subobject overflows
Shortlinks occupy the space of both di_db and di_ib when used. However,
everywhere that wants to read or write a shortlink takes a pointer do
di_db and promptly runs off the end of it into di_ib. This is fine on
most architectures, if a little dodgy. However, on CHERI, the compiler
can optionally restrict the bounds on pointers to subobjects to just
that subobject, in order to mitigate intra-object buffer overflows, and
this is enabled in CheriBSD's pure-capability kernels.

Instead, clean this up by inserting a union such that a new di_shortlink
can be added with the right size and element type, avoiding the need to
cast and allowing the use of the DIP macro to access the field. This
also mirrors how the ext2fs code implements extents support, with the
exact same structure other than having a uint32_t i_data[] instead of a
char di_shortlink[].

Reviewed by:	mckusick, jhb
Differential Revision:	https://reviews.freebsd.org/D33650

(cherry picked from commit 5b13fa7987)
2023-01-24 14:49:19 -07:00
Gordon Bergling 81d8988a75 cxgbetool(8): Fix common typos in sysctl descriptions
- s/addres/address/

(cherry picked from commit 74d2a3c16d)
2023-01-24 09:03:18 +01:00
Corvin Köhne 6192776124
Add a virtio-input device emulation.
This will be used to inject keyboard/mouse input events into a guest.
The command line syntax is:
   -s <slot>,virtio-input,/dev/input/eventX

Reviewed by:	jhb (bhyve), grehan
Obtained from:	Corvin Köhne <C.Koehne@beckhoff.com>
MFC after:	3 weeks
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D30020

(cherry picked from commit 054accac71)
2023-01-24 07:42:27 +01:00
John Baldwin 1154290b46 bhyve: Use XHCI_PORTREG_PTR in one place that open-coded it.
Reviewed by:	corvink, markj
Differential Revision:	https://reviews.freebsd.org/D36888

(cherry picked from commit fd104a6ebc)
2023-01-23 21:13:55 -08:00
Gordon Bergling bae0ebd08f mountd(8): Fix a typo in a source code comment
- s/ingore/ignore/

(cherry picked from commit afc55510b1)
2023-01-22 10:09:43 +01:00
Gordon Bergling afd305ea66 bsnmpget.1: Fix a typo in the man page
- s/ingore/ignore/

(cherry picked from commit 7a184a41c6)
2023-01-22 10:09:09 +01:00
Gordon Bergling 507851359a nfs: Fix a common typo in source code comments
- s/ingore/ignore/

(cherry picked from commit 72e709040f)
2023-01-22 10:08:46 +01:00
Chuck Tuffli c84ec3076e bhyve nvme: Fix uninitialized pointer
The Dataset Management code could free an uninitialized pointer if the
device doesn't support the Dataset Management command.

PR:		264548
Reported by:	Robert Morris <rtm@lcs.mit.edu>

(cherry picked from commit 7376c08cc6)
2023-01-20 16:07:27 -05:00
Gordon Bergling 592bb24c17 iwmbtfw(8): Fix a typo in a kernel message
- s/succesful/successful/

(cherry picked from commit 40bb52c89b)
2023-01-16 07:26:54 +01:00