CVS: cvs.openbsd.org: src

2024-05-20 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/05/20 11:03:36

Modified files:
sys/uvm: uvm_amap.c 

Log message:
Remove always-false condition in amap_free KASSERT.

The if-condition immediately preceding it already checks the value
so the first part of the KASSERT is redundant.

ok mpi@, miod@, jca@



CVS: cvs.openbsd.org: src

2024-05-03 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/05/03 07:48:29

Modified files:
sys/arch/amd64/amd64: pmap.c vmm_machdep.c 

Log message:
vmm: merge VMX and SVM vm initialization functions.

They do the same uvmspace/pmap dance, so just reduce to a single
function. Kernel lock is moved to the uvmspace_free call. In addition,
we should be using the pmap mutex in pmap_convert, called by the
vm initialization routine.

ok mlarkin@



CVS: cvs.openbsd.org: src

2024-04-29 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/04/29 08:47:06

Modified files:
sys/arch/amd64/amd64: vmm_machdep.c 
sys/arch/amd64/include: vmmvar.h 
usr.sbin/vmd   : vm.c 

Log message:
vmm & vmd: drop "continue" flag to simplify running a vcpu.

There's no need to distinguish the "first" time running a vcpu from
the subsequent times because vmm(4) uses in-kernel state tracking
the last vm exit reason to optimize the logic for updating vcpu
registers from userland. While here, clean up the DPRINTF's to make
the Intel VMX logic similar to the AMD SVM.

ok mlarkin@



CVS: cvs.openbsd.org: src

2024-04-10 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/04/10 07:03:41

Modified files:
usr.sbin/vmctl : main.c 

Log message:
vmctl: fix incorrect scaling when converting disk images.

ctl_convert still had old logic assuming disk sizes were in MiB and
not bytes, causing an attempt to create a new disk using the '-i'
argument to generate impossibly large output disk images (e.g. 1 MiB
ends up 1 TiB).

Reported by and diff from Jesper Wallin.



CVS: cvs.openbsd.org: src

2024-04-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/04/09 15:55:16

Modified files:
sys/arch/amd64/amd64: vmm_machdep.c 
sys/arch/amd64/include: vmmvar.h 
regress/sys/arch/amd64/vmm: vcpu.c 
usr.sbin/vmd   : vm.c 

Log message:
vmm/vmd: add exception injection and refactor inject api.

In order to continue work on mmio and other instruction emulation,
vmd(8) needs the ability to inject exceptions (like page faults)
from userland.

Refactor the way events are injected from userland, cleaning up how
hardware (external) interrupts are injected in the process.

ok mlarkin@



CVS: cvs.openbsd.org: www

2024-03-23 Thread Dave Voutila
CVSROOT:/cvs
Module name:www
Changes by: d...@cvs.openbsd.org2024/03/23 08:06:26

Modified files:
.  : 75.html 

Log message:
Add some vmd/vmm updates for 7.5.



CVS: cvs.openbsd.org: src

2024-02-21 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/21 19:38:53

Modified files:
usr.sbin/vmd   : vionet.c 

Log message:
vmd(8): only add vionet tap read events after a notify event.

My recent refactor introduced a bug where the vionet device will
add the tap(4) read event on an unpause regardless of driver and
device state, causing the cpu to peg as the read event fires
indefinitely because the guest's virtqueue isn't ready to receive
the data.

Add in a global flag that tracks if the rx-side is enabled or not
to coordinate adding the tap read event.

ok mlarkin@



CVS: cvs.openbsd.org: src

2024-02-20 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/20 14:40:37

Modified files:
usr.sbin/vmd   : proc.c proc.h vioblk.c vionet.c virtio.c 
 virtio.h vm.c vmd.h 

Log message:
Utilize separate threads for RX and TX in vmd(8)'s vionet.

This commit adds multithreading to allow both virtqueues to be
processed in parallel along with additional synchronization primitives
to protect device configuration state. Allowing RX and TX to operate
independently reduces overall network latency for guests and helps
alleviate the TX side dominating cpu time.

Tested with help from phessler@, kn@, and mlarkin@. ok mlarkin@.



CVS: cvs.openbsd.org: src

2024-02-10 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/10 05:31:16

Modified files:
usr.sbin/vmd   : mmio.c 

Log message:
Prevent use of uninitialized byte in vmd's mmio decoder.

The mmio code isn't wired in, but if the ModRM decode fails, byte
may be used with an uninitialized value. Properly return an error,
but initialize the byte variable as well.

Found by smatch, reported by and ok jsg@.



CVS: cvs.openbsd.org: src

2024-02-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/09 19:19:12

Modified files:
usr.sbin/vmd   : vionet.c 

Log message:
Fix locked address interfaces in vmd(8).

Before comparing the amount of bytes read to the size of a packet
struct, make sure the fd being read was actually the packet injection
pipe(2). Locked address interfaces force using the same copy-based
approach used for the internal dhcp service for "local" interfaces
but were accidentally being treated as reads from the pipe(2) and
not the tap.

This broke networking for any locked address interfaces in vmd(8).

Reported by and ok kn@



CVS: cvs.openbsd.org: src

2024-02-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/09 19:10:41

Modified files:
usr.sbin/vmd   : virtio.c 

Log message:
Set vmd virtio device fds to -1 on close after fork.

After the recent vmd(8) commit to clean up file descriptor lifecycles,
virtio disks with multiple file descriptors (QCOW2 images with at
least one base) would fail to initialize when booted with a network
device.

Use the new fd closing routine in the vm process for virtio devices
to close the device fds and set to -1, removing buggy copying and
closing of fds.

Additionally, close the vm/device sync and async channels when
closing a device's fds.

Issue reported by and ok kn@



CVS: cvs.openbsd.org: src

2024-02-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/09 07:52:39

Modified files:
usr.sbin/vmd   : vionet.c 

Log message:
Only debug log dhcp packet info if packet is found.

No functional change. vmd(8) was being chatty and incorrect.



CVS: cvs.openbsd.org: src

2024-02-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/09 07:35:47

Modified files:
usr.sbin/vmd   : i8253.c 

Log message:
Tuck vmd's i8253 reset debug logs behind DPRINTF.

It's super chatty and pollutes verbose logging.



CVS: cvs.openbsd.org: src

