Commit graph

1180 commits

Author SHA1 Message Date
Mark Johnston 05704402ac bhyve: Add a stub VM_EXITCODE_REG_EMUL handler
This lets us print a few fields of interest before aborting the VM loop.

No functional change intended.

Reviewed by:	corvink, andrew
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D44741
2024-06-04 15:06:42 -04:00
Mark Johnston a0ca4af945 bhyve: Add arm64 support to the gdb stub
- Add -G to the arm64 getopt handler.
- Add static register definitions and extensible XML definitions.
- Provide definitions for MD bits such as breakpoint encoding and
  length.
- Ensure that bhyve re-injects breakpoint exceptions that it is not
  responsible for.

Reviewed by:	andrew
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D44740
2024-06-04 15:03:17 -04:00
Corvin Köhne e425e601b9
bhyve: verify OpRegion size
If the OpRegion size doesn't match the size of our igd_opregion struct, it's
using a different layout than we're expecting. To avoid strange issues, we
should exit hard. If we see any devices in the field with a different OpRegion
size, we can analyse it and fix it accordingly.

Reviewed by:		markj
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45335
2024-06-04 09:08:49 +02:00
Corvin Köhne 5e09c5a1ed
bhyve: use correct size to map the OpRegion
We're already converting the size reported by the OpRegion header from
kilobytes to bytes. We don't have to do that twice when mapping the OpRegion.

Reviewed by:		markj
MFC after:		1 week
Sponsored by:		Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D45334
2024-06-04 09:08:34 +02:00
Pierre Pronchery 19dbf72a27 bhyve: correctly remove a memory mapping
In a normal code path while setting up GPU passthrough, the size
parameter to munmap() is wrong and its operation not checked for errors,
therefore leaking resources.

Reported by:	Coverity Scan
CID:		1519830
Sponsored by:	The FreeBSD Foundation

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1262
2024-05-29 13:39:29 -06:00
Pierre Pronchery f7d45c5443 bhyve: avoid side effect in assertion
An assert() was setting the error variable instead of checking it.

Reported by:	Coverity Scan
CID:		1521431
Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1244
2024-05-17 15:45:18 -04:00
Pierre Pronchery e9806d2128 bhyve: avoid resource leak in error path
In e820_finalize(), the e820_fwcfg_item variable, containing the
etc/e820 file (for the e820 table from the BIOS) is not free()'d when it
could not be added to the QEMU firmware configuration device (fw_cfg).

Reported by:	Coverity Scan
CID:		1522761
Reviewed by:	corvink, jhb
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45223
2024-05-17 12:26:27 -04:00
Pierre Pronchery 1787871a66 bhyve: avoid resource leak
In bhyve_parse_config_option(), a string is allocated and passed to
nvlist_add_string() but not free'd afterwards.

Reported by:	Coverity
CID:		1544049
Sponsored by:	The FreeBSD Foundation

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1234
2024-05-16 11:19:33 -06:00
Mark Johnston 5d62025d82 bhyve: Do not define GDB_LOG
This had been added for debugging and shouldn't have been committed.

Fixes:		f81cdf24ba ("bhyve: Add support for XML register definitions")
MFC after:	3 days
2024-05-08 12:11:09 -04:00
John Baldwin 6f308bcf57 ctl: Support NVMe requests in debug trace functions
Reviewed by:	imp
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D44719
2024-05-02 16:31:34 -07:00
SHENG-YI HONG e10b9d6602 bhyve: Move lock of uart frontend to uart backend
Currently, lock of uart in bhyve is placed in frontend. There are some
problems about it:

1. If every frontend should has a lock, why not move it inside backend
   as they all have same uart_softc.
2. If backend needs to modify the information of uart after initialize,
   it will be impossible as backend cannot use lock. For example, if we
   want implement a telnet support for uart in backend, It should wait
   for connection when initialize. After some remote process connect it,
   it needs to modify rfd and wfd in backend.

So I decide to move it to backend.

Reviewed by:	corvink, jhb, markj
Differential Revision:	https://reviews.freebsd.org/D44947
2024-05-01 11:09:31 -04:00
Mark Johnston 390e44988a bhyve: Fix handling of -r
Just make "restore_file" a global variable so that it can be set by the
MD option handler.

Reviewed by:	corvink
Reported by:	bdrewery
Fixes:		981f9f7495 ("bhyve: Push option parsing down into bhyverun_machdep.c")
Differential Revision:	https://reviews.freebsd.org/D44974
2024-04-29 10:13:50 -04:00
Chris Moerz b30a7e5418
bhyve.8: Update and rearrange to improve readability
bhyve's man page is a very long block of text that has grown to
proportions that make it hard to read.  In particular, the level of
nesting of various content means man can no longer render the text in a
user-friendly way.

