OpenBSD CVS

CVS log for src/usr.sbin/vmd/virtio.c


[BACK] Up to [local] / src / usr.sbin / vmd

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.113 / (download) - annotate - [select for diffs], Tue Feb 20 21:40:37 2024 UTC (3 months, 1 week ago) by dv
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, HEAD
Changes since 1.112: +5 -4 lines
Diff to previous 1.112 (colored)

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@.

Revision 1.112 / (download) - annotate - [select for diffs], Sat Feb 10 02:10:41 2024 UTC (3 months, 3 weeks ago) by dv
Branch: MAIN
Changes since 1.111: +15 -11 lines
Diff to previous 1.111 (colored)

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@

Revision 1.111 / (download) - annotate - [select for diffs], Mon Feb 5 21:58:09 2024 UTC (3 months, 3 weeks ago) by dv
Branch: MAIN
Changes since 1.110: +48 -35 lines
Diff to previous 1.110 (colored)

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.

Revision 1.110 / (download) - annotate - [select for diffs], Fri Nov 3 11:16:43 2023 UTC (6 months, 4 weeks ago) by dv
Branch: MAIN
Changes since 1.109: +2 -2 lines
Diff to previous 1.109 (colored)

vmd(8): fix block size calculation for vioscsi devices.

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@

Revision 1.109 / (download) - annotate - [select for diffs], Tue Sep 26 01:53:54 2023 UTC (8 months ago) by dv
Branch: MAIN
CVS Tags: OPENBSD_7_4_BASE, OPENBSD_7_4
Changes since 1.108: +31 -27 lines
Diff to previous 1.108 (colored)

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@

Revision 1.108 / (download) - annotate - [select for diffs], Sat Sep 23 12:31:41 2023 UTC (8 months, 1 week ago) by dv
Branch: MAIN
Changes since 1.107: +3 -3 lines
Diff to previous 1.107 (colored)

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

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

Revision 1.107 / (download) - annotate - [select for diffs], Thu Sep 14 15:25:43 2023 UTC (8 months, 2 weeks ago) by dv
Branch: MAIN
Changes since 1.106: +3 -3 lines
Diff to previous 1.106 (colored)

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@.

Revision 1.106 / (download) - annotate - [select for diffs], Thu Jul 27 09:27:43 2023 UTC (10 months ago) by dv
Branch: MAIN
Changes since 1.105: +10 -5 lines
Diff to previous 1.105 (colored)

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@

Revision 1.105 / (download) - annotate - [select for diffs], Sat Jul 15 18:32:21 2023 UTC (10 months, 2 weeks ago) by dv
Branch: MAIN
Changes since 1.104: +10 -34 lines
Diff to previous 1.104 (colored)

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@.

Revision 1.104 / (download) - annotate - [select for diffs], Thu Jul 13 18:31:59 2023 UTC (10 months, 2 weeks ago) by dv
Branch: MAIN
Changes since 1.103: +4 -2 lines
Diff to previous 1.103 (colored)

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@

Revision 1.103 / (download) - annotate - [select for diffs], Sat May 13 23:15:28 2023 UTC (12 months, 2 weeks ago) by dv
Branch: MAIN
Changes since 1.102: +10 -6 lines
Diff to previous 1.102 (colored)

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@

Revision 1.102 / (download) - annotate - [select for diffs], Thu Apr 27 22:47:27 2023 UTC (13 months ago) by dv
Branch: MAIN
Changes since 1.101: +867 -1454 lines
Diff to previous 1.101 (colored)

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@

Revision 1.101 / (download) - annotate - [select for diffs], Tue Apr 25 12:46:13 2023 UTC (13 months, 1 week ago) by dv
Branch: MAIN
Changes since 1.100: +38 -42 lines
Diff to previous 1.100 (colored)

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@

Revision 1.100 / (download) - annotate - [select for diffs], Sat Apr 22 19:47:35 2023 UTC (13 months, 1 week ago) by dv
Branch: MAIN
Changes since 1.99: +64 -1 lines
Diff to previous 1.99 (colored)

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@

Revision 1.99 / (download) - annotate - [select for diffs], Wed Dec 28 21:30:19 2022 UTC (17 months ago) by jmc
Branch: MAIN
CVS Tags: OPENBSD_7_3_BASE, OPENBSD_7_3
Changes since 1.98: +2 -2 lines
Diff to previous 1.98 (colored)

spelling fixes; from paul tagliamonte
any parts of his diff not taken are noted on tech

Revision 1.98 / (download) - annotate - [select for diffs], Fri Dec 23 19:25:22 2022 UTC (17 months, 1 week ago) by dv
Branch: MAIN
Changes since 1.97: +146 -209 lines
Diff to previous 1.97 (colored)

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

Revision 1.97 / (download) - annotate - [select for diffs], Sun Aug 29 18:01:32 2021 UTC (2 years, 9 months ago) by dv
Branch: MAIN
CVS Tags: OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0
Changes since 1.96: +11 -10 lines
Diff to previous 1.96 (colored)

Mask viornd descriptor value to prevent out of bound reads.

viornd did not mask the descriptor value in the avialable ring
allowing guest values to read past the end of the descriptor table.

While here, change fatal to fatalx because errno is not set.

Reported by Ilja van Sprundel

ok mlarkin@

Revision 1.96 / (download) - annotate - [select for diffs], Sun Aug 29 12:17:38 2021 UTC (2 years, 9 months ago) by dv
Branch: MAIN
Changes since 1.95: +3 -3 lines
Diff to previous 1.95 (colored)

mask next descriptor value and fix chunk_size calculation

Guest can cause out of bounds read with a malformed descriptor. In same
loop, also fix a chunk size calculation.

Reported by Ilja van Sprundel.

ok mlarkin@

Revision 1.95 / (download) - annotate - [select for diffs], Sun Aug 29 11:41:27 2021 UTC (2 years, 9 months ago) by dv
Branch: MAIN
Changes since 1.94: +6 -1 lines
Diff to previous 1.94 (colored)

check for null vioblk info

If {c,m}alloc fail, info could be NULL and result in NULL deref.

Reported by Ilja van Sprundel.

ok mlarkin@

Revision 1.94 / (download) - annotate - [select for diffs], Sun Aug 29 11:14:27 2021 UTC (2 years, 9 months ago) by dv
Branch: MAIN
Changes since 1.93: +2 -2 lines
Diff to previous 1.93 (colored)

