1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-30 08:19:09 +00:00
Commit Graph

1145 Commits

Author SHA1 Message Date
John Baldwin
c46860dbcb bhyve: Use NVMEF macro to construct fields
Reviewed by:	corvink, chuck (older version)
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43607
2024-01-29 11:02:07 -08:00
John Baldwin
c85b3903d1 bhyve: Use the NVMEM macro instead of expanded versions
Reviewed by:	corvink, chuck
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43603
2024-01-29 11:00:09 -08:00
John Baldwin
1dade1f255 nvme: Rename NVMEB helper macro to NVMEM
The current macro always builds a full mask for a named field, so use
the M suffix for mask.

Reviewed by:	chuck, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43601
2024-01-29 10:58:28 -08:00
John Baldwin
c426923606 bhyve: Use NVMEV to read the ASQS field of AQA
This is not a functional change, but just being consistent instead of
omitting a shift by 0.

Reviewed by:	corvink, chuck, imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43600
2024-01-29 10:51:07 -08:00
John Baldwin
94962f5a72 bhyve: Use the NVMEV macro instead of expanded versions
Reviewed by:	corvink, chuck (older version)
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D43598
2024-01-29 10:49:49 -08:00
Mark Johnston
5f086566e0 bhyve: Prepare to add arm64 support to the gdb stub
In particular:
- Stop assuming that the breakpoint size is one byte.
- Avoid referencing the "rip" field in machine-independent code, use a
  helper.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D43483
2024-01-23 11:41:13 -05:00
Mark Johnston
5e728af444 bhyve: Simplify register definitions a bit
It's awkward to have separate tables for information which is logically
connected.  Merge the gdb_regset[] and gdb_regsize[] arrays and update
gdb_read_regs() to cope with the result.  This makes the addition of
arm64 support a bit cleaner.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D43481
2024-01-23 11:40:52 -05:00
Mark Johnston
cfa2c78aee bhyve: Avoid underflows when handling remote commands
Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D43480
2024-01-23 11:40:40 -05:00
Robert Wing
fdd1e1a564 bhyve: correct slirp_recv_disable()
Reviewed by:	corvink, markj
Differential Revision:	https://reviews.freebsd.org/D43472
2024-01-17 09:12:44 -09:00
rilysh
e2e956828c bhyve: return ENOMEM instead of EFAULT and call free() after being used
1. In basl_load() function, when allocation fails,
it returns an EFAULT instead of ENOMEM. An EFAULT
can mislead in some scenarios, whereas an ENOMEM
for an allocation function makes much more sense.

2. Call free() on addr, as it's not being used
anymore after the basl_table_append_bytes()
function.

Signed-off-by: rilysh <nightquick@proton.me>

MFC after:	1 week
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1016
2024-01-16 09:39:25 -05:00
Peter Grehan
0c243cd4a3 Fix issue with Linux guest XHCI tablet probing.
The USB3 spec mandates that the	device-descriptor max packet size
be 512 bytes, which requires a field size of 9 since it	is a
power-of-2.

Linux kernels recently started validating this field, resulting	in
the table not being probed and the cursor not working in bhyve VNC.

Reviewed by:	corvink
PR:		275760
MFC after:	1 week
2024-01-14 21:38:55 +10:00
Robert Wing
0600b57540 bhyve: verify that user provided fbuf values fall within limits
The upper limits for height/width are already checked, this commit
enforces the lower limit as well.

The behavior is also changed such that, the framebuffer fails to
initialize if the provided values don't parse cleanly.

Reviewed by:	corvink, jhb
Differential Revision:	https://reviews.freebsd.org/D42692
2023-12-29 11:37:57 -09:00
Vitaliy Gusev
b831c7732c bhyve: increase SNAPSHOT_BUFFER_SIZE
After commit fb51ddb20d, suspending a vm fails with the error:
    vm_snapshot_buf: buffer too small

Sponsored by:   vStack
Reviewed by:    markj, rew
Fixes: fb51ddb20d ("bhyve: increase fbuf display resolution limit")
Differential Revision: https://reviews.freebsd.org/D43218
2023-12-29 08:52:40 -09:00
rilysh
8f0498208d bhyve/audio.c: avoid re-calculating the length of dev_name
In the function audio_init(), strlen() is being called two times,
first to get the length of dev_name and second to use in memcpy().
Creating a local variable and keeping the length avoids this
re-calculation.

