1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-03 06:45:37 -08:00
Commit Graph

163 Commits

Author SHA1 Message Date
bluhm
e7a1ead9e6 Fix broken vmd(8) build on arm64 due to missing psp_setup().
The psp.c source is restricted in makefile with .if ${MACHINE} ==
"amd64" so use #ifdef __amd64__ around the call to psp_setup().  On
arm64 set vmd_psp_fd to an invalid value.

OK hshoexer@ mlarkin@
2024-11-06 14:26:20 +00:00
bluhm
5db0dbc53e vmd(8) resets psp(4)
Use shutdown and init to reset psp(4) on vmd(8) startup.  This helps
when hacking on vmd(8) and crashing it.  The psp(4) reset cleans
up all remnants of dead VMs from psp(4).  Otherwise one would have
to reboot the machine.

from hshoexer@; OK mlarkin@
2024-11-05 23:16:46 +00:00
jsg
65bbee46ca remove unneeded includes; ok dv@ mlarkin@ 2024-09-26 01:45:13 +00:00
bluhm
f4b47ae8c1 Implement AMD SEV support in vmd(8).
To launch a guest with AMD SEV enabled, vmd needs to do a few things:
- retrieve ASID used by guest on VM creation
- provide ASID to psp(4)
- let psp(4) encrypt memory used intially by guest
- run guest
- release resources held by psp(4) on guest shutdown
To enable SEV for a guest use the parameter "sev" in the guest's vm
section in vm.conf.

from hshoexer@; OK mlarkin@
2024-09-11 15:42:52 +00:00
dv
c4fd4c5b29 Split vmd into mi/md parts.
Makes as much of the core of vmd mi, pushing x86-isms into separate
compilation units. Adds build logic for arm64, but no emulation
yet. (You can build vmd, but it won't have a vmm device to connect
to.)

Some more cleanup probably needed around interrupt controller
abstraction, but that can come as we implement more than the i8259.

ok mlarkin@
2024-07-10 09:27:32 +00:00
dv
ba66f5646b vmd/vmm: move vm_run_params into mi header.
To prepare for mi/md splitting vmd, need to fixup the dev/vmm/vmm.h
mi header. Move the vm_run_params struct and clean up the includes
in vmd.

"sure", mlarkin@
2024-07-09 09:31:37 +00:00
jsg
9a15c14554 remove prototypes with no matching function 2024-05-18 06:45:00 +00:00
tobhe
dac1ed2549 Call daemon() only in parent and before proc_exec() to avoid orphaning child
processes. Synced from relayd.

ok mlarkin@ dv@
2024-04-08 12:48:26 +00:00
dv
b3bc6112e4 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.
2024-02-05 21:58:09 +00:00
dv
25a75e1b64 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@
2024-02-04 14:56:45 +00:00
claudio
53027660af Use imsg_get_fd() in vmd.
vmd uses a lot of fd passing and does it sometimes via extra abstraction
so this just tries to convert the code without any optimisations.

