summaryrefslogtreecommitdiff
path: root/usr.sbin/vmd
AgeCommit message (Collapse)Author
2024-10-22Use imsg_get_fd() like everywhere else.Claudio Jeker
OK florian@ dv@
2024-10-07drop redundant AF attach ioctlKlemens Nanni
SIOCAIFADDR_IN6 to configure an IPv6 address does everything SIOCIFAFATTACH does, i.e. it enables IPv6 on the interface if not done so already. vm.conf(5) 'local inet6' works as before. OK mlarkin
2024-10-02Move some PCI MMIO defines from vmm(4) kernel headers to userland.Dave Voutila
vmm(4) doesn't need this information anymore. vmd(8) is the only consumer of this information. ok mlarkin@
2024-09-26remove unneeded includes; ok dv@ mlarkin@Jonathan Gray
2024-09-25document why sys/param.h is usedTheo de Raadt
2024-09-24- VM(s) -> VMsJason McIntyre
- simpler tense - fix the -width parameter - add -nosplit to AUTHORS
2024-09-24vmd(8) manpage change for shutdown behaviourMike Larkin
Document the shutdown behaviour for vmd(8). Suggested via bugs@ via eric at mulh.net. ok jmc@, bluhm@
2024-09-21vmm.h is a needed include nowMike Larkin
2024-09-20remove unneeded semicolons; checked by millert@Jonathan Gray
2024-09-16Mention psp(4) in vm.conf(5) man page.Alexander Bluhm
from hshoexer@; OK mlarkin@
2024-09-11Implement AMD SEV support in vmd(8).Alexander Bluhm
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-07-13mmio.c is now empty and can be removedMike Larkin
mmio.c was moved to x86_mmio.c with dv@'s recent refactoring. The resulting empty file can be removed now.
2024-07-13Add missing RCS header to vmd(8)'s vmm.h.Dave Voutila
Apparently it never had one. It's rarely touched, so went unnoticed.
2024-07-12vmd(8): Fix error handling in tx path.Jan Klemkow
ok dv@
2024-07-12Quiet vmd debug logging about page faults.Dave Voutila
When we get bumped to userland and the fault is already handled, don't log anything. It's way too chatty and helps nobody trying to debug things.
2024-07-10Missed some files in previous commit to split vmd into mi/md.Dave Voutila
Forgot `cvs add` and sys/dev/vmm/vmm.h changes.
2024-07-10Split vmd into mi/md parts.Dave Voutila
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-09vmd(8): Avoid double DHCP reply when using the internal dhcp server.Jan Klemkow
DHCP request should no leave vmd if its answered internally. ok dv@
2024-07-09vmd/vmm: move vm_run_params into mi header.Dave Voutila
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-08Quiet vmd in debug logging mode. We don't need to hear about handledDave Voutila
page faults. sure, @mlarkin.
2024-06-20vmd(8): protect global vm and vcpu state with mutex.Dave Voutila
The vm process uses multiple pthreads to emulate vcpu and also drive an event loop doing various io emulation. At points, one or the other needs to read/write global vm state bits and toggle if a vcpu is halted or "done." This adds in a another mutex to protected the global state and untangles areas where the mutex for protecting a condition variable was being used around modifying some global state. ok mlarkin@
2024-05-18remove prototypes with no matching functionJonathan Gray
2024-04-29vmm & vmd: drop "continue" flag to simplify running a vcpu.Dave Voutila
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@
2024-04-09vmm/vmd: add exception injection and refactor inject api.Dave Voutila
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@
2024-04-09Sync removal of setsid(), setpgid() and a few dup2() from relayd. They areTobias Heider
redundant since we call daemon() earlier. ok bluhm@
2024-04-08Call daemon() only in parent and before proc_exec() to avoid orphaning childTobias Heider
processes. Synced from relayd. ok mlarkin@ dv@
2024-02-22vmd(8): only add vionet tap read events after a notify event.Dave Voutila
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@
2024-02-20Utilize separate threads for RX and TX in vmd(8)'s vionet.Dave Voutila
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@.
2024-02-10Prevent use of uninitialized byte in vmd's mmio decoder.Dave Voutila
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@.
2024-02-10Fix locked address interfaces in vmd(8).Dave Voutila
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@
2024-02-10Set vmd virtio device fds to -1 on close after fork.Dave Voutila
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@
2024-02-09Only debug log dhcp packet info if packet is found.Dave Voutila
No functional change. vmd(8) was being chatty and incorrect.
2024-02-09Tuck vmd's i8253 reset debug logs behind DPRINTF.Dave Voutila
It's super chatty and pollutes verbose logging.
2024-02-05Cleanup fcntl(3) usage and fd lifetimes in vmd(8).Dave Voutila
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-04Remove dead code and fix null deref if vm is not found.Dave Voutila
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@.
2024-02-04Prevent null pointer deref is vm isn't found.Dave Voutila
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-04Initialize result in vioblk notification handler.Dave Voutila
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@
2024-02-04Reverse calloc args.Dave Voutila
Found by smatch "double check that we're allocating correct size" warning. Reported by and ok jsg@.
2024-02-03Add tap(4) read events after rx virtqueue notification.Dave Voutila
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@
2024-02-03fix vmd vioblk fd closing bounds testJonathan Gray
found by "buffer overflow 'vioblk->disk_fd' 4 <= 15" smatch error ok dv@
2024-02-02Explain missing group on getgrnam(3) failure.Dave Voutila
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@
2024-01-30Rewrite vmd(8)'s vionet to be zero-copy.Dave Voutila
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@
2024-01-18Use imsg_get_fd() in vmd.Claudio Jeker
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-10vmm/vmd: add io instruction length to exit information.Dave Voutila
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@
2024-01-03vmd(8): improve error messages when out of tap devices.Dave Voutila
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@
2024-01-03vmd(8): remove unused variable from vionet_notify_tx.Dave Voutila
num_enq was assigned and incremented, but never used. clang started pointing out via warnings. No functional change.
2023-11-03vmd(8): fix block size calculation for vioscsi devices.Dave Voutila
During the multi-process rework, I changed the way disk sizes are calculated, switching to storing bytes and not 512-byte blocks. The size calculation from reading an iso did not receive the change in scaling, resulting in the virtio scsi emulation to think iso's are larger than reality. This fixes booting the latest Ubuntu amd64 iso's as apparently there's some program that tries to arbitrarily read the tail end of the iso into memory. ok mlarkin@
2023-10-25vmd(8): stop toggling irq deassert for edge triggered devs.Dave Voutila
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@
2023-09-26vmd(8): disambiguate log messages per vm and device.Dave Voutila
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-26vmd(8): fix vm pause deadlock.Dave Voutila
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@