correct device status write size

Reported by Ilja van Sprundel.

ok mlarkin@

Revision 1.93 / (download) - annotate - [select for diffs], Sun Aug 29 11:09:05 2021 UTC (2 years, 9 months ago) by dv
Branch: MAIN
Changes since 1.92: +1 -41 lines
Diff to previous 1.92 (colored)

remove old descriptor dump function

Used originally to aid dev. Unneeded.

ok mlarkin@

Revision 1.92 / (download) - annotate - [select for diffs], Fri Jul 16 16:21:22 2021 UTC (2 years, 10 months ago) by dv
Branch: MAIN
Changes since 1.91: +5 -56 lines
Diff to previous 1.91 (colored)

vmd(8): simplify vcpu logic, removing uart & vionet reads

Remove legacy state handling on the ns8250 and virtio network devices
originally put in place before using libevent for async device
events. The vcpu thread doesn't need to process device data as it is
handled by the libevent thread.

This has the benefit of simplifying some of the message passing
between threads introduced to the ns8250 uart since both the vcpu
and libevent threads were processing read events.

No functional change intended. Tested by many, including abieber@,
weerd@, Mischa Peters, and Matthias Schmidt. (Thanks.)

OK mlarkin@

Revision 1.91 / (download) - annotate - [select for diffs], Mon Jun 21 02:38:18 2021 UTC (2 years, 11 months ago) by dv
Branch: MAIN
Changes since 1.90: +89 -77 lines
Diff to previous 1.90 (colored)

vmd(8): support variable length vionet rx descriptor chains

The original implementation of the virtio network device assumed a
driver would only provide a 2-descriptor chain for receiving packets.
The virtio spec allows for variable length chains and drivers, in
practice, construct them when they use a sufficiently large MTU.

This change lets the device use variable length chains provided by
the driver, thus allowing for drivers to set an MTU up to the
underlying host-side tap(4)'s limit of TUNMRU (16384).

Size limitations are now enforced on both tx and rx-side dropping
anything violating the underlying tap(4) min and max limits.

More work is needed to increase the read(2) buffer in use by vmd
to prevent packet truncation.

OK mlarkin@

Revision 1.90 / (download) - annotate - [select for diffs], Thu Jun 17 22:03:33 2021 UTC (2 years, 11 months ago) by dv
Branch: MAIN
Changes since 1.89: +54 -2 lines
Diff to previous 1.89 (colored)

vmd(8): handle VIRTIO_BLK_T_GET_ID, check descriptor r/w flags

Linux guests like to issue VIRTIO_BLK_T_GET_ID commands in attempts
to read the device serial number. It's not part of the virtio spec,
but has been part of QEMU and Bhyve for multiple years. It will be
landing in the next version of virtio (1.2), so this stubs out
handling for the request type. The added benefit is it helps squelch
log noise from Linux guests.

For now, no serial number is set and the request status is set to
VIRTIO_BLK_S_UNSUPP to tell the driver we don't support it.

While here, swap the response to VIRTIO_BLK_T_FLUSH{,_OUT} to be
also returning VIRTIO_BLK_S_UNSUPP. It's not negotiated nor
implemented. Lastly, add checks for validating the vioblk device
is only reading/writing descriptors with approrpriate read/write-only
flags per the virtio spec.

With input from claudio@, OK mlarkin@

Revision 1.89 / (download) - annotate - [select for diffs], Wed Jun 16 16:55:02 2021 UTC (2 years, 11 months ago) by dv
Branch: MAIN
Changes since 1.88: +4 -5 lines
Diff to previous 1.88 (colored)

cleanup vmd(8) includes and header files

Lots of organic growth other the years lead to unnecessary includes
(proc.h everywhere) and odd dependencies between header files. This
cleans things up a bit to help with upcoming cleanup around dhcp
code.

No functional change.

"go for it" mlarkin@

Revision 1.88 / (download) - annotate - [select for diffs], Fri Jun 11 21:46:00 2021 UTC (2 years, 11 months ago) by dv
Branch: MAIN
Changes since 1.87: +19 -85 lines
Diff to previous 1.87 (colored)

vmd(8): deduplicate vioblk command logic

No need for each case in the switch block to have the same logic
for updating the used ring and writing the state back to the guest.
Move it outside the switch. No functional change.

ok mlarkin@

Revision 1.82.6.1 / (download) - annotate - [select for diffs], Tue May 18 14:40:47 2021 UTC (3 years ago) by bluhm
Branch: OPENBSD_6_8
Changes since 1.82: +100 -29 lines
Diff to previous 1.82 (colored) next main 1.83 (colored)

vmd(8): guest virtio drivers can cause stack & buffer overflows

A vmd guest can craft invalid virtio descriptor lengths resulting
in reading and writing beyond stack-allocated buffer lengths providing
an escape vector to the host.

Instead of allowing the guest to dictate read/write lengths, this
commit has vmd just use compile-time lengths based on the source
or destination object sizes. For instances where vmd's virtio
implementation can't use this method, such as reading packets from
the vionet device, cap each read with a pre-computed max chunk size.

Reported by Maxime Villard.

Tested with help from Mischa Peters, OK mlarkin@
from dv@

this is errata/6.8/020_vmd.patch.sig

Revision 1.84.2.2 / (download) - annotate - [select for diffs], Tue May 18 14:39:23 2021 UTC (3 years ago) by bluhm
Branch: OPENBSD_6_9
Changes since 1.84.2.1: +100 -32 lines
Diff to previous 1.84.2.1 (colored) to branchpoint 1.84 (colored) next main 1.85 (colored)

vmd(8): guest virtio drivers can cause stack & buffer overflows

A vmd guest can craft invalid virtio descriptor lengths resulting
in reading and writing beyond stack-allocated buffer lengths providing
an escape vector to the host.

Instead of allowing the guest to dictate read/write lengths, this
commit has vmd just use compile-time lengths based on the source
or destination object sizes. For instances where vmd's virtio
implementation can't use this method, such as reading packets from
the vionet device, cap each read with a pre-computed max chunk size.

Reported by Maxime Villard.

Tested with help from Mischa Peters, OK mlarkin@
from dv@

this is errata/6.9/003_vmd.patch.sig

Revision 1.87 / (download) - annotate - [select for diffs], Tue May 18 11:06:43 2021 UTC (3 years ago) by dv
Branch: MAIN
Changes since 1.86: +42 -20 lines
Diff to previous 1.86 (colored)

