Skip to contentSkip to conversation

virt-core: binding together drivers and hypervisors

PATCH New Michael S. Tsirkin 1 participant 3 messages May 31, 2009 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): cover.1243796281.git.mst@sherwood.(none)

#1 lore raw

PATCH 1/3 virt-core: binding together drivers and hypervisors

This adds support for virt-core: generic glue making it possible to implement kernel-level accelerators (drivers) which are independent of a hypervisor, that is can in theory work on top of either kvm or lguest.

Each driver and hypervisor registers with core, and then when user adds a virtual device, drivers can find and interfact with hypervisors through the virt_dev object.

Users add devices by making a hypervisor-specific system call (e.g. ioctl) the result of which is a file descriptor controlling the device.

---
 arch/x86/kvm/Kconfig     |    1 +
 drivers/Makefile         |    1 +
 drivers/virt/Kconfig     |    5 ++
 drivers/virt/Makefile    |    1 +
 drivers/virt/virt_core.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/virt.h     |   94 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 213 insertions(+), 0 deletions(-)
 create mode 100644 drivers/virt/Kconfig
 create mode 100644 drivers/virt/Makefile
 create mode 100644 drivers/virt/virt_core.c
 create mode 100644 include/linux/virt.h
arch/x86/kvm/Kconfig +1 -0
index a58504e..693b807 100644
@@ -71,6 +71,7 @@ config KVM_TRACE
 
 # OK, it's a little counter-intuitive to do this, but it puts it neatly under
 # the virtualization menu.
+source drivers/virt/Kconfig
 source drivers/lguest/Kconfig
 source drivers/virtio/Kconfig
 
drivers/Makefile +1 -0
index 1266ead..9f14b08 100644
@@ -104,6 +104,7 @@ obj-$(CONFIG_HID)		+= hid/
 obj-$(CONFIG_PPC_PS3)		+= ps3/
 obj-$(CONFIG_OF)		+= of/
 obj-$(CONFIG_SSB)		+= ssb/
+obj-$(CONFIG_VIRT_CORE)		+= virt/
 obj-$(CONFIG_VIRTIO)		+= virtio/
 obj-$(CONFIG_STAGING)		+= staging/
 obj-y				+= platform/
drivers/virt/Kconfig new file +5 -0
new file mode 100644
index 0000000..ace7b2e
@@ -0,0 +1,5 @@
+config VIRT_CORE
+	tristate "Generic virtual device binding support"
+	---help---
+	  Core support for binding kernel drivers to virtual devices.
+	  Make sure to also select any drivers you wish to use.
drivers/virt/Makefile new file +1 -0
new file mode 100644
index 0000000..7a77047
@@ -0,0 +1 @@
+obj-$(CONFIG_VIRT_CORE) += virt_core.o
drivers/virt/virt_core.c new file +111 -0

111 lines not on this page · raw message

include/linux/virt.h new file +94 -0

94 lines not on this page · raw message

Signature · 1 line
1.6.3.1.175.g3be7e0
#2 lore raw

PATCH 2/3 kvm: virtual device support

In reply to a message not in the archive

Implement virt_hypervisor in kvm, and add support for creating virtual devices.

---
 include/linux/kvm.h      |   13 ++++++++++++
 include/linux/kvm_host.h |    3 ++
 virt/kvm/kvm_main.c      |   47 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+), 0 deletions(-)
include/linux/kvm.h +13 -0
index 8cc1379..8f6cc79 100644
@@ -487,6 +487,8 @@ struct kvm_irq_routing {
 #define KVM_REINJECT_CONTROL      _IO(KVMIO, 0x71)
 #define KVM_DEASSIGN_PCI_DEVICE _IOW(KVMIO, 0x72, \
 				     struct kvm_assigned_pci_dev)
+#define KVM_CREATE_VIRT_DEVICE  _IOW(KVMIO, 0x73, \
+				     struct kvm_create_virt_device)
 
 /*
  * ioctls for vcpu fds
@@ -602,6 +604,17 @@ struct kvm_assigned_irq {
 	};
 };
 
+struct kvm_create_virt_device {
+	__s32 flags; /* flags from open(2). Only O_CLOEXEC supported for now. */
+	__u32 id_len;
+	union {
+		__u32 reserved[12];
+	};
+	/* Followed by up to MAX_ID_LEN byte id. */
+};
+
+#define KVM_VIRT_DEVICE_MAX_ID_LEN	200
+
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU	(1 << 0)
 
 #define KVM_DEV_IRQ_ASSIGN_MSI_ACTION	KVM_DEV_IRQ_ASSIGN_ENABLE_MSI
include/linux/kvm_host.h +3 -0
index 894a56e..7131851 100644
@@ -26,6 +26,8 @@
 
 #include <asm/kvm_host.h>
 
+#include <linux/virt.h>
+
 /*
  * vcpu->requests bit members
  */
@@ -152,6 +154,7 @@ struct kvm {
 	unsigned long mmu_notifier_seq;
 	long mmu_notifier_count;
 #endif
+	struct virt_hypervisor hypervisor;
 };
 
 /* The guest did something we don't support. */
virt/kvm/kvm_main.c +47 -0

71 lines not on this page · raw message

Signature · 1 line
1.6.3.1.175.g3be7e0
#3 lore raw

PATCH 3/3 virt_irq: virtual device for injecting interrupts

In reply to a message not in the archive

virt_irq is an alternative to irqfd interface, based on the virt core infrastructure, which also serves as an example of virt core usage.

The main advantage here compared to irqfd is the use of fd created by the virt core, which avoids any possibility of deadlock issues with eventfd and kvm file descriptors referencing each other.

As a minor positive side effect, we don't need an extra lock and don't need to schedule work to inject the interrupt.

---
 drivers/virt/Kconfig     |    6 +++
 drivers/virt/Makefile    |    1 +
 drivers/virt/virt_irq.c  |   78 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/virt_irq.h |   19 +++++++++++
 4 files changed, 104 insertions(+), 0 deletions(-)
 create mode 100644 drivers/virt/virt_irq.c
 create mode 100644 include/linux/virt_irq.h
drivers/virt/Kconfig +6 -0
index ace7b2e..060c8da 100644
@@ -3,3 +3,9 @@ config VIRT_CORE
 	---help---
 	  Core support for binding kernel drivers to virtual devices.
 	  Make sure to also select any drivers you wish to use.
+
+config VIRT_IRQ
+	tristate "Virtual device for injecting interrupts from userspace"
+	depends on VIRT_CORE
+	---help---
+	  Simple virtual device that supports injecting interrupts.
drivers/virt/Makefile +1 -0
index 7a77047..0072530 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_VIRT_CORE) += virt_core.o
+obj-$(CONFIG_VIRT_IRQ) += virt_irq.o
drivers/virt/virt_irq.c new file +78 -0

78 lines not on this page · raw message

include/linux/virt_irq.h new file +19 -0
new file mode 100644
index 0000000..6b3421d
@@ -0,0 +1,19 @@
+#ifndef LINUX_VIRT_IRQ_H
+#define LINUX_VIRT_IRQ_H
+
+#include <linux/types.h>
+
+/* Format for IRQ device id */
+
+struct virt_irq_id {
+	__u8 name[4]; /* Must be "irq\0" */
+	__u32 irq;
+};
+
+static inline void virt_irq_id_init(struct virt_irq_id *id, int irq)
+{
+	memcpy(id->name, "irq", sizeof id->name);
+	id->irq = irq;
+}
+
+#endif
Signature · 1 line
1.6.3.1.175.g3be7e0