Commit Graph

1087 Commits

Author SHA1 Message Date
Mark Johnston
f0553616cf bhyve: Address signed/unsigned comparison warnings in the AHCI model
No functional change intended.

MFC after:	1 week
2022-10-25 11:16:57 -04:00
Mark Johnston
46f5c82896 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
2022-10-25 11:16:56 -04:00
Mark Johnston
e008f5be72 bhyve: Fix a typo in a function name
MFC after:	1 week
2022-10-25 11:16:56 -04:00
Mark Johnston
03f7ccab32 bhyve: Avoid arithmetic on void pointers
No functional change intended.

MFC after:	1 week
2022-10-25 11:16:56 -04:00
Mark Johnston
3b6cb9b436 bhyve: Avoid shadowing global variables in bhyverun.c
- Rename the global cores/sockets/threads to cpu_cores/sockets/threads.
  This way, num_vcpus_allowed() doesn't shadow them.
- The global maxcpus is unused, remove it for the same reason.

MFC after:	1 week
2022-10-25 11:16:56 -04:00
Mark Johnston
eefd863cba bhyve: Drop a bogus const qualifier
No functional change intended.

MFC after:	1 week
2022-10-24 17:35:16 -04:00
Mark Johnston
fb7ce0a95e bhyve: Use the new vm_limit_rights() interface
This addresses a compiler warning arising from the fact that bhyve
needs to cast away a const qualifier in order to call free().

No functional change intended.

Reviewed by:	jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D37099
2022-10-24 17:33:13 -04:00
Vitaliy Gusev
3b5e5ce87b bhyve: Handle snapshots of unconfigured virtio-net devices
In case of device reset or not configured - features_negotiated is not
set, calling calling pci_vtnet_neg_features is wrong and resume gets
"Segmentation fault".

Reviewed by:	markj
Sponsored by:	vStack
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36244
2022-10-23 14:50:43 -04:00
Mark Johnston
eb805f4e0f bhyve: Annotate an unused function as such
No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
489392feb7 bhyve: Make hda_ops function tables const
No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
84633b9d52 bhyve: Put the prototype for vga_render() in a header
No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
f703dc0ef0 bhyve: Put the prototype for vmexit_task_switch() in a header
No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
c9faf69874 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
2022-10-23 11:11:33 -04:00
Mark Johnston
63898728b5 bhyve: Avoid arithmetic on void pointers
No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
cd49c066a3 bhyve: USB device model structures can be qualified with "static"
No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
7039bdd535 bhyve: Use the proper type for string literals
No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
33dfef5cf3 bhyve: Fix some warnings in the ps2 emulation code
- Include headers containing prototypes for exported functions.
- Initialize all fields of the extended translation table.
- Qualify an unexported translation table as static.
- Fix error handling for a read(2).
- Fix some style bugs.

No functional change intended.

MFC after:	1 week
2022-10-23 11:11:33 -04:00
Mark Johnston
4a1c23a708 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
2022-10-23 11:11:33 -04:00
Corvin Köhne
0bda8d3e9f vmm: permit some IPIs to be handled by userspace
Add VM_EXITCODE_IPI to permit returning unhandled IPIs to userland.
INIT and STARTUP IPIs are now returned to userland. Due to backward
compatibility reasons, a new capability is added for enabling
VM_EXITCODE_IPI.

Reviewed by:		jhb
Differential Revision:  https://reviews.freebsd.org/D35623
Sponsored by:           Beckhoff Automation GmbH & Co. KG
2022-10-14 12:03:05 +02:00
Mark Johnston
5b966d7871 bhyve: Initialize the return value in blockif_register_resize_callback()
MFC after:	1 week
2022-10-08 11:33:43 -04:00
Mark Johnston
3dddf73ee1 bhyve: Make bc_magic unsigned
This addresses a number of compiler warnings about signed/unsigned
comparisons in assertions.

MFC after:	1 week
2022-10-08 11:33:43 -04:00
Mark Johnston
07d82562d8 bhyve: Make pci_bars local to pci_emul.c
MFC after:	1 week
2022-10-08 11:33:42 -04:00
Mark Johnston
98d920d9cf bhyve: Annotate unused function parameters
MFC after:	1 week
2022-10-08 11:33:21 -04:00
John Baldwin
2fb81691b0 bhyve: Don't free an invalid pointer.
The netmap-specific data stored at be->opaque is freed by the caller
on error as part of freeing be.

Reviewed by:	markj
Reported by:	GCC -Wfree-nonheap-object
Differential Revision:	https://reviews.freebsd.org/D36828
2022-10-03 16:10:44 -07:00
Mark Johnston
65b8109b4e 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
2022-09-29 12:36:44 -04:00
Mark Johnston
6cb261620d 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
2022-09-29 12:36:44 -04:00
Mark Johnston
ee83710bc4 bhyve: Address compiler warnings in audio.c
- Avoid arithmetic on void pointers.
- Avoid a signed/unsigned comparison in loops which write or fill audio
  data buffers.

Convert while loops to for loops while here.

MFC after:	2 weeks
2022-09-29 12:36:44 -04:00
Mark Johnston
57d96d8df9 bhyve: Address -Wno-unused warnings in atkbd.c
MFC after:	2 weeks
2022-09-29 12:36:44 -04:00
Mark Johnston
889cec66d3 bhyve: Make smbios tables local to smbiostbl.c
Also flag them as const.

MFC after:	2 weeks
2022-09-29 12:36:44 -04:00
Filipe da Silva Santos
10c6af3441 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
2022-09-13 08:32:09 +02:00
Emmanuel Vadot
3fc174845c Revert "vmm: permit some IPIs to be handled by userspace"
This reverts commit a5a918b7a9.

This cause some problem with vm using bhyveload.

Reported by:	pho, kp
2022-09-09 15:55:01 +02:00
Corvin Köhne
a5a918b7a9 vmm: permit some IPIs to be handled by userspace
Add VM_EXITCODE_IPI to permit returning unhandled IPIs to userland.
INIT and Startup IPIs are now returned to userland. Due to backward
compatibility reasons, a new capability is added for enabling
VM_EXITCODE_IPI.

MFC after:              2 weeks
Differential Revision:  https://reviews.freebsd.org/D35623
Sponsored by:           Beckhoff Automation GmbH & Co. KG
2022-09-07 09:07:03 +02:00
Corvin Köhne
9cc9abf409 bhyve: create all vcpus on startup
vcpus could be restarted by the guest by sending an INIT SIPI SIPI
sequence to a vcpu. That's not supported by bhyve yet but it will be
supported in a future commit. So, create the vcpu threads only once on
startup to make restarting a vcpu easier.

MFC after:		2 weeks
Differential Revision:	https://reviews.freebsd.org/D35621
Sponsored by:		Beckhoff Automation GmbH & Co. KG
2022-09-07 09:05:36 +02:00
Gordon Bergling
886ce99dea bhyve(4): Remove a double word in a source code comment
- s/the the/the/

MFC after:	3 days
2022-09-04 13:57:00 +02:00
John Baldwin
bb31aee26b bhyve virtio-scsi: Avoid out of bounds accesses to guest requests.
- Ignore I/O requests with insufficiently sized input or output
  buffers (those not containing compete request headers).

- Ignore control requests with improperly sized buffers.

- While here, explicitly zero the output header of an I/O request to
  avoid leaking malloc garbage from the host if the header is not
  fully populated.

PR:		264521
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	mav, emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36271
2022-08-29 15:37:27 -07:00
John Baldwin
62806a7f31 bhyve virtio-scsi: Tidy warning and debug prints.
Use a consistent prefix ("virtio-scsi: ") similar to the e1000 device
model.

Reviewed by:	mav, emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36270
2022-08-29 15:37:15 -07:00
John Baldwin
7afe342dcb bhyve e1000: Sanitize transmit ring indices.
When preparing to transmit pending packets, ensure that the head (TDH)
and tail (TDT) indices are in bounds.  Note that validating values
when they are written is not sufficient along as the transmit length
(TDLEN) could be changed turning a value that was valid when written
into an out of bounds value.

While here, add further restrictions to the head register (TDH).  The
manual states that writing to this value while transmit is enabled can
cause unexpected behavior and that it should only be written after a
reset.  As such, ignore attempts to write while transmit is active,
and also ignore writes of non-zero values.  Later e1000 chipsets have
this register as read-only.

Also ignore any attempts to transmit packets if the transmit ring's
size is zero.

PR:		264567
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36269
2022-08-29 15:36:57 -07:00
John Baldwin
baf753cc19 bhyve: Support other schemes for naming pass-through devices.
Permit naming pass through devices using the syntax accepted by
pciconf (pci[<domain>:]<bus>:<slot>:<func>) as well as by device name
(e.g. "ppt0").

While here, fix an error in the manpage that had the bus and slot
arguments for the original /-delimited scheme swapped.

Reviewed by:	imp, markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36147
2022-08-19 14:58:55 -07:00
John Baldwin
fa46f3704b bhyve e1000: Skip packets with a small header.
Certain operations such as checksum insertion and VLAN insertion
require the device model to rewrite the packet header.  The first step
in rewriting the packet header is to copy the existing packet header
from the source packet.  This copy is done by copying data from an
iovec array that corresponds to the S/G entries described by transmit
descriptors.  However, if the total packet length is smaller than the
headers that need to be copied as the initial template, this copy can
overflow the iovec array and use garbage values as the source pointer
to memcpy.  The PR used a single descriptor with a length of 0 in its
PoC.

To fix, track the total packet length and drop requests to transmit
packets whose payload is smaller than the required header length.

While here, fix another issue where the final descriptor could have an
invalid length (too short) that could underflow 'len' when stripping
the checksum.  Skip those requests instead, too.

PR:		264372
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	grehan, markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36182
2022-08-17 10:01:16 -07:00
John Baldwin
e7439f6aeb bhyve xhci: Cache the value of MaxPStreams when initializing an endpoint.
This avoids type confusion where a malicious guest could rewrite the
MaxPStreams field in an endpoint context after the endpoint was
initialized causing the device model to interpret a guest provided
address (stored in ep_ringaddr of the "software" endpoint state) as a
bhyve host process address (ep_sctx_trbs).  It also prevents a malicious
guest from triggering overflows of ep_sctx_trbs[] by increasing the
number of streams after the endpoint has been initialized.

Rather than re-reading the MaxPStreams value out of the endpoint context
in guest memory on subsequent operations, cache the value in the software
endpoint state.  Possibly the device model should raise errors if the
value of MaxPStreams changes while an endpoint is running.  This approach
simply ignores any such changes by the guest.

PR:		264294, 264347
Reported by:	Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	markj
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36181
2022-08-17 10:00:36 -07:00
John Baldwin
bcab868a65 bhyve: Style fix for read/write_config. 2022-08-17 10:00:09 -07:00
Chuck Tuffli
6391be3089 bhyve nvme: Switch to POSIX standard functions
Switch bzero to memset and bcopy to memcpy