vmd(8): guest virtio drivers can cause stack & buffer overflows

A vmd guest can craft invalid virtio descriptor lengths resulting
in reading and writing beyond stack-allocated buffer lengths providing
an escape vector to the host.

Instead of allowing the guest to dictate read/write lengths, this
commit has vmd just use compile-time lengths based on the source
or destination object sizes. For instances where vmd's virtio
implementation can't use this method, such as reading packets from
the vionet device, cap each read with a pre-computed max chunk size.

Reported by Maxime Villard.

Tested with help from Mischa Peters, OK mlarkin@

Revision 1.84.2.1 / (download) - annotate - [select for diffs], Mon May 3 20:12:10 2021 UTC (3 years ago) by bluhm
Branch: OPENBSD_6_9
Changes since 1.84: +2 -2 lines
Diff to previous 1.84 (colored)

vmd guests can trigger excessive log messages on the host by sending
certain network packets.

this is errata/6.9/001_vmd.patch.sig

Revision 1.86 / (download) - annotate - [select for diffs], Thu Apr 22 18:40:21 2021 UTC (3 years, 1 month ago) by dv
Branch: MAIN
Changes since 1.85: +52 -11 lines
Diff to previous 1.85 (colored)

vmd(8): guard against bad virtio drivers

Add protections against guests with bad virtio-{blk,net,scsi}
drivers, specifically avoiding invalid descriptor chains and
invalid vionet packet sizes. This helps prevent possible lockup
of the host vm process due to a spinning device event loop thread.

Also fix an unneeded cast in the vioblk handling in case of invalid
buffer lengths.

OK mlarkin@

Revision 1.85 / (download) - annotate - [select for diffs], Wed Apr 21 18:27:36 2021 UTC (3 years, 1 month ago) by dv
Branch: MAIN
Changes since 1.84: +11 -5 lines
Diff to previous 1.84 (colored)

Fix packet size checks and remove bad casts.

Because dhcpsz was an uninitialized ssize_t, it was possible that a
garbage "packet" would be queued on the receiving end of the virtio
network device.

Change the type to size_t and add proper checks based on it being
greater than zero. Remove the cast of ssize_t to uint64_t that also
caused garbage sizes when dhcpsz was unintialized and set at runtime
to something < 0.

Revision 1.84 / (download) - annotate - [select for diffs], Mon Mar 29 23:37:01 2021 UTC (3 years, 2 months ago) by dv
Branch: MAIN
CVS Tags: OPENBSD_6_9_BASE
Branch point for: OPENBSD_6_9
Changes since 1.83: +26 -1 lines
Diff to previous 1.83 (colored)

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@

Revision 1.83 / (download) - annotate - [select for diffs], Fri Mar 26 17:40:03 2021 UTC (3 years, 2 months ago) by deraadt
Branch: MAIN
Changes since 1.82: +2 -3 lines
Diff to previous 1.82 (colored)

inspect all the packets to see if they are dhcp, not just the first one
in a ring bundle.
ok florian

Revision 1.82 / (download) - annotate - [select for diffs], Wed Dec 11 06:45:16 2019 UTC (4 years, 5 months ago) by pd
Branch: MAIN
CVS Tags: OPENBSD_6_8_BASE, OPENBSD_6_7_BASE, OPENBSD_6_7
Branch point for: OPENBSD_6_8
Changes since 1.81: +27 -6 lines
Diff to previous 1.81 (colored)

vmd: proper concurrency control when pausing a vm

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@

Revision 1.81 / (download) - annotate - [select for diffs], Sat Nov 30 00:51:29 2019 UTC (4 years, 6 months ago) by mlarkin
Branch: MAIN
Changes since 1.80: +1 -5 lines
Diff to previous 1.80 (colored)

Revert previous - the stability was not as improved as we had thought and
we ended up accidentally breaking vmctl. This will need more thought.

ok ori@

Revision 1.80 / (download) - annotate - [select for diffs], Fri Nov 29 00:51:27 2019 UTC (4 years, 6 months ago) by mlarkin
Branch: MAIN
Changes since 1.79: +4 -1 lines
Diff to previous 1.79 (colored)

Fix at least one cause of VMs spinning at 100% host CPU

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@

Revision 1.79 / (download) - annotate - [select for diffs], Tue Sep 24 12:14:54 2019 UTC (4 years, 8 months ago) by mlarkin
Branch: MAIN
CVS Tags: OPENBSD_6_6_BASE, OPENBSD_6_6
Changes since 1.78: +4 -1 lines
Diff to previous 1.78 (colored)

vmd(8): fix memory leak in virtio network TX path.

ok reyk, mpi, benno, tb

Revision 1.78 / (download) - annotate - [select for diffs], Tue Sep 24 12:12:46 2019 UTC (4 years, 8 months ago) by mlarkin
Branch: MAIN
Changes since 1.77: +2 -2 lines
Diff to previous 1.77 (colored)

vmd(8): virtio.c whitespace removal

Revision 1.77 / (download) - annotate - [select for diffs], Tue Jan 22 10:12:36 2019 UTC (5 years, 4 months ago) by mlarkin
Branch: MAIN
CVS Tags: OPENBSD_6_5_BASE, OPENBSD_6_5
Changes since 1.76: +51 -51 lines
Diff to previous 1.76 (colored)

vmd: reorder PCI device assignment to fix Linux network interface numbering

On some recent Linux guests, the virtio network interface is named based
on its PCI slot assignment, eg "enp0s3".

Prior to this change, vmd assigned disks first, meaning if you used a disk
image to install Linux and then removed it after install, the network
interface name would change from "enp0s3" to "enp0s2" (for example). This
broke any autoconfiguration script config files written during the install
and generally led to users just being confused about what was going on.

This change reorders the vmd PCI device assignment to put network
interfaces before disks, as disk devices don't seem to have the same
naming issue. This means the slot for network interfaces won't change.

IMPORTANT NOTE - if you have existing Linux guest VMs, you'll need to
manually fixup your config files (once).

ok ajacoutot, phessler, ccardenas, deraadt@

Revision 1.76 / (download) - annotate - [select for diffs], Thu Jan 10 18:59:56 2019 UTC (5 years, 4 months ago) by sf
Branch: MAIN
Changes since 1.75: +2 -1 lines
Diff to previous 1.75 (colored)

unbreak vmd build

include new virtio_pcireg.h header