2024-02-05 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/05 14:58:09

Modified files:
usr.sbin/vmd   : config.c vioblk.c vionet.c virtio.c vm.c vmd.c 
 vmm.c 

Log message:
Cleanup fcntl(3) usage and fd lifetimes in vmd(8).

Remove extraneous fcntl(3) usage for setting fd features that can
be set at time of open(2), pipe2(2), or socketpair(2). Also cleans
up pty creation switching to using functions from libutil instead
of direct ioctl(2) calls.

ok mlarkin@, original diff ok claudio@ as well.



CVS: cvs.openbsd.org: src

2024-02-04 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/04 07:57:00

Modified files:
usr.sbin/vmd   : vmm.c 

Log message:
Remove dead code and fix null deref if vm is not found.

Return early if no vm is found in vmd(8)'s primary vm fork/exec
function, preventing null deref in the 'fail' section. Also remove
inner return from the parent routine to prevent unreachable code.

Found by smatch, reported by and ok jsg@.



CVS: cvs.openbsd.org: src

2024-02-04 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/04 07:56:45

Modified files:
usr.sbin/vmd   : vmd.c 

Log message:
Prevent null pointer deref is vm isn't found.

This area of code in vmd(8) is suspect, but the null dereference
is easily avoided.

Found by smatch, reported by and ok jsg@



CVS: cvs.openbsd.org: src

2024-02-04 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/04 07:54:51

Modified files:
usr.sbin/vmd   : vioblk.c 

Log message:
Initialize result in vioblk notification handler.

In the event the driver kicks the vioblk device, but the guest
doesn't have any available virtqueue space, vmd will return an
uninitialized value. If non-zero, it results in a notification to
the driver and effectively a spurious interrupt.

Found by smatch, reported by and ok jsg@



CVS: cvs.openbsd.org: src

2024-02-04 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/04 07:53:12

Modified files:
usr.sbin/vmd   : fw_cfg.c 

Log message:
Reverse calloc args.

Found by smatch "double check that we're allocating correct size"
warning. Reported by and ok jsg@.



CVS: cvs.openbsd.org: src

2024-02-03 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/03 14:41:35

Modified files:
usr.sbin/vmd   : vionet.c 

Log message:
Add tap(4) read events after rx virtqueue notification.

The recent vmd(8) vionet refactor caused cpu spinning when the
device would be activated by a driver but before virtqueues were
provided. (e.g. booting a ramdisk kernel and not running `ifconfig
vio0 up`)

Defer adding the tap and packet injection read events until after
the first RX queue notification from the driver.

ok mlarkin@



CVS: cvs.openbsd.org: src

2024-02-02 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/02/02 07:58:02

Modified files:
usr.sbin/vmd   : vm_agentx.c 

Log message:
Explain missing group on getgrnam(3) failure.

vmd's use of agentx requires the agentx group, but if unavailable,
no details were given to the user.

Zap some whitespace whitespace while here.

"that is better", deraadt@



CVS: cvs.openbsd.org: src

2024-01-30 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/01/30 16:01:49

Modified files:
usr.sbin/vmd   : vionet.c virtio.h 

Log message:
Rewrite vmd(8)'s vionet to be zero-copy.

Similar to the rewrite of the virtio block device to use zero-copy
semantics, this rewrites how the virtio network device works with
the virtqueue ring buffers to minimize data copying. For guests
that don't use the built-in DNS and mac filtering capabilities,
data can now be transfered to/from the virtqueue and the tap(4)
directly without temporary buffers.

A lot of the virtio semantics are cleaned up as well, including
proper error states.

Tested with help by mbuhl@, friehm@, mlarkin@, and others.

"go for it," mlarkin@



CVS: cvs.openbsd.org: src

2024-01-14 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/01/14 19:35:23

Modified files:
sys/dev/fdt: virtio_mmio.c 
sys/dev/pci: virtio_pci.c 

Log message:
vio(4): poll device status after issuing device reset.

The virtio spec says a driver "should" wait for a device to report
a clear device status after performing a reset. In some hypervisors,
this doesn't matter as the vcpu's io instruction emulation and
virtio network device emulation happen serially in the same thread.
In hypervisors like vmd(8), device reset happens asynchronously and
the driver can't assume the device is ready.

This race condition results in mbuf pool corruption, causing panics.

Bug reported and reproduced by bluhm@. Root cause found and diff
from sf@. ok dv@ and committed on sf@'s behalf with his permission.



CVS: cvs.openbsd.org: src

2024-01-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/01/09 21:13:59

Modified files:
usr.sbin/vmd   : vm.c 
sys/arch/amd64/amd64: vmm_machdep.c 
sys/arch/amd64/include: vmmvar.h 

Log message:
vmm/vmd: add io instruction length to exit information.

Add the instruction length to the vm exit information to allower
vmd(8) to manipulate the instruction pointer after io emulation.
This is preparation for emulating string-based io instructions.

Removes the instruction pointer update from the kernel (vmm(4)) as
well as the instruction length checks, which were overly restrictive
anyways based on the way prefixes work in x86 instructions.

ok mlarkin@



CVS: cvs.openbsd.org: src

2024-01-06 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/01/06 06:17:20

Modified files:
sys/arch/amd64/amd64: vmm_machdep.c 
sys/arch/amd64/include: vmmvar.h 

Log message:
vmm(4): reorder segment registers to match SDM.

Shuffles around the defines so the segment register indexes match
the values used by both Intel and AMD in vm exit information.
Simplifies some upcoming changes.

ok mlarkin@



CVS: cvs.openbsd.org: src

2024-01-03 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/01/03 15:34:39

Modified files:
usr.sbin/vmd   : config.c vmm.c 

Log message:
vmd(8): improve error messages when out of tap devices.

The logging and the (lack of) errno don't describe the actual reason
a vm fails to start when there are not enough tap(4) special files
in /dev. Improve the log message to specify the tap file in question
and set ENOENT so vmctl(8) gets something other than an undefined
errno value to report.

ok bluhm@



CVS: cvs.openbsd.org: src

2024-01-02 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2024/01/02 20:14:16

Modified files:
usr.sbin/vmd   : vionet.c 

Log message:
vmd(8): remove unused variable from vionet_notify_tx.

num_enq was assigned and incremented, but never used. clang started
pointing out via warnings. No functional change.



