Skip to contentSkip to conversation

vhost-vdpa: make notifiers _init()/_uninit() symmetric

RFC In review Laurent Vivier 3 participants 5 messages Feb 11, 2022 – Feb 16, 2022

lore
Share & tools
lore
#0 lore raw

RFC 1/1 vhost-vdpa: make notifiers _init()/_uninit() symmetric

vhost_vdpa_host_notifiers_init() initializes queue notifiers for queues "dev->vq_index" to queue "dev->vq_index + dev->nvqs", whereas vhost_vdpa_host_notifiers_uninit() uninitializes the same notifiers for queue "0" to queue "dev->nvqs".

This asymmetry seems buggy, fix that by using dev->vq_index as the base for both.

Fixes d0416d487bd5 ("vhost-vdpa: map virtqueue notification area if possible")
---
 hw/virtio/vhost-vdpa.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
hw/virtio/vhost-vdpa.c +10 -10
index 04ea43704f5d..9be3dc66580c 100644
@@ -395,15 +395,6 @@ static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
     }
 }
 
-static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
-{
-    int i;
-
-    for (i = 0; i < n; i++) {
-        vhost_vdpa_host_notifier_uninit(dev, i);
-    }
-}
-
 static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
 {
     size_t page_size = qemu_real_host_page_size;
@@ -442,6 +433,15 @@ err:
     return -1;
 }
 
+static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
+{
+    int i;
+
+    for (i = dev->vq_index; i < dev->vq_index + n; i++) {
+        vhost_vdpa_host_notifier_uninit(dev, i);
+    }
+}
+
 static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
 {
     int i;
@@ -455,7 +455,7 @@ static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
     return;
 
 err:
-    vhost_vdpa_host_notifiers_uninit(dev, i);
+    vhost_vdpa_host_notifiers_uninit(dev, i - dev->vq_index);
     return;
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 38 lines · Laurent Vivier

vhost_vdpa_host_notifiers_init() initializes queue notifiers for queues "dev->vq_index" to queue "dev->vq_index + dev->nvqs", whereas vhost_vdpa_host_notifiers_uninit() uninitializes the same notifiers for queue "0" to queue "dev->nvqs".

This asymmetry seems buggy, fix that by using dev->vq_index as the base for both.

Fixes d0416d487bd5 ("vhost-vdpa: map virtqueue notification area if possible")
---
 hw/virtio/vhost-vdpa.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
hw/virtio/vhost-vdpa.c +0 -9
index 04ea43704f5d..9be3dc66580c 100644
@@ -395,15 +395,6 @@ static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
     }
 }
 
-static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
-{
-    int i;
-
-    for (i = 0; i < n; i++) {
-        vhost_vdpa_host_notifier_uninit(dev, i);
-    }
-}
-
 static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
 {
     size_t page_size = qemu_real_host_page_size;
@@ -442,6 +433,15 @@ err:
     return -1;

hw/virtio/vhost-vdpa.c err: · line 443

Quoted 10 lines
hw/virtio/vhost-vdpa.c +8 -0
 }
 
+static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
+{
+    int i;
+
+    for (i = dev->vq_index; i < dev->vq_index + n; i++) {
+        vhost_vdpa_host_notifier_uninit(dev, i);
+    }
+}

Patch looks good but I wonder why we need to move this function?

Thanks

Quoted 16 lines
hw/virtio/vhost-vdpa.c +2 -2
+
 static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
 {
     int i;
@@ -455,7 +455,7 @@ static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
     return;
 
 err:
-    vhost_vdpa_host_notifiers_uninit(dev, i);
+    vhost_vdpa_host_notifiers_uninit(dev, i - dev->vq_index);
     return;
 }
 
--

2.34.1

#2 lore raw
Quoted 41 lines · Jason Wang
Quoted 40 lines · Laurent Vivier

vhost_vdpa_host_notifiers_init() initializes queue notifiers for queues "dev->vq_index" to queue "dev->vq_index + dev->nvqs", whereas vhost_vdpa_host_notifiers_uninit() uninitializes the same notifiers for queue "0" to queue "dev->nvqs".

This asymmetry seems buggy, fix that by using dev->vq_index as the base for both.

Fixes d0416d487bd5 ("vhost-vdpa: map virtqueue notification area if possible")
---
  hw/virtio/vhost-vdpa.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
hw/virtio/vhost-vdpa.c +0 -9
index 04ea43704f5d..9be3dc66580c 100644
@@ -395,15 +395,6 @@ static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
      }
  }
 