Revision 1.75 / (download) - annotate - [select for diffs], Thu Dec 6 09:20:06 2018 UTC (5 years, 5 months ago) by claudio
Branch: MAIN
Changes since 1.74: +6 -3 lines
Diff to previous 1.74 (colored)

Make it possible to define the bootdevice in vmd. This information is used
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@

Revision 1.74 / (download) - annotate - [select for diffs], Mon Nov 26 10:39:30 2018 UTC (5 years, 6 months ago) by reyk
Branch: MAIN
Changes since 1.73: +3 -3 lines
Diff to previous 1.73 (colored)

Move the {qcow2,raw} create functions from vmctl into vmd/vio{qcow2,raw}.c

This way they are in the appropriate place and code can be shared with vmd.

Ok ori@ mlarkin@ ccardenas@

Revision 1.73 / (download) - annotate - [select for diffs], Fri Oct 19 10:12:39 2018 UTC (5 years, 7 months ago) by reyk
Branch: MAIN
Changes since 1.72: +3 -3 lines
Diff to previous 1.72 (colored)

Add support to create and convert disk images from existing images

The -i option to vmctl create (eg. vmctl create output.qcow2 -i input.img)
lets you create a new image from an input file and convert it if it is a
different format.  This allows to convert qcow2 images from raw images,
raw from qcow2, or even qcow2 from qcow2 and raw from raw to re-optimize
the disk.

This re-uses Ori's vioqcow2.c from vmd by reaching into it and
compiling it in.  The API has been adjust to be used from both vmctl
and vmd accordingly.

OK mlarkin@

Revision 1.72 / (download) - annotate - [select for diffs], Mon Oct 8 16:32:01 2018 UTC (5 years, 7 months ago) by reyk
Branch: MAIN
CVS Tags: OPENBSD_6_4_BASE, OPENBSD_6_4
Changes since 1.71: +35 -13 lines
Diff to previous 1.71 (colored)

Add support for qcow2 base images (external snapshots).

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@

Revision 1.71 / (download) - annotate - [select for diffs], Wed Oct 3 20:35:32 2018 UTC (5 years, 7 months ago) by ccardenas
Branch: MAIN
Changes since 1.70: +4 -2 lines
Diff to previous 1.70 (colored)

Add check to ensure vioscsi pointer if valid

implicit ok from pd@ since he came up with the same diff

Revision 1.70 / (download) - annotate - [select for diffs], Fri Sep 28 12:35:32 2018 UTC (5 years, 8 months ago) by reyk
Branch: MAIN
Changes since 1.69: +3 -3 lines
Diff to previous 1.69 (colored)

Support vmd-internal's vmboot with qcow2 disk images.

OK mlarkin@

Revision 1.69 / (download) - annotate - [select for diffs], Wed Sep 19 04:29:21 2018 UTC (5 years, 8 months ago) by ccardenas
Branch: MAIN
Changes since 1.68: +12 -1 lines
Diff to previous 1.68 (colored)

Various clean up items for disks.

- 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@

Revision 1.68 / (download) - annotate - [select for diffs], Thu Sep 13 04:23:36 2018 UTC (5 years, 8 months ago) by pd
Branch: MAIN
Changes since 1.67: +8 -1 lines
Diff to previous 1.67 (colored)

vmd: set irq and vm_id in virtio dev structs on restore

This unbreaks vmctl receive.

ok ccardenas@

Revision 1.67 / (download) - annotate - [select for diffs], Tue Sep 11 13:45:29 2018 UTC (5 years, 8 months ago) by ccardenas
Branch: MAIN
Changes since 1.66: +6 -5 lines
Diff to previous 1.66 (colored)

Be consistent in logging messages.

Change "fmt" to "format".

Ok kn@

Revision 1.66 / (download) - annotate - [select for diffs], Tue Sep 11 04:06:32 2018 UTC (5 years, 8 months ago) by ccardenas
Branch: MAIN
Changes since 1.65: +20 -8 lines
Diff to previous 1.65 (colored)

Fail fast when we are unable to determine disk format.

While here, minor cleanup on logging.

Revision 1.65 / (download) - annotate - [select for diffs], Sun Sep 9 04:09:32 2018 UTC (5 years, 8 months ago) by ccardenas
Branch: MAIN
Changes since 1.64: +17 -11 lines
Diff to previous 1.64 (colored)

Add initial qcow2 image support.

Users are able to declare disk images as 'raw' or 'qcow2' using either
vmctl and vm.conf.  The default disk image format is 'raw' if not specified.

Examples of using disk format:

vmctl start bsd -Lc -r cd64.iso -d qcow2:current.qc2
or
vmctl start bsd -Lc -r cd64.iso -d raw:current.raw
is equivalent to
vmctl start bsd -Lc -r cd64.iso -d current.raw

in vm.conf
vm "current" {
    disable
    memory 2G
    disk "/home/user/vmm/current.qc2" format "qcow2"
    interface { switch "external" }
}

or

vm "current" {
    disable
    memory 2G
    disk "/home/user/vmm/current.raw" format "raw"
    interface { switch "external" }
}

is equivlanet to

vm "current" {
    disable
    memory 2G
    disk "/home/user/vmm/current.raw"
    interface { switch "external" }
}

Tested by many.

Big Thanks to Ori Bernstein.

Revision 1.64 / (download) - annotate - [select for diffs], Sat Aug 25 04:16:09 2018 UTC (5 years, 9 months ago) by ccardenas
Branch: MAIN
Changes since 1.63: +33 -25 lines
Diff to previous 1.63 (colored)

Rework disks to have pluggable backends.

This is prep work for adding qcow2 image support.

From Ori Bernstein.  Many thanks!

Tested by many.

OK ccardenas@

Revision 1.63 / (download) - annotate - [select for diffs], Mon Jul 9 16:11:37 2018 UTC (5 years, 10 months ago) by mlarkin
Branch: MAIN
Changes since 1.62: +10 -1 lines
Diff to previous 1.62 (colored)

vmd(8): deassert interrupt pins in the PIC at the right times. Helps fix
situations where vmd gets stuck at 100% cpu usage because the guest VM
is constantly trying to ack interrupts that already occurred.

tested by phessler on a VM that used to exhibit the issue.

ok phessler

Revision 1.62 / (download) - annotate - [select for diffs], Mon Jul 9 08:43:09 2018 UTC (5 years, 10 months ago) by mlarkin
Branch: MAIN
Changes since 1.61: +8 -3 lines
Diff to previous 1.61 (colored)