CVS: cvs.openbsd.org: src

2023-12-20 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/12/20 07:00:17

Modified files:
regress/usr.sbin/btrace: arithm.bt arithm.ok 
usr.sbin/btrace: bt_parse.y 

Log message:
btrace: add support for hex and octal values.

Changes number tokenizing and parsing to support hex & octal values.
Does not address other lexer issues (e.g. $0x1) to close gaps with
bpftrace.

OK claudio@



CVS: cvs.openbsd.org: src

2023-12-19 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/12/19 18:38:46

Modified files:
usr.sbin/btrace: bt_parse.y 

Log message:
btrace: "too long line" -> "line too long"

ok claudio@



CVS: cvs.openbsd.org: src

2023-12-10 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/12/10 14:25:14

Modified files:
sys/arch/amd64/amd64: vmm_machdep.c 

Log message:
vmm(4): flush EPTs after enabling VMX mode.

The Intel SDM states the vmxon/vmxoff instructions don't invalidate
any EPT states on the cpu and recommend invalidating the global
context. vmm(4) opportunistically disables and enables VMX mode as
vms are created or terminated, so this adds a recommended
housekeeping step per the SDM.

While here, tidy up the CR4 toggling by moving it to after the MSR
feature check.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-11-27 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/11/27 17:17:48

Modified files:
sys/arch/amd64/amd64: vmm_support.S 
sys/arch/amd64/include: vmmvar.h 

Log message:
Adapt inv{vpid,ept} to return success or failure.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-11-26 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/11/26 06:02:44

Modified files:
sys/arch/amd64/amd64: vmm_machdep.c 

Log message:
vmm(4)/vmx: pass correct vpid value to invvpid.

While vmm's use of invvpid in the vmx vcpu run loop is questionable
since we require and use EPT, the vpid value is unquestionably wrong
in these calls.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-11-24 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/11/24 14:48:25

Modified files:
sys/arch/amd64/amd64: vmm_machdep.c 

Log message:
vmm(4)/vmx: fix memory scribbling by updating GDTR/TR if vcpu moves.

If the vcpu thread sleeps in the kernel, like when handling a nested
page fault and calling uvm_fault(9), the thread may be rescheduled
on another host cpu. vmm(4) was only setting the GDTR and TR bases
in the VMCS once prior to first vm entry, so a thread migration can
result in restoring the wrong GDTR and TR on vm exit for the host
cpu. This results in borked interrupts and corrupted stack pointers,
causing programs to segfault or sigabort. It can also result in
missed ipi's causing kernel deadlocks.

Use similar logic to the SVM routines and check for cpu migration
within the hot loop. Since we're letting the VMX features of the
cpu restore GDTR, we can also drop the manual store/load routines.

Reported and with much appreciated testing help from Mischa Peters.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-11-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/11/09 05:26:09

Modified files:
usr.sbin/vmctl : vmctl.c 

Log message:
vmctl(8): avoid abort when given an invalid "kernel" file.

The vmctl `start` command allows the user to pass an optional
"kernel" file (either a ramdisk kernel or a SeaBIOS image). This
file is opened by vmctl and the descriptor passed via imsg.

If the file provided isn't a regular file, the attempt to send the
start message to vmd(8)'s control socket will fail and results in
a the vmctl process aborting.

Check the file type after open and fail gracefully if not a regular
file.

reported by and ok gnezdo@



CVS: cvs.openbsd.org: src

2023-10-25 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/10/25 06:44:28

Modified files:
usr.sbin/vmd   : i8253.c mc146818.c ns8250.c 

Log message:
vmd(8): stop toggling irq deassert for edge triggered devs.

For edge-triggered devices, there's no need to deassert an irq given
how vmd(8) emulates a pic.  Deassertion grabs a lock and can trigger
the ioctl for toggling pending interrupts causing a race condition.
This results in a storm of vm-exits and guest vcpu becoming
unresponsive.

The original sign of this issue is guest "pauses" when pasting text
into a serial console connection in something like xterm(1).

Tested by mbuhl@, cheloha@, sashan@, kn@, and mlarkin@.

"go for it", mlarkin@



CVS: cvs.openbsd.org: www

2023-10-12 Thread Dave Voutila
CVSROOT:/cvs
Module name:www
Changes by: d...@cvs.openbsd.org2023/10/12 20:26:29

Modified files:
.  : 74.html 

Log message:
another vmm mention for the list



CVS: cvs.openbsd.org: www

2023-10-11 Thread Dave Voutila
CVSROOT:/cvs
Module name:www
Changes by: d...@cvs.openbsd.org2023/10/11 17:59:57

Modified files:
.  : 74.html 

Log message:
Add in most, if not all, vmm/vmd changes for 7.4.



CVS: cvs.openbsd.org: src

2023-09-25 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/25 19:53:54

Modified files:
usr.sbin/vmd   : log.c proc.c proc.h vioblk.c vionet.c virtio.c 
 virtio.h vm.c vmd.c vmm.c 

Log message:
vmd(8): disambiguate log messages per vm and device.

The logging output from vmd(8) often specifies the function performing
the logging, but leaves which vm or vm device to guesswork and
reading tea leaves.

Change the logging formatting to prefix with information about the
specific vm and potentially the device subprocess. Most of this
logging is behind the "verbose" mode, but for warnings this will
clarify which vm or device logged the warning.

The format of vm// is chosen to be concise and
less ugly than other approaches. This adjusts the process naming
for devices to match, dropping the use of brackets.

In the process of this change, updating log settings dynamically
via vmctl(8) is fixed by properly broadcasting that information to
the device subprocesses. The "vmm" process also now updates its own
state properly, so settings survive vm reboots.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-09-25 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/25 19:23:02

Modified files:
usr.sbin/vmd   : vm.c 

Log message:
vmd(8): fix vm pause deadlock.

When vcpu threads pause, they are holding the run mutex lock. If
the event thread is asked to assert an irq on the pic and interrupts
are pending, it will try to take the run mutex lock on the vcpu.
This deadlocks.

Release the lock in the vcpu thread before waiting on the pause
condition variable.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-09-23 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/23 06:31:41

Modified files:
usr.sbin/vmd   : vionet.c virtio.c 

Log message:
vmd(8): correct log messages, no functional change.

