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