vmd(8): stash device IRQ in the device struct

ok kettenis

Revision 1.61 / (download) - annotate - [select for diffs], Tue Jun 19 17:12:34 2018 UTC (5 years, 11 months ago) by reyk
Branch: MAIN
Changes since 1.60: +20 -11 lines
Diff to previous 1.60 (colored)

knf

Revision 1.60 / (download) - annotate - [select for diffs], Mon Apr 30 08:27:53 2018 UTC (6 years, 1 month ago) by mlarkin
Branch: MAIN
Changes since 1.59: +2 -2 lines
Diff to previous 1.59 (colored)

vmd(8): unbreak i386

Revision 1.59 / (download) - annotate - [select for diffs], Thu Apr 26 15:58:30 2018 UTC (6 years, 1 month ago) by mlarkin
Branch: MAIN
Changes since 1.58: +64 -43 lines
Diff to previous 1.58 (colored)

vmd(8): use #defines for queue indices and cleanup some code

ok phessler

Revision 1.58 / (download) - annotate - [select for diffs], Thu Apr 26 14:17:23 2018 UTC (6 years, 1 month ago) by mlarkin
Branch: MAIN
Changes since 1.57: +54 -11 lines
Diff to previous 1.57 (colored)

vmd(8): fix broken networking on newer linux guest kernels

Linux kernels after about 4.11.x or so exhibited problems with vmd(8)'s
virtio implementation. This commit fixes two bugs - an descriptor index
problem for the receive queue and a problem where the packet data was
being copied into the secondary descriptor buffer (should now be the
first descriptor's buffer, since that has enough size now for a non-jumbo
frame). Verified on ubuntu 17.10 (linux 4.13.x) and regression tested
on a variety of older linux guests and non-linux guests.

ok ccardenas, phessler

Revision 1.57 / (download) - annotate - [select for diffs], Thu Apr 26 01:10:10 2018 UTC (6 years, 1 month ago) by ccardenas
Branch: MAIN
Changes since 1.56: +3 -3 lines
Diff to previous 1.56 (colored)

spelling error in log message

Revision 1.56 / (download) - annotate - [select for diffs], Thu Feb 1 18:33:27 2018 UTC (6 years, 4 months ago) by pd
Branch: MAIN
CVS Tags: OPENBSD_6_3_BASE, OPENBSD_6_3
Changes since 1.55: +10 -4 lines
Diff to previous 1.55 (colored)

vmd: fix vioscsi dump and restore

This unbreaks send / receive. Also tested send / receive for vms with cdrom
by booting install62.iso on a vm with a small empty disk, send to file,
receive into a new vm and running an install of bsd* and base.

ok ccardenas@

Revision 1.55 / (download) - annotate - [select for diffs], Wed Jan 3 05:39:56 2018 UTC (6 years, 4 months ago) by ccardenas
Branch: MAIN
Changes since 1.54: +103 -11 lines
Diff to previous 1.54 (colored)

Add initial CD-ROM support to VMD via vioscsi.

* 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@

Revision 1.54 / (download) - annotate - [select for diffs], Sun Sep 17 23:07:56 2017 UTC (6 years, 8 months ago) by pd
Branch: MAIN
CVS Tags: OPENBSD_6_2_BASE, OPENBSD_6_2
Changes since 1.53: +15 -56 lines
Diff to previous 1.53 (colored)

vmd: send/recv pci config space instead of recreating pci devices on receive

ok mlarkin@

Revision 1.53 / (download) - annotate - [select for diffs], Fri Sep 8 04:48:55 2017 UTC (6 years, 8 months ago) by mlarkin
Branch: MAIN
Changes since 1.52: +13 -9 lines
Diff to previous 1.52 (colored)

vmd: handle queue index wraparound in viornd. Without this, openbsd guests
used to crash after roughly 68 hours uptime.

ok deraadt

Revision 1.52 / (download) - annotate - [select for diffs], Sun Aug 20 05:16:58 2017 UTC (6 years, 9 months ago) by mlarkin
Branch: MAIN
Changes since 1.51: +5 -6 lines
Diff to previous 1.51 (colored)

vmd: return VIRTIO_BLK_S_UNSUPP on any unknown vioblk command, not just
VIRTIO_BLK_T_GET_ID.

suggested by sf@

Revision 1.51 / (download) - annotate - [select for diffs], Thu Aug 10 16:59:04 2017 UTC (6 years, 9 months ago) by mlarkin
Branch: MAIN
Changes since 1.50: +1 -2 lines
Diff to previous 1.50 (colored)

whitespace

Revision 1.50 / (download) - annotate - [select for diffs], Sat Aug 5 05:41:31 2017 UTC (6 years, 9 months ago) by mlarkin
Branch: MAIN
Changes since 1.49: +10 -4 lines
Diff to previous 1.49 (colored)

vmd: report queue size of 0 when invalid queues are requested by the guest

Diff supplied by Nick Owens, who was kind enough to also point out the
virtio spec section numbers that defined this behaviour.

Revision 1.49 / (download) - annotate - [select for diffs], Tue May 30 17:56:47 2017 UTC (7 years ago) by tedu
Branch: MAIN
Changes since 1.48: +98 -42 lines
Diff to previous 1.48 (colored)

split vioblk read/write functions into start and finish as prep for
async io operations. ok mlarkin

Revision 1.48 / (download) - annotate - [select for diffs], Tue May 30 13:13:47 2017 UTC (7 years ago) by mlarkin
Branch: MAIN
Changes since 1.47: +2 -2 lines
Diff to previous 1.47 (colored)

increase vmd(8) virtio queue size from 64 to 128. Also fix an old
copypaste bug that didn't hurt us as long as all the queue sizes were
the same, which was the case up to now.

suggested by sf@, ok krw@

Revision 1.47 / (download) - annotate - [select for diffs], Sat May 27 23:58:16 2017 UTC (7 years ago) by tedu
Branch: MAIN
Changes since 1.46: +3 -16 lines
Diff to previous 1.46 (colored)

use pread and pwrite to save code and syscalls. ok mlarkin

Revision 1.46 / (download) - annotate - [select for diffs], Thu May 11 07:31:20 2017 UTC (7 years ago) by mlarkin
Branch: MAIN
Changes since 1.45: +2 -2 lines
Diff to previous 1.45 (colored)