Signed-off-by: rilysh <nightquick@proton.me>
Reviewed by: imp, zlei
Pull Request: https://github.com/freebsd/freebsd-src/pull/945
2023-12-26 09:36:31 -07:00
Konstantin Belousov
72f1e31f5f bhyve.8: fix -k description
Apparently 19eaa01bea inserted -K description in the middle of -k.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D43164
2023-12-22 17:29:33 +02:00
Konstantin Belousov
59a35b7c6b bhyve.8: add missed dot
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D43164
2023-12-22 17:29:25 +02:00
Bojan Novković
ca96a942ca bhyve: refactor gdbstub to enable single-stepping on AMD CPUs
This patch refactors the existing Intel-specific single-stepping
mechanism in bhyve's GDB stub to work with both AMD and Intel CPUs.

Reviewed by:	jhb
Sponsored by:	Google, Inc. (GSoC 2022)
Differential Revision: https://reviews.freebsd.org/D42298
2023-12-12 15:28:59 -08:00
Mark Johnston
1cc96501e5 bhyve: Fix a leak that happens when we fail to load a hostfwd rule
Reported by:	Coverity
Fixes:		c5359e2af5 ("bhyve: Add a slirp network backend")
2023-12-01 09:46:31 -05:00
Warner Losh
4d65a7c695 usr.sbin: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:01 -07:00
Mark Johnston
c5359e2af5 bhyve: Add a slirp network backend
This enables a subset of the functionality provided by QEMU's user
networking implementation.  In particular, it uses net/libslirp, the
same library as QEMU.

libslirp is permissively licensed but has some dependencies which make
it impractical to bring into the base system (glib in particular).  I
thus opted to make bhyve dlopen the libslirp.so, which can be installed
via pkg.  The library header is imported into bhyve.

The slirp backend takes a "hostfwd" which is identical to QEMU's
hostfwd.  When configured, bhyve opens a host socket and listens for
connections, which get forwarded to the guest.  For instance,
"hostfwd=tcp::1234-:22" allows one to ssh into the guest by ssh'ing to
port 1234 on the host, e.g., via 127.0.0.1.  I didn't try to hook up
guestfwd support since I don't personally have a use-case for it yet,
and I think it won't interact nicely with the capsicum sandbox.

Reviewed by:	jhb
Tested by:	rew
MFC after:	1 month
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D42510
2023-11-22 15:18:46 -05:00
Mark Johnston
be74aede49 bhyve: Split backends into separate files
Currently the net_backend structure definition is private to
net_backends.c, so all of the backend definitions are there.  While
adding a new backend to use libslirp, it was noted that this file is
somewhat cluttered.  Move the netmap and netgraph backends to their own
files and clean up includes a bit.  No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	3 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D42689
2023-11-22 15:18:46 -05:00
Robert Wing
fb51ddb20d bhyve: increase fbuf display resolution limit
This enables connecting to the VNC server at a higher resolution.

Reviewed by:	corvink, markj
Differential Revision:	https://reviews.freebsd.org/D42620
2023-11-20 16:17:53 -09:00
Mark Johnston
4e288572b8 bhyve: Fix the GDB_LOG build
MFC after:	1 week
Fixes:	7d9ef309bd ("libvmmapi: Add a struct vcpu and use it in most APIs.")
2023-11-11 12:15:30 -05:00
Dan McGregor
d7f9a421df bhyve(8): fix manpage formatting
In commit 67c26eb2a5 a stray ".El" was introduced, breaking
formatting of options.

Reviewed by:	corvink, markj
Fixes:		67c26eb2a5 ("bhyve: add cmdline option for TPM emulation")
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D42434
2023-11-02 10:50:10 -04:00
Warner Losh
1fc478fb48 bhyve: ps2 implement command 0xf6
Implement PS2 Keyboard command 0xf6, which is "SET DEFAULTS". This is
the same as 0xf5 (DISABLE KEYBOARD), but without disabling the keyboard
(since that resets all the defaults as a side effect). Normally, we
clear the fifo when we re-enable the keyboard. However, since this
leaves the keyboard enabled, clear the fifo as part of this command and
send an ack.

Linux's keyboard driver sends this command on reboot. Other commands
enable / reset the kebyoard, so it doesn't matter too much this isn't
implemented for booting, eg ubuntu.

