Skip to content

Commit

Permalink
vhost_net: a kernel-level virtio server
Browse files Browse the repository at this point in the history
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 <[email protected]>,
David L Stevens <[email protected]>,
Chris Wright <[email protected]>)

Acked-by: Rusty Russell <[email protected]>
Acked-by: Arnd Bergmann <[email protected]>
Acked-by: "Paul E. McKenney" <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
mstsirkin authored and davem330 committed Jan 15, 2010
1 parent 5da779c commit 3a4d5c9
Show file tree
Hide file tree
Showing 14 changed files with 2,079 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -5803,6 +5803,15 @@ S: Maintained
F: Documentation/filesystems/vfat.txt
F: fs/fat/

VIRTIO HOST (VHOST)
M: "Michael S. Tsirkin" <[email protected]>
L: [email protected]
L: [email protected]
L: [email protected]
S: Maintained
F: drivers/vhost/
F: include/linux/vhost.h

VIA RHINE NETWORK DRIVER
M: Roger Luethi <[email protected]>
S: Maintained
Expand Down
1 change: 1 addition & 0 deletions arch/ia64/kvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ config KVM_INTEL
Provides support for KVM on Itanium 2 processors equipped with the VT
extensions.

source drivers/vhost/Kconfig
source drivers/virtio/Kconfig

endif # VIRTUALIZATION
1 change: 1 addition & 0 deletions arch/powerpc/kvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ config KVM_E500

If unsure, say N.

source drivers/vhost/Kconfig
source drivers/virtio/Kconfig

endif # VIRTUALIZATION
1 change: 1 addition & 0 deletions arch/s390/kvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ config KVM

# OK, it's a little counter-intuitive to do this, but it puts it neatly under
# the virtualization menu.
source drivers/vhost/Kconfig
source drivers/virtio/Kconfig

endif # VIRTUALIZATION
1 change: 1 addition & 0 deletions arch/x86/kvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ config KVM_AMD

# OK, it's a little counter-intuitive to do this, but it puts it neatly under
# the virtualization menu.
source drivers/vhost/Kconfig
source drivers/lguest/Kconfig
source drivers/virtio/Kconfig

Expand Down
1 change: 1 addition & 0 deletions drivers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ obj-$(CONFIG_HID) += hid/
obj-$(CONFIG_PPC_PS3) += ps3/
obj-$(CONFIG_OF) += of/
obj-$(CONFIG_SSB) += ssb/
obj-$(CONFIG_VHOST_NET) += vhost/
obj-$(CONFIG_VIRTIO) += virtio/
obj-$(CONFIG_VLYNQ) += vlynq/
obj-$(CONFIG_STAGING) += staging/
Expand Down
11 changes: 11 additions & 0 deletions drivers/vhost/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
config VHOST_NET
tristate "Host kernel accelerator for virtio net (EXPERIMENTAL)"
depends on NET && EVENTFD && EXPERIMENTAL
---help---
This kernel module can be loaded in host kernel to accelerate
guest networking with virtio_net. Not to be confused with virtio_net
module itself which needs to be loaded in guest kernel.

To compile this driver as a module, choose M here: the module will
be called vhost_net.

2 changes: 2 additions & 0 deletions drivers/vhost/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
obj-$(CONFIG_VHOST_NET) += vhost_net.o
vhost_net-y := vhost.o net.o
Loading

0 comments on commit 3a4d5c9

Please sign in to comment.