Skip to contentSkip to conversation

vdpasim: allow to enable a vq repeatedly

PATCH Superseded Eugenio Pérez 2 participants 3 messages May 19, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eugenio Pérez

author maintainer
#0 lore raw

PATCH 1/1 vdpasim: allow to enable a vq repeatedly

Code must be resilient to enable a queue many times.

At the moment the queue is resetting so it's definitely not the expected behavior.

Fixes 2c53d0f64c06 ("vdpasim: vDPA device simulator")
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +3 -2
index ddbe142af09a..b53cd00ad161 100644
@@ -355,9 +355,10 @@ static void vdpasim_set_vq_ready(struct vdpa_device *vdpa, u16 idx, bool ready)
 	struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
 
 	spin_lock(&vdpasim->lock);
-	vq->ready = ready;
-	if (vq->ready)
+	if (!vq->ready) {
+		vq->ready = ready;
 		vdpasim_queue_ready(vdpasim, idx);
+	}
 	spin_unlock(&vdpasim->lock);
 }
 
Signature · 1 line
2.27.0
#1 lore raw
Quoted 17 lines · Eugenio Pérez

Code must be resilient to enable a queue many times.

At the moment the queue is resetting so it's definitely not the expected behavior.

Fixes 2c53d0f64c06 ("vdpasim: vDPA device simulator")

---
drivers/vdpa/vdpa_sim/vdpa_sim.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +0 -0
index ddbe142af09a..b53cd00ad161 100644

drivers/vdpa/vdpa_sim/vdpa_sim.c static void vdpasim_set_vq_ready(struct vdpa_device *vdpa, u16 idx, bool ready) · line 361

Quoted 9 lines
drivers/vdpa/vdpa_sim/vdpa_sim.c +3 -2
@@ -355,9 +355,10 @@ static void vdpasim_set_vq_ready(struct vdpa_device *vdpa, u16 idx, bool ready)
 	struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
 
 	spin_lock(&vdpasim->lock);
-	vq->ready = ready;
-	if (vq->ready)
+	if (!vq->ready) {
+		vq->ready = ready;
 		vdpasim_queue_ready(vdpasim, idx);
+	}

But this way the first time vq->ready is set to true, then it will never be set back to false.

Should we leave the assignment out of the block? Maybe after the if block to avoid the problem we are fixing.

Thanks,
Stefano

author maintainer
#2 lore raw
Quoted 21 lines · Stefano Garzarella
Quoted 19 lines · Eugenio Pérez

Code must be resilient to enable a queue many times.

At the moment the queue is resetting so it's definitely not the expected behavior.

Fixes 2c53d0f64c06 ("vdpasim: vDPA device simulator")

---
drivers/vdpa/vdpa_sim/vdpa_sim.c | 5 +++--

1 file changed, 3 insertions(+), 2 deletions(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +0 -0
index ddbe142af09a..b53cd00ad161 100644
@@ -355,9 +355,10 @@ static void vdpasim_set_vq_ready(struct vdpa_device *vdpa, u16 idx, bool ready)
      struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
 
Quoted 11 lines

drivers/vdpa/vdpa_sim/vdpa_sim.c static void vdpasim_set_vq_ready(struct vdpa_device *vdpa, u16 idx, bool ready) · line 361

Quoted 7 lines
drivers/vdpa/vdpa_sim/vdpa_sim.c +3 -2
      spin_lock(&vdpasim->lock);
-      vq->ready = ready;
-      if (vq->ready)
+      if (!vq->ready) {
+              vq->ready = ready;
              vdpasim_queue_ready(vdpasim, idx);
+      }

But this way the first time vq->ready is set to true, then it will never be set back to false.

You're right, I had in mind to reset the flow before enabling as the only possibility.

Sending v2 with that part fixed, thanks!

Quoted 6 lines

Should we leave the assignment out of the block? Maybe after the if block to avoid the problem we are fixing.

Thanks,
Stefano