typo, spotted by dhill.

ok reyk@

Revision 1.45 / (download) - annotate - [select for diffs], Mon May 8 09:08:40 2017 UTC (7 years ago) by reyk
Branch: MAIN
Changes since 1.44: +270 -1 lines
Diff to previous 1.44 (colored)

Adds functions to read and write state of devices in vmd.

This is required for implementing vmctl send and vmctl receive.  vmctl
send / receive are two new options that will support snapshotting VMs
and migrating VMs from one host to another. The atomicio files are
copied from usr.bin/ssh.

Patch from Pratik Vyas; this project was undertaken at San Jose State
University along with his three teammates, Ashwin, Harshada and Siri
with mlarkin@ as the advisor.

OK mlarkin@

Revision 1.44 / (download) - annotate - [select for diffs], Tue May 2 09:51:19 2017 UTC (7 years, 1 month ago) by mlarkin
Branch: MAIN
Changes since 1.43: +21 -2 lines
Diff to previous 1.43 (colored)

Resynchronize the guest RTC via vmmci(4) on host resume from zzz/ZZZ
(vmd part)

This feature is for OpenBSD guests only.

ok reyk, kettenis

Revision 1.43 / (download) - annotate - [select for diffs], Tue Apr 25 16:38:23 2017 UTC (7 years, 1 month ago) by reyk
Branch: MAIN
Changes since 1.42: +4 -23 lines
Diff to previous 1.42 (colored)

Generate randomized MAC addresses earlier to keep them across reboots.

OK deraadt@

Revision 1.42 / (download) - annotate - [select for diffs], Wed Apr 19 15:38:32 2017 UTC (7 years, 1 month ago) by reyk
Branch: MAIN
Changes since 1.41: +28 -9 lines
Diff to previous 1.41 (colored)

Add support for dynamic "NAT" interfaces (-L/local interface).

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@

Revision 1.41 / (download) - annotate - [select for diffs], Sat Apr 8 19:08:18 2017 UTC (7 years, 1 month ago) by mlarkin
Branch: MAIN
Changes since 1.40: +2 -2 lines
Diff to previous 1.40 (colored)

change a log message from "warn" to "debug" level, as the condition it is
reporting is not actually a warning.

Revision 1.40 / (download) - annotate - [select for diffs], Sun Mar 26 22:19:47 2017 UTC (7 years, 2 months ago) by mlarkin
Branch: MAIN
CVS Tags: OPENBSD_6_1_BASE, OPENBSD_6_1
Changes since 1.39: +105 -15 lines
Diff to previous 1.39 (colored)

Implement a missing command in vioblk and allow > MAXPHYS transfers.

This diff (with the others previously committed) allows ubuntu 14.04
amd64 guests to work.

Revision 1.39 / (download) - annotate - [select for diffs], Sat Mar 25 22:36:53 2017 UTC (7 years, 2 months ago) by mlarkin
Branch: MAIN
Changes since 1.38: +19 -3 lines
Diff to previous 1.38 (colored)

Last bits needed to get seabios + alpine linux working. This is enough
to get started and let more people help finding and fixing bugs.

ok kettenis, deraadt

Revision 1.38 / (download) - annotate - [select for diffs], Sat Mar 25 16:34:26 2017 UTC (7 years, 2 months ago) by mlarkin
Branch: MAIN
Changes since 1.37: +151 -147 lines
Diff to previous 1.37 (colored)

Process more than one avail slot in vioblk ring, if requested by the
guest VM. We probably need to do this same fix for vionet later.

Revision 1.37 / (download) - annotate - [select for diffs], Sat Mar 25 16:24:44 2017 UTC (7 years, 2 months ago) by mlarkin
Branch: MAIN
Changes since 1.36: +5 -1 lines
Diff to previous 1.36 (colored)

The virtio spec says isr_status should be cleared to 0 on read, which
we were not doing. That confused the virtio subsystem in linux.

Revision 1.36 / (download) - annotate - [select for diffs], Sat Mar 25 16:05:33 2017 UTC (7 years, 2 months ago) by mlarkin
Branch: MAIN
Changes since 1.35: +23 -3 lines
Diff to previous 1.35 (colored)

implement missing vioblk reset function and improve the partially
implemented vionet one

Revision 1.35 / (download) - annotate - [select for diffs], Sat Mar 25 15:47:37 2017 UTC (7 years, 2 months ago) by mlarkin
Branch: MAIN
Changes since 1.34: +82 -8 lines
Diff to previous 1.34 (colored)

Implement some missing functionality and clean up some code in vmd
pci emulation.

ok kettenis

Revision 1.34 / (download) - annotate - [select for diffs], Wed Mar 15 18:06:18 2017 UTC (7 years, 2 months ago) by reyk
Branch: MAIN
Changes since 1.33: +68 -2 lines
Diff to previous 1.33 (colored)

Improve vmmci(4) shutdown and reboot.

This change handles various cases to power off the VM, even if it is
unresponsive, stuck in ddb, or when the shutdown was initiated from
the VM guest side.  Usage of timeout and VM ACKs make sure that the VM
is really turned off at some point.

OK mlarkin@

Revision 1.33 / (download) - annotate - [select for diffs], Thu Mar 2 07:33:37 2017 UTC (7 years, 3 months ago) by reyk
Branch: MAIN
Changes since 1.32: +27 -8 lines
Diff to previous 1.32 (colored)

Add "locked lladdr" option to prevent VMs from spoofing MAC addresses.

This is especially useful when multiple VMs share a switch, the
implementation is independent from the underlying switch or bridge.

no objections mlarkin@

Revision 1.32 / (download) - annotate - [select for diffs], Mon Feb 13 18:49:01 2017 UTC (7 years, 3 months ago) by reyk
Branch: MAIN
Changes since 1.31: +8 -1 lines
Diff to previous 1.31 (colored)

Fix powerdown with vmmci(4) VMs using a shutdown and no reset.

vmm VMs don't support powerdown - no ACPI or power management - so we
use a trick to issue a reboot and just don't reset after the triple
fault.  This worked before but was broken with the previous fix to
pvbus_shutdown() - move the trick to vmd instead.

OK mlarkin@

Revision 1.31 / (download) - annotate - [select for diffs], Sat Jan 21 11:36:54 2017 UTC (7 years, 4 months ago) by reyk
Branch: MAIN
Changes since 1.30: +3 -3 lines
Diff to previous 1.30 (colored)

