Message ID | 20210315194842.277740-14-eperezma@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | vDPA software assisted live migration | expand |
在 2021/3/16 上午3:48, Eugenio Pérez 写道: > Signed-off-by: Eugenio Pérez <eperezma@redhat.com> > --- > hw/virtio/vhost-shadow-virtqueue.c | 28 +++++++++++++++++++++++++++- > 1 file changed, 27 insertions(+), 1 deletion(-) > > diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c > index 7df98fc43f..e3879a4622 100644 > --- a/hw/virtio/vhost-shadow-virtqueue.c > +++ b/hw/virtio/vhost-shadow-virtqueue.c > @@ -71,10 +71,35 @@ typedef struct VhostShadowVirtqueue { > /* Next head to consume from device */ > uint16_t used_idx; > > + /* Cache for the exposed notification flag */ > + bool notification; > + > /* Descriptors copied from guest */ > vring_desc_t descs[]; > } VhostShadowVirtqueue; > > +static void vhost_shadow_vq_set_notification(VhostShadowVirtqueue *svq, > + bool enable) > +{ > + uint16_t notification_flag; > + > + if (svq->notification == enable) { > + return; > + } > + > + notification_flag = virtio_tswap16(svq->vdev, VRING_AVAIL_F_NO_INTERRUPT); > + > + svq->notification = enable; > + if (enable) { > + svq->vring.avail->flags &= ~notification_flag; > + } else { > + svq->vring.avail->flags |= notification_flag; > + } > + > + /* Make sure device reads our flag */ > + smp_mb(); This is a hint, so we don't need memory barrier here. Thanks > +} > + > static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, > const struct iovec *iovec, > size_t num, bool more_descs, bool write) > @@ -251,7 +276,7 @@ static void vhost_shadow_vq_handle_call_no_test(EventNotifier *n) > do { > unsigned i = 0; > > - /* TODO: Use VRING_AVAIL_F_NO_INTERRUPT */ > + vhost_shadow_vq_set_notification(svq, false); > while (true) { > g_autofree VirtQueueElement *elem = vhost_shadow_vq_get_buf(svq); > if (!elem) { > @@ -269,6 +294,7 @@ static void vhost_shadow_vq_handle_call_no_test(EventNotifier *n) > svq->masked_notifier.signaled = true; > event_notifier_set(svq->masked_notifier.n); > } > + vhost_shadow_vq_set_notification(svq, true); > } while (vhost_shadow_vq_more_used(svq)); > > if (masked_notifier) {
On Tue, Mar 16, 2021 at 9:08 AM Jason Wang <jasowang@redhat.com> wrote: > > > 在 2021/3/16 上午3:48, Eugenio Pérez 写道: > > Signed-off-by: Eugenio Pérez <eperezma@redhat.com> > > --- > > hw/virtio/vhost-shadow-virtqueue.c | 28 +++++++++++++++++++++++++++- > > 1 file changed, 27 insertions(+), 1 deletion(-) > > > > diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c > > index 7df98fc43f..e3879a4622 100644 > > --- a/hw/virtio/vhost-shadow-virtqueue.c > > +++ b/hw/virtio/vhost-shadow-virtqueue.c > > @@ -71,10 +71,35 @@ typedef struct VhostShadowVirtqueue { > > /* Next head to consume from device */ > > uint16_t used_idx; > > > > + /* Cache for the exposed notification flag */ > > + bool notification; > > + > > /* Descriptors copied from guest */ > > vring_desc_t descs[]; > > } VhostShadowVirtqueue; > > > > +static void vhost_shadow_vq_set_notification(VhostShadowVirtqueue *svq, > > + bool enable) > > +{ > > + uint16_t notification_flag; > > + > > + if (svq->notification == enable) { > > + return; > > + } > > + > > + notification_flag = virtio_tswap16(svq->vdev, VRING_AVAIL_F_NO_INTERRUPT); > > + > > + svq->notification = enable; > > + if (enable) { > > + svq->vring.avail->flags &= ~notification_flag; > > + } else { > > + svq->vring.avail->flags |= notification_flag; > > + } > > + > > + /* Make sure device reads our flag */ > > + smp_mb(); > > > This is a hint, so we don't need memory barrier here. > > Thanks > I will delete it for the next revision. Thanks! > > > +} > > + > > static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, > > const struct iovec *iovec, > > size_t num, bool more_descs, bool write) > > @@ -251,7 +276,7 @@ static void vhost_shadow_vq_handle_call_no_test(EventNotifier *n) > > do { > > unsigned i = 0; > > > > - /* TODO: Use VRING_AVAIL_F_NO_INTERRUPT */ > > + vhost_shadow_vq_set_notification(svq, false); > > while (true) { > > g_autofree VirtQueueElement *elem = vhost_shadow_vq_get_buf(svq); > > if (!elem) { > > @@ -269,6 +294,7 @@ static void vhost_shadow_vq_handle_call_no_test(EventNotifier *n) > > svq->masked_notifier.signaled = true; > > event_notifier_set(svq->masked_notifier.n); > > } > > + vhost_shadow_vq_set_notification(svq, true); > > } while (vhost_shadow_vq_more_used(svq)); > > > > if (masked_notifier) { >
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c index 7df98fc43f..e3879a4622 100644 --- a/hw/virtio/vhost-shadow-virtqueue.c +++ b/hw/virtio/vhost-shadow-virtqueue.c @@ -71,10 +71,35 @@ typedef struct VhostShadowVirtqueue { /* Next head to consume from device */ uint16_t used_idx; + /* Cache for the exposed notification flag */ + bool notification; + /* Descriptors copied from guest */ vring_desc_t descs[]; } VhostShadowVirtqueue; +static void vhost_shadow_vq_set_notification(VhostShadowVirtqueue *svq, + bool enable) +{ + uint16_t notification_flag; + + if (svq->notification == enable) { + return; + } + + notification_flag = virtio_tswap16(svq->vdev, VRING_AVAIL_F_NO_INTERRUPT); + + svq->notification = enable; + if (enable) { + svq->vring.avail->flags &= ~notification_flag; + } else { + svq->vring.avail->flags |= notification_flag; + } + + /* Make sure device reads our flag */ + smp_mb(); +} + static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, const struct iovec *iovec, size_t num, bool more_descs, bool write) @@ -251,7 +276,7 @@ static void vhost_shadow_vq_handle_call_no_test(EventNotifier *n) do { unsigned i = 0; - /* TODO: Use VRING_AVAIL_F_NO_INTERRUPT */ + vhost_shadow_vq_set_notification(svq, false); while (true) { g_autofree VirtQueueElement *elem = vhost_shadow_vq_get_buf(svq); if (!elem) { @@ -269,6 +294,7 @@ static void vhost_shadow_vq_handle_call_no_test(EventNotifier *n) svq->masked_notifier.signaled = true; event_notifier_set(svq->masked_notifier.n); } + vhost_shadow_vq_set_notification(svq, true); } while (vhost_shadow_vq_more_used(svq)); if (masked_notifier) {
Signed-off-by: Eugenio Pérez <eperezma@redhat.com> --- hw/virtio/vhost-shadow-virtqueue.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)