[PATCH 1/2] kvm tools: Move ioeventfd registration to virtio-pci

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch removed ioeventfd registration from devices and moves it
to a single place in virtio-pci layer.

Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx>
---
 tools/kvm/include/kvm/virtio-pci.h |    6 ++++++
 tools/kvm/virtio/9p.c              |   21 ---------------------
 tools/kvm/virtio/balloon.c         |   20 +-------------------
 tools/kvm/virtio/blk.c             |   21 ---------------------
 tools/kvm/virtio/net.c             |   19 -------------------
 tools/kvm/virtio/pci.c             |   33 +++++++++++++++++++++++++++++++++
 tools/kvm/virtio/rng.c             |   15 ---------------
 7 files changed, 40 insertions(+), 95 deletions(-)

diff --git a/tools/kvm/include/kvm/virtio-pci.h b/tools/kvm/include/kvm/virtio-pci.h
index 0c2a035..ce44e84 100644
--- a/tools/kvm/include/kvm/virtio-pci.h
+++ b/tools/kvm/include/kvm/virtio-pci.h
@@ -22,6 +22,11 @@ struct virtio_pci_ops {
 	int (*get_size_vq)(struct kvm *kvm, void *dev, u32 vq);
 };
 
+struct virtio_pci_ioevent_param {
+	struct virtio_pci	*vpci;
+	u32			vq;
+};
+
 struct virtio_pci {
 	struct pci_device_header pci_hdr;
 	struct virtio_pci_ops	ops;
@@ -43,6 +48,7 @@ struct virtio_pci {
 
 	/* virtio queue */
 	u16			queue_selector;
+	struct virtio_pci_ioevent_param ioeventfds[VIRTIO_PCI_MAX_VQ];
 };
 
 int virtio_pci__init(struct kvm *kvm, struct virtio_pci *vpci, void *dev,
diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c
index 1682e64..0dffc7a 100644
--- a/tools/kvm/virtio/9p.c
+++ b/tools/kvm/virtio/9p.c
@@ -2,7 +2,6 @@
 #include "kvm/ioport.h"
 #include "kvm/util.h"
 #include "kvm/threadpool.h"
-#include "kvm/ioeventfd.h"
 #include "kvm/irq.h"
 #include "kvm/virtio-9p.h"
 #include "kvm/guest_compat.h"
@@ -1116,13 +1115,6 @@ static void virtio_p9_do_io(struct kvm *kvm, void *param)
 	}
 }
 
-static void ioevent_callback(struct kvm *kvm, void *param)
-{
-	struct p9_dev_job *job = param;
-
-	thread_pool__do_job(&job->job_id);
-}
-
 static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
 {
 	struct p9_dev *p9dev = dev;
@@ -1155,7 +1147,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	struct p9_dev_job *job;
 	struct virt_queue *queue;
 	void *p;
-	struct ioevent ioevent;
 
 	compat__remove_message(p9dev->compat_id);
 
@@ -1172,18 +1163,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	};
 	thread_pool__init_job(&job->job_id, kvm, virtio_p9_do_io, job);
 
-	ioevent = (struct ioevent) {
-		.io_addr	= p9dev->vpci.base_addr + VIRTIO_PCI_QUEUE_NOTIFY,
-		.io_len		= sizeof(u16),
-		.fn		= ioevent_callback,
-		.fn_ptr		= &p9dev->jobs[vq],
-		.datamatch	= vq,
-		.fn_kvm		= kvm,
-		.fd		= eventfd(0, 0),
-	};
-
-	ioeventfd__add_event(&ioevent);
-
 	return 0;
 }
 
diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
index 6b93121..0f24539 100644
--- a/tools/kvm/virtio/balloon.c
+++ b/tools/kvm/virtio/balloon.c
@@ -7,7 +7,6 @@
 #include "kvm/kvm.h"
 #include "kvm/pci.h"
 #include "kvm/threadpool.h"
-#include "kvm/ioeventfd.h"
 #include "kvm/guest_compat.h"
 #include "kvm/virtio-pci.h"
 
@@ -21,6 +20,7 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <pthread.h>
+#include <sys/eventfd.h>
 
 #define NUM_VIRT_QUEUES		3
 #define VIRTIO_BLN_QUEUE_SIZE	128
@@ -125,11 +125,6 @@ static void virtio_bln_do_io(struct kvm *kvm, void *param)
 	}
 }
 