Sponsored by:		Netflix
Reviewed by:		corvink, markj
Differential Revision:	https://reviews.freebsd.org/D42384
2023-10-31 14:52:22 -06:00
Gleb Smirnoff
f407a72a50 bhyve: fix arguments to ioctl(VMIO_SIOCSIFFLAGS)
ioctl(2)'s with integer argument shall pass command argument by value,
not by pointer.  The ioctl(2) manual page is not very clear about that.
See sys/kern/sys_generic.c:sys_ioctl() near IOC_VOID.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D42366
Fixes:			fd8b9c73a5
2023-10-26 02:59:21 -07:00
Vitaliy Gusev
7de582874e bhyve: Remove init_snapshot() and initialize static vars
vCPU threads are starting before init_snapshot() is called. That can lead
to corruption of vcpu_lock userspace mutex (snapshot.c) and then VM hangs
in acquiring that mutex.

init_snapshot() initializes only static variables (mutex, cv) and that
code can be optimized and removed.

Fixes:		9a9a248964 ("bhyve: init checkput before caph_enter")
Reviewed by:	markj
MFC after:	1 week
Sponsored by:	vStack
2023-10-17 14:26:51 -04:00
Jan Bramkamp
fd8b9c73a5 bhyve: Use VMIO_SIOCSIFFLAGS instead of SIOCGIFFLAGS
Creating an IP socket to invoke the SIOCGIFFLAGS ioctl on is the only
thing preventing bhyve from working inside a bhyve jail with IPv4 and
IPv6 disabled restricting the jailed bhyve process to only access the
host network via a tap/vmnet device node.

PR:		273557
Fixes:		56be282bc9 ("bhyve: net_backends, automatically IFF_UP tap devices")
Reviewed by:	markj
MFC after:	1 week
2023-10-17 11:24:11 -04:00
Corvin Köhne
4a3810075f
bhyve: fix buffer overflow in QemuFwCfg
We're accessing one element of the newly allocated and the old directory
too much.

Reported by:		andy@omniosce.org
Reviewed by:		markj
Fixes:			6f9ebb3d0f ("bhyve: add helper for adding fwcfg files")
MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D42220
2023-10-17 15:57:28 +02:00
John Baldwin
b0936440b8 bhyve: Replace many fprintf(stderr, ...) calls with EPRINTLN
EPRINTLN handles newlines appropriately when stdout/stderr have been
reused as the backend for a serial port.

For bhyverun.c itself, the rule this attempts to follow is to use
regular fprintf/perror/warn/err prior to init_pci() (which is when
serial ports are configured) and to switch to EPRINTLN afterwards.

Reviewed by:	corvink, markj
Differential Revision:	https://reviews.freebsd.org/D42182
2023-10-16 15:17:48 -07:00
John Baldwin
edd2a9b887 bhyve ahci: Replace WPRINTF with EPRINTLN
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D42181
2023-10-13 12:26:58 -07:00
John Baldwin
f0852344e7 bhyve: Some fwctl simplifications.
- Collapse IDENT_SEND/IDENT_WAIT states down to a single state.

- Remove unused 'len' argument to op_data callback.  The value passed
  in (total amount of remaining data to receive) didn't seem very useful
  and no op_data implementations used it.

