Skip to contentSkip to conversation

kvm tools: Add ivshmem device

PATCH New Sasha Levin 1 participant 1 message Aug 29, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvm tools: Add ivshmem device

The patch adds an ivshmem device which can be used to share memory between guests on the same host.

This implementation is lacking inter-guest communication which should be implemented later once information regarding the client-server protocol is gathered, though infrastructure used to add and remove clients already exists in the patch (but isn't used anywhere).

Patch is based on David Evansky's shmem device.

---
 tools/kvm/Makefile                     |    1 +
 tools/kvm/builtin-run.c                |  134 ++++++++++++++++
 tools/kvm/hw/pci-shmem.c               |  266 ++++++++++++++++++++++++++++++++
 tools/kvm/include/kvm/pci-shmem.h      |   28 ++++
 tools/kvm/include/kvm/pci.h            |    3 +-
 tools/kvm/include/kvm/virtio-pci-dev.h |    3 +
 tools/kvm/pci.c                        |    5 +-
 tools/kvm/virtio/pci.c                 |    4 +-
 8 files changed, 438 insertions(+), 6 deletions(-)
 create mode 100644 tools/kvm/hw/pci-shmem.c
 create mode 100644 tools/kvm/include/kvm/pci-shmem.h
tools/kvm/Makefile +1 -0
index 25cbd7e..efa032d 100644
@@ -81,6 +81,7 @@ OBJS	+= virtio/9p.o
 OBJS	+= virtio/9p-pdu.o
 OBJS	+= hw/vesa.o
 OBJS	+= hw/i8042.o
+OBJS	+= hw/pci-shmem.o
 
 FLAGS_BFD := $(CFLAGS) -lbfd
 has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
tools/kvm/builtin-run.c +134 -0

164 lines not on this page · raw message

tools/kvm/hw/pci-shmem.c new file +266 -0

266 lines not on this page · raw message

tools/kvm/include/kvm/pci-shmem.h new file +28 -0
new file mode 100644
index 0000000..599ab37
@@ -0,0 +1,28 @@
+#ifndef KVM__PCI_SHMEM_H
+#define KVM__PCI_SHMEM_H
+
+#include <linux/types.h>
+#include <linux/list.h>
+
+#define SHMEM_DEFAULT_SIZE (16 << MB_SHIFT)
+#define SHMEM_DEFAULT_ADDR (0xc8000000)
+#define SHMEM_DEFAULT_HANDLE "/kvm_shmem"
+
+struct kvm;
+struct shmem_info;
+
+struct shmem_info {
+	u64 phys_addr;
+	u64 size;
+	char *handle;
+	int create;
+};
+
+int pci_shmem__init(struct kvm *self);
+int pci_shmem__register_mem(struct shmem_info *si);
+
+int pci_shmem__get_local_irqfd(struct kvm *kvm);
+int pci_shmem__add_client(struct kvm *kvm, u32 id, int fd);
+int pci_shmem__remove_client(struct kvm *kvm, u32 id);
+
+#endif
tools/kvm/include/kvm/pci.h +2 -1
index e74d3ec..5ee8005 100644
@@ -13,6 +13,7 @@
 #define PCI_CONFIG_ADDRESS	0xcf8
 #define PCI_CONFIG_DATA		0xcfc
 #define PCI_CONFIG_BUS_FORWARD	0xcfa
+#define PCI_IO_SIZE		0x100
 
 struct pci_config_address {
 	unsigned	zeros		: 2;		/* 1  .. 0  */
@@ -69,6 +70,6 @@ struct pci_device_header {
 
 void pci__init(void);
 void pci__register(struct pci_device_header *dev, u8 dev_num);
-u32 pci_get_io_space_block(void);
+u32 pci_get_io_space_block(u32 size);
 
 #endif /* KVM__PCI_H */
tools/kvm/include/kvm/virtio-pci-dev.h +3 -0
index 4eee831..bfcb076 100644
@@ -15,10 +15,13 @@
 #define PCI_DEVICE_ID_VIRTIO_BLN		0x1005
 #define PCI_DEVICE_ID_VIRTIO_P9			0x1009
 #define PCI_DEVICE_ID_VESA			0x2000
+#define PCI_DEVICE_ID_PCI_SHMEM			0x0001
 
 #define PCI_VENDOR_ID_REDHAT_QUMRANET		0x1af4
+#define PCI_VENDOR_ID_PCI_SHMEM			0x0001
 #define PCI_SUBSYSTEM_VENDOR_ID_REDHAT_QUMRANET	0x1af4
 
 #define PCI_SUBSYSTEM_ID_VESA			0x0004
+#define PCI_SUBSYSTEM_ID_PCI_SHMEM		0x0001
 
 #endif /* VIRTIO_PCI_DEV_H_ */
tools/kvm/pci.c +2 -3
index a046c19..d1afc05 100644
@@ -6,7 +6,6 @@
 #include <assert.h>
 
 #define PCI_MAX_DEVICES			256
-#define PCI_IO_SIZE			0x100
 #define PCI_BAR_OFFSET(b)		(offsetof(struct pci_device_header, bar[b]))
 
 static struct pci_device_header		*pci_devices[PCI_MAX_DEVICES];
@@ -16,10 +15,10 @@ static struct pci_config_address	pci_config_address;
 /* This is within our PCI gap - in an unused area */
 static u32 io_space_blocks		= KVM_32BIT_GAP_START + 0x1000000;
 
-u32 pci_get_io_space_block(void)
+u32 pci_get_io_space_block(u32 size)
 {
 	u32 block = io_space_blocks;
-	io_space_blocks += PCI_IO_SIZE;
+	io_space_blocks += size;
 
 	return block;
 }
tools/kvm/virtio/pci.c +2 -2
index 9e2a1ed..2745b25 100644
@@ -266,8 +266,8 @@ int virtio_pci__init(struct kvm *kvm, struct virtio_pci *vpci, void *dev,
 	u8 pin, line, ndev;
 
 	vpci->dev = dev;
-	vpci->msix_io_block = pci_get_io_space_block();
-	vpci->msix_pba_block = pci_get_io_space_block();
+	vpci->msix_io_block = pci_get_io_space_block(PCI_IO_SIZE);
+	vpci->msix_pba_block = pci_get_io_space_block(PCI_IO_SIZE);
 
 	vpci->base_addr = ioport__register(IOPORT_EMPTY, &virtio_pci__io_ops, IOPORT_SIZE, vpci);
 	kvm__register_mmio(kvm, vpci->msix_io_block, 0x100, callback_mmio_table, vpci);
Signature · 1 line
1.7.6.1