diff mbox series

[RFC,v4,16/20] vhost: Check for device VRING_USED_F_NO_NOTIFY at shadow virtqueue kick

Message ID 20211001070603.307037-17-eperezma@redhat.com
State New
Headers show
Series vDPA shadow virtqueue | expand

Commit Message

Eugenio Perez Martin Oct. 1, 2021, 7:05 a.m. UTC
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/virtio/vhost-shadow-virtqueue.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Jason Wang Oct. 13, 2021, 4:35 a.m. UTC | #1
在 2021/10/1 下午3:05, Eugenio Pérez 写道:
> Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> ---
>   hw/virtio/vhost-shadow-virtqueue.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
> index df7e6fa3ec..775f8d36a0 100644
> --- a/hw/virtio/vhost-shadow-virtqueue.c
> +++ b/hw/virtio/vhost-shadow-virtqueue.c
> @@ -173,6 +173,15 @@ static void vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem)
>       svq->ring_id_maps[qemu_head] = elem;
>   }
>   
> +static void vhost_svq_kick(VhostShadowVirtqueue *svq)
> +{
> +    /* Make sure we are reading updated device flag */


I guess this would be better:

         /* We need to expose available array entries before checking used
          * flags. */

(Borrowed from kernel codes).

Thanks


> +    smp_mb();
> +    if (!(svq->vring.used->flags & VRING_USED_F_NO_NOTIFY)) {
> +        event_notifier_set(&svq->kick_notifier);
> +    }
> +}
> +
>   /* Handle guest->device notifications */
>   static void vhost_handle_guest_kick(EventNotifier *n)
>   {
> @@ -197,7 +206,7 @@ static void vhost_handle_guest_kick(EventNotifier *n)
>               }
>   
>               vhost_svq_add(svq, elem);
> -            event_notifier_set(&svq->kick_notifier);
> +            vhost_svq_kick(svq);
>           }
>   
>           virtio_queue_set_notification(svq->vq, true);
Eugenio Perez Martin Oct. 15, 2021, 6:17 a.m. UTC | #2
On Wed, Oct 13, 2021 at 6:35 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> 在 2021/10/1 下午3:05, Eugenio Pérez 写道:
> > Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
> > ---
> >   hw/virtio/vhost-shadow-virtqueue.c | 11 ++++++++++-
> >   1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
> > index df7e6fa3ec..775f8d36a0 100644
> > --- a/hw/virtio/vhost-shadow-virtqueue.c
> > +++ b/hw/virtio/vhost-shadow-virtqueue.c
> > @@ -173,6 +173,15 @@ static void vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem)
> >       svq->ring_id_maps[qemu_head] = elem;
> >   }
> >
> > +static void vhost_svq_kick(VhostShadowVirtqueue *svq)
> > +{
> > +    /* Make sure we are reading updated device flag */
>
>
> I guess this would be better:
>
>          /* We need to expose available array entries before checking used
>           * flags. */
>
> (Borrowed from kernel codes).
>
> Thanks
>

Right, I will replace it, thanks!

>
> > +    smp_mb();
> > +    if (!(svq->vring.used->flags & VRING_USED_F_NO_NOTIFY)) {
> > +        event_notifier_set(&svq->kick_notifier);
> > +    }
> > +}
> > +
> >   /* Handle guest->device notifications */
> >   static void vhost_handle_guest_kick(EventNotifier *n)
> >   {
> > @@ -197,7 +206,7 @@ static void vhost_handle_guest_kick(EventNotifier *n)
> >               }
> >
> >               vhost_svq_add(svq, elem);
> > -            event_notifier_set(&svq->kick_notifier);
> > +            vhost_svq_kick(svq);
> >           }
> >
> >           virtio_queue_set_notification(svq->vq, true);
>
diff mbox series

Patch

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index df7e6fa3ec..775f8d36a0 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -173,6 +173,15 @@  static void vhost_svq_add(VhostShadowVirtqueue *svq, VirtQueueElement *elem)
     svq->ring_id_maps[qemu_head] = elem;
 }
 
+static void vhost_svq_kick(VhostShadowVirtqueue *svq)
+{
+    /* Make sure we are reading updated device flag */
+    smp_mb();
+    if (!(svq->vring.used->flags & VRING_USED_F_NO_NOTIFY)) {
+        event_notifier_set(&svq->kick_notifier);
+    }
+}
+
 /* Handle guest->device notifications */
 static void vhost_handle_guest_kick(EventNotifier *n)
 {
@@ -197,7 +206,7 @@  static void vhost_handle_guest_kick(EventNotifier *n)
             }
 
             vhost_svq_add(svq, elem);
-            event_notifier_set(&svq->kick_notifier);
+            vhost_svq_kick(svq);
         }
 
         virtio_queue_set_notification(svq->vq, true);