To remedy this:
- move the -s argument documentation into a separate section and
  reformat the various arguments so they are consistent
- add documentation on how to use the -o config.dump feature
- make the listing of various arguments more consistent
- consolidated duplicate listings of TPM backends
- add an example for the config.dump feature
- fix various formatting inconsistencies.

Reviewed by:	emaste, imp, jrm, Pau Amma <pauamma@gundo.com>, rgrimes
Differential Revision:	https://reviews.freebsd.org/D43940
2024-04-28 00:18:35 -03:00
Mark Johnston 71b2ba9099 bhyve.8: Document arm64 support
- Mention the options that are amd64-only.
- Provide a minimal example for booting an arm64 guest.

Reviewed by:	corvink
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D44738
2024-04-24 09:58:04 -04:00
Mark Johnston 107584716c bhyve.8: Remove mention of the -A flag
It is a no-op on amd64 now and is not implemented on arm64, so let's
remove mention of it altogether so as to reduce confusion for arm64
users.

Reviewed by:	corvink, jhb
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D44737
2024-04-24 09:57:12 -04:00
Elyes Haouas ec8a394d9c usr.sbin: Remove repeated words
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/887
2024-04-11 11:53:37 -06:00
Jessica Clarke 014d7082a2 bhyve: Implement a PL031 RTC on arm64
Unlike amd64's, this RTC is implemented entirely in userspace. This is
the same RTC as is provided by QEMU's virt machine.

Reviewed by:	jhb
MFC after:	2 weeks
Obtained from:	CheriBSD
2024-04-10 11:17:56 -04:00
Jessica Clarke e3bd5730ca bhyve: Extract uart-clock from fdt_add_uart as an apb-pclk
This clock will also be used by the PL031 RTC (rather than defining
redundant per-device clocks).

Reviewed by:	jhb
MFC after:	2 weeks
Obtained from:	CheriBSD
2024-04-10 11:17:56 -04:00
Jessica Clarke 4dfa329f48 bhyve: Extend mevent to support updating timers
This will be used by a new PL031 implementation to provide an RTC for
arm64 guests.

Reviewed by:	jhb
MFC after:	2 weeks
Obtained from:	CheriBSD
2024-04-10 11:17:56 -04:00
Jessica Clarke 95b948c1d1 bhyve: Fix arm64 PCI I/O range to match FDT
This is supposed to combine with the memory range to make one contiguous
block, as is laid out in the FDT, so make this match what the OS is told
and thus actually configures.

Also drop the confusing leading zero from all three of these constants
that is making these 9 rather than 8 hex digits long (as one would
expect for a 32-bit address).

Reviewed by:	jhb
MFC after:	2 weeks
Obtained from:	CheriBSD
2024-04-10 11:17:56 -04:00
Jessica Clarke 0efad4aceb bhyve: Support legacy PCI interrupts on arm64
This allows us to remove various #ifdef hacks and enable building more
PCI devices.

Note that a hole is left in the interrupt mapping for the RTC rather
than having the two core devices straddle the PCIe interrupts. QEMU's
virt machine also takes this approach.

Reviewed by:	jhb
MFC after:	2 weeks
Obtained from:	CheriBSD
2024-04-10 11:17:56 -04:00
Mark Johnston 981f9f7495 bhyve: Push option parsing down into bhyverun_machdep.c
After a couple of attempts I think this is the cleanest approach despite
the expense of some code duplication.  Quite a few of the single-letter
bhyve options are x86-specific.

I think that going forward we should strongly discourage the addition of
new options and instead configure guests using the more general
configuration file syntax.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D41753
2024-04-10 11:17:56 -04:00
Mark Johnston 4bb929cc6d bhyve: Partially disable INT#x support in virtio for arm64
A FreeBSD guest won't make use of this support and pci_lintr_* is not
implemented on arm64.  Simply make pci_lintr_*() calls amd64-specific
for now.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D41741
2024-04-10 11:17:56 -04:00
Mark Johnston dc6a00f2e4 bhyve: Use vm_raise_msi() instead of vm_lapic_msi()
No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D41740
2024-04-10 11:17:56 -04:00
Mark Johnston f286f746f4 bhyve: Add PCI mappings for arm64
- The extended config space and BAR ranges are listed in the FDT.
- Avoid referencing I/O ports in ACPI tables.  Currently the arm64 port
  does not support ACPI in any case.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D41739