Reviewed by:	imp, jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36215
2022-08-16 17:23:27 -07:00
Mark Johnston
d06bf11c06 bhyve: Sprinkle const qualifiers where appropriate
No functional change intended.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-08-16 14:21:44 -04:00
Mark Johnston
37045dfa89 bhyve: Mark variables and functions as static where appropriate
Mark them const as well when it makes sense to do so.  No functional
change intended.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-08-16 14:21:44 -04:00
Mark Johnston
75ce327a2c bhyve: Use "void" instead of empty parameter lists
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-08-16 14:21:44 -04:00
Chuck Tuffli
715f82e4f5 bhyve nvme: Support minimal Controller list
Controllers must support the Identify Controller list if they support
Namespace Management. But the UNH NVMe tests use this command regardless
of whether the device under test supports Namespace Management.

This implementation returns an empty Controller list (i.e., Number of
Identifiers is zero).

Fixes UNH Test 1.1.2

Reviewed by:	jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36193
2022-08-16 09:15:53 -07:00
Chuck Tuffli
ec0efe34dd bhyve nvme: Fix reported SANICAP value
The NVMe specification only allows Controllers compliant with the
revision 1.3 and earlier specification to report a value of 0x0 in the
No-Deallocate Modifies Media After Sanitize (NODMMAS) field.

For our revision 1.4 Controller, report that media is not modified after
Sanitize as the implementation does not implement Sanitize.

Fixes UNH Test 1.1.2

Reviewed by:	jhb
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36192
2022-08-16 09:14:43 -07:00
Wanpeng Qian
9f678cfcb4 bhyve nvme: Fix firmware read only initialization
Summary:
Code was using the mask value without the shift.

Test Plan: Within FreeBSD/Linux guest, Identify NVMe controller to check the result.

Reviewed by:	chuck, imp
MFC after:	2 weeks
Signed-off-by:	Wanpeng Qian <wanpengqian@gmail.com>
Differential Revision: https://reviews.freebsd.org/D32659
2022-08-14 09:59:36 -07:00
WanpengQian
3cae10048d bhyve nvme: Fix Active Firmware Info
Summary:
Currently Active Firmware Info is not initialized.

Fix is to initialize the Active Firmware Info to Slot 1.

Test Plan: Within FreeBSD/Linux guests, show the Firmware Logpage to confirm.

Reviewed By:	chuck
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D32658
2022-08-14 09:59:36 -07:00
WanpengQian
eae0210cdd bhyve: Fix Number of Power States Supported value
Summary:
Set Number of Power States Supported to indicate 1 power state. Keep the
Power State Descriptor data structures as zero to indicate "Not
reported".

Test Plan:
Within FreeBSD/Linux guests, list the number of power states and check
the Max Power value.

Reviewed By:	markj, chuck
MFC after:	2 weeks
Signed-off-by:	Wanpeng Qian <wanpengqian@gmail.com>
Differential Revision: https://reviews.freebsd.org/D32657
2022-08-14 09:59:36 -07:00
Mark Johnston
b6ecef28bf bhyve: Address uses of uninitialized variables in pci_nvme.c
The debug print in nvme_opc_get_log_page() would print an uninitialized
local variable.

In nvme_opc_write_read(), a failed LBA bounds check would cause
pci_nvme_stats_write_read_update() to be called with an uninitialized
variable as a parameter.  Although the parameter is unused when the
check fails (and so status != 0), LLVM 14 emits some bogus machine code
in this path, which happens to result in a segfault when it gets
executed.

PR:		265749
Reviewed by:	chuck, emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36119
2022-08-14 11:59:01 -04:00
Mark Johnston
af86d12c80 bhyve: Address -Wunused* warnings in pci_nvme.c
Currently these are not reported because bhyve is compiled with WARNS=2.
Let's start taking small steps towards enabling more warnings.

No functional change intended.

Reviewed by:	chuck, imp, emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36118
2022-08-14 11:56:33 -04:00
Chuck Tuffli
7376c08cc6 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>
2022-08-14 07:53:22 -07:00
Chuck Tuffli
d7d1becad4 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
2022-08-14 07:47:34 -07:00
Chuck Tuffli
3d3678627c bhyve nvme: Check return value of mapped memory
Fuzzing of bhyve using hyfuzz discovered a way to cause a segmentation
fault in the NVMe emulation. If a guest specifies a physical address in
either the PRP1 or PRP2 field of a command that cannot be mapped from
guest to host, the function paddr_guest2host() returns a NULL pointer.
The NVMe emulation did not check for this error case, which allowed for
the segmentation fault to occur.

Fix is to check for a return value of NULL and indicate an error back to
the guest (Data Transfer error). While in the area, slightly refactor
the write/read blockif function to use a common error exit path.

PR:		256321
Reported by:	Cheolwoo Myung <cwmyung@snu.ac.kr>
Reviewed by:	imp, jhb
Differential Revision:	https://reviews.freebsd.org/D35452
2022-08-14 07:45:21 -07:00
Chuck Tuffli
88951aaaee bhyve nvme: Fix out-of-bound IOV array access
Summary:
NVMe operations indicate the memory region(s) associated with a command
via physical region pages (PRPs). Since each PRP has a fixed size,
contiguous memory regions larger than the PRP size require multiple PRP
entries.

Instead of issuing a blockif call for each PRP, the NVMe emulation
concatenates multiple contiguous PRP entries into a single blockif
request. The test for contiguous regions has a bug such that it
mistakenly treats an initial PRP address of zero as a contiguous range
and concatenates it with the previous. But because there is no previous
IOV, the concatenation code corrupts the IO request structure and leads
to a segmentation fault when the blockif request completes.

Fix is to test for the existence of a previous range before trying to
concatenate the current range with the previous one.

While in the area, rename pci_nvme_append_iov_req()'s lba parameter to
offset to match its usage.

PR:             264177
Reported by:    Robert Morris <rtm@lcs.mit.edu>
Reviewed by:	jhb
MFC after:      2 weeks
Differential Revision:	https://reviews.freebsd.org/D35328
2022-08-13 12:16:02 -07:00
Corvin Köhne
50526f522b bhyve: fix spelling mistake in passthru emulation
Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D35707
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-07-27 18:20:47 +02:00
John Baldwin
e5ed417bb4 bhyve: Document the "type" config variable for network device models. 2022-06-30 15:14:36 -07:00
Yan Ka Chiu
b9c3e544c4 bhyve virtio-net: Allow backend type to be explicitly specified.
Surrently virtio-net uses the prefix of the backing interface to
choose the backend.  This patch adds an additional option "type" to
choose the backend type explicitly.  This allows greater flexibility
for end users to manage bhyve specific resources (such as by naming
the tap interfaces to more descriptive names).  The option "type" is
optional.  When it is not presented, the backend is derived from the
name of the backend interface.

For example, the line `-s 3,virtio-net,bsdvm0,type=tap` will create a
virtio-net device for the guest using the tap interface "bsdvm0".

Adding a new "type" option preserves the current legacy format in which
the first value after virtio-net names an instance of a backend.

Note that tap interfaces not following the pattern "tap*" will not be
created on demand via devfs cloning but must be created explicitly.

Reviewed by:	vmaffione, jhb
Differential Revision:	https://reviews.freebsd.org/D35143
2022-06-30 10:29:45 -07:00
Vitaliy Gusev
a85bbbea91 bhyve: Enable suspend/resume support for virtio-blk.
Reviewed by:	jhb
Sponsored by:	vStack
Differential Revision: https://reviews.freebsd.org/D26267
2022-06-23 11:46:06 -07:00
Vitaliy Gusev
cd9618bdb2 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
2022-06-23 11:46:06 -07:00
James Mintram
e16b709e2d bhyve: Report an error for invalid UUIDs.
Reviewed by:	rgrimes, grehan, jhb
Differential Revision:	https://reviews.freebsd.org/D30050
2022-06-16 13:18:01 -07:00
Corvin Köhne
8284799a23 bhyve: use bhyve_config for SMBIOS strings
Some software uses SMBIOS entries to identify the system on which it's
running. In order to make it possible to use such software inside a VM,
SMBIOS entries should be configurable. Therefore, bhyve_config can be
used. While only a few SMBIOS entries might be of interest, it makes
sense that all SMBIOS entries are configurable. This way all SMBIOS
tables are build the same way and there's no special handling for some
tables.

Reviewed by:	jhb
Sponsored by:	Beckhoff Automation GmbH & Co. KG
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D34465
2022-05-30 10:03:43 +02:00
Yan Ka Chiu
3cdfaefa4b 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
2022-05-06 15:34:17 -04:00
Robert Wing
690b7ea081 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
2022-04-28 07:43:01 -08:00
Robert Wing
c79331a42c bhyve: use linker set for ipc commands
Reviewed by:	markj, jhb
Differential Revision:	https://reviews.freebsd.org/D34760
2022-04-09 18:46:00 -08:00
Christian Weisgerber
81d1214e8a man pages: Fix typo
s/the the/the/

Approved by:	ygy (doc)
2022-04-07 14:58:13 +02:00
Mark Johnston
b0aa20bec5 bhyve: validate e82545 checksum offset field
Reported by:	Mehdi Talbi, Synacktiv
2022-04-05 22:58:28 +00:00
Corvin Köhne
3256b7ca36 bhyve: avoid an empty passthru config value
pci_parse_legacy_config splits the options string by comma characters.
strchr returns a pointer to the first occurence of a character. In that
case, it's a comma. So, pci_parse_legacy_config will stop at the first
character and creates a new config node with a name of NULL.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D34600
2022-04-01 11:13:16 +02:00
Corvin Köhne
8ac8adda8d bhyve: avoid uninitialized variable
Reviewed by:	markj
Signed-off-by: Corvin Köhne <c.koehne@beckhoff.com>
Reported-by: Andy Fiddaman <andy@omniosce.org>
Differential Revision:	https://reviews.freebsd.org/D34688
2022-04-01 11:13:16 +02:00
Corvin Köhne
45ddbf2112 bhyve: avoid overflow of BAR index
At the moment, writes to BAR registers that aren't 4 byte aligned are
ignored. So, there's no overflow yet. Nevertheless, if this behaviour
changes in the future, it could unintentionally, introduce a buffer
overflow. Additionally, some compiler or tools will detect this
potential overflow and complain about it.

Reviewed by:	markj
Signed-off-by: Corvin Köhne <c.koehne@beckhoff.com>
Reported-by: Andy Fiddaman <andy@omniosce.org>
Differential Revision:	https://reviews.freebsd.org/D34689
2022-04-01 11:13:16 +02:00
Robert Wing
3ebe110934 bhyve: sweep MAX_VMNAME
MAX_VMNAME is no longer used.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D34292
2022-03-17 21:55:52 -08:00
Robert Wing
961e6a12ef 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
2022-03-17 21:51:31 -08:00
Robert Wing
3efc45f34e 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
2022-03-17 21:38:21 -08:00
Andy Fiddaman
f6f357efb1 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
2022-03-15 19:54:16 -08:00
Mateusz Piotrowski
5e19a51853 bhyve.8: Fix a typo
The Li macro is deprecated. Also, the Cm macro should be used here
instead for consistency with the rest of the manual and style.mdoc(5).

Fixes:		e47fe3183e bhyve: add ROM emulation
MFC after:	1 month
2022-03-10 17:46:43 +01:00
Corvin Köhne
afd4f7fa25 bhyve/usage: memory size is not in MB
For backward compatibility, the memory size will be interpreted in MB if
it's smaller than1 MB and has no suffix. Nowadays, the -m switch accepts
more than just MB. Respect it in the usage message.

