Skip to content

Commit 3a4d5c9

Browse files
mstsirkindavem330
authored andcommitted
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 <[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]>
1 parent 5da779c commit 3a4d5c9

File tree

14 files changed

+2079
-0
lines changed

14 files changed

+2079
-0
lines changed

MAINTAINERS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5803,6 +5803,15 @@ S: Maintained
58035803
F: Documentation/filesystems/vfat.txt
58045804
F: fs/fat/
58055805

5806+
VIRTIO HOST (VHOST)
5807+
M: "Michael S. Tsirkin" <[email protected]>
5808+
5809+
5810+
5811+
S: Maintained
5812+
F: drivers/vhost/
5813+
F: include/linux/vhost.h
5814+
58065815
VIA RHINE NETWORK DRIVER
58075816
M: Roger Luethi <[email protected]>
58085817
S: Maintained

arch/ia64/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ config KVM_INTEL
4747
Provides support for KVM on Itanium 2 processors equipped with the VT
4848
extensions.
4949

50+
source drivers/vhost/Kconfig
5051
source drivers/virtio/Kconfig
5152

5253
endif # VIRTUALIZATION

arch/powerpc/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ config KVM_E500
7575

7676
If unsure, say N.
7777

78+
source drivers/vhost/Kconfig
7879
source drivers/virtio/Kconfig
7980

8081
endif # VIRTUALIZATION

arch/s390/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config KVM
3535

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

4041
endif # VIRTUALIZATION

arch/x86/kvm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ config KVM_AMD
6565

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

drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ obj-$(CONFIG_HID) += hid/
106106
obj-$(CONFIG_PPC_PS3) += ps3/
107107
obj-$(CONFIG_OF) += of/
108108
obj-$(CONFIG_SSB) += ssb/
109+
obj-$(CONFIG_VHOST_NET) += vhost/
109110
obj-$(CONFIG_VIRTIO) += virtio/
110111
obj-$(CONFIG_VLYNQ) += vlynq/
111112
obj-$(CONFIG_STAGING) += staging/

drivers/vhost/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
config VHOST_NET
2+
tristate "Host kernel accelerator for virtio net (EXPERIMENTAL)"
3+
depends on NET && EVENTFD && EXPERIMENTAL
4+
---help---
5+
This kernel module can be loaded in host kernel to accelerate
6+
guest networking with virtio_net. Not to be confused with virtio_net
7+
module itself which needs to be loaded in guest kernel.
8+
9+
To compile this driver as a module, choose M here: the module will
10+
be called vhost_net.
11+

drivers/vhost/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
obj-$(CONFIG_VHOST_NET) += vhost_net.o
2+
vhost_net-y := vhost.o net.o

0 commit comments

Comments
 (0)