-static void ioevent_callback(struct kvm *kvm, void *param)
-{
-	thread_pool__do_job(param);
-}
-
 static int virtio_bln__collect_stats(void)
 {
 	u64 tmp;
@@ -230,7 +225,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	struct bln_dev *bdev = dev;
 	struct virt_queue *queue;
 	void *p;
-	struct ioevent ioevent;
 
 	compat__remove_message(bdev->compat_id);
 
@@ -241,18 +235,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	thread_pool__init_job(&bdev->jobs[vq], kvm, virtio_bln_do_io, queue);
 	vring_init(&queue->vring, VIRTIO_BLN_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN);
 
-	ioevent = (struct ioevent) {
-		.io_addr	= bdev->vpci.base_addr + VIRTIO_PCI_QUEUE_NOTIFY,
-		.io_len		= sizeof(u16),
-		.fn		= ioevent_callback,
-		.fn_ptr		= &bdev->jobs[vq],
-		.datamatch	= vq,
-		.fn_kvm		= kvm,
-		.fd		= eventfd(0, 0),
-	};
-
-	ioeventfd__add_event(&ioevent);
-
 	return 0;
 }
 
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 2e047d7..5f312b5 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -122,13 +122,6 @@ static void virtio_blk_do_io(struct kvm *kvm, struct virt_queue *vq, struct blk_
 	}
 }
 
-static void ioevent_callback(struct kvm *kvm, void *param)
-{
-	struct blk_dev *bdev = param;
-
-	virtio_blk_do_io(kvm, &bdev->vqs[0], bdev);
-}
-
 static void set_config(struct kvm *kvm, void *dev, u8 data, u32 offset)
 {
 	struct blk_dev *bdev = dev;
@@ -160,7 +153,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	struct blk_dev *bdev = dev;
 	struct virt_queue *queue;
 	void *p;
-	struct ioevent ioevent;
 
 	compat__remove_message(bdev->compat_id);
 
@@ -170,18 +162,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 
 	vring_init(&queue->vring, VIRTIO_BLK_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN);
 
-	ioevent = (struct ioevent) {
-		.io_addr	= bdev->vpci.base_addr + VIRTIO_PCI_QUEUE_NOTIFY,
-		.io_len		= sizeof(u16),
-		.fn		= ioevent_callback,
-		.fn_ptr		= bdev,
-		.datamatch	= vq,
-		.fn_kvm		= kvm,
-		.fd		= eventfd(0, 0),
-	};
-
-	ioeventfd__add_event(&ioevent);
-
 	return 0;
 }
 
@@ -261,7 +241,6 @@ void virtio_blk__delete_all(struct kvm *kvm)
 		struct blk_dev *bdev;
 
 		bdev = list_first_entry(&bdevs, struct blk_dev, list);
-		ioeventfd__del_event(bdev->vpci.base_addr + VIRTIO_PCI_QUEUE_NOTIFY, 0);
 		list_del(&bdev->list);
 		free(bdev);
 	}
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 6247642..4661e06 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -7,7 +7,6 @@
 #include "kvm/kvm.h"
 #include "kvm/irq.h"
 #include "kvm/uip.h"
-#include "kvm/ioeventfd.h"
 #include "kvm/guest_compat.h"
 #include "kvm/virtio-pci.h"
 
@@ -170,11 +169,6 @@ static void virtio_net_handle_callback(struct kvm *kvm, u16 queue_index)
 	}
 }
 
-static void ioevent_callback(struct kvm *kvm, void *param)
-{
-	virtio_net_handle_callback(kvm, (u64)(long)param);
-}
-
 static bool virtio_net__tap_init(const struct virtio_net_parameters *params)
 {
 	int sock = socket(AF_INET, SOCK_STREAM, 0);
@@ -337,7 +331,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	struct net_dev *ndev = dev;
 	struct virt_queue *queue;
 	void *p;
-	struct ioevent ioevent;
 
 	compat__remove_message(ndev->compat_id);
 
@@ -347,18 +340,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 
 	vring_init(&queue->vring, VIRTIO_NET_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN);
 
-	ioevent = (struct ioevent) {
-		.io_addr	= ndev->vpci.base_addr + VIRTIO_PCI_QUEUE_NOTIFY,
-		.io_len		= sizeof(u16),
-		.fn		= ioevent_callback,
-		.fn_ptr		= (void *)(u64)vq,
-		.datamatch	= vq,
-		.fn_kvm		= kvm,
-		.fd		= eventfd(0, 0),
-	};
-
-	ioeventfd__add_event(&ioevent);
-
 	return 0;
 }
 