Differential Revision:	https://reviews.freebsd.org/D34506
Reviewed by:	grehan
Sponsored by:   Beckhoff Automation GmbH & Co. KG
MFC after:      1 month
2022-03-10 12:31:00 +01:00
Corvin Köhne
e47fe3183e bhyve: add ROM emulation
Some PCI devices especially GPUs require a ROM to work properly.
The ROM is executed by boot firmware to initialize the device.
To add a ROM to a device use the new ROM option for passthru device
(e.g. -s passthru,0/2/0,rom=<path>/<to>/<rom>).

It's necessary that the ROM is executed by the boot firmware.
It won't be executed by any OS.
Additionally, the boot firmware should be configured to execute the
ROM file.
For that reason, it's only possible to use a ROM when using
OVMF with enabled bus enumeration.

Differential Revision:	https://reviews.freebsd.org/D33129
Sponsored by:   Beckhoff Automation GmbH & Co. KG
MFC after:      1 month
2022-03-10 12:30:37 +01:00
Corvin Köhne
563fd2240e bhyve: export funcs for read/write pci config
Export functions for reading and writing the pci config space from passthru
device to be used by other devices.
This is required for lpc devices to set their vendor/device ids to their
physical values.
Otherwise, GPU passthrough for integrated Intel GPUs won't work properly.

Differential Revision:	https://reviews.freebsd.org/D33769
Reviewed by:	markj
Sponsored by:	Beckhoff Automation GmbH & Co. KG
MFC after:	1 month
2022-03-10 12:30:02 +01:00
John Baldwin
c76e4b89d9 bhyve: Use vm_get_topology to query kernel's maximum vCPU count.
Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D34493
2022-03-09 15:39:23 -08:00
John Baldwin
fd6f92946f bhyve: Don't force an upper bound on vCPUs when parsing pinning.
Even today it is possible to specify pinning for a vCPU higher than
the configured number of CPUs but lower than VM_MAXCPU without raising
an error.

Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D34492
2022-03-09 15:39:16 -08:00
John Baldwin
7261f82156 bhyve: Allocate dynamic arrays to hold per-VCPU state.
This avoids hardcoding VM_MAXCPU in userspace.

Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D34491
2022-03-09 15:39:08 -08:00
John Baldwin
340a293f91 bhyve: Make the MADT dynamically sized.
Use basl_ncpu instead of VM_MAXCPU in MADT_SIZE.  Since several of the
offsets are no longer compile time constants, unroll the loop
generating ACPI tables.

Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D34490
2022-03-09 15:38:58 -08:00
John Baldwin
730510dc1a bhyve: Allocate mmio_hint array based on number of guest CPUs.
This avoids an instance of hardcoding VM_MAXCPU in userspace.

Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D34489
2022-03-09 15:38:49 -08:00
Corvin Köhne
87f6367f10 bhyve: add varfile option to nvlist of lpc device
Use seperate nvlist entries for the romfile and the varfile.

While here, don't leak varfd in bootrom_loadrom().

Reviewed by:    jhb, markj
Differential Revision:  https://reviews.freebsd.org/D33433
2022-03-02 22:50:24 -09:00
Andy Fiddaman
ad3da82996 bhyve: plug memory leak in topology_parse()
Reviewed by:    jhb, rew
Differential Revision:  https://reviews.freebsd.org/D34301
2022-02-24 08:38:53 -09:00
Chuck Tuffli
e0ac9dc2b0 bhyve nvme: Advertise Namespace changed AEN
Advertise Namespace Attribute Notices events in the Optional
Asynchronous Events Supported (OAES) field of the Identify Controller
data structure. Additionally, rename the enums and macros to clarify
these are AEN's related to Notices and not generic information.

Reported by: andy@omniosce.org

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D34331
2022-02-23 09:15:45 -08:00
Chuck Tuffli
c2318cf80a nvme: fix spelling of Namespace
Fix spelling of a macro definition.

Reviewed by:	mav, imp
Differential Revision:	https://reviews.freebsd.org/D34330
2022-02-21 10:34:46 -08:00
Robert Wing
4379c1da56 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
2022-02-15 08:12:15 -09:00
Robert Wing
edfb339d38 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
2022-02-09 08:11:57 -09:00
Mark Johnston
927aa5fefd 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
2022-02-08 12:40:41 -05:00
Robert Wing
b4cc5d63b6 bhyve/virtio: use correct device id for virtio-scsi
Section 4.1.2.1 of the virtio spec states that the transitional PCI
device id for a scsi device is 0x1004.

Fix suggested by reporter.

PR:             259961
Reported by:    me@nanaya.pro
Reviewed by:	imp, jhb
Fixes:  f9c005a17f ("Add bhyve virtio-scsi storage backend support.")
Differential Revision:	https://reviews.freebsd.org/D34103
2022-01-31 09:44:47 -09:00
Chuck Tuffli
ac678b4aaf bhyve nvme: Fix Identify Namespace, NSID=ffffffff
If the NVMe Controller doesn't support Namespace Management, it should
return "Invalid Namespace or Format" when the Host request Identify
Namespace with the global NSID value.

Fixes UNH IOL 16.0 Test 9.1, Case 6

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33578
2022-01-29 23:11:14 -08:00
Chuck Tuffli
fa263c532b bhyve nvme: Fix Set Features, AEN
NVMe Controllers which do not support Endurance Groups must return an
error when the Endurance Group Event Aggregate Log Change Notices bit is
set in Set Features, Asynchronous Event Configuration.

Fixes UNH IOL Test 3.12, Case 8

Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33577
2022-01-29 23:10:59 -08:00
Chuck Tuffli
ff5ed0fac4 bhyve nvme: Fix reported VWC value
v1.4 and later NVMe Controllers report "Flush all Namespaces" support
differently.

Fixes UNH IOL 16.0 Test 2.6, Case 3

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33576
2022-01-29 23:10:42 -08:00
Chuck Tuffli
9d8cd04694 bhyve nvme: Fix LBA out-of-range calculation
The function which checks for a valid LBA range mistakenly named an
input value as NLB ("Number of Logical Blocks") instead of "number of
blocks". The NVMe specification defines NLB as a zero-based value (i.e.
NLB=0x0 represents 1 block, 0x1 is 2 blocks, etc.), but the passed
parameter is a 1's-based value.

Fix is to rename the variable to avoid future confusion.

While in the neighborhood, also check that the starting LBA is less than
the size of the backing storage to avoid an integer overflow.

Reviewed by:	imp, allanjude, jhb
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33575
2022-01-29 23:09:57 -08:00
Chuck Tuffli
073f2076fe bhyve nvme: Add Select support to Get Features
Implement basic support for the SEL field of Get Features. This returns
information about Namespace Specific features.

Fixes UNH ILO 16.0 Test 1.2, Case 13

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33574
2022-01-29 23:09:35 -08:00
Chuck Tuffli
29241c96f7 bhyve nvme: Update v1.4 Identify Controller data
Compliant v1.4 Controllers must report a Controller Type (CNTRLTYPE).
Also, do not advertise secure erase functionality in the Format NVM
Attributes field of the Identify Controller data structure as the
Controller does not implement secure erase.

Fixes UNH ILO Test 1.1, Case 2

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33573
2022-01-29 23:09:10 -08:00
Chuck Tuffli
ea9ee35583 bhyve nvme: Add Temperature Threshold support
This adds the ability for a guest OS to send Set / Get Feature,
Temperature Threshold commands. The implementation assumes a constant
temperature and will generate an Asynchronous Event Notification if the
specified threshold is above/below this value. Although the
specification allows 9 temperature values, this implementation only
implements the Composite Temperature.

While in the neighborhood, move the clear of the CSTS register in the
reset function after all other cleanup. This avoids a race with the
guest thinking the reset is complete (i.e. CSTS.RDY = 0) before the NVMe
emulation is actually complete with the reset.

Fixes UNH IOL 16.0 Test 1.7, cases 1, 2, and 4.

Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33572
2022-01-29 23:08:47 -08:00
Chuck Tuffli
1381a11829 bhyve nvme: Fix Set Features
Be more conservative and only support the Features mandatory for an I/O
Controller.

Avoids a "hang" in UNH test 1.2.10 associated with Predictable Latency
Mode Configuration and Host Behavior Support features.

Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33571
2022-01-29 23:07:44 -08:00
Chuck Tuffli
45ab4076f3 bhyve nvme: Remove redundant AER Limit checks
The NVMe emulation checked if the Asynchronous Event Request Limit
(a.k.a AERL) would be exceeded in pci_nvme_aer_add(), but this function
is only called from nvme_opc_async_event_req() which also checks for
exceeding the AERL.

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33570
2022-01-29 23:07:29 -08:00
Chuck Tuffli
785b5da318 bhyve nvme: Add missing Admin opcodes
Don't treat unsupported Admin commands as Invalid Opcode. Instead return
the proper Invalid Field in Command.

Fixes UNH IOL test 1.17.2

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33569
2022-01-29 23:07:04 -08:00
Chuck Tuffli
b1b2a4d9e8 bhyve nvme: Implement Log Page Offset
Modify the Get Log Page command to parse the Log Page Offset fields to
support more recent versions of the NVMe specification.

Fixes various tests for UNH Test 1.3.*

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33568
2022-01-29 23:06:46 -08:00
Chuck Tuffli
62d47feceb bhyve nvme: Fix Namespace Specific Set Features
Return an error if the feature specified in Set Features is Namespace
specific but the Namespace ID uses the Global Namespace tag.

Fixes UNH Test 1.2.7

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33566
2022-01-29 23:06:23 -08:00
Chuck Tuffli
cf76cdd4bf bhyve nvme: Fix NVM Format completion status
The NVM Format command is unique among the Admin commands in that it
needs to finish asynchronously. For this reason, the emulation code
invented a synthetic completion status (NVME_NO_STATUS) to indicate that
the command was still in progress and the command processing loop should
not generate a completion message. The implementation used the value
0xffff for the synthetic value as this set both the Status Code and
Status Code Type fields to reserved values.

Format initialized the completion status to this value and expected
error cases to override it with a status code/type appropriate to the
situation. The macros used to set the NVMe status are careful not to
modify bit 0 (i.e. the phase bit), which with the synthetic completion
status, causes the phase bit to get out of sync. When running tests in a
guest with illegal NVM Format commands, Admin commands would eventually
hang because it appeared there were no completions due to the incorrect
phase bit value.

Fix is to only set NVME_NO_STATUS if the blockif delete command
succeeds. While in the neighborhood, add a missing break statement when
NVM Format is not supported.

Reviewed by:	imp, allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33565
2022-01-29 23:05:58 -08:00
Chuck Tuffli
595a12f18b bhyve nvme: Advertise v1.4 support
Bump advertised NVMe support from v1.3 to v1.4

Reviewed by:	allanjude
Tested by:      jason@tubnor.net
MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33564
2022-01-29 23:04:25 -08:00
Emmanuel Vadot
9acd521dbd pkgbase: bhyve: Tag the kbdlayout file to be in the bhyve package 2022-01-26 19:32:19 +01:00
Robert Wing
08cb63a12f bhyve/block_if: allow DIOCGMEDIASIZE ioctl
This is needed to get mediasize of the device after a resize event.

I missed this earlier as I was building WITH_BHYVE_SNAPSHOT, which
disables capsicum.

