summaryrefslogtreecommitdiffstats
path: root/usr.sbin/vmd/vm.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* vmd(8): correctly terminate vm processes after sending vmpd2020-04-301-1/+5
| | | | | | | | | | | | | | | | | | | Instead of a round about way of sending a message to vmm that 'send is successful' and terminating by vm_remove from vmm, we can send the imsg and exit in the vm process. The sigchld handler in vmm will vm_remove it from its structures. This is how a normal vm is terminated as well. Previously, vm_remove was called in vmm_dispatch_vm (ie. the event handler to receive messages from vm process) when hanlding the IMSG_VMDOP_SEND_VM_RESPONSE (ie. the vm process has written the vm state to the fd passed on by vmctl send). This is not how vm_remove was intented to be used as it does a free(vm). The vm struct holds the buffers for imsg and so after handling this IMSG_VMDOP_SEND_VM_RESPONSE message, vmm_dispatch_vm loops again to do imsg_get(ibuf, &imsg) to read the next message (and we had just freed this *ibuf when we freed the vm struct) causing it to segfault. reported by kn@ ok kn@
* vmd: improve concurrency control in pausepd2020-04-211-38/+25
| | | | | | | | Previous implementation hit a deadlock sometimes as the pthread_cond_broadcast for the pause mutex could happen before pthread_cond_wait. This implementation uses a barrier which is hit when all vpcus are paused. ok mpi@
* vmm(4): add IOCTL handler to sets the access protections of the eptpd2020-04-081-2/+40
| | | | | | | | | | | | This exposes VMM_IOC_MPROTECT_EPT which can be used by vmd to lock in physical pages. Currently, vmd just terminates the vm in case it gets a protection fault in the future. This feature is used by solo5 which uses vmm(4) as a backend hypervisor. ok mpi@ Patch from Adam Steen <adam@adamsteen.com.au>
* vmd: proper concurrency control when pausing a vmpd2019-12-111-31/+117
| | | | | | | | | | | | | | | Removes an XXX which slept for 1s waiting for the vcpu thread to reach HLT and pause. We now define a paused and unpaused condition so that a call to pause_vm() / vmctl pause blocks till the vm really reaches a paused state. Also, detach events for devices from event loop when pausing and add them back when unpausing. This is because some callbacks call pthread_mutex_lock and if the vm is paused, it would block also causing the libevent thread to block. This would mean that we would not be able to process any IMSGs received from vmm (parent process) including a message to unpause. ok mlarkin@
* Revert previous - the stability was not as improved as we had thought andmlarkin2019-11-301-5/+3
| | | | | | we ended up accidentally breaking vmctl. This will need more thought. ok ori@
* Fix at least one cause of VMs spinning at 100% host CPUmlarkin2019-11-291-3/+5
| | | | | | | | | | | | | | | After debugging with ori@, it looks like an event ends up on the wrong libevent queue, and we end continually de-queueing and re-queueing the event continually. While it's unclear exactly why this happened, a clue on libevent's github issues page for the same problem pointed us to using a different event base for the device events. This seems to have unstuck ori@'s problematic VM, and I have also seen no more hangs after this. We have not completely separated the queues; ori@ will work on setting new libevent bases for those later. But those events are pretty frequency. with help from and ok ori@
* vmm/vmd: Fix migration with pvclockpd2019-07-171-1/+43
| | | | | | | Implement VMM_IOC_READVMPARAMS and VMM_IOC_WRITEVMPARAMS ioctls to read and write pvclock state. reads ok mlarkin@
* When system calls indicate an error they return -1, not some arbitraryderaadt2019-06-281-7/+7
| | | | | | 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.
* vmd: unset CR0_CD and CR0_NW in default flat64 register valuespd2019-05-281-2/+2
| | | | | | | These never got unset on AMD/SVM guests when booted via vmctl start -b causing them to run very slow ok mlarkin@
* vmm: add a x86 page table walkerpd2019-05-121-1/+137
| | | | | | | | | | Add a first cut of x86 page table walker to vmd(8) and vmm(4). This function is not used right now but is a building block for future features like HPET, OUTSB and INSB emulation, nested virtualisation support, etc. With help from Mike Larkin ok mlarkin@
* vm_dump_header allocated space for a signature but it was never set;jasper2019-05-111-1/+4
| | | | | | set it to VMM_HV_SIGNATURE and check for it upon restoring a vm image ok mlarkin@ pd@
* track the state of the vm (running, paused, etc) using a single bitfield instead ofjasper2019-05-111-11/+11
| | | | | | | | | a handful of separate variables. this will makes it easier for vmd to report and check on the individual vm states no functional change intended ok ccardenas@ mlarkin@
* vmd(8): remove some i386 remnants that missed the original cleanupmlarkin2019-03-011-17/+1
| | | | ok pd, kn, deraadt
* vmd(8): initialize guest %drX registers to power-on defaults on launchmlarkin2019-02-201-1/+13
| | | | | | | Initializes the %drX registers to power on defaults, and bump the VM send/recieve header to reflect same discussed with deraadt@
* Implement the fw_cfg interface basics and use it to set the bootorderclaudio2018-12-101-5/+25
| | | | | | | | | if a bootdevice was forced. This implements both the pure IO port interface and also the new DMA interface, a few direct commands are implemented which are needed but in general the "file" interface should be used. There is no write support for the guest. Tested against the latest vmm-firmware port. This requires also a -current kernel to pass the IO ports to vmd(8). OK mlarkin@ ccardenas@
* Make it possible to define the bootdevice in vmd. This information is usedclaudio2018-12-061-2/+2
| | | | | | | | currently only when booting a OpenBSD kernel. If VMBOOTDEV_NET is used the internal dhcp server will pass "auto_install" as boot file to the client and the boot loader passes the MAC of the first interface to the kernel to indicate PXE booting. Adding boot order support to SeaBIOS is not yet implemented. Ok ccardenas@
* Add support for qcow2 base images (external snapshots).reyk2018-10-081-10/+14
| | | | | | | | | | | | | | | | | | | | | This works is from Ori Bernstein, committing on his behalf: Add support to vmd for external snapshots. That is, snapshots that are derived from a base image. Data lookups start in the derived image, and if the derived image does not contain some data, the search proceeds ot the base image. Multiple derived images may exist off of a single base image. A limitation of this format is that modifying the base image will corrupt the derived image. This change also adds support for creating disk derived disk images to vmctl. To use it: vmctl create derived.qcow2 -s 16G -b base.qcow2 From Ori Bernstein OK mlarkin@ reyk@
* Support vmd-internal's vmboot with qcow2 disk images.reyk2018-09-281-3/+4
| | | | OK mlarkin@
* Various clean up items for disks.ccardenas2018-09-191-1/+4
| | | | | | | | | | | - qcow2: general cleanup - vioraw: check malloc - virtio: add function to sync disks - vm: call virtio_shutdown to sync disks when vm is finished executing Thanks to Ori Bernstein. Ok miko@
* vmd(8): fix vmctl -b option for i386 kernels.mlarkin2018-07-171-6/+6
| | | | ok pd@
* vmm(8)/vmm(4): send a copy of the guest register state to vmd on exit,mlarkin2018-07-121-6/+6
| | | | | | | avoiding multiple readregs ioctls back to vmm in case register content is needed subsequently. ok phessler
* vmd(8): route ELCR handler to the right functionmlarkin2018-07-101-3/+3
|
* vmd(8): better debug message in a failure casemlarkin2018-07-091-2/+3
|
* knfreyk2018-06-191-8/+11
|
* vmd(8): implement vmd side of ELCR registersmlarkin2018-04-271-1/+3
| | | | ok guenther
* vmd(8): handle PIT channel 2 status readback via port 0x61mlarkin2018-04-261-1/+2
| | | | | | | Allow PIT channel 2 status (fired/counting) readback via port 0x61 bit 5. ok guenther@
* Add initial CD-ROM support to VMD via vioscsi.ccardenas2018-01-031-14/+19
| | | | | | | | | | | | | * Adds 'cdrom' keyword to vm.conf(5) and '-r' to vmctl(8) * Support various sized ISOs (Limitation of 4G ISOs on Linux guests) * Known working guests: OpenBSD (primary), Alpine Linux (primary), CentOS 6 (secondary), Ubuntu 17.10 (secondary). NOTE: Secondary indicates some issue(s) preventing full/reliable functionality outside the scope of the vioscsi work. * If the attached disks are non-bootable (i.e. empty), SeaBIOS (vmd's default BIOS) will boot from CD-ROM. ok mlarkin@, jca@
* make vmm(4) less responsible for initial register state, preferring to letmlarkin2017-11-291-2/+8
| | | | | | usermode daemons handle that. ok pd@
* fix some spelling errors in a few commentsmlarkin2017-11-281-4/+4
|
* Clarify a wrong conditional, found by jsg.mlarkin2017-09-191-7/+11
| | | | ok jsg
* vmd: send/recv pci config space instead of recreating pci devices on receivepd2017-09-171-2/+4
| | | | ok mlarkin@
* vmd: re add rtc.per and rtc.sec evtimers on receivepd2017-09-171-1/+2
| | | | | | | This was missed in receive. mc146818_start is already defined. This fixes rtc time resync on receive. ok mlarkin@
* add functions to provide direct access to guest memory as vmd addressesdlg2017-09-111-1/+61
| | | | | | | | | | | | | | | iovec_mem() populates an iovec array based on guest physical addresses. this allows the use of things like readv and writev for moving data between the guest and a disk image file without having to bounce the memory. vaddr_mem() provides a vmd usable pointer based on a guests physical address. this makes it possible to directly reference things like virtio rings without having to bounce that memory either. however, it assumes that a contiguous range of guest physical memory will sit in a single vm memory range. mlarkin@ says this is right. ok mlarkin@
* vmd: Allow only upward migrationpd2017-08-201-7/+41
| | | | | | | | | | This restricts receiving vms from hosts with more cpu features. Tested on broadwell -> skylake (works) skylake -> broadwell (don't work) ok mlarkin@
* vmd: set MSR_MISC_ENABLE=0 on vm creation, this will be re-set in vmmmlarkin2017-08-141-1/+2
| | | | based on proper values from the host in use.
* Add vmctl send and vmctl receivepd2017-07-151-25/+268
| | | | ok reyk@ and mlarkin@
* vmd/vmctl: Add ability to pause / unpause vmspd2017-07-091-10/+79
| | | | | | With help from Ashwin Agrawal ok reyk@ mlarkin@
* vmd: Implement simulated baudrate support in the ns8250 module. Themlarkin2017-06-071-1/+22
| | | | | | | | | | | | | | | | | previous version was allowing an output rate that is "too fast", and linux guests would give up after 512 characters TXed ("too much work for irq4"). This diff calculates the approximate rate we can sustain at the current programmed baud rate and limits the output to that rate by inserting a HZ delay after a specified number of characters have been transmitted. This fixes the linux guest console issue. Note that the console now outputs at more or less the selected baud rate, instead of nearly instantaneously as before - if you selected 9600 in your guest VMs before, you might want to change that to 115200 now for a better console experience. krw@ "seems like a good idea to me"
* split vioblk read/write functions into start and finish as prep fortedu2017-05-301-3/+4
| | | | async io operations. ok mlarkin
* SVM: add some exit typesmlarkin2017-05-281-3/+7
| | | | | Also, fix a comment that wasn't applicable anymore, and change a format from decimal to hex
* VMs cannot use proc_compose() to PROC_VMM, they have to usereyk2017-05-051-8/+6
| | | | | imsg_compose() on the "vmm_pipe" directly. This fixes the communication channel from VMs back to vmm.
* Allow vmd(8) to set guest %xcr0mlarkin2017-05-051-3/+5
| | | | | | Usermode part of previous vmm(4) diff. Posted to tech by Pratik Vyas
* fix an error in i386 vmd buildmlarkin2017-05-021-2/+6
|
* Matching vmd(8) part of previous diff (first part of vmctl send/receive).mlarkin2017-05-021-1/+13
| | | | ok kettenis
* spacingreyk2017-04-251-19/+19
|
* Add support for dynamic "NAT" interfaces (-L/local interface).reyk2017-04-191-2/+2
| | | | | | | | | | | | | When a local interface is configured, vmd configures a /31 address on the tap(4) interface of the host and provides another IP in the same subnet via DHCP (BOOTP) to the VM. vmd runs an internal BOOTP server that replies with IP, gateway, and DNS addresses to the VM. The built-in server only ever responds to the VM on the inside and cannot leak its DHCP responses to the outside. Thanks to Uwe Werler, Josh Grosse, and some others for testing! OK deraadt@
* die whitespace die die diederaadt2017-03-271-2/+2
|
* Last bits needed to get seabios + alpine linux working. This is enoughmlarkin2017-03-251-8/+18
| | | | | | to get started and let more people help finding and fixing bugs. ok kettenis, deraadt
* Boot using BIOS from /etc/firmware/vmm-bios by default.reyk2017-03-251-10/+87
| | | | | | | | | | | | | | | | Instead of using the internal "vmboot", VMs will now be booted using the external BIOS firmware in /etc/firmware/vmm-bios (which is subject to a LGPLv3 license). Direct booting of OpenBSD kernels or non-default BIOS images is still supported for now using the -b/boot option that is replacing the -k/kernel option. As requested by Theo, vmd(8) fails if neither the default BIOS is found nor a kernel has been specified in the VM configuration. The "vmm" BIOS has to be installed using fw_update(1), which will be done automatically in most cases where the OpenBSD can fetch it after install/upgrade. OK mlarkin@
* Implement some missing functionality and clean up some code in vmdmlarkin2017-03-251-2/+8
| | | | | | pci emulation. ok kettenis