|
|
7f1c5b |
From 9a234f849273d3480e4a88042cb1ea06a37a626b Mon Sep 17 00:00:00 2001
|
|
|
7f1c5b |
From: Cindy Lu <lulu@redhat.com>
|
|
|
7f1c5b |
Date: Thu, 22 Dec 2022 15:04:43 +0800
|
|
|
7f1c5b |
Subject: [PATCH 02/31] virtio-pci: decouple notifier from 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: [2/10] a20f4c9ff38b239531d12cbcc7deaa649c86abc3 (lulu6/qemu-kvm3)
|
|
|
7f1c5b |
|
|
|
7f1c5b |
https://bugzilla.redhat.com/show_bug.cgi?id=1905805
|
|
|
7f1c5b |
To reuse the notifier process. We add the virtio_pci_get_notifier
|
|
|
7f1c5b |
to get the notifier and vector. The INPUT for this function is IDX,
|
|
|
7f1c5b |
The OUTPUT is the notifier and the vector
|
|
|
7f1c5b |
|
|
|
7f1c5b |
Signed-off-by: Cindy Lu <lulu@redhat.com>
|
|
|
7f1c5b |
Message-Id: <20221222070451.936503-3-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 2e07f69d0c828e21515b63dc22884d548540b382)
|
|
|
7f1c5b |
Signed-off-by: Cindy Lu <lulu@redhat.com>
|
|
|
7f1c5b |
---
|
|
|
7f1c5b |
hw/virtio/virtio-pci.c | 88 +++++++++++++++++++++++++++---------------
|
|
|
7f1c5b |
1 file changed, 57 insertions(+), 31 deletions(-)
|
|
|
7f1c5b |
|
|
|
7f1c5b |
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
|
|
|
7f1c5b |
index a1c9dfa7bb..52c7692fff 100644
|
|
|
7f1c5b |
--- a/hw/virtio/virtio-pci.c
|
|
|
7f1c5b |
+++ b/hw/virtio/virtio-pci.c
|
|
|
7f1c5b |
@@ -728,29 +728,41 @@ static void kvm_virtio_pci_vq_vector_release(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
|
|
|
7f1c5b |
static int kvm_virtio_pci_irqfd_use(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
- unsigned int queue_no,
|
|
|
7f1c5b |
+ EventNotifier *n,
|
|
|
7f1c5b |
unsigned int vector)
|
|
|
7f1c5b |
{
|
|
|
7f1c5b |
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
|
|
|
7f1c5b |
- VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
7f1c5b |
- VirtQueue *vq = virtio_get_queue(vdev, queue_no);
|
|
|
7f1c5b |
- EventNotifier *n = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
return kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, n, NULL, irqfd->virq);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
|
|
|
7f1c5b |
static void kvm_virtio_pci_irqfd_release(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
- unsigned int queue_no,
|
|
|
7f1c5b |
+ EventNotifier *n ,
|
|
|
7f1c5b |
unsigned int vector)
|
|
|
7f1c5b |
{
|
|
|
7f1c5b |
- VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
7f1c5b |
- VirtQueue *vq = virtio_get_queue(vdev, queue_no);
|
|
|
7f1c5b |
- EventNotifier *n = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
VirtIOIRQFD *irqfd = &proxy->vector_irqfd[vector];
|
|
|
7f1c5b |
int ret;
|
|
|
7f1c5b |
|
|
|
7f1c5b |
ret = kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, n, irqfd->virq);
|
|
|
7f1c5b |
assert(ret == 0);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
+static int virtio_pci_get_notifier(VirtIOPCIProxy *proxy, int queue_no,
|
|
|
7f1c5b |
+ EventNotifier **n, unsigned int *vector)
|
|
|
7f1c5b |
+{
|
|
|
7f1c5b |
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
7f1c5b |
+ VirtQueue *vq;
|
|
|
7f1c5b |
+
|
|
|
7f1c5b |
+ if (queue_no == VIRTIO_CONFIG_IRQ_IDX) {
|
|
|
7f1c5b |
+ return -1;
|
|
|
7f1c5b |
+ } else {
|
|
|
7f1c5b |
+ if (!virtio_queue_get_num(vdev, queue_no)) {
|
|
|
7f1c5b |
+ return -1;
|
|
|
7f1c5b |
+ }
|
|
|
7f1c5b |
+ *vector = virtio_queue_vector(vdev, queue_no);
|
|
|
7f1c5b |
+ vq = virtio_get_queue(vdev, queue_no);
|
|
|
7f1c5b |
+ *n = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
+ }
|
|
|
7f1c5b |
+ return 0;
|
|
|
7f1c5b |
+}
|
|
|
7f1c5b |
|
|
|
7f1c5b |
static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
7f1c5b |
{
|
|
|
7f1c5b |
@@ -759,12 +771,15 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
7f1c5b |
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
7f1c5b |
unsigned int vector;
|
|
|
7f1c5b |
int ret, queue_no;
|
|
|
7f1c5b |
-
|
|
|
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 |
- vector = virtio_queue_vector(vdev, queue_no);
|
|
|
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 |
@@ -776,7 +791,7 @@ static int kvm_virtio_pci_vector_use(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
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, queue_no, vector);
|
|
|
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 |
@@ -792,7 +807,11 @@ undo:
|
|
|
7f1c5b |
continue;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
7f1c5b |
- kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
|
|
|
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 |
}
|
|
|
7f1c5b |
kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
@@ -806,12 +825,16 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
7f1c5b |
unsigned int vector;
|
|
|
7f1c5b |
int queue_no;
|
|
|
7f1c5b |
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
7f1c5b |
-
|
|
|
7f1c5b |
+ EventNotifier *n;
|
|
|
7f1c5b |
+ int ret ;
|
|
|
7f1c5b |
for (queue_no = 0; queue_no < nvqs; queue_no++) {
|
|
|
7f1c5b |
if (!virtio_queue_get_num(vdev, queue_no)) {
|
|
|
7f1c5b |
break;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
- vector = virtio_queue_vector(vdev, queue_no);
|
|
|
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 |
@@ -819,21 +842,20 @@ static void kvm_virtio_pci_vector_release(VirtIOPCIProxy *proxy, int nvqs)
|
|
|
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, queue_no, vector);
|
|
|
7f1c5b |
+ kvm_virtio_pci_irqfd_release(proxy, n, vector);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
kvm_virtio_pci_vq_vector_release(proxy, vector);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
|
|
|
7f1c5b |
-static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
+static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
unsigned int queue_no,
|
|
|
7f1c5b |
unsigned int vector,
|
|
|
7f1c5b |
- MSIMessage msg)
|
|
|
7f1c5b |
+ MSIMessage msg,
|
|
|
7f1c5b |
+ EventNotifier *n)
|
|
|
7f1c5b |
{
|
|
|
7f1c5b |
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
7f1c5b |
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
7f1c5b |
- VirtQueue *vq = virtio_get_queue(vdev, queue_no);
|
|
|
7f1c5b |
- EventNotifier *n = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
VirtIOIRQFD *irqfd;
|
|
|
7f1c5b |
int ret = 0;
|
|
|
7f1c5b |
|
|
|
7f1c5b |
@@ -860,14 +882,15 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
event_notifier_set(n);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
} else {
|
|
|
7f1c5b |
- ret = kvm_virtio_pci_irqfd_use(proxy, queue_no, vector);
|
|
|
7f1c5b |
+ ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
return ret;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
|
|
|
7f1c5b |
-static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
+static void virtio_pci_one_vector_mask(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
unsigned int queue_no,
|
|
|
7f1c5b |
- unsigned int vector)
|
|
|
7f1c5b |
+ unsigned int vector,
|
|
|
7f1c5b |
+ EventNotifier *n)
|
|
|
7f1c5b |
{
|
|
|
7f1c5b |
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
7f1c5b |
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
7f1c5b |
@@ -878,7 +901,7 @@ static void virtio_pci_vq_vector_mask(VirtIOPCIProxy *proxy,
|
|
|
7f1c5b |
if (vdev->use_guest_notifier_mask && k->guest_notifier_mask) {
|
|
|
7f1c5b |
k->guest_notifier_mask(vdev, queue_no, true);
|
|
|
7f1c5b |
} else {
|
|
|
7f1c5b |
- kvm_virtio_pci_irqfd_release(proxy, queue_no, vector);
|
|
|
7f1c5b |
+ kvm_virtio_pci_irqfd_release(proxy, n, vector);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
|
|
|
7f1c5b |
@@ -888,6 +911,7 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector,
|
|
|
7f1c5b |
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
|
|
|
7f1c5b |
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
7f1c5b |
VirtQueue *vq = virtio_vector_first_queue(vdev, vector);
|
|
|
7f1c5b |
+ EventNotifier *n;
|
|
|
7f1c5b |
int ret, index, unmasked = 0;
|
|
|
7f1c5b |
|
|
|
7f1c5b |
while (vq) {
|
|
|
7f1c5b |
@@ -896,7 +920,8 @@ static int virtio_pci_vector_unmask(PCIDevice *dev, unsigned vector,
|
|
|
7f1c5b |
break;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
if (index < proxy->nvqs_with_notifiers) {
|
|
|
7f1c5b |
- ret = virtio_pci_vq_vector_unmask(proxy, index, vector, msg);
|
|
|
7f1c5b |
+ n = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
+ ret = virtio_pci_one_vector_unmask(proxy, index, vector, msg, n);
|
|
|
7f1c5b |
if (ret < 0) {
|
|
|
7f1c5b |
goto undo;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
@@ -912,7 +937,8 @@ undo:
|
|
|
7f1c5b |
while (vq && unmasked >= 0) {
|
|
|
7f1c5b |
index = virtio_get_queue_index(vq);
|
|
|
7f1c5b |
if (index < proxy->nvqs_with_notifiers) {
|
|
|
7f1c5b |
- virtio_pci_vq_vector_mask(proxy, index, vector);
|
|
|
7f1c5b |
+ n = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
+ virtio_pci_one_vector_mask(proxy, index, vector, n);
|
|
|
7f1c5b |
--unmasked;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
vq = virtio_vector_next_queue(vq);
|
|
|
7f1c5b |
@@ -925,15 +951,17 @@ static void virtio_pci_vector_mask(PCIDevice *dev, unsigned vector)
|
|
|
7f1c5b |
VirtIOPCIProxy *proxy = container_of(dev, VirtIOPCIProxy, pci_dev);
|
|
|
7f1c5b |
VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
7f1c5b |
VirtQueue *vq = virtio_vector_first_queue(vdev, vector);
|
|
|
7f1c5b |
+ EventNotifier *n;
|
|
|
7f1c5b |
int index;
|
|
|
7f1c5b |
|
|
|
7f1c5b |
while (vq) {
|
|
|
7f1c5b |
index = virtio_get_queue_index(vq);
|
|
|
7f1c5b |
+ n = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
if (!virtio_queue_get_num(vdev, index)) {
|
|
|
7f1c5b |
break;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
if (index < proxy->nvqs_with_notifiers) {
|
|
|
7f1c5b |
- virtio_pci_vq_vector_mask(proxy, index, vector);
|
|
|
7f1c5b |
+ virtio_pci_one_vector_mask(proxy, index, vector, n);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
vq = virtio_vector_next_queue(vq);
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
@@ -949,19 +977,17 @@ static void virtio_pci_vector_poll(PCIDevice *dev,
|
|
|
7f1c5b |
int queue_no;
|
|
|
7f1c5b |
unsigned int vector;
|
|
|
7f1c5b |
EventNotifier *notifier;
|
|
|
7f1c5b |
- VirtQueue *vq;
|
|
|
7f1c5b |
+ int ret;
|
|
|
7f1c5b |
|
|
|
7f1c5b |
for (queue_no = 0; queue_no < proxy->nvqs_with_notifiers; queue_no++) {
|
|
|
7f1c5b |
- if (!virtio_queue_get_num(vdev, queue_no)) {
|
|
|
7f1c5b |
+ ret = virtio_pci_get_notifier(proxy, queue_no, ¬ifier, &vector);
|
|
|
7f1c5b |
+ if (ret < 0) {
|
|
|
7f1c5b |
break;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
- vector = virtio_queue_vector(vdev, queue_no);
|
|
|
7f1c5b |
if (vector < vector_start || vector >= vector_end ||
|
|
|
7f1c5b |
!msix_is_masked(dev, vector)) {
|
|
|
7f1c5b |
continue;
|
|
|
7f1c5b |
}
|
|
|
7f1c5b |
- vq = virtio_get_queue(vdev, queue_no);
|
|
|
7f1c5b |
- notifier = virtio_queue_get_guest_notifier(vq);
|
|
|
7f1c5b |
if (k->guest_notifier_pending) {
|
|
|
7f1c5b |
if (k->guest_notifier_pending(vdev, queue_no)) {
|
|
|
7f1c5b |
msix_set_pending(dev, vector);
|
|
|
7f1c5b |
--
|
|
|
7f1c5b |
2.31.1
|
|
|
7f1c5b |
|