|
|
ed5979 |
From 58cd577ff157cfaf7506bba135db58e75c330ff0 Mon Sep 17 00:00:00 2001
|
|
|
ed5979 |
From: Cindy Lu <lulu@redhat.com>
|
|
|
ed5979 |
Date: Thu, 22 Dec 2022 15:04:44 +0800
|
|
|
ed5979 |
Subject: [PATCH 03/31] virtio-pci: decouple the single vector from the
|
|
|
ed5979 |
interrupt process
|
|
|
ed5979 |
MIME-Version: 1.0
|
|
|
ed5979 |
Content-Type: text/plain; charset=UTF-8
|
|
|
ed5979 |
Content-Transfer-Encoding: 8bit
|
|
|
ed5979 |
|
|
|
ed5979 |
RH-Author: Cindy Lu <lulu@redhat.com>
|
|
|
ed5979 |
RH-MergeRequest: 132: vhost-vdpa: support config interrupt in vhost-vdpa
|
|
|
ed5979 |
RH-Bugzilla: 1905805
|
|
|
ed5979 |
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
|
|
ed5979 |
RH-Acked-by: Eugenio PĂ©rez <eperezma@redhat.com>
|
|
|
ed5979 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ed5979 |
RH-Commit: [3/10] 2c79cb678f005fb2f53b2db0f237347634ab3422 (lulu6/qemu-kvm3)
|
|
|
ed5979 |
|
|
|
ed5979 |
https://bugzilla.redhat.com/show_bug.cgi?id=1905805
|
|
|
ed5979 |
|
|
|
ed5979 |
To reuse the interrupt process in configure interrupt
|
|
|
ed5979 |
Need to decouple the single vector from the interrupt process.
|
|
|
ed5979 |
We add new function kvm_virtio_pci_vector_use_one and _release_one.
|
|
|
ed5979 |
These functions are used for the single vector, the whole process will
|
|
|
ed5979 |
finish in the loop with vq number.
|
|
|
ed5979 |
|
|
|
ed5979 |
Signed-off-by: Cindy Lu <lulu@redhat.com>
|
|
|
ed5979 |
Message-Id: <20221222070451.936503-4-lulu@redhat.com>
|
|
|
ed5979 |
Acked-by: Jason Wang <jasowang@redhat.com>
|
|
|
ed5979 |
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
ed5979 |
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
|
|
ed5979 |
(cherry picked from commit ee3b8dc6cc496ba7f4e27aed4493275c706a7942)
|
|
|
ed5979 |
Signed-off-by: Cindy Lu <lulu@redhat.com>
|
|
|
ed5979 |
---
|
|
|
ed5979 |
hw/virtio/virtio-pci.c | 131 +++++++++++++++++++++++------------------
|
|
|
ed5979 |
1 file changed, 73 insertions(+), 58 deletions(-)
|
|
|
ed5979 |
|
|
|
ed5979 |
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
|
|
|
ed5979 |
index 52c7692fff..ec816ea367 100644
|
|
|
ed5979 |
--- a/hw/virtio/virtio-pci.c
|
|
|
ed5979 |
+++ b/hw/virtio/virtio-pci.c
|
|
|
ed5979 |
@@ -699,7 +699,6 @@ static uint32_t virtio_read_config(PCIDevice *pci_dev,
|
|
|
ed5979 |
}
|
|
|
ed5979 |
|
|
|
ed5979 |
static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
|
|
|
ed5979 |
- unsigned int queue_no,
|
|
|
ed5979 |
unsigned int vector)
|
|
|
ed5979 |
{
|
|
|
ed5979 |
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
|
|
|
ed5979 |
@@ -764,87 +763,103 @@ static int virtio_pci_get_notifier(VirtIOPCIProxy *proxy, int queue_no,
|
|
|
ed5979 |
return 0;
|
|
|
ed5979 |
}
|
|
|
ed5979 |
|
|
|
ed5979 |
-static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
ed5979 |
+static int kvm_virtio_pci_vector_use_one(VirtIOPCIProxy *proxy, int queue_no)
|
|
|
ed5979 |
{
|
|
|
ed5979 |
+ unsigned int vector;
|
|
|
ed5979 |
+ int ret;
|
|
|
ed5979 |
+ EventNotifier *n;
|
|
|
ed5979 |
PCIDevice *dev = &proxy->pci_dev;
|
|
|
ed5979 |
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
ed5979 |
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
ed5979 |
- unsigned int vector;
|
|
|
ed5979 |
- int ret, queue_no;
|
|
|
ed5979 |
- EventNotifier *n;
|
|
|
ed5979 |
- for (queue_no = 0; queue_no < nvqs; queue_no++) {
|
|
|
ed5979 |
- if (!virtio_queue_get_num(vdev, queue_no)) {
|
|
|
ed5979 |
- break;
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- ret = virtio_pci_get_notifier(proxy, queue_no, &n, &vector);
|
|
|
ed5979 |
- if (ret < 0) {
|
|
|
ed5979 |
- break;
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- if (vector >= msix_nr_vectors_allocated(dev)) {
|
|
|
ed5979 |
- continue;
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- ret = kvm_virtio_pci_vq_vector_use(proxy, queue_no, vector);
|
|
|
ed5979 |
+
|
|
|
ed5979 |
+ ret = virtio_pci_get_notifier(proxy, queue_no, &n, &vector);
|
|
|
ed5979 |
+ if (ret < 0) {
|
|
|
ed5979 |
+ return ret;
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ if (vector >= msix_nr_vectors_allocated(dev)) {
|
|
|
ed5979 |
+ return 0;
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ ret = kvm_virtio_pci_vq_vector_use(proxy, vector);
|
|
|
ed5979 |
+ if (ret < 0) {
|
|
|
ed5979 |
+ goto undo;
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ /*
|
|
|
ed5979 |
+ * If guest supports masking, set up irqfd now.
|
|
|
ed5979 |
+ * Otherwise, delay until unmasked in the frontend.
|
|
|
ed5979 |
+ */
|
|
|
ed5979 |
+ if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
ed5979 |
+ ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
|
|
|
ed5979 |
if (ret < 0) {
|
|
|
ed5979 |
+ kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
ed5979 |
goto undo;
|
|
|
ed5979 |
}
|
|
|
ed5979 |
- /* If guest supports masking, set up irqfd now.
|
|
|
ed5979 |
- * Otherwise, delay until unmasked in the frontend.
|
|
|
ed5979 |
- */
|
|
|
ed5979 |
- if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
ed5979 |
- ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
|
|
|
ed5979 |
- if (ret < 0) {
|
|
|
ed5979 |
- kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
ed5979 |
- goto undo;
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
}
|
|
|
ed5979 |
- return 0;
|
|
|
ed5979 |
|
|
|
ed5979 |
+ return 0;
|
|
|
ed5979 |
undo:
|
|
|
ed5979 |
- while (--queue_no >= 0) {
|
|
|
ed5979 |
- vector = virtio_queue_vector(vdev, queue_no);
|
|
|
ed5979 |
- if (vector >= msix_nr_vectors_allocated(dev)) {
|
|
|
ed5979 |
- continue;
|
|
|
ed5979 |
+
|
|
|
ed5979 |
+ vector = virtio_queue_vector(vdev, queue_no);
|
|
|
ed5979 |
+ if (vector >= msix_nr_vectors_allocated(dev)) {
|
|
|
ed5979 |
+ return ret;
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
ed5979 |
+ ret = virtio_pci_get_notifier(proxy, queue_no, &n, &vector);
|
|
|
ed5979 |
+ if (ret < 0) {
|
|
|
ed5979 |
+ return ret;
|
|
|
ed5979 |
}
|
|
|
ed5979 |
- if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
ed5979 |
- ret = virtio_pci_get_notifier(proxy, queue_no, &n, &vector);
|
|
|
ed5979 |
- if (ret < 0) {
|
|
|
ed5979 |
- break;
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- kvm_virtio_pci_irqfd_release(proxy, n, vector);
|
|
|
ed5979 |
+ kvm_virtio_pci_irqfd_release(proxy, n, vector);
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ return ret;
|
|
|
ed5979 |
+}
|
|
|
ed5979 |
+static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
ed5979 |
+{
|
|
|
ed5979 |
+ int queue_no;
|
|
|
ed5979 |
+ int ret = 0;
|
|
|
ed5979 |
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
ed5979 |
+
|
|
|
ed5979 |
+ for (queue_no = 0; queue_no < nvqs; queue_no++) {
|
|
|
ed5979 |
+ if (!virtio_queue_get_num(vdev, queue_no)) {
|
|
|
ed5979 |
+ return -1;
|
|
|
ed5979 |
}
|
|
|
ed5979 |
- kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
ed5979 |
+ ret = kvm_virtio_pci_vector_use_one(proxy, queue_no);
|
|
|
ed5979 |
}
|
|
|
ed5979 |
return ret;
|
|
|
ed5979 |
}
|
|
|
ed5979 |
|
|
|
ed5979 |
-static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
ed5979 |
+
|
|
|
ed5979 |
+static void kvm_virtio_pci_vector_release_one(VirtIOPCIProxy *proxy,
|
|
|
ed5979 |
+ int queue_no)
|
|
|
ed5979 |
{
|
|
|
ed5979 |
- PCIDevice *dev = &proxy->pci_dev;
|
|
|
ed5979 |
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
ed5979 |
unsigned int vector;
|
|
|
ed5979 |
- int queue_no;
|
|
|
ed5979 |
- VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
ed5979 |
EventNotifier *n;
|
|
|
ed5979 |
- int ret ;
|
|
|
ed5979 |
+ int ret;
|
|
|
ed5979 |
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
ed5979 |
+ PCIDevice *dev = &proxy->pci_dev;
|
|
|
ed5979 |
+
|
|
|
ed5979 |
+ ret = virtio_pci_get_notifier(proxy, queue_no, &n, &vector);
|
|
|
ed5979 |
+ if (ret < 0) {
|
|
|
ed5979 |
+ return;
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ if (vector >= msix_nr_vectors_allocated(dev)) {
|
|
|
ed5979 |
+ return;
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
ed5979 |
+ kvm_virtio_pci_irqfd_release(proxy, n, vector);
|
|
|
ed5979 |
+ }
|
|
|
ed5979 |
+ kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
ed5979 |
+}
|
|
|
ed5979 |
+
|
|
|
ed5979 |
+static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
ed5979 |
+{
|
|
|
ed5979 |
+ int queue_no;
|
|
|
ed5979 |
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
ed5979 |
+
|
|
|
ed5979 |
for (queue_no = 0; queue_no < nvqs; queue_no++) {
|
|
|
ed5979 |
if (!virtio_queue_get_num(vdev, queue_no)) {
|
|
|
ed5979 |
break;
|
|
|
ed5979 |
}
|
|
|
ed5979 |
- ret = virtio_pci_get_notifier(proxy, queue_no, &n, &vector);
|
|
|
ed5979 |
- if (ret < 0) {
|
|
|
ed5979 |
- break;
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- if (vector >= msix_nr_vectors_allocated(dev)) {
|
|
|
ed5979 |
- continue;
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- /* If guest supports masking, clean up irqfd now.
|
|
|
ed5979 |
- * Otherwise, it was cleaned when masked in the frontend.
|
|
|
ed5979 |
- */
|
|
|
ed5979 |
- if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
ed5979 |
- kvm_virtio_pci_irqfd_release(proxy, n, vector);
|
|
|
ed5979 |
- }
|
|
|
ed5979 |
- kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
ed5979 |
+ kvm_virtio_pci_vector_release_one(proxy, queue_no);
|
|
|
ed5979 |
}
|
|
|
ed5979 |
}
|
|
|
ed5979 |
|
|
|
ed5979 |
--
|
|
|
ed5979 |
2.31.1
|
|
|
ed5979 |
|