Switch include of virtio header from dev/pci/ to dev/pv/

Revision 1.30 / (download) - annotate - [select for diffs], Thu Jan 19 10:16:22 2017 UTC (7 years, 4 months ago) by reyk
Branch: MAIN
Changes since 1.29: +20 -2 lines
Diff to previous 1.29 (colored)

Export the host time to the guest, add it as a timedelta sensor in vmmci(4)

OK kettenis@ mlarkin@

Revision 1.29 / (download) - annotate - [select for diffs], Tue Jan 17 21:51:01 2017 UTC (7 years, 4 months ago) by krw
Branch: MAIN
Changes since 1.28: +3 -3 lines
Diff to previous 1.28 (colored)

Nuke some whitespace that keeps poking me in the eye as I try to
steal code.

Revision 1.28 / (download) - annotate - [select for diffs], Fri Jan 13 15:12:13 2017 UTC (7 years, 4 months ago) by reyk
Branch: MAIN
Changes since 1.27: +1 -4 lines
Diff to previous 1.27 (colored)

I accidentally committed three lines from the future.

Revision 1.27 / (download) - annotate - [select for diffs], Fri Jan 13 14:50:56 2017 UTC (7 years, 4 months ago) by reyk
Branch: MAIN
Changes since 1.26: +119 -2 lines
Diff to previous 1.26 (colored)

Add host side of vmmci(4) to vmd(8).

It currently uses the device to request graceful shutdown of a VM on
"vmctl stop myvm" but will be extended for reboot and a other edge cases.

OK mlarkin@

Revision 1.26 / (download) - annotate - [select for diffs], Mon Dec 5 09:28:11 2016 UTC (7 years, 5 months ago) by reyk
Branch: MAIN
Changes since 1.25: +10 -1 lines
Diff to previous 1.25 (colored)

Add debug message to print VM's mac addresses (lladdr).

Revision 1.25 / (download) - annotate - [select for diffs], Sat Nov 26 16:05:11 2016 UTC (7 years, 6 months ago) by sf
Branch: MAIN
Changes since 1.24: +11 -1 lines
Diff to previous 1.24 (colored)

virtio-net: Partially implement device reset

Implement some bits of the device reset and don't do DMA if the DRIVER_OK bit
is not set. This is enough to avoid vio(4) panicking on if down/up.

Tested by rzalamena@ and mikeb@
OK reyk@

Revision 1.24 / (download) - annotate - [select for diffs], Tue Oct 18 05:33:57 2016 UTC (7 years, 7 months ago) by reyk
Branch: MAIN
Changes since 1.23: +21 -5 lines
Diff to previous 1.23 (colored)

When the guest OS gets a zero MAC address on a network interface, it should
create a randomized locally administrated address.  OpenBSD as a guest OS
does this correctly but we cannot rely on it for other guests, so randomize
the MAC address in vmd(8) on the host side if it is not specified by the
user.  I incremented the prefix by one to differentiate from the ones
that are generated by OpenBSD in the kernel; fe:e1:bb:xx:xx:xx.

OK deraadt@ mlarkin@

Revision 1.23 / (download) - annotate - [select for diffs], Sun Oct 16 19:07:05 2016 UTC (7 years, 7 months ago) by guenther
Branch: MAIN
Changes since 1.22: +2 -2 lines
Diff to previous 1.22 (colored)

Prefer memcpy/memmove over bcopy

ok mlarkin@

Revision 1.22 / (download) - annotate - [select for diffs], Wed Oct 12 06:56:54 2016 UTC (7 years, 7 months ago) by mlarkin
Branch: MAIN
Changes since 1.21: +13 -14 lines
Diff to previous 1.21 (colored)


Allow 4 vio(4) interfaces in each VM. Also fix a bad interrupt assignment that
caused IRQ9 to be shared between the second disk device and the vio(4)s,
which caused poor network performance.

ok reyk, stefan

Revision 1.21 / (download) - annotate - [select for diffs], Wed Oct 5 17:30:13 2016 UTC (7 years, 7 months ago) by reyk
Branch: MAIN
Changes since 1.20: +7 -5 lines
Diff to previous 1.20 (colored)

Add support for enhanced networking configuration and virtual switches.
See vm.conf(5) for more details.

OK mlarkin@

Revision 1.20 / (download) - annotate - [select for diffs], Mon Oct 3 05:59:24 2016 UTC (7 years, 8 months ago) by mlarkin
Branch: MAIN
Changes since 1.19: +3 -5 lines
Diff to previous 1.19 (colored)


style cleanup

Revision 1.19 / (download) - annotate - [select for diffs], Sat Sep 3 11:35:24 2016 UTC (7 years, 8 months ago) by nayden
Branch: MAIN
Changes since 1.18: +22 -43 lines
Diff to previous 1.18 (colored)

Adding a clean up block to vioblk_notifyq() and vionet_enq_rx()
OK mlarkin@

Revision 1.18 / (download) - annotate - [select for diffs], Fri Sep 2 17:08:28 2016 UTC (7 years, 9 months ago) by stefan
Branch: MAIN
Changes since 1.17: +90 -4 lines
Diff to previous 1.17 (colored)

Process incoming host->guest packets asynchronously to running VCPU

This registers a handler with libevent that is called on incoming packets
for the guest. If they cannot be handled immediately (because the virtq is
full), make sure they are handled on VCPU exits.

ok mlarkin@

Revision 1.17 / (download) - annotate - [select for diffs], Wed Aug 17 05:07:13 2016 UTC (7 years, 9 months ago) by deraadt
Branch: MAIN
Changes since 1.16: +10 -8 lines
Diff to previous 1.16 (colored)

small bits of header cleanup; ok mlarkin

Revision 1.16 / (download) - annotate - [select for diffs], Tue Jul 19 09:52:34 2016 UTC (7 years, 10 months ago) by natano
Branch: MAIN
CVS Tags: OPENBSD_6_0_BASE, OPENBSD_6_0
Changes since 1.15: +13 -25 lines
Diff to previous 1.15 (colored)

Replace malloc() + memset() with calloc().
ok mlarkin

Revision 1.15 / (download) - annotate - [select for diffs], Sat Jul 9 09:06:22 2016 UTC (7 years, 10 months ago) by stefan
Branch: MAIN
Changes since 1.14: +59 -45 lines
Diff to previous 1.14 (colored)