Reviewed by:	khng, markj
Fixes: ae9ea22e14 ("bhyve: get mediasize for character devices when ...")
Differential Revision:	https://reviews.freebsd.org/D34013
2022-01-25 07:44:13 -09:00
Ryan Moeller
b252fb2430 bhyve: ahci: Fix regression with no ports
An AHCI controller may be specified with no connected ports.  Avoid
dumping core in this case for compatibility with existing VM configs.

Reviewed by:	khng, jhb
Fixes:		621b509048 Refactor configuration management in bhyve.
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D33969
2022-01-21 12:59:25 +00:00
Michael Reifenberger
19eaa01bea Append Keyboard Layout specified option for using VNC.
Part two: Append bhyve -K option for specified keyboard layout
with layout setting files every languages.
Since the cmd option '-k' was used in the meantime
it was changed to '-K'

PR:		246121
Submitted by:	koinec@yahoo.co.jp
Reviewed by:	grehan@
Differential Revision:	https://reviews.freebsd.org/D29473

MFC after:	4 weeks
2022-01-20 23:49:27 +01:00
Robert Wing
51fbd894dd 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
2022-01-19 08:40:06 -09:00
Robert Wing
ae9ea22e14 bhyve: get mediasize for character devices when resizing virtio-blk
Reviewed by:	imp, allanjude, jhb
Differential Revision:	https://reviews.freebsd.org/D33403
2022-01-18 11:26:49 -09:00
Corvin Köhne
fe453891d7 bhyve: add nvlist functions for setting unset nodes
If an emulation uses those functions instead of set_config_value_node
or set_config_value, it allows the config values to get
overwritten. Introducing new functions is much more readable than
if else statements in the emulation code.

Reviewed by:	khng
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33770
2022-01-14 12:41:44 +01:00
Mark Johnston
4558c11f1b bhyve: Correct unmapping of the MSI-X table BAR
The starting address passed to mprotect was wrong, so in the case where
the last page containing the table is not the last page of the BAR, the
wrong region would be unmapped.

Reported by:	Andy Fiddaman <andy@omniosce.org>
Reviewed by:	jhb
Fixes:		7fa2335347 ("bhyve: Map the MSI-X table unconditionally for passthrough")
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33739
2022-01-05 10:12:09 -05:00
Mark Johnston
76b45e688a bhyve: Map the right BAR in init_msix_table()
The PBA and MSI-X table can reside in different BARs.

Reported by:	Andy Fiddaman <andy@omniosce.org>
Reviewed by:	jhb
Fixes:		7fa2335347 ("bhyve: Map the MSI-X table unconditionally for passthrough")
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33739
2022-01-05 10:12:09 -05:00
Corvin Köhne
9fe79f2f2b bhyve: dynamically register FwCtl ports
Qemu's FwCfg uses the same ports as Bhyve's FwCtl. Static allocated
ports wouldn't allow to switch between Qemu's FwCfg and Bhyve's
FwCtl.

Reviewed by:    markj
MFC after:      2 weeks
Sponsored by:   Beckhoff Automation GmbH & Co. KG
Differential Revision:  https://reviews.freebsd.org/D33496
2022-01-03 16:32:55 +01:00
Corvin Köhne
7d55d29508 bhyve: add more slop to 64 bit BARs
Bhyve allocates small 64 bit BARs below 4 GB and generates ACPI tables
based on this allocation. If the guest decides to relocate those BARs
above 4 GB, it could lead to mismatching ACPI tables. Especially
when using OVMF with enabled bus enumeration it could cause
issues. OVMF relocates all 64 bit BARs above 4 GB. The guest OS
may be unable to recover from this situation and disables some PCI
devices because their BARs are located outside of the MMIO space
reported by ACPI. Avoid this situation by giving the guest more
space for relocating BARs.

Let's be paranoid. The available space for BARs below 4 GB is 512 MB
large. Use a slop of 512 MB. It'll allow the guest to relocate all
BARs below 4 GB to an address above 4 GB. We could run into issues
when we exceeding the memlimit above 4 GB. However, this space has
a size of 32 GB. Even when using many PCI device with large BARs
like framebuffer or when using multiple PCI busses, it's very
unlikely that we run out of space due to the large slop.
Additionally, this situation will occur on startup and not at runtime
which is much better.

Reviewed by:    markj
MFC after:      2 weeks
Sponsored by:   Beckhoff Automation GmbH & Co. KG
Differential Revision:  https://reviews.freebsd.org/D33118
2022-01-03 16:32:55 +01:00
Corvin Köhne
8ec366ec6c bhyve: allow reading of fwctl signature multiple times
At the moment, you only have one single chance to read the fwctl
signature. At boot bhyve is in the state IDENT_WAIT. It's then
possible to switch to IDENT_SEND. After bhyve sends the signature,
it switches to REQ. From now on it's impossible to switch back to
IDENT_SEND to read the signature. For that reason, only a single
driver can read the signature. A guest can't use two drivers to
identify that fwctl is present. It gets even worse when using
OVMF. OVMF uses a library to access fwctl. Therefore, every single
OVMF driver would try to read the signature. Currently, only a
single OVMF driver accesses the fwctl. So, there's no issue with
it yet. However, no OS driver would have a chance to detect fwctl when
using OVMF because it's signature was already consumed by OVMF.

Reviewed by:    markj
MFC after:      2 weeks
Sponsored by:   Beckhoff Automation GmbH & Co. KG
Differential Revision:  https://reviews.freebsd.org/D31981
2022-01-03 16:32:55 +01:00
Corvin Köhne
01f9362ef4 bhyve: enumerate BARs by size
E.g. Framebuffers can require large space and BARs need to be aligned
by their size. If BARs aren't allocated by size, it'll cause much
fragmentation of the MMIO space. Reduce fragmentation by ordering
the BAR allocation on their size to reduce the risk of
OUT_OF_MMIO_SPACE issues.

Reviewed by:	markj
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D28278
2022-01-03 16:32:55 +01:00
Corvin Köhne
338a1be836 bhyve: only init MSI-X table if passthru device supports it
Some passthru devices only support MSI instead of MSI-X. For those
devices the initialization of MSI-X table will fail. Re-add the
check erroneously removed in f1442847c9.

MFC after:	3 days
X-MFC with:	f1442847c9
PR:		260148
Reviewed by:	manu, bz
Differential Revision:	https://reviews.freebsd.org/D33728
2022-01-03 14:55:10 +00:00
Toomas Soome
04f55b5b0e bhyve smbios type 3 structure is incorrect
If you look at the SMBIOS specification, we'll find something is
missing. In particular at offset 0Dh is supposed to be the OEM-defined
field. This should go between security and height. It is not legal to
actually skip this and will lead to other folks not properly
interpreting later parts of the table.

https://www.illumos.org/issues/14312

Reviewed by:	jhb
Submitted by:	Robert Mustacchi <rm@fingolfin.org>
Obtained from:	ilumos
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D33682
2021-12-27 20:06:33 +02:00
Toomas Soome
c2fa905cf6 bhyve: clean up trailing whitespaces
Clean up trailing whitespaces. No functional changes.

Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D33681
2021-12-27 19:58:10 +02:00
Bjoern A. Zeeb
f1442847c9 bhyve: passthru: enable BARs before possibly mmap(2)ing them
The first time we start bhyve with a passthru device everything is fine
as on boot we do enable BARs.  If a driver (unload) inside bhyve disables
the BAR(s) as some Linux drivers do, we need to make sure we re-enable
them on next bhyve start.

If we are trying to mmap a disabled BAR for MSI-X (PCIOCBARMMAP)
the kernel will give us an EBUSY.
While we were re-enabling the BAR(s) in the current code loop
cfginit() was writing the changes out too late to the real hardware.

Move the call to init_msix_table() after the register on the real
hardware was updated.  That way the kernel will be happy and the
mmap will succeed and bhyve will start.
Also simplify the code given the last argument to init_msix_table()
is unused we do not need to do checks for each bar. [1]

MFC after:	3 days
PR:		260148
Pointed out by:	markj [1]
Sponsored by:	The FreeBSD Foundation
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D33628
2021-12-29 17:01:05 +00:00
Vitaliy Gusev
d079fc197a bhyve: Only snapshot initialized VirtIO queues
If the virtio device is not fully initialized, then suspend fails with:

  vi_pci_snapshot_queues: invalid address: vq->vq_desc
  Failed to snapshot virtio-rnd; ret=14

MFC after:	1 week
Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D26268
2021-12-17 13:06:53 -05:00
Chuck Tuffli
cf3ed8e0cd bhyve nvme: Inform guests of namespace resize
Register a "block resize" callback to be notified of changes to the
backing storage for the Namespace. Use this to generate an Asynchronous
Event Notification, Namespace Attributes Changed when the guest OS
provides an Asynchronous Event Request.

MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D32953
2021-12-14 23:17:55 -08:00
Chuck Tuffli
9f1fa1a461 bhyve nvme: Add AEN support to NVMe emulation
Add Asynchronous Event Notification infrastructure to the NVMe
emulation.

Reviewed by:	imp, grehan
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D32952
2021-12-14 23:16:49 -08:00
Robert Wing
0b29683b32 bhyve: set EV_CLEAR for EVFILT_VNODE mevents
When an EVFILT_VNODE filter event is triggered, reset it.

This fixes the issue where a virtio-blk resize event would cause the
mevent thread to consume 100% of the cpu.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D33326
2021-12-12 12:39:40 -09:00
Rebecca Cran
866036f46c bhyve: Support a _VARS.fd file for bootrom
OVMF creates two separate .fd files, a _CODE.fd file containing
the UEFI code, and a _VARS.fd file containing a template of an
empty UEFI variable store.

OVMF decides to write variables to the memory range just below the
boot rom code if it detects a CFI flash device. So here we add
just the barest facsimile of CFI command handling to bootrom.c
that is needed to placate OVMF.

Submitted by: D Scott Phillips <d.scott.phillips@intel.com>
Sponsored by: Intel Corporation
Differential Revision: https://reviews.freebsd.org/D19976
MFC After: 1 week
2021-12-12 08:07:27 -07:00
Robert Wing
2616ee608c bhyve: fix -Wunused-but-set-variable warning
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D33306
2021-12-06 10:52:08 -09:00
Chuck Tuffli
d8c1d7b652 bhyve blockif: fix blockif_candelete with Capsicum
NVMe conformance tests for the Format command failed if the
backing-storage for the bhyve device was a file instead of a Zvol. The
tests (and the specification) expect a Format to destroy all previously
written data. The bhyve NVMe emulation implements this by trimming /
deallocating all data from the backing-storage.

The blockif_candelete() function indicated the file did not support
deallocation (i.e. fpathconf(..., _PC_DEALLOC_PRESENT) returned FALSE)
even though the kernel supported file hole punching. This occurs on
builds with Capsicum enabled because blockif did not allow the
fpathconf(2) right.

Fix is to add CAP_FPATHCONF to the cap_rights_init(3) call.

PR:		260081
Reviewed by:	allanjude, markj, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33203
2021-11-30 21:49:34 -08:00
Emmanuel Vadot
fc7207c877 bhyve: Fix compile
We need err.h

