Skip to contentSkip to conversation

kvm tools: Fix virtio console pci class number and device id number

PATCH New Asias He 1 participant 4 messages Apr 12, 2011 KVM

lore
Share & tools
lore

Asias He

author
#0 lore raw

PATCH 1/4 kvm tools: Fix virtio console pci class number and device id number

Make lscpi report correct device name

---
 tools/kvm/virtio-console.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/kvm/virtio-console.c +2 -2
index a140aea..9675090 100644
@@ -212,7 +212,7 @@ static struct ioport_operations virtio_console_io_ops = {
 };
 
 #define PCI_VENDOR_ID_REDHAT_QUMRANET		0x1af4
-#define PCI_DEVICE_ID_VIRTIO_CONSOLE		0x1002
+#define PCI_DEVICE_ID_VIRTIO_CONSOLE		0x1003
 #define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET	0x1af4
 #define PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE		0x0003
 
@@ -221,7 +221,7 @@ static struct pci_device_header virtio_console_pci_device = {
 	.device_id		= PCI_DEVICE_ID_VIRTIO_CONSOLE,
 	.header_type		= PCI_HEADER_TYPE_NORMAL,
 	.revision_id		= 0,
-	.class			= (0x07 << 8) | (0x80 << 4) | (0x0 << 0),
+	.class			= 0x078000,
 	.subsys_vendor_id	= PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET,
 	.subsys_id		= PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE,
 	.bar[0]			= IOPORT_VIRTIO_CONSOLE | PCI_BASE_ADDRESS_SPACE_IO,
Signature · 1 line
1.7.4.1
author
#1 lore raw

PATCH 2/4 kvm tools: Do not forget to take the lock in virtio_console_pci_io_out

---
 tools/kvm/virtio-console.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/kvm/virtio-console.c +2 -0
index 9675090..aa9b1bd 100644
@@ -163,6 +163,8 @@ static bool virtio_console_pci_io_out(struct kvm *self, uint16_t port, void *dat
 	unsigned long offset = port - IOPORT_VIRTIO_CONSOLE;
 	bool ret = true;
 
+	mutex_lock(&console_device.mutex);
+
 	switch (offset) {
 	case VIRTIO_PCI_GUEST_FEATURES:
 		console_device.guest_features	= ioport__read32(data);
Signature · 1 line
1.7.4.1
author
#2 lore raw

PATCH 3/4 kvm tools: Let's use irq pin 2 for virtio console

In reply to Asias He

Left irq pin 3 for virtio networking

---
 tools/kvm/virtio-console.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kvm/virtio-console.c +1 -1
index aa9b1bd..14f61ae 100644
@@ -227,7 +227,7 @@ static struct pci_device_header virtio_console_pci_device = {
 	.subsys_vendor_id	= PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET,
 	.subsys_id		= PCI_SUBSYSTEM_ID_VIRTIO_CONSOLE,
 	.bar[0]			= IOPORT_VIRTIO_CONSOLE | PCI_BASE_ADDRESS_SPACE_IO,
-	.irq_pin		= 3,
+	.irq_pin		= 2,
 	.irq_line		= VIRTIO_CONSOLE_IRQ,
 };
 
Signature · 1 line
1.7.4.1
author
#3 lore raw

PATCH 4/4 kvm tools: Implement virtio network device

In reply to Asias He

This patch implement virtio network device.

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 tread:
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                |    3 +
 tools/kvm/virtio-net.c             |  321 ++++++++++++++++++++++++++++++++++++
 6 files changed, 341 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
index 7a2863d..6895113 100644
@@ -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
index 0218329..2fdcca4 100644
@@ -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		256
 
 struct kvm;
 
tools/kvm/include/kvm/types.h new file +7 -0
new file mode 100644
index 0000000..0cbc5fb
@@ -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
new file mode 100644
index 0000000..a1cab15
@@ -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 +3 -0
index 8f6ebdc..5cfeddc 100644
@@ -13,6 +13,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>
@@ -215,6 +216,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	virtio_console__init(kvm);
 
+	virtio_net__init(kvm);
+
 	kvm__start_timer(kvm);
 
 	for (i = 0; i < nrcpus; i++) {
tools/kvm/virtio-net.c new file +321 -0

321 lines not on this page · raw message

Signature · 1 line
1.7.4.1