ok dv@
2024-01-18 14:49:59 +00:00
dv
08d0da61ad 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/<name>/<device><index> 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@
2023-09-26 01:53:54 +00:00
jasper
d4fb4f4dde when shutting down a vm, handle the VM id in the same way as a VM name argument
ok dv@
2023-07-03 08:32:20 +00:00
op
9cc9891368 relax absolute path requirement for configtest (-n)
ok dv@
2023-06-18 11:45:11 +00:00
dv
3c817da7c9 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@
2023-05-13 23:15:28 +00:00
dv
96788695d6 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@.
2023-05-12 16:18:17 +00:00
dv
4ff80aa38f 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@.
2023-05-12 14:42:30 +00:00
dv
b848b186fe 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@
2023-04-28 19:46:41 +00:00
dv
3481ecdf8a 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@
2023-04-27 22:47:27 +00:00
dv
73a98491f9 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@
2023-04-25 12:46:13 +00:00
kn
5d39640420 Missing the optional default config is not an error
/var/log/{messages,daemon} logs ENOENT as error on default configless vmd.
Only complain on explicitly passed files and print a debug hint under `-vv'
in case someone forgot to populate their /etc/vm.conf.

OK dv mlarkin
2023-04-24 15:12:14 +00:00
dv
24386e31c8 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@
2023-04-23 12:11:37 +00:00
jsg
6bae335dd0 remove duplicate includes 2023-04-19 12:58:15 +00:00
dv
3bbc9b4e3b 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@
2023-04-16 12:47:26 +00:00
dv
2264709366 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@
2023-04-02 02:04:10 +00:00
dv
d489aa7e71 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@
2023-01-28 14:40:53 +00:00
dv
10ccde237d 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@
2023-01-22 22:18:40 +00:00
dv
2748f5e225 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@
2023-01-14 20:55:55 +00:00
jmc
3a50f0a93a spelling fixes; from paul tagliamonte
any parts of his diff not taken are noted on tech
2022-12-28 21:30:15 +00:00
dv
70fdfbb3aa Add explicit casts to ctype functions in vmd(8).
OK millert@
2022-12-15 16:01:40 +00:00
dv
0fef3eb39e vmd(8): remove unfinished user accounting.
User accounting and enforcement was never finished. tedu the thing
until someone wants to pick it up and finish it.

Originally found by Matthew Martin.

ok mlarkin@, kn@. input from tb@.
2022-10-31 14:02:11 +00:00
martijn
f94ca20ec5 Add (partial) support for agentx in vmd.
Metrics can be found under mib-2.236 and VM-MIB (RFC7666).

Stress tested by and happy noises from Mischa Peters
OK dv@
2022-09-13 10:28:19 +00:00
dv
7933afb4f7 vmd: fix rebooting a received vm
Rebooting a received vm resulted in vmd(8) exiting as a result of
flawed state tracking in the parent process.

When stopping a vm, clear the VM_RECEIVE_STATE flag. When starting
a vm, make sure the parent process collapses any existing memory
ranges after the vm is sent to the vmm process (responsible for
launching the vm).

ok mlarkin@
2022-05-08 14:44:54 +00:00
dv
fbbcf6cd7f vmd(8): gracefully handle hitting data limits when starting a vm
With recent changes to login.conf(5) to restrict daemon datasize
to a finite value, users can now hit resource limits when attempting
to start a vm.

This change fixes the error path when hitting the limit. vmd(8)
will no longer abort and memory error messages are relayed to the
user.

While here, address potential under-reads/writes using atomicio
when relaying data between the child vm process and vmd's vmm
process.

Original diff from tedu@. OK mlarkin@.
2022-03-01 21:46:19 +00:00
claudio
98142e86aa Fix some simple -Wunused-but-set-variable warnings.
OK benno@ dv@
2022-01-04 15:18:44 +00:00
deraadt
e16a722a8a including sys/cdefs.h manually started as a result of netbsd trying to
macro-build a replacement for sccsid, and was done without any concern
for namespace damage.  Unfortunately this practice started infecting
other code as others were unaware they didn't need the file.
ok millert guenther
2021-12-13 18:28:39 +00:00
deraadt
24fb43d058 mostly avoid sys/param.h with a local nitems()
ok mlarkin
2021-11-29 05:17:35 +00:00
dv
2d54575624 vmd(8): remove invalid errno values from config_setvm
Refactor config_setvm to directly return error code on failure
instead of returning -1 and setting errno. It was setting unsupported
values not defined in <errno.h>.

OK mlarkin@
2021-07-18 11:55:45 +00:00
dv
15e0465666 Refactor vm_instance to return error value directly.
vmd(8)'s vm_instance function set unsupported errno values. Change the
api to directly return an error (either errno or custom vmd error).

"go for it" -mlarkin@
2021-05-05 21:33:11 +00:00
dv
0e786ea082 Init debug logging state before attempting to log.
Error messages related to bad configuration were not flushing to
stderr.

OK mlarkin@
2021-05-04 10:36:01 +00:00
dv
e73ceaac63 vmd(8): fix vmctl client "wait" state corruption
Adds queue-based tracking of waiting client state to fix the cause of
state corruption when a vmctl(8) user cancels a wait and restarts it.
The socket fd value for the control process client was being used to
track the waiting party, but this also prevented multiple waiting
clients.

This moves all the state tracking of who to notify of a vm's stopping
to the control process and no longer requires the parent process to
track it in the global environment state.

Future work will be needed to smooth out the difference between the
IMSG_VMDOP_TERMINATE_VM_{EVENT,RESPONSE} events instead of needing to
translate before relaying to the vmctl(8) client.

Tested by Mischa Peters (thanks!)

ok mlarkin@
2021-04-26 22:58:27 +00:00
dv
16e779b998 Send correct response type on unpause errors.
ok pd@
2021-04-05 11:35:26 +00:00
dv
97f33f1d96 Propagate host-side tap(4) lladdr to guest vm process to allow unicast dhcp
and bootp renewals with vmd(8)'s built-in dhcp server. Previous behavior
ignored did not intercept these packets and instead transmitted them.

This should make vmd(8)'s dhcp behave more as a true dhcp server should and
allows it to work properly with the new dhcpleased(8) attempting a renewal.

OK mlarkin@
2021-03-29 23:37:01 +00:00
deraadt
488a4384c6 these programs (with common ancestry) had a -fno-common problem related
to privsep_procid.
ok mortimer
2021-01-27 07:21:52 +00:00
martijn
11f064074a Revert agentx support for now, we're too close to release.
requested by deraadt@
2020-09-23 19:18:18 +00:00
martijn
9110f00595 Add support for agentx to vmd.
This is based around VM-MIB from RFC7666,but  does not export the full
spec. People more knowledgeable of vmd are encouraged to expand on this.
2020-09-23 15:52:06 +00:00
pd
de12a37756 vmd: start vms defined in vm.conf in a staggered fashion
This addresses 'thundering herd' problem when a lot of
vms are configured in vm.conf.  A lot of vms booting in parallel can
overload the host and also mess up tsc calibration in openbsd guests as
it uses PIT which doesn't fire reliably if the host is overloaded.

We default to starting vms with parallelism of ncpuonline and a delay 30 seconds
between batches.  This is configurable in vm.conf.

ok mlarkin@ (also addressed comments from cheloha@)
2019-12-12 03:53:38 +00:00
mlarkin
670ad819ff vmd(8): memory leak in an error path
Found by Hiltjo Posthuma, thanks!
2019-09-04 07:02:03 +00:00
anton
baf88fe322 Improve the error message when supplying an invalid template to vmctl
start. Favoring 'invalid template' over 'permission denied' should give
the user a better hint on what went wrong.

ok kn@ mlarkin@
2019-08-14 07:34:49 +00:00
deraadt
df69c215c7 When system calls indicate an error they return -1, not some arbitrary
value < 0.  errno is only updated in this case.  Change all (most?)
callers of syscalls to follow this better, and let's see if this strictness
helps us in the future.
2019-06-28 13:32:41 +00:00