Fixes:	5cf21e48cc ("bhyve: use a fixed 32 bit BAR base address")
Sponsored by:	Bechoff Automation GmbH & Co. KG
2021-11-22 17:13:09 +01:00
Corvin Köhne
fe66bcf9ff bhyve: emulate reads of MSI-X capabilities for passthru devices
Reads of the MSI-X capabilites aren't emulated by passthru devices
yet. The guest will read the host MSI-X capabilites which could
cause issues.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D32686
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2021-11-22 16:27:33 +01:00
Corvin Köhne
2eb2079554 bhyve: keep physical and virtual COMMAND reg in sync
On startup all virtual BARs are registered.
Additionally, the encoding bit in the virtual cmd register is set.
After that, the passthru emulation overwrites the virtual cmd register with
the physical one.
This could lead to a mismatch between registered BARs and the encoding
bits in the cmd register.
Instead of writing the physical to the virtual cmd register,
write the virtual to the physical cmd register to solve this issue.

Reviewed by:	  markj
Differential Revision:	https://reviews.freebsd.org/D32687
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2021-11-22 16:26:03 +01:00
Corvin Köhne
5cf21e48cc bhyve: use a fixed 32 bit BAR base address
OVMF always uses 0xC0000000 as base address for 32 bit PCI MMIO space.
For that reason, we should use that address too.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D31051
Sponsored by:	Beckhoff Automation GmbH & Co. KG
2021-11-22 16:24:47 +01:00
Corvin Köhne
4a4053e1b0 bhyve: move 64 bit BAR location to match OVMF assumptions
OVMF will fail, if large 64 bit BARs are used. GCD-Map doesn't cover
64 bit addresses of BARs.
OVMF assumes that 64 bit addresses of BARS are located on next 32 GB
boundary behind Top of High RAM.

This patch moves 64 bit BARs on next 32 GB boundary behind Top of High
RAM to match OVMF assumptions.

Differential Revision:	https://reviews.freebsd.org/D27970
Sponsored by: Beckhoff Automation GmbH & Co. KG
2021-11-22 16:22:48 +01:00
Corvin Köhne
5085153ae4 bhyve: do not explicitly map fbuf framebuffer
Allocating a BAR will call baraddr which maps the framebuffer. No need
to allocate it explicitly on init.

Reviewed by:     grehan
Sponsored by:    Beckhoff Autmation GmbH & Co. KG
Differential Revision:    https://reviews.freebsd.org/D32596
2021-11-18 16:26:34 +01:00
Corvin Köhne
e87a6f3ef2 bhyve: use physical lobits for BARs of passthru devices
Tell the guest whether a BAR uses prefetched memory or not for
passthru devices by using the same lobits as the physical device.

Reviewed by:	 grehan
Sponsored by:	 Beckhoff Autmation GmbH & Co. KG
Differential Revision:	  https://reviews.freebsd.org/D32685
2021-11-18 16:25:09 +01:00
Rebecca Cran
35175e100a bhyve: Bump the SMBIOS firmware version to 14.0 for 14-CURRENT
Bump the firmware version to 14.0 and set the firmware release date
to today.

Reviewed by: jhb, bz, imp
Differential Revision: https://reviews.freebsd.org/D32534
2021-10-20 22:10:33 -06:00
Mark Johnston
77bc75c7ab bhyve: Fix the WITH_BHYVE_SNAPSHOT build
Note, this breaks compatibility with snapshots generated by older builds
of bhyve(8).

Fixes: 7fa2335347 ("bhyve: Map the MSI-X table unconditionally for passthrough")
Reported by:	Greg V <greg@unrelenting.technology>
Reviewed by:	grehan, bz
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32523
2021-10-18 09:56:59 -04:00
Corvin Köhne
1b0e2f0b60 bhyve: ignore low bits of CFGADR
Bhyve could emulate wrong PCI registers.
In the best case, the guest reads wrong registers and the device driver would
report some errors.
In the worst case, the guest writes to wrong PCI registers and could brick
hardware when using PCI passthrough.

According to Intels specification, low bits of CFGADR should be
ignored. Some OS like linux may rely on it. Otherwise, bhyve could
emulate a wrong PCI register.

E.g.
If linux would like to read 2 bytes from offset 0x02, following would
happen.
linux:
	outl 0x80000002 at CFGADR
	inw  at CFGDAT + 2
bhyve:
	cfgoff = 0x80000002 & 0xFF = 0x02
	coff   = cfgoff + (port - CFGDAT) = 0x02 + 0x02 = 0x04
Bhyve would emulate the register at offset 0x04 not 0x02.

Reviewed By: #bhyve, grehan
Differential Revision: https://reviews.freebsd.org/D31819
Sponsored by:	       Beckhoff Automation GmbH & Co. KG
2021-10-15 09:29:45 +02:00
Mateusz Piotrowski
f656df586a bhyve: Update usage and synopsis for the -k flag
Let's make it clear to users that -k is for configuration files.
Also, point to bhyve_config(5) in the paragraph describing the flag.

Reviewed by:	jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D32467
2021-10-13 08:39:57 +02:00
Mateusz Piotrowski
775f6f4595 bhyve.8: Fix markup of the -G flag 2021-10-12 16:09:28 +02:00
Mark Johnston
7fa2335347 bhyve: Map the MSI-X table unconditionally for passthrough
It is possible for the PBA to reside in the same page as the MSI-X
table.  And, while devices are not supposed to do this, at least some
Intel wifi devices place registers in a page shared with the MSI-X
table.  To handle the first case we currently map the PBA page using
/dev/mem, and the second case is not handled.

Kill two birds with one stone: map the MSI-X table BAR using the
PCIOCBARMMAP ioctl instead of /dev/mem, and map the entire table so that
accesses beyond the bounds of the table can be emulated.  Regions of the
BAR not containing the table are left unmapped.

Reviewed by:	bz, grehan, jhb
MFC after:	3 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32359
2021-10-09 11:36:19 -04:00
John Baldwin
7ecdfc8237 bhyve: Add an empty case for event types in mevent_kq_fflags().
This fixes a -Wswitch error raised by GCC 9.

Differential Revision:	https://reviews.freebsd.org/D31938
2021-09-25 11:25:25 -07:00
John Baldwin
48759c4ed7 bhyve_config.5: Document gdb.address. 2021-09-25 10:07:18 -07:00
John Baldwin
b70b050ab5 bhyve: Update the -G description in the SYNPOSIS.
It was missing both the 'w' flag and 'bind_address'.
2021-09-25 10:01:43 -07:00
John Baldwin
c6efcb1281 bhyve: Support setting the disk serial number for VirtIO block devices.
Reviewed by:	allanjude
Obtained from:	illumos
Differential Revision:	https://reviews.freebsd.org/D31983
2021-09-17 09:55:48 -07:00
Ka Ho Ng
e31cc1d526 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
2021-09-13 04:35:03 +08:00
Elliott Mitchell
e76c0e4f45 bhyve: Nuke double-semicolons
A distinct number of double-semicolons ended up in bhyve. Take a pass at
getting rid of many of these harmless typos.

MFC after:	3 days
2021-08-30 15:31:04 +08:00
Mark Johnston
71fbc6faed bhyve: Fix vq_getchain() error handling bugs in various device models
Reviewed by:	grehan, khng
Approved by:	so
Security:	CVE-2021-29631
Security:	FreeBSD-SA-21:13.bhyve
2021-08-24 14:29:13 -04:00
Mariusz Zaborski
3a92927bb6 bhyve: change a default address from ANY to localhost
Discussed with:     grehan, jhb
2021-08-21 19:43:17 +02:00
Mariusz Zaborski
2cdff9918e byhve: add option to specify IP address for gdb
Allow user to specify the IP address available for gdb debugger.

Reviewed by:	jhb, grehan, rgrimes, bcr (man pages)
Differential Revision:	https://reviews.freebsd.org/D29607
2021-08-21 19:43:17 +02:00
Mark Johnston
42375556e5 bhyve: Use pci(4) to access I/O port BARs
This removes the dependency on /dev/io.

PR:		251046
Reviewed by:	jhb
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31308
2021-08-14 10:59:04 -04:00
Ka Ho Ng
3676512b60 bhyve: Use fspacectl(2) for BOP_DELETE on regular file images
bhyve can also make use of fspacectl(2) to implement BOP_DELETE with
hole-punching. Since it is not desirable to do zero-filling for large
DEALLOCATE/UNMAP range, candelete is not set if pathconf(2) indicates
that the underlying file system does not support native
VOP_DEALLOCATE(9).

Sponsored by:	The FreeBSD Foundation
Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D28880
2021-08-07 17:10:30 +08:00
Bjoern A. Zeeb
56be282bc9 bhyve: net_backends, automatically IFF_UP tap devices
If you want communications with the outside world and tell bhyve to
create an interfaces then it should be usable as well.
Rather than relying on the sysctl net.link.tap.up_on_open automatically
try to IFF_UP the opened tap device.

MFC after:	10 days
Reviewed by:	markj, grehan
Differential Revision: https://reviews.freebsd.org/D31342
2021-08-01 20:50:53 +00:00
Chuck Tuffli
91064841d7 bhyve: Fix NVMe iovec construction for large IOs
The UEFI driver included with Rocky Linux 8.4 uncovered an existing bug
in the NVMe emulation's construction of iovec's.

By default, NVMe data transfer operations use a scatter-gather list in
which all entries point to a fixed size memory region. For example, if
the Memory Page Size is 4KiB, a 2MiB IO requires 512 entries. Lists
themselves are also fixed size (default is 512 entries).

Because the list size is fixed, the last entry is special. If the IO
requires more than 512 entries, the last entry in the list contains the
address of the next list of entries. But if the IO requires exactly 512
entries, the last entry points to data.

The NVMe emulation missed this logic and unconditionally treated the
last entry as a pointer to the next list. Fix is to check if the
remaining data is greater than the page size before using the last entry
as a pointer to the next list.

PR:		256422
Reported by:	dave@syix.com
Tested by:	jason@tubnor.net
MFC after:	5 days
Relnotes:	yes
Reviewed by:	imp, grehan
Differential Revision:	https://reviews.freebsd.org/D30897
2021-06-27 15:14:52 -07:00
Chuck Tuffli
a11ca79cd9 bhyve: fix NVMe MDTS comment
Removes an obsolete comment and adds parenthesis around the macro while
in the area. No functional change.
2021-06-25 08:02:28 -07:00
Chuck Tuffli
3a4ab18377 bhyve: Fix cli regression with NVMe ram
The configuration management refactoring inadvertently removed support
for a RAM-backed NVMe Namespace (i.e. -s X,nvme,ram=16384). This adds it
back.

Reported by:	andy@omniosce.org
Reviewed by:	jhb, andy@omniosce.org
Fixes:		621b509048
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D30717
2021-06-16 14:19:01 -07:00
Robert Crowston
efec757b20 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
2021-06-13 16:41:45 -06:00
John Baldwin
2349cda44f bhyve vtblk: Inform guests of disk resize events.
Register a resize callback with the blockif interface.  When the
callback fires, update the size of the disk and notify the guest via a
configuration change interrupt.

Reviewed by:	grehan, markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D30506
2021-06-11 18:00:25 -07:00
John Baldwin
c06676bee3 bhyve: Split out a lower-level helper for VirtIO interrupts.
This allows device models to assert VirtIO interrupts for reasons
other than publishing changes to a VirtIO ring such as configuration
changes.