Some log messages incorrectly said "vionet" or "vioblk". Fix based
on the context.



CVS: cvs.openbsd.org: src

2023-09-23 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/23 06:27:21

Modified files:
usr.sbin/vmd   : vm.c 

Log message:
vmd(8): log vmd's vm id, not vmm's in vcpu_run_loop.

Some guests cause a warning message during a shutdown. Log the vmd
vm id and not the kernel vmm id as it's next to useless to the end
user. This has annoyed me too much.



CVS: cvs.openbsd.org: src

2023-09-14 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/14 09:25:43

Modified files:
usr.sbin/vmd   : vioblk.c vioqcow2.c vioraw.c virtio.c virtio.h 

Log message:
vmd(8)/vioblk: use zero-copy approach & vectored io.

The original version of the virtio block device dynamically allocated
buffers to hold intermediate data when reading or writing to the
underlying disk fd(s). Since vioblk drivers may chain multiple
segments together, this leads to overly complex logic and on
read(2)/write(2) call per data segment.

Additionally, the virtio block logic in vmd didn't handle segments
that weren't block aligned (e.g. 512 bytes). If a guest provided
unaligned segments, garbage will be read or written.

Since virtio descriptors mimic iovec structures, this changes vmd's
device emulation to use that model. (This is how other hypervisors
emulate virtio devices.) This allows for zero-copy semantics using
iovec's, reducing memcpy and multiple read/write syscalls per io
transaction.

Testing by phessler@ and mlarkin@. OK mlarkin@.



CVS: cvs.openbsd.org: src

2023-09-06 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/06 13:27:54

Modified files:
usr.sbin/vmd   : vioblk.c 

Log message:
Correct error message: vionet -> vioblk. No functional change.



CVS: cvs.openbsd.org: src

2023-09-06 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/06 13:26:39

Modified files:
usr.sbin/vmd   : vioblk.c vioscsi.c virtio.h 

Log message:
vmd(8): clean up struct ioinfo.

In prep for fixing some vioblk device issues, simplify the ioinfo
struct by dropping members that aren't needed.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-09-05 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/05 21:35:57

Modified files:
sys/arch/amd64/amd64: vmm_machdep.c 
sys/arch/amd64/include: vmmvar.h 
usr.sbin/vmd   : vm.c 

Log message:
vmm(4)/vmd(8): include pending interrupt in vm_run_parmams.

To remove an ioctl(2) from the vcpu thread hotpath in vmd(8), add
a flag in the vm_run_params structure to indicate if there's another
interrupt pending. This reduces latency in vcpu work related to
i/o as we save a trip into the kernel just to flip the interrupt
pending flag on or off.

Tested by phessler@, mbuhl@, stsp@, and Mischa Peters.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-09-02 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/02 13:28:47

Modified files:
usr.sbin/btrace: bt_parse.y 
regress/usr.sbin/btrace: Makefile 
Added files:
regress/usr.sbin/btrace: empty-stmts.bt empty-stmts.ok 

Log message:
btrace(8): allow empty statements in probes.

Allows for probes like `BEGIN {}`, in parity with bpftrace.

Also fixes an incorrect syntax error parsing argN builtins in
subsequent probes after an empty BEGIN block.

ok mpi@



CVS: cvs.openbsd.org: src

2023-09-02 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/02 09:16:12

Modified files:
usr.sbin/btrace: btrace.c 
regress/usr.sbin/btrace: beginend.bt 

Log message:
btrace(8): fix probe builtin in BEGIN/END.

Resolves segfaults when using probe within BEGIN or END.

ok mpi@



CVS: cvs.openbsd.org: src

2023-09-01 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/09/01 13:42:26

Modified files:
usr.sbin/vmd   : i8259.c vioblk.c vionet.c 

Log message:
vmd(8): ignore masks on asserts, use synchronous deasserts.

The i8259 was considering the state of the mask register when a
device requested raising the bit in the interrupt request register.
This caused a race condition where if the virtio device asserted
the irq while it was masked in the i8259 by the vm, we'd miss the
interrupt request. The device and the pic would become out of sync
and users reported virtio block device stalls as the vioblk(4)
driver would starve, waiting for an interrupt that will never arrive.

The mask is now considered only at ack time, when finding possible
interrupts to inject. This bug was never a problem previously as
virtio devices were emulated synchronously.

Deasserts related to the vcpu reading the virtio isr register are
also made now in response to the read request instead of issued
asynchronously. This removes a subsequent race condition.

Testing from mbuhl@, stsp@, and Florian Riehm.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-08-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/08/28 15:23:46

Modified files:
usr.sbin/btrace: bt_parse.y 
regress/usr.sbin/btrace: Makefile 
Added files:
regress/usr.sbin/btrace: beginend-argn.bt beginend-argn.ok 

Log message:
btrace(8): prohibit use of argN builtins in BEGIN/END.

The argN builtins are undefined for BEGIN and END special probes.
Similar to bpftrace, produce an error from the parser.

Adds a regress test, as well.

ok mpi@



CVS: cvs.openbsd.org: src

2023-08-16 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/08/16 07:07:11

Modified files:
usr.sbin/btrace: btrace.c 

Log message:
Backout changes for btrace(8) argN builtins.

Talking with mpi@, going to rework this to be part of the parser.
Reverts commit 0iIzGtIFgBXVfbNa.



CVS: cvs.openbsd.org: src

2023-08-15 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/08/15 14:51:45

Modified files:
usr.sbin/btrace: btrace.c 

Log message:
btrace(8): fix out of bounds read using argN in BEGIN/END.

The argN builtins aren't valid in BEGIN or END actions. The fake
probe number btrace uses to facilitate other valid builtins caused
an out of bound read of an array, producing a segfault.

Change the fake probe number to 0 as it's an unsigned int and check
for that condition.

Adds asserts near other probe array indexing to catch future issues.

ok kn@



CVS: cvs.openbsd.org: src

2023-08-13 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/08/13 07:19:23

Modified files:
usr.sbin/btrace: bt_parse.y 

Log message:
btrace(8): fix yacc reduce conflicts and undefined symbol warnings.

Define the STR symbol, used for the str function.

Tune the grammar, simplifying the 'pat' rule to 'expr'. Resolves
the reduce conflicts related to 'pat' and 'factor' both matching a
lone CSTRING token.