diff --git a/tools/kvm/virtio/pci.c b/tools/kvm/virtio/pci.c
index 7181123..bb77f55 100644
--- a/tools/kvm/virtio/pci.c
+++ b/tools/kvm/virtio/pci.c
@@ -5,6 +5,7 @@
 #include "kvm/virtio-pci-dev.h"
 #include "kvm/irq.h"
 #include "kvm/virtio.h"
+#include "kvm/ioeventfd.h"
 
 #include <linux/virtio_pci.h>
 #include <string.h>
@@ -14,6 +15,37 @@ static inline bool virtio_pci__msix_enabled(struct virtio_pci *vpci)
 	return vpci->pci_hdr.msix.ctrl & PCI_MSIX_FLAGS_ENABLE;
 }
 
+static void virtio_pci__ioevent_callback(struct kvm *kvm, void *param)
+{
+	struct virtio_pci_ioevent_param *ioeventfd = param;
+
+	ioeventfd->vpci->ops.notify_vq(kvm, ioeventfd->vpci->dev, ioeventfd->vq);
+}
+
+static int virtio_pci__init_ioeventfd(struct kvm *kvm, struct virtio_pci *vpci, u32 vq)
+{
+	struct ioevent ioevent;
+
+	vpci->ioeventfds[vq] = (struct virtio_pci_ioevent_param) {
+		.vpci		= vpci,
+		.vq		= vq,
+	};
+
+	ioevent = (struct ioevent) {
+		.io_addr	= vpci->base_addr + VIRTIO_PCI_QUEUE_NOTIFY,
+		.io_len		= sizeof(u16),
+		.fn		= virtio_pci__ioevent_callback,
+		.fn_ptr		= &vpci->ioeventfds[vq],
+		.datamatch	= vq,
+		.fn_kvm		= kvm,
+		.fd		= eventfd(0, 0),
+	};
+
+	ioeventfd__add_event(&ioevent);
+
+	return 0;
+}
+
 static bool virtio_pci__specific_io_in(struct kvm *kvm, struct virtio_pci *vpci, u16 port,
 					void *data, int size, int offset)
 {
@@ -140,6 +172,7 @@ static bool virtio_pci__io_out(struct ioport *ioport, struct kvm *kvm, u16 port,
 		break;
 	case VIRTIO_PCI_QUEUE_PFN:
 		val = ioport__read32(data);
+		virtio_pci__init_ioeventfd(kvm, vpci, vpci->queue_selector);
 		vpci->ops.init_vq(kvm, vpci->dev, vpci->queue_selector, val);
 		break;
 	case VIRTIO_PCI_QUEUE_SEL:
diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c
index 5bea56c..dc97729 100644
--- a/tools/kvm/virtio/rng.c
+++ b/tools/kvm/virtio/rng.c
@@ -6,7 +6,6 @@
 #include "kvm/util.h"
 #include "kvm/kvm.h"
 #include "kvm/threadpool.h"
-#include "kvm/ioeventfd.h"
 #include "kvm/guest_compat.h"
 #include "kvm/virtio-pci.h"
 
@@ -97,7 +96,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	struct virt_queue *queue;
 	struct rng_dev_job *job;
 	void *p;
-	struct ioevent ioevent;
 
 	compat__remove_message(rdev->compat_id);
 
@@ -114,18 +112,6 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 		.rdev		= rdev,
 	};
 
-	ioevent = (struct ioevent) {
-		.io_addr	= rdev->vpci.base_addr + VIRTIO_PCI_QUEUE_NOTIFY,
-		.io_len		= sizeof(u16),
-		.fn		= virtio_rng_do_io,
-		.fn_ptr		= &rdev->jobs[vq],
-		.datamatch	= vq,
-		.fn_kvm		= kvm,
-		.fd		= eventfd(0, 0),
-	};
-
-	ioeventfd__add_event(&ioevent);
-
 	thread_pool__init_job(&job->job_id, kvm, virtio_rng_do_io, job);
 
 	return 0;
@@ -192,7 +178,6 @@ void virtio_rng__delete_all(struct kvm *kvm)
 
 		rdev = list_first_entry(&rdevs, struct rng_dev, list);
 		list_del(&rdev->list);
-		ioeventfd__del_event(rdev->vpci.base_addr + VIRTIO_PCI_QUEUE_NOTIFY, 0);
 		free(rdev);
 	}
 }
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux