kvm tools: Implement virtio network device
PATCH 1/1 kvm tools: Implement virtio network device
This patch implement virtio network device.
Use '-n virtio or --network=virtio' to enable it.
The current implementation uses tap which needs root privileges to create a virtual network device (tap0) on host side. Actually, what we need is CAP_NET_ADMIN.
The host side tap0 is set to 192.168.33.2/24.
You need to configure the guest side eth0 to any ip address in 192.168.33.0/24.
Here are some scp performance test for differenct implementations:
None of rx and tx as thread:
guest to host 3.2MB/s
host to guest 3.1MB/s
Only rx as thread:
guest to host 14.7MB/s
host to guest 33.4MB/s
Both rx and tx as thread(This patch works this way):
guest to host 19.8MB/s
host to guest 32.5MB/s
--- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/ioport.h | 2 + tools/kvm/include/kvm/types.h | 7 + tools/kvm/include/kvm/virtio-net.h | 7 + tools/kvm/kvm-run.c | 11 ++ tools/kvm/virtio-net.c | 318 ++++++++++++++++++++++++++++++++++++ 6 files changed, 346 insertions(+), 0 deletions(-) create mode 100644 tools/kvm/include/kvm/types.h create mode 100644 tools/kvm/include/kvm/virtio-net.h create mode 100644 tools/kvm/virtio-net.c
tools/kvm/Makefile +1 -0
@@ -14,6 +14,7 @@ TAGS = ctags OBJS += 8250-serial.o OBJS += virtio-blk.o +OBJS += virtio-net.o OBJS += virtio-console.o OBJS += cpuid.o OBJS += read-write.o
tools/kvm/include/kvm/ioport.h +2 -0
@@ -10,6 +10,8 @@#define IOPORT_VIRTIO_BLK_SIZE 256#define IOPORT_VIRTIO_CONSOLE 0xd200/* Virtio console device */ #define IOPORT_VIRTIO_CONSOLE_SIZE 256 +#define IOPORT_VIRTIO_NET 0xe200/* Virtio network device */ +#define IOPORT_VIRTIO_NET_SIZE 256struct kvm ;
tools/kvm/include/kvm/types.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef KVM_TYPES_H +#define KVM_TYPES_H + +/* FIXME: include/linux/if_tun.h and include/linux/if_ether.h complains */ +#define __be16 u16 + +#endif /* KVM_TYPES_H */
tools/kvm/include/kvm/virtio-net.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef KVM__VIRTIO_NET_H +#define KVM__VIRTIO_NET_H + +struct kvm ; +void virtio_net__init (struct kvm *self); + +#endif /* KVM__VIRTIO_NET_H */
tools/kvm/kvm-run.c +11 -0
@@ -16,6 +16,7 @@#include <kvm/kvm-cpu.h> #include <kvm/8250-serial.h> #include <kvm/virtio-blk.h> +#include <kvm/virtio-net.h> #include <kvm/virtio-console.h> #include <kvm/disk-image.h> #include <kvm/util.h>
@@ -29,6 +30,7 @@#define DEFAULT_KVM_DEV "/dev/kvm"#define DEFAULT_CONSOLE "serial" +#define DEFAULT_NETWORK "none"#define MB_SHIFT (20)#define MIN_RAM_SIZE_MB (64ULL)
@@ -63,6 +65,7 @@ static const char *initrd_filename;static const char *image_filename;static const char *console;static const char *kvm_dev; +static const char *network;static bool single_step;static bool readonly_image;extern bool ioport_debug;
@@ -84,6 +87,8 @@ static const struct option options[] = { "Don't write changes back to disk image"),OPT_STRING ('c' ,"console" , &console,"serial or virtio" ,"Console to use" ), +OPT_STRING ('n' ,"network" , &network,"virtio" , +"Network to use" ),OPT_GROUP ("Kernel options:" ), OPT_STRING('k', "kernel", &kernel_filename, "kernel",
@@ -250,6 +255,12 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)virtio_console__init (kvm); +if (!network) + network =DEFAULT_NETWORK ; + +if (!strncmp (network,"virtio" ,6 )) +virtio_net__init (kvm); +kvm__start_timer (kvm);for (i =0 ; i < nrcpus; i++) {
tools/kvm/virtio-net.c new file +318 -0
318 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Quoted 20 lines · Asias He
This patch implement virtio network device.
Use '-n virtio or --network=virtio' to enable it.The current implementation uses tap which needs root privileges to create a virtual network device (tap0) on host side. Actually, what we need is
CAP_NET_ADMIN.The host side tap0 is set to 192.168.33.2/24.
You need to configure the guest side eth0 to any ip address in 192.168.33.0/24.Here are some scp performance test for differenct implementations:
None of rx and tx as thread:
guest to host 3.2MB/s
host to guest 3.1MB/sOnly rx as thread:
guest to host 14.7MB/s
host to guest 33.4MB/s
Quoted 5 lines
Both rx and tx as thread(This patch works this way):
guest to host 19.8MB/s
host to guest 32.5MB/sSigned-off-by Asias He<[email protected]>
This is already in master. Thanks!
Quoted 22 lines · Pekka Enberg
Quoted 21 lines · Asias He
This patch implement virtio network device.
Use '-n virtio or --network=virtio' to enable it.The current implementation uses tap which needs root privileges to create a
virtual network device (tap0) on host side. Actually, what we need isCAP_NET_ADMIN.The host side tap0 is set to 192.168.33.2/24.
You need to configure the guest side eth0 to any ip address in 192.168.33.0/24.Here are some scp performance test for differenct implementations:
None of rx and tx as thread:
guest to host 3.2MB/s
host to guest 3.1MB/sOnly rx as thread:
guest to host 14.7MB/s
host to guest 33.4MB/s
Quoted 8 lines
Quoted 5 lines
Both rx and tx as thread(This patch works this way):
guest to host 19.8MB/s
host to guest 32.5MB/sSigned-off-by Asias He<[email protected]>This is already in master. Thanks!
Ingo suggested to CC the updated version of this patch to kvm list. So I am posting this patch again.
Signature · 2 lines
Best Regards, Asias He
Quoted 13 lines · Asias He
Quoted 13 lines
Quoted 13 lines
Here are some scp performance test for differenct implementations:
None of rx and tx as thread:
guest to host 3.2MB/s
host to guest 3.1MB/sOnly rx as thread:
guest to host 14.7MB/s
host to guest 33.4MB/sBoth rx and tx as thread(This patch works this way):
guest to host 19.8MB/s
host to guest 32.5MB/s
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Asias He<[email protected]>This is already in master. Thanks!
Ingo suggested to CC the updated version of this patch to kvm list. So I am posting this patch again.
Thanks Asias, cool stuff.
Maybe other KVM developers want to chime in about how to best implement transparent (non-TAP-using) guest-side networking.
The best approach would be to not go down as low as the IP/Ethernet packeting level (it's unnecessary protocol overhead), but to implement some sort of streaming, virtio based TCP connection proxying support.
Strictly talking the guest does not need ICMP packets to have working Internet connectivity - only passing/tunneling through TCP sockets would be enough. The following highlevel ops are needed:
- connect/shutdown/close
- send/receive
- poll
And would be passed through to the host side and mirrored there into real connect/shutdown TCP socket ops and into send/receive ops.
The guest OS does not need to be 'aware' of this in any way, as long as the bzImage has this magic guest tunneling support included.
Obviously, such a highlevel approach would be much faster as well than any packet level virtual networking approach.
Does something like this exist upstream, or do we have to implement it?
Thanks,
Ingo
Quoted 43 lines · Ingo Molnar
Quoted 13 lines · Asias He
Quoted 13 lines
Quoted 13 lines
Here are some scp performance test for differenct implementations:
None of rx and tx as thread:
guest to host 3.2MB/s
host to guest 3.1MB/sOnly rx as thread:
guest to host 14.7MB/s
host to guest 33.4MB/sBoth rx and tx as thread(This patch works this way):
guest to host 19.8MB/s
host to guest 32.5MB/sQuoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Asias He<[email protected]>This is already in master. Thanks!
Ingo suggested to CC the updated version of this patch to kvm list. So I am posting this patch again.
Thanks Asias, cool stuff.
Maybe other KVM developers want to chime in about how to best implement transparent (non-TAP-using) guest-side networking.
The best approach would be to not go down as low as the IP/Ethernet packeting level (it's unnecessary protocol overhead), but to implement some sort of streaming, virtio based TCP connection proxying support.
Strictly talking the guest does not need ICMP packets to have working Internet connectivity - only passing/tunneling through TCP sockets would be enough. The following highlevel ops are needed:
- connect/shutdown/close
- send/receive
- pollAnd would be passed through to the host side and mirrored there into real connect/shutdown TCP socket ops and into send/receive ops.
Quoted 8 lines
The guest OS does not need to be 'aware' of this in any way, as long as the bzImage has this magic guest tunneling support included.
Obviously, such a highlevel approach would be much faster as well than any packet level virtual networking approach.
Does something like this exist upstream, or do we have to implement it?
macvtap does non-privileged setupless networking.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 48 lines · Avi Kivity
Quoted 47 lines · Ingo Molnar
Quoted 13 lines · Asias He
Quoted 13 lines
Quoted 13 lines
Here are some scp performance test for differenct implementations:
None of rx and tx as thread:
guest to host 3.2MB/s
host to guest 3.1MB/sOnly rx as thread:
guest to host 14.7MB/s
host to guest 33.4MB/sBoth rx and tx as thread(This patch works this way):
guest to host 19.8MB/s
host to guest 32.5MB/sQuoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Asias He<[email protected]>This is already in master. Thanks!
Ingo suggested to CC the updated version of this patch to kvm
list. So I
Quoted 1 line
am posting this patch again.
Thanks Asias, cool stuff.
Maybe other KVM developers want to chime in about how to best implement transparent (non-TAP-using) guest-side networking.
The best approach would be to not go down as low as the IP/Ethernet packeting level (it's unnecessary protocol overhead), but to implement some sort of streaming, virtio based TCP connection proxying support.
Strictly talking the guest does not need ICMP packets to have working Internet connectivity - only passing/tunneling through TCP sockets would be enough. The following highlevel ops are needed:
- connect/shutdown/close
- send/receive
- pollAnd would be passed through to the host side and mirrored there into real connect/shutdown TCP socket ops and into send/receive ops.
The guest OS does not need to be 'aware' of this in any way, as long as the bzImage has this magic guest tunneling support included.
Quoted 8 lines
Quoted 5 lines
Obviously, such a highlevel approach would be much faster as well than any packet level virtual networking approach.
Does something like this exist upstream, or do we have to implement it?
macvtap does non-privileged setupless networking.
But this doesn't really answer your message. No, there is no tcp-level virtio device. However, because of GSO/GRO, I don't think there is a huge win to be gained by bypassing the lower layers. If you want to send a megabyte's worth of data into a tcp stream, you prepend a header and post it to virtio-net, and this goes all the way down to the real device.
I'm not sure tcp-offload like you propose would pass netdev@. Similar approaches for real hardware were rejected since they would bypass the tcp stack. Things like netfilter would no longer work.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 52 lines · Avi Kivity
Quoted 51 lines · Ingo Molnar
Quoted 13 lines · Asias He
Quoted 13 lines
Quoted 13 lines
Here are some scp performance test for differenct implementations:
None of rx and tx as thread:
guest to host 3.2MB/s
host to guest 3.1MB/sOnly rx as thread:
guest to host 14.7MB/s
host to guest 33.4MB/sBoth rx and tx as thread(This patch works this way):
guest to host 19.8MB/s
host to guest 32.5MB/sQuoted 6 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Asias He<[email protected]>This is already in master. Thanks!
Ingo suggested to CC the updated version of this patch to kvm list.
So I
Quoted 1 line
am posting this patch again.
Thanks Asias, cool stuff.
Maybe other KVM developers want to chime in about how to best implement transparent (non-TAP-using) guest-side networking.
The best approach would be to not go down as low as the IP/Ethernet packeting
level (it's unnecessary protocol overhead), but to implement some sort of streaming, virtio based TCP connection proxying support.Strictly talking the guest does not need ICMP packets to have working Internet
connectivity - only passing/tunneling through TCP sockets would be enough. The
following highlevel ops are needed:- connect/shutdown/close
- send/receive
- pollAnd would be passed through to the host side and mirrored there into real connect/shutdown TCP socket ops and into send/receive ops.
The guest OS does not need to be 'aware' of this in any way, as long as the
bzImage has this magic guest tunneling support included.
Quoted 8 lines
Quoted 6 lines
Obviously, such a highlevel approach would be much faster as well than any
packet level virtual networking approach.Does something like this exist upstream, or do we have to implement it?
macvtap does non-privileged setupless networking.
Great! Thanks Avi!
Signature · 2 lines
Best Regards, Asias He
Quoted 2 lines · Ingo Molnar
Strictly talking the guest does not need ICMP packets to have working Internet connectivity - only passing/tunneling through TCP sockets would be enough.
Don't forget UDP for DNS.
Stefan