ok mpi@



CVS: cvs.openbsd.org: src

2023-07-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/07/28 10:54:48

Modified files:
sys/dev/pv : if_vio.c vioblk.c viocon.c viornd.c 

Log message:
Initialize handlers with NULL, not 0.



CVS: cvs.openbsd.org: src

2023-07-27 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/07/27 03:27:43

Modified files:
usr.sbin/vmd   : virtio.c vmd.h vmm.c 

Log message:
vmd(8): fix verbose logging in child processes.

The introduction of exec for vm's and fork+exec for virtio block
and network devices missed passing the log verbosity in argv. Add
the "-v" arguments based on current vverbosity at time of exec.

ok brynet@, mlarkin@



CVS: cvs.openbsd.org: src

2023-07-15 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/07/15 12:32:21

Modified files:
usr.sbin/vmd   : virtio.c 

Log message:
vmd(8): fix use of qcow base images.

The vm process was prematurely setting device fds to not close-on-exec
and then trying to close(2) them after the fork(2) of the device
process.

This caused a reuse of an fd for one of the socketpair(2)'s for
communication between vm and device. Having device processes close(2)
other device fds after fork would break the socketpair, causing the
device to fail during startup post-exec when trying to receive its
device state from the parent vm process.

Instead, mark the fds to not close on exec post-fork(2) call allowing
other device fds to be closed automatically and avoid closing by
the tracked fd.

Reported by solene@. OK tb@.



CVS: cvs.openbsd.org: src

2023-07-13 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/07/13 12:31:59

Modified files:
usr.sbin/vmd   : config.c dhcp.c parse.y priv.c virtio.c 
 virtio.h vm.c vmd.h vmm.c 

Log message:
vmd(8): pull validation into local prefix parser.

Validation for local prefixes, both inet and inet6, was scattered
around. To make it even more confusing, vmd was using generic address
parsing logic from prior network daemons. vmd doesn't need to parse
addresses other than when parsing the local prefix settings in
vm.conf and no runtime parsing is needed.

This change merges parsing and validation based on vmd's specific
needs for local prefixes (e.g. reserving enough bits for vm id and
network interface id encoding in an ipv4 address). In addition, it
simplifies the struct from a generic address struct to one focused
on just storing the v4 and v6 prefixes and masks. This cleans up an
unused TAILQ struct member that isn't used by vmd and was leftover
copy-pasta from those prior daemons.

The address parsing that vmd uses is also updated to using the
latest logic in bgpd(8).

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-05-13 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/05/13 17:15:28

Modified files:
regress/sys/arch/amd64/vmm: vcpu.c 
sys/dev/vmm: vmm.c vmm.h 
usr.sbin/vmd   : vioblk.c vionet.c virtio.c vm.c vmd.c vmd.h 
 vmm.c 

Log message:
vmm(4)/vmd(8): switch to anonymous shared mappings.

While splitting out emulated virtio network and block devices into
separate processes, I originally used named mappings via shm_mkstemp(3).
While this functionally achieved the desired result, it had two
unintended consequences:

1) tearing down a vm process and its child processes required
excessive locking as the guest memory was tied into the VFS layer.

2) it was observed by mlarkin@ that actions in other parts of the
VFS layer could cause some of the guest memory to flush to storage,
possibly filling /tmp.

This commit adds a new vmm(4) ioctl dedicated to allowing a process
request the kernel share a mapping of guest memory into its own vm
space. This requires an open fd to /dev/vmm (requiring root) and
both the "vmm" and "proc" pledge(2) promises. In addition, the caller
must know enough about the original memory ranges to reconstruct them
to make the vm's ranges.

Tested with help from Mischa Peters.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-05-12 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/05/12 10:18:17

Modified files:
usr.sbin/vmd   : vmd.c 

Log message:
vmd(8): fix segfault on vm creation.

vm_instance was using the wrong vm instance for checking the
vm_kernel_path member. Switch to using the value from the parent
vm instance in the check for if a kernel is known.

Issue reported by kn@. OK mlarkin@, kn@.



CVS: cvs.openbsd.org: src

2023-05-12 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/05/12 08:42:30

Modified files:
usr.sbin/vmd   : vmd.c 

Log message:
vmd(8): fix console attach from vmctl(8).

Adding in the ability to override the boot kernel created an edge
case in the ipc message handling logic for the parent process (vmd)
when receiving a "start vm" request. Result was incorrectly responding
to the control process, and as a result the vmctl client, with a
bogus "start vm response" reply with an empty tty name.

This commit rewrites the logic of how vmd goes about processing the
"start vm" request with the aim of making it simpler to understand
while addressing the edge case.

Issue reported by kn@. OK mlarkin@.



CVS: cvs.openbsd.org: src

2023-04-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/28 15:22:20

Modified files:
usr.sbin/vmd   : parse.y 

Log message:
vmd(8): fix specifying boot image in vm.conf

Previous change to allow overriding changed the way we parsed and
stored the boot image path. The lifetime of the path was...much too
short. Heap allocate the kernel path.

Found by Mischa Peters.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/28 14:13:56

Modified files:
usr.sbin/vmctl : vmctl.8 

Log message:
Clarify -b usage by `vmctl start`.



CVS: cvs.openbsd.org: src

2023-04-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/28 13:46:42

Modified files:
usr.sbin/vmctl : main.c vmctl.c 
usr.sbin/vmd   : config.c control.c parse.y vm.c vmd.c vmd.h 

Log message:
vmd(8)/vmctl(8): allow vm owners to override boot kernel.

vmd allows non-root users to "own" a vm defined in vm.conf(5). While
the user can start/stop the vm, if they break their filesystem they
have no means of booting recovery media like a ramdisk kernel.

This change opens the provided boot kernel via vmctl and passes the
file descriptor through the control channel to vmd. The next boot
of the vm will use the provided file descriptor as boot kernel/bios.
Subsequent boots (e.g. a reboot) will return to using behavior
defined in vm.conf or the default bios image.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/28 12:52:22

Modified files:
usr.sbin/vmd   : vioblk.c vionet.c vioqcow2.c 

Log message:
Remove unneeded header includes in vmd.

No functional change. virtio block/networking emulation do not need
to know about vmm or any kernel types.



CVS: cvs.openbsd.org: src