-static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
-{
-    int i;
-
-    for (i = 0; i < n; i++) {
-        vhost_vdpa_host_notifier_uninit(dev, i);
-    }
-}
-
  static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
  {
      size_t page_size = qemu_real_host_page_size;
@@ -442,6 +433,15 @@ err:
      return -1;
  }
 
Quoted 10 lines

hw/virtio/vhost-vdpa.c err: · line 443

Quoted 8 lines
hw/virtio/vhost-vdpa.c +8 -0
+static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
+{
+    int i;
+
+    for (i = dev->vq_index; i < dev->vq_index + n; i++) {
+        vhost_vdpa_host_notifier_uninit(dev, i);
+    }
+}

Patch looks good but I wonder why we need to move this function?

I moved the _uninit function close to the _init one to be able to compare them easier. I think it will help reviewers in the future if code is side-by-side.

But we can let it at its original place.

Thanks,
Laurent

Acked-by
#3 lore raw
Quoted 54 lines · Laurent Vivier
Quoted 41 lines · Jason Wang
Quoted 40 lines · Laurent Vivier

vhost_vdpa_host_notifiers_init() initializes queue notifiers for queues "dev->vq_index" to queue "dev->vq_index + dev->nvqs", whereas vhost_vdpa_host_notifiers_uninit() uninitializes the same notifiers for queue "0" to queue "dev->nvqs".

This asymmetry seems buggy, fix that by using dev->vq_index as the base for both.

Fixes d0416d487bd5 ("vhost-vdpa: map virtqueue notification area if possible")
---
  hw/virtio/vhost-vdpa.c | 20 ++++++++++----------
  1 file changed, 10 insertions(+), 10 deletions(-)
hw/virtio/vhost-vdpa.c +0 -9
index 04ea43704f5d..9be3dc66580c 100644
@@ -395,15 +395,6 @@ static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
      }
  }
 
-static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
-{
-    int i;
-
-    for (i = 0; i < n; i++) {
-        vhost_vdpa_host_notifier_uninit(dev, i);
-    }
-}
-
  static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
  {
      size_t page_size = qemu_real_host_page_size;
@@ -442,6 +433,15 @@ err:
      return -1;
  }
 
Quoted 10 lines

hw/virtio/vhost-vdpa.c err: · line 443

Quoted 8 lines
hw/virtio/vhost-vdpa.c +8 -0
+static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
+{
+    int i;
+
+    for (i = dev->vq_index; i < dev->vq_index + n; i++) {
+        vhost_vdpa_host_notifier_uninit(dev, i);
+    }
+}

Patch looks good but I wonder why we need to move this function?

Quoted 2 lines

I moved the _uninit function close to the _init one to be able to compare them easier. I think it will help reviewers in the future if code is side-by-side.

Fine.

So

Thanks

Quoted 6 lines

But we can let it at its original place.

Thanks,
Laurent

Reviewed-by on v1 1/1
#4 lore raw
In reply to Laurent Vivier
Quoted 8 lines · Laurent Vivier

vhost_vdpa_host_notifiers_init() initializes queue notifiers for queues "dev->vq_index" to queue "dev->vq_index + dev->nvqs", whereas vhost_vdpa_host_notifiers_uninit() uninitializes the same notifiers for queue "0" to queue "dev->nvqs".

This asymmetry seems buggy, fix that by using dev->vq_index as the base for both.

Quoted 6 lines
Fixes d0416d487bd5 ("vhost-vdpa: map virtqueue notification area if possible")

---
hw/virtio/vhost-vdpa.c | 20 ++++++++++----------

1 file changed, 10 insertions(+), 10 deletions(-)
Quoted 50 lines
hw/virtio/vhost-vdpa.c +9 -9
index 04ea43704f5d..9be3dc66580c 100644
@@ -395,15 +395,6 @@ static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
    }
 }
 
-static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
-{
-    int i;
-
-    for (i = 0; i < n; i++) {
-        vhost_vdpa_host_notifier_uninit(dev, i);
-    }
-}
-
 static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
 {
    size_t page_size = qemu_real_host_page_size;
@@ -442,6 +433,15 @@ err:
    return -1;
 }
 
+static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
+{
+    int i;
+
+    for (i = dev->vq_index; i < dev->vq_index + n; i++) {
+        vhost_vdpa_host_notifier_uninit(dev, i);
+    }
+}
+
 static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
 {
    int i;
@@ -455,7 +455,7 @@ static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
    return;
 

err:

hw/virtio/vhost-vdpa.c +1 -1
-    vhost_vdpa_host_notifiers_uninit(dev, i);
+    vhost_vdpa_host_notifiers_uninit(dev, i - dev->vq_index);
    return;

}

Signature · 1 line
2.34.1