2024-04-10 11:17:56 -04:00
Mark Johnston fc98569fc3 bhyve: Do not compile PCI passthrough support on arm64
Some required kernel functionality is not yet implemented.

For now this means that one cannot specify host PCI register values, but
that functionality is only used by amd64-specific device models for now.
Note that this limitation is rather artificial; it arises only because
pci_host_read_config() lives in pci_passthru.c.

Reviewed by:	corvink, andrew, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D41738
2024-04-10 11:17:56 -04:00
Andrew Turner ff50e9d53f bhyve: Add bhyverun and vmexit handlers for arm64
Reviewed by:	corvink, jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D41006
2024-04-10 11:17:56 -04:00
Mark Johnston e497fe8657 bhyve: Use vm_get_highmem_base() instead of hard-coding the value
This reduces the coupling between libvmmapi (which creates the highmem
segment) and bhyve, in preparation for the arm64 port.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40992
2024-04-10 11:17:55 -04:00
Mark Johnston eaff4c4f92 bhyve: Add FDT building code for arm64
fdt.c provides some basic routines which let platform initialization
code build the FDT that gets passed into the guest.  For now this is not
very generic; we declare info about CPUs, memory, a single UART
(specified by -o console), a PCIe controller (used for virtio devices),
an interrupt controller and the platform timer.

Co-authored-by:	andrew
Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40996
2024-04-10 11:17:55 -04:00
Mark Johnston d878f72a73 bhyve: Provide optional libfdt linking
The arm64 port currently does not support ACPI, it instead builds up an
FDT which is exported to the guest.  This mechanism will not be used on
amd64 but isn't really arm64-specific either, so provide an opt-in
mechanism to link libfdt.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40995
2024-04-10 11:17:55 -04:00
Andrew Turner f3003a0dfb bhyve: Add PL011 UART emulation
This will be use for arm64 guests, instead of the existing ns16550 UART
model.

Reviewed by:	corvink, jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D40997
2024-04-10 11:17:55 -04:00
Mark Johnston d1c5d0cfcc bhyve: Move device model-independent UART code into a separate file
Currently bhyve implements a ns16550-compatible UART in uart_emul.c.
This file also contains generic code to manage RX FIFOs and to handle
reading from and writing to a TTY.  bhyve instantiates UARTs to
implement COM devices (via pci_lpc.c) and PCI UART devices.

The arm64 port will bring with it a PL011 device model which is used as
the default console (i.e., no COM ports).  To simplify its integration,
add a UART "backend" layer which lets UART device models allocate an RX
FIFO and interact with TTYs without duplicating code.  In particular,
code in uart_backend.* is to be shared among device models, and the
namespace for uart_emul.* is changed to uart_ns16550_*.

This is based on andrew@'s work in
https://github.com/zxombie/freebsd/tree/bhyvearm64 but I've made a
number of changes, particularly with respect to naming and source code
organization.

No functional change intended.

Reviewed by:	corvink, jhb
MFC after:	1 week
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D40993
2024-03-21 01:04:48 -04:00
Mark Johnston 8a802df1de bhyve/gdb: Avoid rebuilding target.xml for install targets
Otherwise it's impossible to install from a read-only objdir.

Fixes:	f81cdf24ba ("bhyve: Add support for XML register definitions")
Reported by:	olivier
2024-03-07 00:39:07 -05:00
Mark Johnston f81cdf24ba bhyve: Add support for XML register definitions
This is useful for exposing additional registers to debuggers.  For
instance, control registers are now available on amd64 when using gdb to
debug a guest.

The stub indicates support by including the string
"qXfer:features:read+" in its feature list.  The debugger queries for
target descriptions by sending the query "qXfer:features:read:" followed
by a file path.

The XML definitions are copied from QEMU and installed to
/usr/share/bhyve/gdb.

Note that we currently don't handle the SIMD registers at all, since
that's of somewhat limited utility (for me at least) and since that
requires new ioctls to fetch the register values.

Reviewed by:	jhb
MFC after:	2 weeks
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D43666
2024-02-20 19:51:34 -05:00
Mark Johnston e6516294f4 bhyve: Add support for the 'p' query
This lets gdb query individual registers.  It's easy to implement and is
used by gdb when attaching to a CHERI target, so let's support it.

Sponsored by:	Innovate UK
Reviewed by:	corvink, jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D43664
2024-02-07 08:46:59 -05:00
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