Skip to contentSkip to conversation

kvm tools: Use GSI routing

PATCH New Sasha Levin 1 participant 4 messages Jul 28, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 kvm tools: Use GSI routing

Map GSIs manually when starting the guest.
This will allow us mapping new GSIs for MSIX in the future.

---
 tools/kvm/builtin-run.c     |    3 ++
 tools/kvm/include/kvm/irq.h |    5 +++
 tools/kvm/irq.c             |   80 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 0 deletions(-)
tools/kvm/builtin-run.c +3 -0
index 941129c..bf54448 100644
@@ -35,6 +35,7 @@
 #include <kvm/vnc.h>
 #include <kvm/sdl.h>
 #include <kvm/framebuffer.h>
+#include <kvm/irq.h>
 
 /* header files for gitish interface  */
 #include <kvm/builtin-run.h>
@@ -573,6 +574,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	kvm = kvm__init(kvm_dev, ram_size, guest_name);
 
+	irq__init(kvm);
+
 	kvm->single_step = single_step;
 
 	ioeventfd__init();
tools/kvm/include/kvm/irq.h +5 -0
index 7a75a0c..401bee9 100644
@@ -5,6 +5,8 @@
 #include <linux/rbtree.h>
 #include <linux/list.h>
 
+struct kvm;
+
 struct irq_line {
 	u8			line;
 	struct list_head	node;
@@ -21,4 +23,7 @@ int irq__register_device(u32 dev, u8 *num, u8 *pin, u8 *line);
 
 struct rb_node *irq__get_pci_tree(void);
 
+void irq__init(struct kvm *kvm);
+int irq__add_msix_route(struct kvm *kvm, u32 low, u32 high, u32 data);
+
 #endif
tools/kvm/irq.c +80 -0

102 lines not on this page · raw message

Signature · 1 line
1.7.6
#1 lore raw

PATCH v2 2/4 kvm tools: Fix PCI probing

PCI BAR probing is done in four steps:

1. Read address (and flags).
2. Mask BAR.
3. Read BAR again - Now the expected result is the size of the BAR.
4. Mask BAR with address.

So far, we have only took care of the first step. This means that the kernel was using address as the size, causing a PCI allocation blunder.

This patch fixes the issue by passing a proper size after masking.

---
 tools/kvm/include/kvm/pci.h |    1 +
 tools/kvm/pci.c             |   60 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 56 insertions(+), 5 deletions(-)
tools/kvm/include/kvm/pci.h +1 -0
index 6ad4426..a7532e3 100644
@@ -51,5 +51,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);
 
 #endif /* KVM__PCI_H */
tools/kvm/pci.c +55 -5

87 lines not on this page · raw message

Signature · 1 line
1.7.6
#2 lore raw

PATCH v2 3/4 kvm tools: Add a void ptr to be passed to mmio callback

In reply to Sasha Levin

This makes MMIO callback similar to it's PIO counterpart by passing a void* value provided in the registration to the callback function.

This allows to keep context within the MMIO callback function.

---
 tools/kvm/include/kvm/kvm.h |    2 +-
 tools/kvm/mmio.c            |   10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)
tools/kvm/include/kvm/kvm.h +1 -1
index eeb55b6..5f3cbbf 100644
@@ -64,7 +64,7 @@ void kvm__irq_line(struct kvm *kvm, int irq, int level);
 bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count);
 bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_write);
 void kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr);
-bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write));
+bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr), void *ptr);
 bool kvm__deregister_mmio(struct kvm *kvm, u64 phys_addr);
 void kvm__pause(void);
 void kvm__continue(void);
tools/kvm/mmio.c +6 -4
index 64bef37..de7320f 100644
@@ -14,7 +14,8 @@
 
 struct mmio_mapping {
 	struct rb_int_node	node;
-	void			(*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write);
+	void			(*mmio_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr);
+	void			*ptr;
 };
 
 static struct rb_root mmio_tree = RB_ROOT;
@@ -55,7 +56,7 @@ static const char *to_direction(u8 is_write)
 	return "read";
 }
 
-bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*kvm_mmio_callback_fn)(u64 addr, u8 *data, u32 len, u8 is_write))
+bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void (*mmio_fn)(u64 addr, u8 *data, u32 len, u8 is_write, void *ptr), void *ptr)
 {
 	struct mmio_mapping *mmio;
 	struct kvm_coalesced_mmio_zone zone;
@@ -67,7 +68,8 @@ bool kvm__register_mmio(struct kvm *kvm, u64 phys_addr, u64 phys_addr_len, void
 
 	*mmio = (struct mmio_mapping) {
 		.node = RB_INT_INIT(phys_addr, phys_addr + phys_addr_len),
-		.kvm_mmio_callback_fn = kvm_mmio_callback_fn,
+		.mmio_fn = mmio_fn,
+		.ptr	= ptr,
 	};
 
 	zone = (struct kvm_coalesced_mmio_zone) {
@@ -120,7 +122,7 @@ bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 *data, u32 len, u8 is_
 	mmio = mmio_search(&mmio_tree, phys_addr, len);
 
 	if (mmio)
-		mmio->kvm_mmio_callback_fn(phys_addr, data, len, is_write);
+		mmio->mmio_fn(phys_addr, data, len, is_write, mmio->ptr);
 	else
 		fprintf(stderr, "Warning: Ignoring MMIO %s at %016llx (length %u)\n",
 			to_direction(is_write), phys_addr, len);
Signature · 1 line
1.7.6
#3 lore raw

PATCH v2 4/4 kvm tools: Implement MSI-X for virtio-rng

In reply to Sasha Levin

This patch implements basic MSI-X support for virtio-rng.

The device uses the virtio preferred method of working with MSI-X by creating one vector for configuration and one vector for each vq in the device.

---
 tools/kvm/include/kvm/pci.h |   16 +++++++++++++
 tools/kvm/virtio/rng.c      |   53 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 64 insertions(+), 5 deletions(-)
tools/kvm/include/kvm/pci.h +16 -0
index a7532e3..27fa349 100644
@@ -24,6 +24,21 @@ struct pci_config_address {
 	unsigned	enable_bit	: 1;		/* 31       */
 };
 
+struct msix_table {
+	u32 low;
+	u32 high;
+	u32 data;
+	u32 ctrl;
+};
+
+struct msix_cap {
+	u8 cap;
+	u8 next;
+	u16 table_size;
+	u32 table_offset;
+	struct msix_table table[3 * PCI_MSIX_ENTRY_SIZE];
+};
+
 struct pci_device_header {
 	u16		vendor_id;
 	u16		device_id;
@@ -47,6 +62,7 @@ struct pci_device_header {
 	u8		irq_pin;
 	u8		min_gnt;
 	u8		max_lat;
+	struct msix_cap msix;
 };
 
 void pci__init(void);
tools/kvm/virtio/rng.c +48 -5

106 lines not on this page · raw message

Signature · 1 line
1.7.6