Reviewed by:	corvink, markj
Differential Revision:	https://reviews.freebsd.org/D41286
2023-10-13 12:26:22 -07:00
Chuck Tuffli
32557d16e2 bhyve nvme: Add NQN value
Add a NVMe Qualified Name (NQN) to the Controller Data structure using
the "first format" (i.e., "... used by any organization that owns a
domain name" Section 7.9 NVM-Express 1.4c 2021.06.28 Ratified).

This avoids a Linux kernel warning about a missing or invalid NQN.

Reviewed by:	jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42058
2023-10-12 15:08:05 -07:00
Yuri Pankov
da202b0fe6 bhyve: Document the hw.vmm.maxcpu tunable and the current limit on vCPUs
Reviewed by:	corvink (original version)
Co-authored-by: John Baldwin <jhb@FreeBSD.org>
Differential Revision:	https://reviews.freebsd.org/D40074
2023-10-12 12:49:47 -07:00
Benedict Reuschling
a3b3e89ff1 bhyve(8): Fix style warnings emitted by mandoc, no content changes 2023-10-09 16:43:35 +00:00
Felix Johnson
8120190f80 bhyve(8): Expand the -p option text with additional text and an example
PR:	249981
2023-10-09 16:32:33 +00:00
Mark Johnston
7228ad8da9 bhyve: Move the vm_inject_fault() implementation to vmexit.c
This function isn't generic and has a different signature on arm64.  No
functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40991
2023-10-04 12:53:17 -04:00
Mark Johnston
83b003fbe9 bhyve: Build the HPET ACPI table on amd64 only
There is no HPET on arm64 and vm_get_hpet_capabilities() is not
implemented there.  Move the vm_get_hpet_capabilities() call into
build_hpet(): I cannot see a downside, and doing so eliminates a global
variable and reduces the amount of code that needs to be conditionally
compiled.  No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40990
2023-10-04 12:53:17 -04:00
Mark Johnston
f82af74c76 bhyve: Move most early initialization into an MD routine
Prior to initializing PCI devices, main() calls a number of
initialization routines, many of which are amd64-specific.  Move this
list of calls to bhyverun_machdep.c.  Similarly, add an MD function to
handle late initialization.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40989
2023-10-04 12:53:17 -04:00
Mark Johnston
e20b74da22 bhyve: Move vcpu initialization into a MD source file
- Make handling of x86 config options, like x86.x2apic, conditional to
  amd64.
- Move fbsdrun_set_capabilities() and spinup_vcpu() to a new file,
  bhyverun_machdep.c.  The moved code is all highly x86 specific.

I'm not sure how best to handle the namespace.  I'm using "bhyve_" for
MD functions called from MI code.  We also have "fbsdrun_" for some MI
routines that are typically called from MD code.  The file name is
prefixed by "bhyverun_".

Reviewed by:	corvink
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40987
2023-10-04 12:53:17 -04:00
Mark Johnston
ca2cda98d2 bhyve: Make gdb support optional
Add a BHYVE_GDB_SUPPORT make variable that can be set by per-arch
makefiles.  When set, BHYVE_GDB is defined and can be used as a
preprocessor predicate.  Use it to guard gdb stub calls in MI code.

The arm64 bhyve port currently does not have a functional gdb stub, but
that's not critical to landing the port, so this mechanism slightly
reduces the friction of adding support for a new platform.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40986
2023-10-04 12:53:17 -04:00
Mark Johnston
31cf78c921 bhyve: Make most I/O port handling specific to amd64
- The qemu_fwcfg interface, as implemented, is I/O port-based, but QEMU
  implements an MMIO interface that we'll eventually want to port for
  arm64.
- Retain support for I/O space PCI BARs, simply treat them like MMIO
  BARs for most purposes, similar to what the arm64 kernel does.  Such
  BARs are created by virtio devices.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40741
2023-10-04 12:53:17 -04:00
Mark Johnston
61429b49d2 bhyve: Conditionally compile framebuffer-related code
The arm64 port does not implement VGA, so move the device model sources.
Compile framebuffer code only on amd64 for now, but do not move the
sources, as we ought to be able to add support later.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40740
2023-10-04 12:53:17 -04:00
Mark Johnston
55c13f6e7a bhyve: Move legacy PCI interrupt handling under amd64/
Specifically, move IO-APIC, LPC and PIRQ routing code under amd64/.

Use ifdefs to conditionally compile related code in other files.  In
particular, legacy PCI interrupt handling is now compiled only on amd64.
This is not too invasive, but suggestions for a more modular approach
would be appreciated.

I am not sure why qemu fwcfg handling is tied to LPC, and I suspect it
should be decoupled.  In this commit I just apply an ifdef hammer, but
we will eventually want fwcfg on arm64 as well.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40739
2023-10-04 12:53:17 -04:00
Mark Johnston
71cc76e8d7 bhyve: Compile some device models only on amd64
These models register legacy PCI interrupts, which won't be supported in
the arm64 port.  In principle it should be possible to make these models
work on arm64 with a bit of effort, so don't move the sources to the
amd64 subdirectory.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40738
2023-10-04 12:53:17 -04:00
Mark Johnston
c7c5d3e388 bhyve: Move AP startup code to amd64/
This code is only invoked via MD vmexit handlers.  No functional change
intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40737
2023-10-04 12:53:17 -04:00
Mark Johnston
4ab7aea8ec bhyve: Move the gvt-d driver to amd64/
It is amd64-only.  No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40736
2023-10-04 12:53:16 -04:00
Mark Johnston
75d1e855b0 bhyve: Move power management code to amd64/
This implements various x86-specific interfaces.  No functional change
intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40735
2023-10-04 12:53:16 -04:00
Mark Johnston
a7f6c2ff73 bhyve: Move the RTC driver to amd64/
No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40734
2023-10-04 12:53:16 -04:00
Mark Johnston
548b11228f bhyve: Move MSR emulation into amd64/
No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40733
2023-10-04 12:53:16 -04:00