2023-04-27 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/27 16:47:27

Modified files:
usr.sbin/vmd   : Makefile dhcp.c vioqcow2.c vioraw.c virtio.c 
 virtio.h vm.c vmd.c vmd.h vmm.c 
Added files:
usr.sbin/vmd   : vioblk.c vionet.c 

Log message:
vmd(8): introduce multi-process model for virtio devices.

Isolate virtio network and block device emulation in dedicated
processes, forked and exec'd from the vm process. This allows for
tightening pledge promises to just "stdio".

Communication between the vcpu's and these devices now occurs via
imsg channels, which adds the benefit of not always blocking the
vcpu thread while emulating the device.

With this commit, it's possible that vmd is the first open source
hypervisor that *defaults* to a multi-process device emulation
model without requiring any additional configuration from the
operator.

Testing help from phessler@ and Mischa Peters.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-26 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/26 04:14:21

Modified files:
regress/usr.sbin/vmd/config: Makefile 
Removed files:
regress/usr.sbin/vmd/config: vmd-fail-boot-name-too-long.conf 
 vmd-fail-boot-name-too-long.ok 
 vmd-fail-cdrom-name-too-long.conf 
 vmd-fail-cdrom-name-too-long.ok 
 vmd-fail-disk-path-too-long.conf 
 vmd-fail-disk-path-too-long.ok 
 vmd-fail-vm-name-too-long.conf 
 vmd-fail-vm-name-too-long.ok 

Log message:
regress: remove vmd path length tests.

These add no value and we'd now that we don't artificially limit
path lengths just be updating them to check PATH_MAX.



Re: CVS: cvs.openbsd.org: src

2023-04-26 Thread Dave Voutila


Jonathan Gray  writes:

> On Wed, Apr 26, 2023 at 07:39:38AM +0200, Anton Lindqvist wrote:
>> On Mon, Apr 24, 2023 at 10:53:57AM -0600, Dave Voutila wrote:
>> > CVSROOT:   /cvs
>> > Module name:   src
>> > Changes by:d...@cvs.openbsd.org2023/04/24 10:53:57
>> >
>> > Modified files:
>> >sys/arch/amd64/amd64: vmm.c
>> >
>> > Log message:
>> > vmm(4): allow guests to enable and use supervisor IBT.
>> >
>> > Why should hosts have all the fun? Conditionally unmask the cpuid
>> > bits for IBT and allow r/w access to the supervisor CET msr.
>> >
>> > Will need revisiting when we introduce usage of userland CET msr.
>> >
>> > ok marlkin@
>>
>> Running on older hardware where CET is not enumerated causes guests to
>> panic in cpu_fix_msrs() during RDMSR 0x6a2.
>
> vcpu_reset_regs_vmx() also has:
>
> if (rcr4() | CR4_CET)
>   vmx_setmsrbrw(vcpu, MSR_S_CET);
>

Thanks!



CVS: cvs.openbsd.org: src

2023-04-26 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/26 03:39:56

Modified files:
sys/arch/amd64/amd64: vmm.c 

Log message:
Unbreak vmm on Intel. Mistakenly enabled CET on non-CET systems.

Found by anton@ & jsg@



CVS: cvs.openbsd.org: src

2023-04-25 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/25 06:51:07

Modified files:
usr.sbin/vmctl : main.c vmctl.c 

Log message:
vmctl(8): no longer needs vmmvar.h

Finally! We can remove kernel headers from vmctl.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-25 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/25 06:46:13

Modified files:
sys/arch/amd64/include: vmmvar.h 
usr.sbin/vmd   : config.c loadfile.h loadfile_elf.c parse.y 
 virtio.c virtio.h vm.c vmd.c vmd.h vmm.c 
usr.sbin/vmctl : vmctl.c 

Log message:
vmm(4)/vmd(8): pull struct members out of vmm ioctl create struct.

The object sent to vmm(4) contained file paths and details the
kernel does not need for cpu virtualization as device emulation is
in userland. Effectively, "pull up" the struct members from the
vm_create_params struct to the parent vmop_create_params struct.

This allows us to clean up some of vmd(8) and simplify things for
switching to having vmctl(8) open the "kernel" file (SeaBIOS, bsd.rd,
etc.) to allow users to boot recovery ramdisk kernels.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-24 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/24 10:53:57

Modified files:
sys/arch/amd64/amd64: vmm.c 

Log message:
vmm(4): allow guests to enable and use supervisor IBT.

Why should hosts have all the fun? Conditionally unmask the cpuid
bits for IBT and allow r/w access to the supervisor CET msr.

Will need revisiting when we introduce usage of userland CET msr.

ok marlkin@



CVS: cvs.openbsd.org: src

2023-04-24 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/24 03:04:03

Modified files:
sys/arch/amd64/amd64: acpi_machdep.c cpu.c hibernate_machdep.c 

Log message:
Toggle IBT off during amd64 hibernate before dropping to real mode.

Hibernate on IBT-capable MP systems broke when trying to quiesce
cpus. Instead of finding the locations of endbr64 in the asm indirect
jumps in acpi_wakecode.S, simply disable CR4.CET beforehand and
re-enable on resume.

This will also disable shadowstack, but there are no plans to use it.

"this approach is fine" deraadt@



CVS: cvs.openbsd.org: src

2023-04-23 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/23 06:11:37

Modified files:
usr.sbin/vmd   : vm.c vmd.c vmd.h vmm.c 

Log message:
vmd(8): teach vmm process how to exec.

Use execvp(2) to launch vm children with new address spaces.
Consequently, introduces use of unveil(2) into the vmm and vm
processes.

This imposes the requirement of launching vmd with absolute paths,
similar to sshd(8).

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-22 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/22 13:47:35

Modified files:
usr.sbin/vmd   : virtio.c 

Log message:
vmd(8): fix vm send/receive due to invalid hva's.

Moving some of the virtio devices to zero-copy approaches required
tracking the host-side virtual address for the gpa of virtqueues.
Upon a send/receive they are invalid as the restoring system will
most likely use a different address space layout.

Recompute the hva's on receive and NULL them on send.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-16 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/16 06:52:54

Modified files:
usr.sbin/vmd   : vioraw.c 

Log message:
vmd(8): correct comment in vioraw, cleanup formatting.

