vhost_net: a kernel-level virtio server
What it is: vhost net is a character device that can be used to reduce
the number of system calls involved in virtio networking.
Existing virtio net code is used in the guest without modification.
There's similarity with vringfd, with some differences and reduced scope
- uses eventfd for signalling
- structures can be moved around in memory at any time (good for
migration, bug work-arounds in userspace)
- write logging is supported (good for migration)
- support memory table and not just an offset (needed for kvm)
common virtio related code has been put in a separate file vhost.c and
can be made into a separate module if/when more backends appear. I used
Rusty's lguest.c as the source for developing this part : this supplied
me with witty comments I wouldn't be able to write myself.
What it is not: vhost net is not a bus, and not a generic new system
call. No assumptions are made on how guest performs hypercalls.
Userspace hypervisors are supported as well as kvm.
How it works: Basically, we connect virtio frontend (configured by
userspace) to a backend. The backend could be a network device, or a tap
device. Backend is also configured by userspace, including vlan/mac
etc.
Status: This works for me, and I haven't see any crashes.
Compared to userspace, people reported improved latency (as I save up to
4 system calls per packet), as well as better bandwidth and CPU
utilization.
Features that I plan to look at in the future:
- mergeable buffers
- zero copy
- scalability tuning: figure out the best threading model to use
Note on RCU usage (this is also documented in vhost.h, near
private_pointer which is the value protected by this variant of RCU):
what is happening is that the rcu_dereference() is being used in a
workqueue item. The role of rcu_read_lock() is taken on by the start of
execution of the workqueue item, of rcu_read_unlock() by the end of
execution of the workqueue item, and of synchronize_rcu() by
flush_workqueue()/flush_work(). In the future we might need to apply
some gcc attribute or sparse annotation to the function passed to
INIT_WORK(). Paul's ack below is for this RCU usage.
(Includes fixes by Alan Cox <alan@linux.intel.com>,
David L Stevens <dlstevens@us.ibm.com>,
Chris Wright <chrisw@redhat.com>)
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-01-14 06:17:27 +00:00
|
|
|
#ifndef _LINUX_VHOST_H
|
|
|
|
#define _LINUX_VHOST_H
|
|
|
|
/* Userspace interface for in-kernel virtio accelerators. */
|
|
|
|
|
|
|
|
/* vhost is used to reduce the number of system calls involved in virtio.
|
|
|
|
*
|
|
|
|
* Existing virtio net code is used in the guest without modification.
|
|
|
|
*
|
|
|
|
* This header includes interface used by userspace hypervisor for
|
|
|
|
* device configuration.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/compiler.h>
|
|
|
|
#include <linux/ioctl.h>
|
|
|
|
#include <linux/virtio_config.h>
|
|
|
|
#include <linux/virtio_ring.h>
|
|
|
|
|
|
|
|
struct vhost_vring_state {
|
|
|
|
unsigned int index;
|
|
|
|
unsigned int num;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vhost_vring_file {
|
|
|
|
unsigned int index;
|
|
|
|
int fd; /* Pass -1 to unbind from file. */
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vhost_vring_addr {
|
|
|
|
unsigned int index;
|
|
|
|
/* Option flags. */
|
|
|
|
unsigned int flags;
|
|
|
|
/* Flag values: */
|
|
|
|
/* Whether log address is valid. If set enables logging. */
|
|
|
|
#define VHOST_VRING_F_LOG 0
|
|
|
|
|
|
|
|
/* Start of array of descriptors (virtually contiguous) */
|
|
|
|
__u64 desc_user_addr;
|
|
|
|
/* Used structure address. Must be 32 bit aligned */
|
|
|
|
__u64 used_user_addr;
|
|
|
|
/* Available structure address. Must be 16 bit aligned */
|
|
|
|
__u64 avail_user_addr;
|
|
|
|
/* Logging support. */
|
|
|
|
/* Log writes to used structure, at offset calculated from specified
|
|
|
|
* address. Address must be 32 bit aligned. */
|
|
|
|
__u64 log_guest_addr;
|
|
|
|
};
|
|
|
|
|
2016-06-23 06:04:32 +00:00
|
|
|
/* no alignment requirement */
|
|
|
|
struct vhost_iotlb_msg {
|
|
|
|
__u64 iova;
|
|
|
|
__u64 size;
|
|
|
|
__u64 uaddr;
|
|
|
|
#define VHOST_ACCESS_RO 0x1
|
|
|
|
#define VHOST_ACCESS_WO 0x2
|
|
|
|
#define VHOST_ACCESS_RW 0x3
|
|
|
|
__u8 perm;
|
|
|
|
#define VHOST_IOTLB_MISS 1
|
|
|
|
#define VHOST_IOTLB_UPDATE 2
|
|
|
|
#define VHOST_IOTLB_INVALIDATE 3
|
|
|
|
#define VHOST_IOTLB_ACCESS_FAIL 4
|
|
|
|
__u8 type;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VHOST_IOTLB_MSG 0x1
|
|
|
|
|
|
|
|
struct vhost_msg {
|
|
|
|
int type;
|
|
|
|
union {
|
|
|
|
struct vhost_iotlb_msg iotlb;
|
|
|
|
__u8 padding[64];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
vhost_net: a kernel-level virtio server
What it is: vhost net is a character device that can be used to reduce
the number of system calls involved in virtio networking.
Existing virtio net code is used in the guest without modification.
There's similarity with vringfd, with some differences and reduced scope
- uses eventfd for signalling
- structures can be moved around in memory at any time (good for
migration, bug work-arounds in userspace)
- write logging is supported (good for migration)
- support memory table and not just an offset (needed for kvm)
common virtio related code has been put in a separate file vhost.c and
can be made into a separate module if/when more backends appear. I used
Rusty's lguest.c as the source for developing this part : this supplied
me with witty comments I wouldn't be able to write myself.
What it is not: vhost net is not a bus, and not a generic new system
call. No assumptions are made on how guest performs hypercalls.
Userspace hypervisors are supported as well as kvm.
How it works: Basically, we connect virtio frontend (configured by
userspace) to a backend. The backend could be a network device, or a tap
device. Backend is also configured by userspace, including vlan/mac
etc.
Status: This works for me, and I haven't see any crashes.
Compared to userspace, people reported improved latency (as I save up to
4 system calls per packet), as well as better bandwidth and CPU
utilization.
Features that I plan to look at in the future:
- mergeable buffers
- zero copy
- scalability tuning: figure out the best threading model to use
Note on RCU usage (this is also documented in vhost.h, near
private_pointer which is the value protected by this variant of RCU):
what is happening is that the rcu_dereference() is being used in a
workqueue item. The role of rcu_read_lock() is taken on by the start of
execution of the workqueue item, of rcu_read_unlock() by the end of
execution of the workqueue item, and of synchronize_rcu() by
flush_workqueue()/flush_work(). In the future we might need to apply
some gcc attribute or sparse annotation to the function passed to
INIT_WORK(). Paul's ack below is for this RCU usage.
(Includes fixes by Alan Cox <alan@linux.intel.com>,
David L Stevens <dlstevens@us.ibm.com>,
Chris Wright <chrisw@redhat.com>)
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-01-14 06:17:27 +00:00
|
|
|
struct vhost_memory_region {
|
|
|
|
__u64 guest_phys_addr;
|
|
|
|
__u64 memory_size; /* bytes */
|
|
|
|
__u64 userspace_addr;
|
|
|
|
__u64 flags_padding; /* No flags are currently specified. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* All region addresses and sizes must be 4K aligned. */
|
|
|
|
#define VHOST_PAGE_SIZE 0x1000
|
|
|
|
|
|
|
|
struct vhost_memory {
|
|
|
|
__u32 nregions;
|
|
|
|
__u32 padding;
|
|
|
|
struct vhost_memory_region regions[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ioctls */
|
|
|
|
|
|
|
|
#define VHOST_VIRTIO 0xAF
|
|
|
|
|
|
|
|
/* Features bitmask for forward compatibility. Transport bits are used for
|
|
|
|
* vhost specific features. */
|
|
|
|
#define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
|
|
|
|
#define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
|
|
|
|
|
|
|
|
/* Set current process as the (exclusive) owner of this file descriptor. This
|
|
|
|
* must be called before any other vhost command. Further calls to
|
|
|
|
* VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
|
|
|
|
#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
|
|
|
|
/* Give up ownership, and reset the device to default values.
|
|
|
|
* Allows subsequent call to VHOST_OWNER_SET to succeed. */
|
|
|
|
#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
|
|
|
|
|
|
|
|
/* Set up/modify memory layout */
|
|
|
|
#define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
|
|
|
|
|
|
|
|
/* Write logging setup. */
|
|
|
|
/* Memory writes can optionally be logged by setting bit at an offset
|
|
|
|
* (calculated from the physical address) from specified log base.
|
|
|
|
* The bit is set using an atomic 32 bit operation. */
|
|
|
|
/* Set base address for logging. */
|
|
|
|
#define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
|
|
|
|
/* Specify an eventfd file descriptor to signal on log write. */
|
|
|
|
#define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
|
|
|
|
|
|
|
|
/* Ring setup. */
|
|
|
|
/* Set number of descriptors in ring. This parameter can not
|
|
|
|
* be modified while ring is running (bound to a device). */
|
|
|
|
#define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
|
|
|
|
/* Set addresses for the ring. */
|
|
|
|
#define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
|
|
|
|
/* Base value where queue looks for available descriptors */
|
|
|
|
#define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
|
|
|
|
/* Get accessor: reads index, writes value in num */
|
|
|
|
#define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
|
|
|
|
|
2015-04-24 12:27:24 +00:00
|
|
|
/* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
|
|
|
|
* or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
|
|
|
|
* The byte order cannot be changed while the device is active: trying to do so
|
|
|
|
* returns -EBUSY.
|
|
|
|
* This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
|
|
|
|
* set.
|
|
|
|
* Not all kernel configurations support this ioctl, but all configurations that
|
|
|
|
* support SET also support GET.
|
|
|
|
*/
|
|
|
|
#define VHOST_VRING_LITTLE_ENDIAN 0
|
|
|
|
#define VHOST_VRING_BIG_ENDIAN 1
|
|
|
|
#define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
|
|
|
|
#define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
|
|
|
|
|
vhost_net: a kernel-level virtio server
What it is: vhost net is a character device that can be used to reduce
the number of system calls involved in virtio networking.
Existing virtio net code is used in the guest without modification.
There's similarity with vringfd, with some differences and reduced scope
- uses eventfd for signalling
- structures can be moved around in memory at any time (good for
migration, bug work-arounds in userspace)
- write logging is supported (good for migration)
- support memory table and not just an offset (needed for kvm)
common virtio related code has been put in a separate file vhost.c and
can be made into a separate module if/when more backends appear. I used
Rusty's lguest.c as the source for developing this part : this supplied
me with witty comments I wouldn't be able to write myself.
What it is not: vhost net is not a bus, and not a generic new system
call. No assumptions are made on how guest performs hypercalls.
Userspace hypervisors are supported as well as kvm.
How it works: Basically, we connect virtio frontend (configured by
userspace) to a backend. The backend could be a network device, or a tap
device. Backend is also configured by userspace, including vlan/mac
etc.
Status: This works for me, and I haven't see any crashes.
Compared to userspace, people reported improved latency (as I save up to
4 system calls per packet), as well as better bandwidth and CPU
utilization.
Features that I plan to look at in the future:
- mergeable buffers
- zero copy
- scalability tuning: figure out the best threading model to use
Note on RCU usage (this is also documented in vhost.h, near
private_pointer which is the value protected by this variant of RCU):
what is happening is that the rcu_dereference() is being used in a
workqueue item. The role of rcu_read_lock() is taken on by the start of
execution of the workqueue item, of rcu_read_unlock() by the end of
execution of the workqueue item, and of synchronize_rcu() by
flush_workqueue()/flush_work(). In the future we might need to apply
some gcc attribute or sparse annotation to the function passed to
INIT_WORK(). Paul's ack below is for this RCU usage.
(Includes fixes by Alan Cox <alan@linux.intel.com>,
David L Stevens <dlstevens@us.ibm.com>,
Chris Wright <chrisw@redhat.com>)
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-01-14 06:17:27 +00:00
|
|
|
/* The following ioctls use eventfd file descriptors to signal and poll
|
|
|
|
* for events. */
|
|
|
|
|
|
|
|
/* Set eventfd to poll for added buffers */
|
|
|
|
#define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
|
|
|
|
/* Set eventfd to signal when buffers have beed used */
|
|
|
|
#define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
|
|
|
|
/* Set eventfd to signal an error */
|
|
|
|
#define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
|
2016-03-04 11:24:53 +00:00
|
|
|
/* Set busy loop timeout (in us) */
|
|
|
|
#define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \
|
|
|
|
struct vhost_vring_state)
|
|
|
|
/* Get busy loop timeout (in us) */
|
|
|
|
#define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \
|
|
|
|
struct vhost_vring_state)
|
vhost_net: a kernel-level virtio server
What it is: vhost net is a character device that can be used to reduce
the number of system calls involved in virtio networking.
Existing virtio net code is used in the guest without modification.
There's similarity with vringfd, with some differences and reduced scope
- uses eventfd for signalling
- structures can be moved around in memory at any time (good for
migration, bug work-arounds in userspace)
- write logging is supported (good for migration)
- support memory table and not just an offset (needed for kvm)
common virtio related code has been put in a separate file vhost.c and
can be made into a separate module if/when more backends appear. I used
Rusty's lguest.c as the source for developing this part : this supplied
me with witty comments I wouldn't be able to write myself.
What it is not: vhost net is not a bus, and not a generic new system
call. No assumptions are made on how guest performs hypercalls.
Userspace hypervisors are supported as well as kvm.
How it works: Basically, we connect virtio frontend (configured by
userspace) to a backend. The backend could be a network device, or a tap
device. Backend is also configured by userspace, including vlan/mac
etc.
Status: This works for me, and I haven't see any crashes.
Compared to userspace, people reported improved latency (as I save up to
4 system calls per packet), as well as better bandwidth and CPU
utilization.
Features that I plan to look at in the future:
- mergeable buffers
- zero copy
- scalability tuning: figure out the best threading model to use
Note on RCU usage (this is also documented in vhost.h, near
private_pointer which is the value protected by this variant of RCU):
what is happening is that the rcu_dereference() is being used in a
workqueue item. The role of rcu_read_lock() is taken on by the start of
execution of the workqueue item, of rcu_read_unlock() by the end of
execution of the workqueue item, and of synchronize_rcu() by
flush_workqueue()/flush_work(). In the future we might need to apply
some gcc attribute or sparse annotation to the function passed to
INIT_WORK(). Paul's ack below is for this RCU usage.
(Includes fixes by Alan Cox <alan@linux.intel.com>,
David L Stevens <dlstevens@us.ibm.com>,
Chris Wright <chrisw@redhat.com>)
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-01-14 06:17:27 +00:00
|
|
|
|
|
|
|
/* VHOST_NET specific defines */
|
|
|
|
|
|
|
|
/* Attach virtio net ring to a raw socket, or tap device.
|
|
|
|
* The socket must be already bound to an ethernet device, this device will be
|
|
|
|
* used for transmit. Pass fd -1 to unbind from the socket and the transmit
|
|
|
|
* device. This can be used to stop the ring (e.g. for migration). */
|
|
|
|
#define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
|
|
|
|
|
|
|
|
/* Feature bits */
|
|
|
|
/* Log all write descriptors. Can be changed while device is active. */
|
|
|
|
#define VHOST_F_LOG_ALL 26
|
|
|
|
/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */
|
|
|
|
#define VHOST_NET_F_VIRTIO_NET_HDR 27
|
|
|
|
|
2013-05-02 00:50:34 +00:00
|
|
|
/* VHOST_SCSI specific definitions */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
|
|
|
|
*
|
|
|
|
* ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
|
|
|
|
* RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
|
|
|
|
* ABI Rev 1: January 2013. Ignore vhost_tpgt filed in struct vhost_scsi_target.
|
|
|
|
* All the targets under vhost_wwpn can be seen and used by guset.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VHOST_SCSI_ABI_VERSION 1
|
|
|
|
|
|
|
|
struct vhost_scsi_target {
|
|
|
|
int abi_version;
|
|
|
|
char vhost_wwpn[224]; /* TRANSPORT_IQN_LEN */
|
|
|
|
unsigned short vhost_tpgt;
|
|
|
|
unsigned short reserved;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
|
|
|
|
#define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
|
|
|
|
/* Changing this breaks userspace. */
|
|
|
|
#define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
|
|
|
|
/* Set and get the events missed flag */
|
|
|
|
#define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
|
|
|
|
#define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
|
|
|
|
|
2016-07-28 14:36:34 +00:00
|
|
|
/* VHOST_VSOCK specific defines */
|
|
|
|
|
|
|
|
#define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64)
|
|
|
|
#define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int)
|
|
|
|
|
vhost_net: a kernel-level virtio server
What it is: vhost net is a character device that can be used to reduce
the number of system calls involved in virtio networking.
Existing virtio net code is used in the guest without modification.
There's similarity with vringfd, with some differences and reduced scope
- uses eventfd for signalling
- structures can be moved around in memory at any time (good for
migration, bug work-arounds in userspace)
- write logging is supported (good for migration)
- support memory table and not just an offset (needed for kvm)
common virtio related code has been put in a separate file vhost.c and
can be made into a separate module if/when more backends appear. I used
Rusty's lguest.c as the source for developing this part : this supplied
me with witty comments I wouldn't be able to write myself.
What it is not: vhost net is not a bus, and not a generic new system
call. No assumptions are made on how guest performs hypercalls.
Userspace hypervisors are supported as well as kvm.
How it works: Basically, we connect virtio frontend (configured by
userspace) to a backend. The backend could be a network device, or a tap
device. Backend is also configured by userspace, including vlan/mac
etc.
Status: This works for me, and I haven't see any crashes.
Compared to userspace, people reported improved latency (as I save up to
4 system calls per packet), as well as better bandwidth and CPU
utilization.
Features that I plan to look at in the future:
- mergeable buffers
- zero copy
- scalability tuning: figure out the best threading model to use
Note on RCU usage (this is also documented in vhost.h, near
private_pointer which is the value protected by this variant of RCU):
what is happening is that the rcu_dereference() is being used in a
workqueue item. The role of rcu_read_lock() is taken on by the start of
execution of the workqueue item, of rcu_read_unlock() by the end of
execution of the workqueue item, and of synchronize_rcu() by
flush_workqueue()/flush_work(). In the future we might need to apply
some gcc attribute or sparse annotation to the function passed to
INIT_WORK(). Paul's ack below is for this RCU usage.
(Includes fixes by Alan Cox <alan@linux.intel.com>,
David L Stevens <dlstevens@us.ibm.com>,
Chris Wright <chrisw@redhat.com>)
Acked-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-01-14 06:17:27 +00:00
|
|
|
#endif
|