Reviewed by:	grehan, markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D30505
2021-06-11 18:00:25 -07:00
John Baldwin
8794846a91 bhyve: Add support for handling disk resize events to block_if.
Allow clients of blockif to register a resize callback handler.  When
a callback is registered, register an EVFILT_VNODE kevent watching the
backing store for a change in the file's attributes.  If the size has
changed when the kevent fires, invoke the clients' callback.

Currently resize detection is limited to backing stores that support
EVFILT_VNODE kevents such as regular files.

Reviewed by:	grehan, markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D30504
2021-06-11 18:00:24 -07:00
John Baldwin
67d60dcce6 bhyve: Add support for EVFILT_VNODE mevents.
This allows registering an event to watch for changes to a file's
attributes.  This is a bit imperfect as it would be nice to have a way
to determine if an fd can use EVFILT_VNODE successfully.  mevent's
current structure does not permit that and a failure to register a
single kevent impacts several other kevents.

Reviewed by:	grehan, markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D30503
2021-06-11 18:00:24 -07:00
John Baldwin
e8424e2947 bhyve: Register new kevents synchronously.
Change mevent_add*() to synchronously add the new kevent.  This
permits reporting event registration failures to the caller and avoids
failing the registration of other, unrelated events queued up in the
same batch.

Reviewed by:	grehan, markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D30502
2021-06-11 18:00:24 -07:00
Corvin Köhne
054accac71 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
2021-06-08 19:05:09 +10:00
Robert Wing
fdbc86cf79 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
2021-05-21 11:23:06 -08:00
Robert Wing
d4870e3a72 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
2021-05-12 17:20:15 -08:00
Mark Johnston
02e7a6514e bhyve: Set SO_REUSEADDR on the gdb stub socket
Reviewed by:	jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30037
2021-05-03 13:24:30 -04:00
Ryan Moeller
89c3c32647 bhyve: Gracefully handle virtio-scsi with no conf
Fixes segfault with the command `bhyve -s 0,virtio-scsi`, which is used
by some third party software to probe bhyve for virtio-scsi support.

Reviewed by:	jhb
MFC after:	1 day
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D29926
2021-04-22 12:06:08 -04:00
Michael Reifenberger
b563ff5d4f Append Keyboard Layout specified option for using VNC.
Part one: supporting QEMU Extended Keyboard Event Message

PR:             246121
Submitted by:   koinec@yahoo.co.jp
Differential Revision: https://reviews.freebsd.org/D29430
2021-04-21 12:40:44 +02:00
John Baldwin
e15bf05e0a bhyve: Be explicit that setting config.dump will not start a VM.
Suggested by:	rpokala
Reviewed by:	bcr (manpages)
Differential Revision:	https://reviews.freebsd.org/D29738
2021-04-20 13:34:07 -07:00
Mateusz Piotrowski
8d9fefe643 bhyve.8: Fix mandoc -Tlint issues
While here, keep network backends section consistent with other
sections.

MFC after:	2 weeks
2021-04-19 02:16:14 +02:00
Mateusz Piotrowski
061f37d280 bhyve: Document the format for HD audio backends
- This change is done for consistency with other backend definitions.

MFC after:	2 weeks
2021-04-19 02:16:14 +02:00
Mateusz Piotrowski
d5fcc4b606 bhyve.8: Improve AHCI backends documentation
- Document the backend format.

MFC after:	2 weeks
2021-04-19 02:16:13 +02:00
Mateusz Piotrowski
6eff58acc7 bhyve.8: Improve documentation of NVME backend
- Document the configuration format.
- Document two additional configuration options: eui64 and dsm.

MFC after:	2 weeks
2021-04-19 02:16:13 +02:00
Mateusz Piotrowski
8b97e97548 bhyve.8: Improve framebuffer backends description
- Use appropriate mdoc macros
- Document that tcp= is a synonym to rfb= (tcp is used in the examples,
  but never mentioned)
- Clarify the IP address specification

MFC after:	2 weeks
2021-04-19 02:16:13 +02:00
Mateusz Piotrowski
3f4c771f64 bhyve.8: Clean up virtio console device backends description
MFC after:	2 weeks
2021-04-19 02:16:13 +02:00
Mateusz Piotrowski
2fda01a1b7 bhyve.8: Clean up TTY, boot ROM, and pass-through descriptions
MFC after:	2 weeks
2021-04-19 02:16:12 +02:00
Mateusz Piotrowski
2d00b57022 bhyve.8: Clean up 9P device backends section
MFC after:	2 weeks
2021-04-19 02:16:12 +02:00
Mateusz Piotrowski
7c5829c942 bhyve.8: Clean up SCSI device backends section
MFC after:	2 weeks
2021-04-19 02:16:12 +02:00
Mateusz Piotrowski
5232a35f1e bhyve.8: Clean up block storage device backends description
MFC after:	2 weeks
2021-04-19 02:16:12 +02:00
Mateusz Piotrowski
7fb2272981 bhyve.8: Clean up network backends section
- Reformat the format lists, use appropriate mdoc macros for
  readability.
- Add a missing Oxford comma.

MFC after:	2 weeks
2021-04-18 23:33:24 +02:00
Mateusz Piotrowski
7014cb2393 bhyve.8: Improve emulation description of the -s flag
- Set width of the list to the longest key word for readability.
- Separate descriptions of amd_hostbridge and hostbridge emulations.
  Also, wordsmith their descriptions for consistency with other entries.
- Use Cm instead of Li for command modifiers.
- Do not stylize AMD with Li, there's no need to do it.
- Mention COM3 and COM4 in the definition of lpc.
- Fix a typo in the definition of ahci-hd ("hard drive" instead of
  "hard-drive").

MFC after:	2 weeks
2021-04-18 23:33:23 +02:00
Mateusz Piotrowski
234d8c470b bhyve.8: Clean up the slot description of -s
Also, remove the macros of the nested list which contained slot,
emulation and conf. This decreases the indention of the -s description.
It was necessary to clean up the slot description.

MFC after:	2 weeks
2021-04-18 23:33:23 +02:00
Mateusz Piotrowski
449f0e48e9 bhyve.8: Clean-up synopsis of -s
- Document "-s help" separately for readability.
- Use appropriate mdoc macros.

MFC after:	2 weeks
2021-04-18 23:33:23 +02:00
Mateusz Piotrowski
3357e9482f bhyve.8: Fix indention in the signals table
MFC after:	2 weeks
2021-04-18 22:09:39 +02:00
Mateusz Piotrowski
b24eea8c7a bhyve.8: Clean up description of -r
There is no need to wrap those flags in Op macros.

MFC after:	2 weeks
2021-04-18 22:09:37 +02:00
Mateusz Piotrowski
90df54374f bhyve.8: Fix the synopsis of -p
Use appropriate mdoc macros.

MFC after:	2 weeks
2021-04-18 22:09:36 +02:00
Mateusz Piotrowski
7e0cb3df68 bhyve.8: Improve the description of the -m flag
- Stylize the synopsis with proper mdoc macros
- Do some wordsmithing on the description for consistency.

MFC after:	2 weeks
2021-04-18 22:09:34 +02:00
Mateusz Piotrowski
4c08b978b2 bhyve.8: Improve the description and synopsis of -l
- Describe "-l help" separately for readability.
- List all the supported comX devices explicitly
- Use Cm instead of Ar for command modifiers (i.e., literal values a
  user can specify as an argument to the command).
- Explain where to get more information about the possible values of the
  conf argument.

MFC after:	2 weeks
2021-04-18 22:09:33 +02:00
Mateusz Piotrowski
ccb1c87a6a bhyve.8: Sort the options in the OPTIONS section
No content change intended. Just moving the option descriptions around
to follow the order suggested by style(9).

MFC after:	2 weeks
2021-04-18 22:09:24 +02:00
Mateusz Piotrowski
b6a572d03f bhyve: Improve the option description in the usage message
- Sort options as suggested by style(9)
- Capitalize some words like CPU and HLT
- Add a missing description for the -G flag

MFC after:	2 weeks
2021-04-18 20:22:13 +02:00
Mateusz Piotrowski
03c3e5e40d bhyve: Fix synopsis in the usage message
In particular:
- Sort short options to align with style(9)
- Add two missing flags: -G and -r
- Drop unnecessary angle brackets for consistency
- Rename the "vm" argument to vmname for consistency with the manual
  page

MFC after:	2 weeks
2021-04-18 20:22:13 +02:00
Mateusz Piotrowski
bfe40b692d bhyve.8: Make synopsis more readable
There is no need to squeeze all the possible options into one synopsis
entry. Let "-l help" and "-s help" be listed separately.

While here, keep -s and its arguments on the same line.

MFC after:	2 weeks
2021-04-18 20:22:13 +02:00
Corvin Köhne
17d214c2ca bhyve: implement rdmsr for MSR_IA32_FEATURE_CONTROL
Without the -w option, Windows guests crash on boot. This is caused by a rdmsr
of MSR_IA32_FEATURE_CONTROL. Windows checks this MSR to determine enabled VMX
features. This MSR isn't emulated in bhyve, so a #GP exception is injected
which causes Windows to crash.

Fix by returning a rdmsr of MSR_IA32_FEATURE_CONTROL with Lock Bit set and
VMX disabled to informWindows that VMX isn't available.

Reviewed by:	jhb, grehan (bhyve)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D29665
2021-04-15 13:49:19 +10:00
John Baldwin
eacc27affe bhyve: Move the gdb_active check to gdb_cpu_suspend().
The check needs to be in the public routine (gdb_cpu_suspend()), not
in the internal routine called from various places
(_gdb_cpu_suspend()).  All the other callers of _gdb_cpu_suspend()
already check gdb_active, and this breaks the use of snapshots when
the debug server is not enabled since gdb_cpu_suspend() tries to lock
an uninitialized mutex.

Reported by:	Darius Mihai, Elena Mihailescu
Reviewed by:	elenamihailescu22_gmail.com
Fixes:		621b509048
Differential Revision:	https://reviews.freebsd.org/D29538
2021-04-12 11:43:34 -07:00
Chuck Tuffli
0c6282e842 bhyve: add SMBIOS Baseboard Information
Add the System Management BIOS Baseboard (or Module) Information
a.k.a. Type 2 structure to the SMBIOS emulation.

Reviewed by:	rgrimes, bcran, grehan
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D29657
2021-04-12 08:09:52 -07:00
Roman Bogorodskiy
f2ecc0d1b7 bhyve: fix regression in legacy virtio-9p config parsing
Commit 621b509048 introduced a regression
in legacy virtio-9p config parsing by not initializing *sharename to
NULL. As a result, "sharename != NULL" check in the first iteration fails
and bhyve exits with "virtio-9p: more than one share name given".

Fix by adding NULL back.

Approved by:	grehan
2021-04-08 18:44:58 +04:00
Peter Grehan
ab899f8937 Fix typo in xhci nvlist node name, and also increment device counter.
This allows the xhci tablet device to be recognized and a PCI device
instantiated.

Reviewed by:	jhb
Fixes:		621b509048 Refactor configuration management in bhyve.
MFC after:	3 months.
2021-04-03 14:32:54 +10:00
Ka Ho Ng
b013912772 bhyve: change vq_getchain to return iovecs in both directions
The old prototype requires callers to inspect flags of each descriptors
to get the starting position of host-writable iovecs.