Comment incorrectly mentioned returning sectors when this function
returns bytes; the logic in virtio.c computes the number of 512
byte sectors after calling virtio_raw_init.

While here, adjust the formatting of return's to match the rest of vmd.

No functional change.



CVS: cvs.openbsd.org: src

2023-04-16 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/16 06:47:26

Modified files:
usr.sbin/vmd   : vmd.c vmd.h vmm.c 

Log message:
vmd(8): clean up fd closing in vmm process.

Some mild tidying of fd closing in the vmm process in prep for
landing parts of my fork+exec diff.

With input from guenther@ on the nuances of if/when EINTR may happen
in a call to close(2).

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-15 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/15 19:50:12

Modified files:
sys/arch/amd64/amd64: vmm.c 

Log message:
vmm(4): save and restore Intel CET state on vm entry/exit.



CVS: cvs.openbsd.org: src

2023-04-14 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/14 17:56:57

Modified files:
sys/arch/amd64/amd64: vmm_support.S 

Log message:
vmm: NENTRY -> ENTRY

Originally used NENTRY macros in the asm, but the plan is for endbr64
to appear in the ENTRY macros.

cluestick from deraadt@



CVS: cvs.openbsd.org: src

2023-04-14 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/14 14:27:47

Modified files:
sys/arch/amd64/amd64: vmm_support.S 

Log message:
vmm(4): add NENTRY/END macros around asm functions.

Part of prep for endbr64 on amd64 hosts.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-04-14 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/14 12:27:31

Modified files:
sys/arch/amd64/include: specialreg.h 

Log message:
add VMX/VMCS defines for amd64 endbr64 features

"these are fine," mlarkin@



CVS: cvs.openbsd.org: www

2023-04-05 Thread Dave Voutila
CVSROOT:/cvs
Module name:www
Changes by: d...@cvs.openbsd.org2023/04/05 08:03:42

Modified files:
papers : asiabsdcon2023-hardening_vmd_devices-slides.pdf 

Log message:
Replace my slides with compressed version. 32MB was ridiculous.



CVS: cvs.openbsd.org: www

2023-04-02 Thread Dave Voutila
CVSROOT:/cvs
Module name:www
Changes by: d...@cvs.openbsd.org2023/04/02 01:38:41

Modified files:
.  : events.html 
Added files:
papers : asiabsdcon2023-hardening_vmd_devices-slides.pdf 
 asiabsdcon2023-hardening_vmd_devices.pdf 

Log message:
Add my AsiaBSDCon2023 talk on hardening vmd(8) devices.



CVS: cvs.openbsd.org: src

2023-04-01 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/04/01 20:04:10

Modified files:
usr.sbin/vmd   : config.c vmd.c vmd.h 

Log message:
vmd(8): migrate vmd_vm.vm_ttyname to char array.

Other structs use a fixed length array already. This allows a vmd_vm
object to be transmitted over an ipc channel, too.

Additionally, solves a segfault caused by a strlcpy(3) in an error
path.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-03-13 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/03/13 12:09:41

Modified files:
usr.sbin/vmd   : ns8250.c 

Log message:
vmd(8): backout ns8250 changes.

This backs out commit h1IJwTVsYWfnRKWy which intended to fix interrupt
issues on slower host hardware. Unfortunately, this causes a race
condition on much faster host hardware. It still requires investigation.

With an "I told you so" about touching ns8250 from mlarkin@



CVS: cvs.openbsd.org: src

2023-02-18 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/02/18 07:32:02

Modified files:
sys/dev/acpi   : acpipwrres.c 

Log message:
acpipwrres(4): remove unused aml_value's.

ok kettenis@



CVS: cvs.openbsd.org: src

2023-02-06 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/02/06 13:33:34

Modified files:
usr.sbin/vmd   : fw_cfg.c pci.c pci.h vm.c 

Log message:
vmd(8): scan pci bus to determine bootorder strings.

vmd's SeaBIOS bootorder strings had hardcoded pci device ids, so
if a user added a network interface the bootorder strings didn't
line up with reality. Using vmctl(8) to boot from a cdrom (-B cdrom)
would fail, for instance, if attaching both a nic and a disk as
well.

This change scans the pci devices and finds the first of each type
to construct viable bootorder strings.

ok jan@



CVS: cvs.openbsd.org: src

2023-01-30 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/30 14:43:12

Modified files:
usr.sbin/vmd   : ns8250.c 

Log message:
vmd(8): fix an interrupt storm in ns8250.

On slower hosts, such as those in a nested virtualization scenario
of OpenBSD guest inside OpenBSD atop Linux KVM, ns8250 can cause a
race between the kevent firing and the vcpu being kicked by an
assert/deassert of the irq.

The end user experiences a "stuck" serial console and the host will
see a vmd process peg the cpu.

This change only toggles the irq if we were in a position of being
ready to receive data on the device so while the kevent might
continuously fire, the vcpu will not be kicked repeatedly.

OK mlarkin@



CVS: cvs.openbsd.org: src

2023-01-30 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/30 07:05:36

Modified files:
sys/arch/amd64/amd64: vmm.c 

Log message:
vmm(4): expose PKU cpuid bit if in use on host.

We are using {rd,wr}pkru instructions for saving and restoring the
PKRU, so tie the exposure of PKU feature bit to vmm having the
ability to properly handle the guest state.



CVS: cvs.openbsd.org: src

2023-01-29 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/29 19:32:01

Modified files:
sys/arch/amd64/amd64: vmm.c 
sys/arch/amd64/include: cpufunc.h vmmvar.h 

Log message:
vmm(4): save and restore guest pkru.

Take a simple approach for saving and restoring PKRU if the host
has PKE support enabled. Uses explicit rdpkru/wrpkru instructions
for now instead of xsave.

This functionality is still gated behind amd64 pmap checking for
operation under a hypervisor as well as vmm masking the cpuid bit
for PKU.

"if your diff is good, then commit it" -deraadt@



CVS: cvs.openbsd.org: src

2023-01-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/28 07:40:53

Modified files:
sys/arch/amd64/include: vmmvar.h 
usr.sbin/vmd   : config.c parse.y pci.c priv.c vm.c vmd.c vmd.h 
usr.sbin/vmctl : vmctl.c 

Log message:
Move some header definitions from vmm(4) to vmd(8).

