Skip to contentSkip to conversation

vhost: Don't set vring call if guest notifier is disabled

PATCH Superseded [email protected] 3 participants 3 messages Feb 18, 2025 – Feb 28, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: Don't set vring call if guest notifier is disabled

From: Huaitong Han <[email protected]>

The vring call fd is set even when the guest does not use MSIX (e.g., virtio PMD). This results in unnecessary CPU overhead for handling virtio interrupts. The previous patch only optimized the condition when query_queue_notifier was enabled and the vector was unset. However, if query_queue_notifier is disabled, the vring call FD should also be unset to avoid this inefficiency.

---
 hw/virtio/vhost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +2 -2
index 6aa72fd434..d17e7cc6fe 100644
@@ -1342,8 +1342,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev,
     }
 
     if (k->query_guest_notifiers &&
-        k->query_guest_notifiers(qbus->parent) &&
-        virtio_queue_vector(vdev, idx) == VIRTIO_NO_VECTOR) {
+        (!k->query_guest_notifiers(qbus->parent) ||
+            virtio_queue_vector(vdev, idx) == VIRTIO_NO_VECTOR)) {
         file.fd = -1;
         r = dev->vhost_ops->vhost_set_vring_call(dev, &file);
         if (r) {
Signature · 1 line
2.43.5
#1 lore raw
Quoted 5 lines · On Tue, Feb 18, 2025 at 04:32:08PM +0800, [email protected] wrote:

From: Huaitong Han <[email protected]>

The vring call fd is set even when the guest does not use MSIX (e.g., virtio PMD). This results in unnecessary CPU overhead for handling virtio interrupts. The previous patch only optimized the condition when query_queue_notifier was

Which patch/commit are you referring to?

The last commit touching that check is commit 96a3d98d2c ("vhost: don't set vring call if no vector"), but I'm not sure if you are referring to it. If it's the case, please add it in that form in the description.

It would also be better to add the Fixes tag as well and Cc stable if we would like to have this fix in the stable branch.

Thanks,
Stefano

Quoted 27 lines

enabled and the vector was unset. However, if query_queue_notifier is disabled, the vring call FD should also be unset to avoid this inefficiency.

---
hw/virtio/vhost.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +2 -2
index 6aa72fd434..d17e7cc6fe 100644
@@ -1342,8 +1342,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev,
    }
 
    if (k->query_guest_notifiers &&
-        k->query_guest_notifiers(qbus->parent) &&
-        virtio_queue_vector(vdev, idx) == VIRTIO_NO_VECTOR) {
+        (!k->query_guest_notifiers(qbus->parent) ||
+            virtio_queue_vector(vdev, idx) == VIRTIO_NO_VECTOR)) {
        file.fd = -1;
        r = dev->vhost_ops->vhost_set_vring_call(dev, &file);
        if (r) {
Signature · 1 line
2.43.5
Tested-by
#2 lore raw

I tested this patch with virtio-net regression tests, everything works fine.

Quoted 49 lines · Stefano Garzarella
Quoted 5 lines · On Tue, Feb 18, 2025 at 04:32:08PM +0800, [email protected] wrote:

From: Huaitong Han <[email protected]>

The vring call fd is set even when the guest does not use MSIX (e.g., virtio PMD). This results in unnecessary CPU overhead for handling virtio interrupts. The previous patch only optimized the condition when query_queue_notifier was

Which patch/commit are you referring to?

The last commit touching that check is commit 96a3d98d2c ("vhost: don't set vring call if no vector"), but I'm not sure if you are referring to it. If it's the case, please add it in that form in the description.

It would also be better to add the Fixes tag as well and Cc stable if we would like to have this fix in the stable branch.

Thanks,
Stefano

Quoted 27 lines

enabled and the vector was unset. However, if query_queue_notifier is disabled, the vring call FD should also be unset to avoid this inefficiency.

---
hw/virtio/vhost.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost.c +2 -3
index 6aa72fd434..d17e7cc6fe 100644
@@ -1342,8 +1342,8 @@ int vhost_virtqueue_start(struct vhost_dev *dev,
    }
 
    if (k->query_guest_notifiers &&
-        k->query_guest_notifiers(qbus->parent) &&
-        virtio_queue_vector(vdev, idx) == VIRTIO_NO_VECTOR) {
+        (!k->query_guest_notifiers(qbus->parent) ||
+            virtio_queue_vector(vdev, idx) == VIRTIO_NO_VECTOR)) {
        file.fd = -1;
        r = dev->vhost_ops->vhost_set_vring_call(dev, &file);
        if (r) {
--

2.43.5