Prepare vionet to be handled asynchronously to the VCPU thread

This splits the handling of received data into a separate function
that can later be called in parallel to the VCPU thread instead of
handling received packets on VCPU exits only.

It also makes virtq accesses in the rx path safe to run in parallel
to the VCPU thread: the last index into the 'avail' ring the driver
has notified to the host is kept track of. It also makes sure that
the host only writes back to the 'avail' ring instead of modifying
the whole receive virtq.

While there, describe what virtio_vq_info and virtio_io_cfg are used
for, as suggested by mlarkin@

ok mlarkin@

Revision 1.14 / (download) - annotate - [select for diffs], Thu Jul 7 00:58:31 2016 UTC (7 years, 10 months ago) by mlarkin
Branch: MAIN
Changes since 1.13: +83 -79 lines
Diff to previous 1.13 (colored)


sanity check vm create and run args earlier

Revision 1.13 / (download) - annotate - [select for diffs], Mon Jul 4 23:03:52 2016 UTC (7 years, 10 months ago) by mlarkin
Branch: MAIN
Changes since 1.12: +9 -4 lines
Diff to previous 1.12 (colored)


limit each viornd request to 64KB.

Revision 1.12 / (download) - annotate - [select for diffs], Thu Jun 30 02:29:22 2016 UTC (7 years, 11 months ago) by mlarkin
Branch: MAIN
Changes since 1.11: +3 -3 lines
Diff to previous 1.11 (colored)


remove some unused variables (that were commented out anyway)

Revision 1.11 / (download) - annotate - [select for diffs], Mon Apr 4 17:13:54 2016 UTC (8 years, 1 month ago) by stefan
Branch: MAIN
Changes since 1.10: +22 -22 lines
Diff to previous 1.10 (colored)

Directly use physical addresses from ELF header for kernel loading.

This allows us to remove the 'do_mask' parameters in read_mem and
write_mem as well as the address mask operaton itself.

ok mlarkin@

Revision 1.10 / (download) - annotate - [select for diffs], Sun Mar 13 13:11:47 2016 UTC (8 years, 2 months ago) by stefan
Branch: MAIN
Changes since 1.9: +20 -23 lines
Diff to previous 1.9 (colored)

Introduce memory ranges to support VMs with >= 4G RAM

Kernel bits:
- When creating a VM, a list of memory ranges has to be specified,
  similar to the BIOS memory map. This is necessary for VMs with
  RAM sizes approaching 4G because we'll need PCI MMIO space in
  the higher parts of the 32 bit address space.

vmctl and vmd bits:
- Construct appropriate memory ranges to create a VM with a given
  RAM size
- Construct a corresponding BIOS memory map from the memory ranges
  and update the boot params page accordingly.
- Make sure that all variables that represent guest physical addresses
  match the address width of the target CPU instead of using uint32_t.
- Fix some integer promotion glitches that actually restricted VM
  RAM size to 2G.

This changes the VM create ioctl interface, so update your kernel,
vmd, and vmctl.

ok mlarkin@

Revision 1.9 / (download) - annotate - [select for diffs], Sun Feb 7 10:17:19 2016 UTC (8 years, 3 months ago) by jsg
Branch: MAIN
CVS Tags: OPENBSD_5_9_BASE, OPENBSD_5_9
Changes since 1.8: +1 -2 lines
Diff to previous 1.8 (colored)

avoid a double free in an error path
ok stefan@

Revision 1.8 / (download) - annotate - [select for diffs], Sat Jan 16 08:55:40 2016 UTC (8 years, 4 months ago) by stefan
Branch: MAIN
Changes since 1.7: +60 -109 lines
Diff to previous 1.7 (colored)

vmd(8) sometimes attempts page-crossing data copies between the host
and guest. The readpage/writepage ioctls of vmm(4) do not support this
and they return EINVAL on such attempts since recently.

Avoid page-crossing guest memory accesses by changing read_page() and
write_page() into read_mem() and write_mem() that can copy arbitrary
lengths of data between host<->guest without page-crossing accesses.

This also allows us to remove page-wise copy-loops in a few places.

ok mlarkin@

Revision 1.7 / (download) - annotate - [select for diffs], Thu Jan 14 02:46:40 2016 UTC (8 years, 4 months ago) by mlarkin
Branch: MAIN
Changes since 1.6: +1 -2 lines
Diff to previous 1.6 (colored)


stdio.h is not needed here anymore.

Revision 1.6 / (download) - annotate - [select for diffs], Mon Jan 4 02:07:28 2016 UTC (8 years, 4 months ago) by mlarkin
Branch: MAIN
Changes since 1.5: +11 -11 lines
Diff to previous 1.5 (colored)


bzero -> memset for consistency

Revision 1.5 / (download) - annotate - [select for diffs], Sun Jan 3 22:36:09 2016 UTC (8 years, 4 months ago) by mlarkin
Branch: MAIN
Changes since 1.4: +15 -26 lines
Diff to previous 1.4 (colored)


Add a cleanup block, fix a couple of memory leaks, fix a typo and a bit
of KNF.

Submitted by Michal Mazurek, thanks!

Revision 1.4 / (download) - annotate - [select for diffs], Thu Dec 3 08:42:11 2015 UTC (8 years, 6 months ago) by reyk
Branch: MAIN
Changes since 1.3: +19 -19 lines
Diff to previous 1.3 (colored)

spacing

Revision 1.3 / (download) - annotate - [select for diffs], Mon Nov 23 13:04:49 2015 UTC (8 years, 6 months ago) by reyk
Branch: MAIN
Changes since 1.2: +81 -90 lines
Diff to previous 1.2 (colored)

Add support for logging to stderr or syslog, and to run vmd in
foreground with -d.

OK mlarkin@ jung@

Revision 1.2 / (download) - annotate - [select for diffs], Sun Nov 22 21:51:32 2015 UTC (8 years, 6 months ago) by reyk
Branch: MAIN
Changes since 1.1: +2 -0 lines
Diff to previous 1.1 (colored)

Add $ Ids

Revision 1.1 / (download) - annotate - [select for diffs], Sun Nov 22 20:20:32 2015 UTC (8 years, 6 months ago) by mlarkin
Branch: MAIN


vmd(8) - virtual machine daemon.

There is still a lot to be done, and fixed, in these userland components
but I have received enough "it works, commit it" emails that it's time
to finish those things in tree.

discussed with many, tested by many.

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.