Part of an ongoing effort to move userland-specific information out
of a kernel header and directly into vmd(8). No functional change.

ok mlarkin@



CVS: cvs.openbsd.org: src

2023-01-22 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/22 15:18:40

Modified files:
usr.sbin/vmd   : vmd.c 

Log message:
vmd(8): don't remove known vm's from the config on error.

Multiple error paths, specifically the one related to if a guest
cannot allocate memory at start, resulted in a known vm (via
vm.conf(5)) being removed from the vm list. Adjust the error paths
to check if the failing vm is defined in the config before tearing
it down.

Tested with help from beck@ and Mischa Peters.

ok beck@



CVS: cvs.openbsd.org: src

2023-01-19 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/19 08:52:51

Modified files:
sys/arch/amd64/include: vmmvar.h 

Log message:
Restrict vmm(4) exposed cpuid extended feature flags.

We don't emulate or support most of the EAX=7,ECX=0 feature bits,
so restrict the mask further to just UMIP.

ok deraadt@



CVS: cvs.openbsd.org: src

2023-01-14 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/14 13:55:55

Modified files:
usr.sbin/vmd   : vmd.c vmd.h vmm.c 

Log message:
Only open /dev/vmm once in vmd(8).

Have the parent process open /dev/vmm and send the fd to the vmm
child process. Only the vmm process and its resulting children
(guest vms) need it for ioctl calls.

ok kn@



CVS: cvs.openbsd.org: src

2023-01-13 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/13 07:15:49

Modified files:
sys/arch/amd64/amd64: vmm.c 

Log message:
Retake kernel lock in error paths of vmmioctl.

>From Christian Ludwig.



CVS: cvs.openbsd.org: src

2023-01-09 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/09 18:09:14

Modified files:
sys/arch/amd64/amd64: identcpu.c 
sys/arch/amd64/include: specialreg.h vmmvar.h 
sys/arch/i386/i386: machdep.c 
sys/arch/i386/include: specialreg.h 

Log message:
Hide WAITPKG cpu feature from vmm(4) guests.

Alder Lake and similar-era Intel platforms introduced new userland
wait instructions. Since vmm was passing this cpuid bit into guests,
some would attempt TPAUSE instructions and trigger invalid instruction
exceptions because VMX requires additional configuration to support
emulation.

This also adds WAITPKG to i386 and amd64 cpu feature identification.

Input from anton@, cheloha@, and guenther@. Tested by jmatthew@.

OK deraadt.



CVS: cvs.openbsd.org: src

2023-01-08 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/08 12:57:17

Modified files:
usr.sbin/vmd   : vm.c 

Log message:
vmd(8): add thread names to vm process.

ok guenther@.



CVS: cvs.openbsd.org: src

2023-01-03 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2023/01/03 19:19:19

Modified files:
usr.sbin/vmd   : vm.c 

Log message:
Typos in vmd error message. No functional change.



CVS: cvs.openbsd.org: src

2022-12-26 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2022/12/26 16:50:20

Modified files:
sys/arch/amd64/amd64: vmm.c 
sys/arch/amd64/include: vmmvar.h 
usr.sbin/vmd   : fw_cfg.c loadfile_elf.c vm.c 

Log message:
vmd(8): provide a detailed e820 memory map.

When booting guests with SeaBIOS, vmd(8) supplied details about the
available guest memory via CMOS registers. Consequently, we've been
carrying some patches in the ports tree to SeaBIOS to fetch this
information like it's the 1990s.

When a vm initializes memory ranges, we now track what each range
represents. This information can be used to supply the e820 memory
map to SeaBIOS via the fw_cfg interface allowing it to properly
communicate memory ranges to a guest operating system. (This will
also allow us to drop some patches from the port.)

Given the ranges can now be marked with a purpose, this also allows
vmm(4) to switch from hard-coded mmio ranges and instead let the
information on the memory range dictate if vmm should be handling
a page fault or sending to vmd for a memory assist.

Tested by Mischa Peters and others. OK mlarkin@.



CVS: cvs.openbsd.org: src

2022-12-23 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2022/12/23 12:25:22

Modified files:
usr.sbin/vmd   : vioscsi.c virtio.c virtio.h vm.c vmd.h 

Log message:
vmd(8): implement zero-copy operations on virtqueues.

The original virtio device implementation relied on allocating a
buffer on heap, copying the virtqueue from the guest, mutating the
copy, and then overwriting the virtqueue in the guest.

While the approach worked, it was both complex and added extra
overhead. On older hardware, switching to the zero-copy approach
can show a noticeable performance improvement for vionet devices.
An added benefit is this diff also reduces the amount of code in
vmd, which is always a welcome change.

In addition, change to talking about the queue pfn and not "address"
as the virtio-pci spec has drivers provide a 32-bit value representing
the physical page number of the location in guest memory, not the
linear address.

Original idea from dlg@ while working on re-adding async task queues.

ok dlg@, tested by many



CVS: cvs.openbsd.org: src

2022-12-19 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2022/12/19 13:27:26

Modified files:
usr.sbin/vmd   : ns8250.c 

Log message:
Silence vmd ns8250 log noise about reading com1 before ready.

ok marlkin@



CVS: cvs.openbsd.org: src

2022-12-15 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2022/12/15 09:01:40

Modified files:
usr.sbin/vmd   : priv.c vmd.c 

Log message:
Add explicit casts to ctype functions in vmd(8).

OK millert@



CVS: cvs.openbsd.org: src

2022-11-28 Thread Dave Voutila
CVSROOT:/cvs
Module name:src
Changes by: d...@cvs.openbsd.org2022/11/28 11:24:52

Modified files:
usr.sbin/vmd   : loadfile_elf.c 

Log message:
vmd(8): zero consdev in bootargs to fix booting ramdisks

Mischa Peters reported that booting a bsd.rd from 7.2 or newer
stopped working with vmd(8) in 7.2.

Direct booting kernels requires vmd to build boot args in guest
memory. Recently, the bios_consdev_t struct changed in amd64
machdep.c, adding additional struct members. vmd wasn't zeroing out
the struct, causing the booted kernel to read garbage.

While here, cleanup some of push_bootargs to use descriptive names
for boot args and standardize on explicit usage of uint32_t.

ok claudio, mlarkin



  1   2   3   >