vq_getchain() is changed to return a virtio request with the number of
host-readable iovecs and host-writable iovecs instead. Callers can avoid
boilerplate code of getting the start offset of host-writable iovecs.

Sponsored by:	The FreeBSD Foundation
MFC after:	3 weeks
Reviewed by:	afedorov
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D29433
2021-03-30 16:44:07 +08:00
John Baldwin
4d5460a720 bhyve: Enable virtio-scsi legacy config parsing.
The previous commit added the handler to parse the command line
options for virtio-scsi devices but forgot to set the correct function
pointer to point to the handler.

Reported by:	vangyzen
Reviewed by:	vangyzen
Fixes:		621b509048
Differential Revision:	https://reviews.freebsd.org/D29438
2021-03-29 10:25:45 -07:00
John Baldwin
9f40a3be3d bhyve hostbridge: Rename "device" property to "devid".
"device" is already used as the generic PCI-level name of the device
model to use (e.g. "hostbridge").  The result was that parsing
"hostbridge" as an integer failed and the host bridge used a device ID
of 0.  The EFI ROM asserts that the device ID of the hostbridge is not
0, so booting with the current EFI ROM was failing during the ROM
boot.

Fixes:		621b509048
2021-03-24 09:29:15 -07:00
D Scott Phillips
f8a6ec2d57 bhyve: support relocating fbuf and passthru data BARs
We want to allow the UEFI firmware to enumerate and assign
addresses to PCI devices so we can boot from NVMe[1]. Address
assignment of PCI BARs is properly handled by the PCI emulation
code in general, but a few specific cases need additional support.
fbuf and passthru map additional objects into the guest physical
address space and so need to handle address updates. Here we add a
callback to emulated PCI devices to inform them of a BAR
configuration change. fbuf and passthru then watch for these BAR
changes and relocate the frame buffer memory segment and passthru
device mmio area respectively.

We also add new VM_MUNMAP_MEMSEG and VM_UNMAP_PPTDEV_MMIO ioctls
to vmm(4) to facilitate the unmapping needed for addres updates.

[1]: https://github.com/freebsd/uefi-edk2/pull/9/

Originally by:	scottph
MFC After:	1 week
Sponsored by:	Intel Corporation
Reviewed by:	grehan
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D24066
2021-03-19 11:04:36 +08:00
John Baldwin
621b509048 Refactor configuration management in bhyve.
Replace the existing ad-hoc configuration via various global variables
with a small database of key-value pairs.  The database supports
heirarchical keys using a MIB-like syntax to name the path to a given
key.  Values are always stored as strings.  The API used to manage
configuation values does include wrappers to handling boolean values.
Other values use non-string types require parsing by consumers.

The configuration values are stored in a tree using nvlists.  Leaf
nodes hold string values.  Configuration values are permitted to
reference other configuration values using '%(name)'.  This permits
constructing template configurations.

All existing command line arguments now set configuration values.  For
devices, the "-s" option parses its option argument to generate a list
of key-value pairs for the given device.

A new '-o' command line option permits setting an individual
configuration variable.  The key name is always given as a full path
of dot-separated components.

A new '-k' command line option parses a simple configuration file.
This configuration file holds a flat list of 'key=value' lines where
the 'key' is the full path of a configuration variable.  Lines
starting with a '#' are comments.

In general, bhyve starts by parsing command line options in sequence
and applying those settings to configuration values.  Once this is
complete, bhyve then begins initializing its state based on the
configuration values.  This means that subsequent configuration
options or files may override or supplement previously given settings.

A special 'config.dump' configuration value can be set to true to help
debug configuration issues.  When this value is set, bhyve will print
out the configuration variables as a flat list of 'key=value' lines.

Most command line argments map to a single configuration variable,
e.g.  '-w' sets the 'x86.strictmsr' value to false.  A few command
line arguments have less obvious effects:

- Multiple '-p' options append their values (as a comma-seperated
  list) to "vcpu.N.cpuset" values (where N is a decimal vcpu number).

- For '-s' options, a pci.<bus>.<slot>.<function> node is created.
  The first argument to '-s' (the device type) is used as the value of
  a "device" variable.  Additional comma-separated arguments are then
  parsed into 'key=value' pairs and used to set additional variables
  under the device node.  A PCI device emulation driver can provide
  its own hook to override the parsing of the additonal '-s' arguments
  after the device type.

  After the configuration phase as completed, the init_pci hook
  then walks the "pci.<bus>.<slot>.<func>" nodes.  It uses the
  "device" value to find the device model to use.  The device
  model's init routine is passed a reference to its nvlist node
  in the configuration tree which it can query for specific
  variables.

  The result is that a lot of the string parsing is removed from
  the device models and centralized.  In addition, adding a new
  variable just requires teaching the model to look for the new
  variable.

- For '-l' options, a similar model is used where the string is
  parsed into values that are later read during initialization.
  One key note here is that the serial ports use the commonly
  used lowercase names from existing documentation and examples
  (e.g. "lpc.com1") instead of the uppercase names previously
  used internally in bhyve.

Reviewed by:	grehan
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D26035
2021-03-18 16:30:26 -07:00
Ka Ho Ng
54ac6f721e bhyve: virtio shares definitions between sys/dev/virtio
Definitions inside usr.sbin/bhyve/virtio.h are thrown away.
Definitions in sys/dev/virtio are used instead.

This reduces code duplication.

Sponsored by:	The FreeBSD Foundation
Reviewed by:	grehan
Approved by:	philip (mentor)
Differential Revision:	https://reviews.freebsd.org/D29084
2021-03-16 19:29:39 +08:00
Robert Wing
38dfb0626f 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
2021-03-07 15:23:29 -09:00
Robert Wing
d656ce199d 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
2021-02-27 12:07:35 -09:00
Robert Wing
b7fd9c4e5e 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
2021-02-27 12:03:03 -09:00
Robert Wing
5ce2d4a1c2 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
2021-02-22 11:31:07 -09:00
Robert Wing
4f4065e0a2 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
2021-02-17 17:46:42 -09:00
Allan Jude
e6d795d154 Fix manpage markup in 2c8bb126de 2021-01-21 20:32:15 +00:00
Allan Jude
2c8bb126de bhyve: Add missing man page section on the nodelete block-device-option
Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D28272
2021-01-21 20:30:55 +00:00
Peter Grehan
eed1cc6cdf Support COM3 and COM4 serial ports.
Submitted by: Jan Poctavek <janci@binaryparadise.com>, otis
Reviewed by: grehan (bhyve), imp, 0mp (manpages)
Differential Revision: https://reviews.freebsd.org/D28207
2021-01-20 03:30:22 +10:00
Mariusz Zaborski
845b273728 bhyve: fix build without casper/capsicum support
Fix typo introduced in 966026246e.

Pointed out by:	jbeich
2021-01-03 18:17:04 +01:00
Mariusz Zaborski
966026246e bhyve: fix build without casper/capsicum support
PR:		252353
2021-01-03 17:21:28 +01:00
Robert Wing
c4df8cbfde Remove bvmconsole and bvmdebug.
Now that bhyve(8) supports UART, bvmconsole and bvmdebug are no longer needed.

This also removes the '-b' and '-g' flag from bhyve(8). These two flags were
marked deprecated in r368519.

Reviewed by:    grehan, kevans
Approved by:    kevans (mentor)
Differential Revision:  https://reviews.freebsd.org/D27490
2020-12-23 17:15:23 -09:00
Peter Grehan
2bb4be0f86 Fix issues with various VNC clients.
- support VNC version 3.3 (macos "Screen Sharing" builtin client)
- wait until client has requested an update prior to sending framebuffer data
- don't send an update if no framebuffer updates detected
- increase framebuffer poll frequency to 30Hz, and double that when
  kbd/mouse input detected
- zero uninitialized array elements in rfb_send_server_init_msg()
- fix overly large allocation in rfb_init()
- use atomics for flags shared between input and output threads
- use #defines for constants

 This work was contributed by Marko Kiiskila, with reuse of some earlier
work by Henrik Gulbrandsen.

Clients tested :
FreeBSD-current
 - tightvnc
 - tigervnc
 - krdc
 - vinagre

Linux (Ubuntu)
 - krdc
 - vinagre
 - tigervnc
 - xtightvncviewer
 - remmina

MacOS
 - VNC Viewer
 - TigerVNC
 - Screen Sharing (builtin client)

Windows 10
 - Tiger VNC
 - VNC Viewer (cursor lag)
 - UltraVNC (cursor lag)

o/s independent
 - noVNC (browser) using websockify relay

PR: 250795
Submitted by:	Marko Kiiskila <marko@apache.org>
Reviewed by:	jhb (bhyve)
MFC after:	3 weeks
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D27605
2020-12-18 00:38:48 +00:00
Aleksandr Fedorov
ea57b2d7a8 [bhyve] virtio-net: Do not allow receiving packets until features have been negotiated.
Enforce the requirement that the RX callback cannot be called after a reset until the features have been negotiated.
This fixes a race condition where the receive callback is called during a device reset.

Reviewed by:	vmaffione, grehan
Approved by:	vmaffione (mentor)
Sponsored by:	vstack.com
Differential Revision:	https://reviews.freebsd.org/D27381
2020-12-17 16:52:40 +00:00
Robert Wing
92f7309929 Add deprecation notice for bvmconsole and bvmdebug
Now that bhyve(8) supports UART, bvmconsole and bvmdebug are no longer needed.

Mark the '-b' and '-g' flag as deprecated for bhyve(8).

These will be removed in 13.

Reviewed by:    jhb, grehan
Approved by:    kevans (mentor)
MFC after:      1 week
Differential Revision:  https://reviews.freebsd.org/D27519
2020-12-10 18:07:25 +00:00
John Baldwin
1b9c78611d Suspend I/O on ahci-cd devices during a snapshot.
Submitted by:	Vitaliy Gusev <gusev.vitaliy@gmail.com>
2020-11-28 04:21:22 +00:00
John Baldwin
bb481f6718 bhyve: Add snapshot support for virtio-rnd.
This uses the same snapshot routine as other VirtIO devices.

Submitted by:	Vitaliy Gusev <gusev.vitaliy@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D26265
2020-11-28 04:06:09 +00:00
John Baldwin
57b0a3aaca bhyve: 'xhci,tablet' snapshot fixes
Permit suspend/resume of a XHCI device model that has not been
attached to by a driver in a guest OS.

Submitted by:	Vitaliy Gusev <gusev.vitaliy@gmail.com>
Differential Revision:	https://reviews.freebsd.org/D26264
2020-11-28 03:54:48 +00:00
Rebecca Cran
866db2fef0 Fix bhyve SMBIOS type 19 handling to avoid misreporting total RAM amount
This fixes the amount of memory displayed in the EDK2 UiApp to be the same
as passed on the bhyve command line. Otherwise, 8GB is displayed as 4GB,
32GB as 28GB etc.

Reviewed by:	jhb, kib, rgrimes
Differential Revision:	https://reviews.freebsd.org/D27348
2020-11-27 08:00:32 +00:00
Rebecca Cran
5285d5e8e1 bhyve: fix smbiostbl.c style issues and add comment about date format
Fix a couple of style issues introduced in my previous commit.
Add a comment explaining that the SMBIOS specification defines the date
format to be mm/dd/yyyy, which is why we don't use ISO 8601.
2020-11-27 07:53:15 +00:00
John Baldwin
1925586e03 Honor the disabled setting for MSI-X interrupts for passthrough devices.
Add a new ioctl to disable all MSI-X interrupts for a PCI passthrough
device and invoke it if a write to the MSI-X capability registers
disables MSI-X.  This avoids leaving MSI-X interrupts enabled on the
host if a guest device driver has disabled them (e.g. as part of
detaching a guest device driver).

This was found by Chelsio QA when testing that a Linux guest could
switch from MSI-X to MSI interrupts when using the cxgb4vf driver.

While here, explicitly fail requests to enable MSI on a passthrough
device if MSI-X is enabled and vice versa.

Reported by:	Sony Arpita Das @ Chelsio
Reviewed by:	grehan, markj
MFC after:	2 weeks
Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D27212
2020-11-24 23:18:52 +00:00
Peter Grehan
887d46ef5b Advance RIP after userspace instruction decode
Add update to RIP after a userspace instruction decode (as is done for
the in-kernel counterpart of this case).

Submitted by:	adam_fenn.io
Reviewed by:	cem, markj
Approved by:	grehan (bhyve)
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D27243
2020-11-19 07:23:39 +00:00
Peter Grehan
2f40fc6ff3 Add legacy debug/test interfaces for kvm unit tests.
Implement the legacy debug/test interfaces expected by KVM-unit-tests'
realmode, emulator, and ioapic tests.

Submitted by:	adam_fenn.io
Reviewed by:	markj, grehan
Approved by:	grehan (bhyve)
MFC after:	3 weeks
Relnotes:	Yes
Differential Revision:	https://reviews.freebsd.org/D27130
2020-11-17 13:14:04 +00:00
Peter Grehan
cd5b6d16ca Fix regression in AHCI controller settings.
When the AHCI code was reworked to use FreeBSD struct
definitions, the valid element was mis-transcribed resulting
in the UMDA capability being hidden. This prevented Illumos
from using AHCI disk/cdrom drives.

Fix by using definitions that match the code pre-rework.

PR:	250924
Submitted by:	Rolf Stalder
Reported by:	Rolf Stalder
MFC after:	3 days
2020-11-15 12:59:24 +00:00
Rebecca Cran
a2fe464c81 bhyve: update smbiostbl.c to bump the version and release date
Since lots of work has been done on bhyve since 2014, increase the version
to 13.0 to match 13-CURRENT, and update the release date.

Reviewed by:	grehan
Differential Revision:	https://reviews.freebsd.org/D27147
2020-11-13 19:47:16 +00:00
Konstantin Belousov
038f5c7bfe bhyve: remove a hack to map all 8G BARs 1:1
Suggested and reviewed by:	grehan
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D27186
2020-11-12 02:52:01 +00:00
Konstantin Belousov
670b364b76 bhyve: increase allowed size for 64bit BAR allocation below 4G from 32 to 128 MB.
Reviewed by:	grehan
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D27095
2020-11-12 00:51:53 +00:00
Konstantin Belousov
9922872ba2 bhyve: avoid allocating BARs above the end of supported physical addresses.
Read CPUID leaf 0x8000008 to determine max supported phys address and
create BAR region right below it, reserving 1/4 of the supported guest
physical address space to the 64bit BARs mappings.

PR:    250802 (although the issue from PR is not fixed by the change)
Noted and reviewed by:	grehan
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D27095
2020-11-12 00:46:53 +00:00
Olivier Cochard
c4fd0cc9ee Return the same value for smbios.chassis.maker as smbios.system.maker (and prevents returning a space character).
Reviewed by:	grehan
Approved by:	grehan
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D27123
2020-11-08 07:49:39 +00:00
Allan Jude
cc3568c1d0 VirtIO: Make sure the guest knows the TRIM alignment requirements
If bhyve is used to emulate 512e access in guest OS, then discard addresses should be properly aligned.
Otherwise ioctl DIOCGDELETE fails for 512b requires on devices with 4K sector size.
see g_dev_ioctl() in sys/geom/geom_dev.c

Submitted by:	Vitaliy Gusev <gusev.vitaliy@gmail.com>
MFC after:	1 week
Sponsored by:	vStack.com
Differential Revision:	https://reviews.freebsd.org/D27075
2020-11-05 17:10:14 +00:00
Olivier Cochard
ac8f506b85 bhyve currently reports each of "smbios.system.maker" and
"smbios.system.family" as " ".
This presents challenges for both humans and tools when trying to parse output
that uses those results.
The new values reported are now:
smbios.system.family="Virtual Machine"
smbios.system.maker="FreeBSD"

PR:		250728
Approved by:	grehan@FreeBSD.org
Sponsored by:	Netflix
2020-10-30 00:03:59 +00:00
Ryan Moeller
60dc6bee1f bhyve: Update TX descriptor base address and host mapping on change
bhyve sometimes segfaults when using an e1000 NIC with a Windows guest.

We are only updating our tdba and cached host mapping when the low address
register is written and when tx is set enabled, but not when the high address
or length registers are written. It is observed that Windows 10 is occasionally
enabling tx first then writing the registers in the order low, high, len. This
leaves us with a bogus base address and mapping, which causes a segfault later
when we try to copy from a descriptor that has unpredictable garbage in a
pointer.

Updating the address and mapping when any of those registers change seems to fix
that particular issue.

Reviewed by:	mav, grehan (bhyve)
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D26798
2020-10-16 20:27:20 +00:00
Jakub Wojciech Klama
100353cfbf Add virtio-9p (aka VirtFS) filesystem sharing to bhyve.
VirtFS allows sharing an arbitrary directory tree between bhyve virtual
machine and the host. Current implementation has a fairly complete support
for 9P2000.L protocol, except for the extended attribute support. It has
been verified to work with the qemu-kvm hypervisor.

Reviewed by:	rgrimes, emaste, jhb, trasz
Approved by:	trasz (mentor)
MFC after:	1 month
Relnotes:	yes
Sponsored by:	Conclusive Engineering (development), vStack.com (funding)
Differential Revision:	https://reviews.freebsd.org/D10335
2020-10-03 19:05:13 +00:00
John Baldwin
6f64e4f361 bhyve: Fix build with option BHYVE_SNAPSHOT
'ident' was replaced with 'ata_ident' in revision r363596.

Submitted by:	Vitaliy Gusev <gusev.vitaliy_gmail.com>
Reviewed by:	Darius Mihai
Differential Revision:	 https://reviews.freebsd.org/D26263
2020-10-01 17:16:05 +00:00
Peter Grehan
285e35e6f1 Fix byte-reversal of language ID in string descriptor.
The language id of String Descriptors in usb mouse is
0x0904, while the spec require 0x0409 (English - United States)

Submitted by:	Wanpeng Qian
Reviewed by:	grehan
Approved by:	grehan (#bhyve)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D26472
2020-09-18 05:54:59 +00:00
Chuck Tuffli
71a51f69a4 bhyve: NVMe queue create must init head/tail
The NVMe emulation code did not explicitly initialize queue head and
tail pointers on queue creation. As these pointers are part of
calloc()'ed memory, this only becomes a problem if the queues are
deleted and then recreated.

This error can manifest with messages about completions not matching a
command.
2020-08-24 01:51:21 +00:00
Chuck Tuffli
c4a86c1fc0 bhyve: NVMe set nominal health values
Some operating systems believe bhyve's emulated NVMe drive is failing
based on certain values in the SMART / Health Information log page being
zero. Fix is to set the reported temperature and available spare values
to reasonable defaults.

Submitted by:	wanpengqian@gmail.com
Reviewed by:    grehan
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D24202
2020-08-24 01:51:17 +00:00
Konstantin Belousov
f3eb12e4a6 Add bhyve support for LA57 guest mode.
Noted and reviewed by:	grehan
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D25273
2020-08-23 20:37:21 +00:00
Peter Grehan
f1c3dac414 Replace magic numbers in Identify page register 0 with ATA definitions.
No functional change. Verified with objdump output before/after.

Requested by:	rpokala
Reviewed by:	rpokala
MFC after:	3 weeks
2020-07-31 12:10:28 +00:00
Peter Grehan
9af3bcd7c9 Support the setting of additional AHCI controller parameters.
Allow the serial number, firmware revision, model number and nominal media
rotation rate (nmrr) parameters to be set from the command line.

Note that setting the nmrr value can be	used to	indicate the AHCI
device is an SSD.

Submitted by:	Wanpeng Qian
Reviewed by:	jhb, grehan (#bhyve)
Approved by:	jhb, grehan
MFC after:	3 weeks
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D24174
2020-07-27 07:56:55 +00:00
Peter Grehan
fb5f5a17ef Advertise 64-bit physical-address capability.
This fixes a coredump with NetBSD guests when XHCI is configured.
On seeing the AC64 flag clear, the NetBSD XHCI driver was only writing
to the lower 32-bits of 64-bit physical address registers. The emulation
relies on a write to the hi 32-bits to calculate a host virtual address
for internal use, and has always supported 64-bit addressing.

All other guests were seen to write to both the lo- and hi- address
registers, regardless of the AC64 setting.

Discussed with:  Leon Dang (author)
Tested with:  Ubuntu 16/18/20, Windows10, OpenBSD UEFI guests.

MFC after:	2 weeks.
2020-07-10 07:26:50 +00:00
Peter Grehan
6a7ff0600b Silence ACPI RTC error/warning in Linux guests.
Allow guests to	set the	RTC bit	in the ACPI PM control register.
This eliminates an annoying	(and harmless) Linux kernel boot message.

PR:	244721
Submitted by:	Jose Luis Duran
MFC after:	1 week
2020-07-06 08:36:14 +00:00
Chuck Tuffli
0ed1d2e484 bhyve: fix NVMe Active Namespace list
The NVMe specification requires unused entries in the Identify, Active
Namespace ID data to be zero. Fix is bzero the provided page, similar to
what is done for the Namespace Descriptors list.

Fixes UNH Tests 2.6 and 2.9

Tested by:	Jason Tubnor
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D24901
2020-06-29 00:32:24 +00:00
Chuck Tuffli
a104b18c52 bhyve: NVMe handle zero length DSM ranges
Dataset Management range specifications may have a zero length (a.k.a.
an empty range definition). Handle the case of all ranges being empty by
completing with Success (DSM commands are advisory only). For
Deallocate, skip empty range definitions when sending TRIM's to the
backing storage.

Fixes UNH Test 2.2.4

Reviewed by:	imp
Tested by:	Jason Tubnor
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D24900
2020-06-29 00:32:21 +00:00
Chuck Tuffli
7669ea7bb0 bhyve: fix NVMe Get Features, Predictable Latency
If the Predictable Latency Mode is not supported, NVMe Controllers must
return Invalid Field in Command status for the Get Features command
with IDs:
 - Predictable Latency Mode Config
 - Predictable Latency Mode Window

Fixes UNH Tests 3.6

Tested by:	Jason Tubnor
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D24899
2020-06-29 00:32:18 +00:00
Chuck Tuffli
f97ed15123 bhyve: add NVMe Feature Interrupt Vector Config
This adds support for NVMe Get Features, Interrupt Vector Config
parameter error checking done by the UNH compliance tests.

Fixes UNH Tests 1.6.8 and 5.5.6

Tested by:	Jason Tubnor
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D24898
2020-06-29 00:32:15 +00:00