[PATCH kvmtool v2 02/12] virtio: Extract init_vq() for PCI and MMIO

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

 



Modern virtio will need to reuse this code when initializing a
virtqueue. It's not much, but still nicer to have next to exit_vq().

Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@xxxxxxx>
---
 virtio/mmio.c | 19 +++++++++++++++----
 virtio/pci.c  | 19 +++++++++++++++----
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/virtio/mmio.c b/virtio/mmio.c
index 268a4391..2a96e0e3 100644
--- a/virtio/mmio.c
+++ b/virtio/mmio.c
@@ -79,6 +79,20 @@ int virtio_mmio_signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq)
 	return 0;
 }
 
+static int virtio_mmio_init_vq(struct kvm *kvm, struct virtio_device *vdev,
+			       int vq)
+{
+	int ret;
+	struct virtio_mmio *vmmio = vdev->virtio;
+
+	ret = virtio_mmio_init_ioeventfd(vmmio->kvm, vdev, vq);
+	if (ret) {
+		pr_err("couldn't add ioeventfd for vq %d: %d", vq, ret);
+		return ret;
+	}
+	return vdev->ops->init_vq(vmmio->kvm, vmmio->dev, vq);
+}
+
 static void virtio_mmio_exit_vq(struct kvm *kvm, struct virtio_device *vdev,
 				int vq)
 {
@@ -200,10 +214,7 @@ static void virtio_mmio_config_out(struct kvm_cpu *vcpu,
 				.align	= vmmio->hdr.queue_align,
 				.pgsize	= vmmio->hdr.guest_page_size,
 			};
-			virtio_mmio_init_ioeventfd(vmmio->kvm, vdev,
-						   vmmio->hdr.queue_sel);
-			vdev->ops->init_vq(vmmio->kvm, vmmio->dev,
-					   vmmio->hdr.queue_sel);
+			virtio_mmio_init_vq(kvm, vdev, vmmio->hdr.queue_sel);
 		} else {
 			virtio_mmio_exit_vq(kvm, vdev, vmmio->hdr.queue_sel);
 		}
diff --git a/virtio/pci.c b/virtio/pci.c
index 9b710852..f0459925 100644
--- a/virtio/pci.c
+++ b/virtio/pci.c
@@ -128,6 +128,20 @@ free_ioport_evt:
 	return r;
 }
 
+static int virtio_pci_init_vq(struct kvm *kvm, struct virtio_device *vdev,
+			      int vq)
+{
+	int ret;
+	struct virtio_pci *vpci = vdev->virtio;
+
+	ret = virtio_pci__init_ioeventfd(kvm, vdev, vq);
+	if (ret) {
+		pr_err("couldn't add ioeventfd for vq %d: %d", vq, ret);
+		return ret;
+	}
+	return vdev->ops->init_vq(kvm, vpci->dev, vq);
+}
+
 static void virtio_pci_exit_vq(struct kvm *kvm, struct virtio_device *vdev,
 			       int vq)
 {
@@ -314,10 +328,7 @@ static bool virtio_pci__data_out(struct kvm_cpu *vcpu, struct virtio_device *vde
 				.align	= VIRTIO_PCI_VRING_ALIGN,
 				.pgsize	= 1 << VIRTIO_PCI_QUEUE_ADDR_SHIFT,
 			};
-			virtio_pci__init_ioeventfd(kvm, vdev,
-						   vpci->queue_selector);
-			vdev->ops->init_vq(kvm, vpci->dev,
-					   vpci->queue_selector);
+			virtio_pci_init_vq(kvm, vdev, vpci->queue_selector);
 		} else {
 			virtio_pci_exit_vq(kvm, vdev, vpci->queue_selector);
 		}
-- 
2.36.1




[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