vhost: fix interrupt suppression for the split ring

Message ID 1550823230-16809-1-git-send-email-jiayu.hu@intel.com
State Changes Requested, archived
Delegated to: Maxime Coquelin
Headers show
Series
  • vhost: fix interrupt suppression for the split ring
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Hu, Jiayu Feb. 22, 2019, 8:13 a.m.
The VIRTIO_RING_F_EVENT_IDX feature of split ring might
be broken, as the value of signalled_used is unpredictable
after live migration or start up. This patch fixes it by
using signalled_used_valid.

In addition, this patch makes the VIRTIO_RING_F_EVENT_IDX
implementation of split ring match kernel backend to suppress
more interrupts.

Fixes: e37ff954405a ("vhost: support virtqueue interrupt/notification suppression")
Cc: stable@dpdk.org

Signed-off-by: Jiayu Hu <jiayu.hu@intel.com>
---
 lib/librte_vhost/vhost.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Tiwei Bie Feb. 25, 2019, 7:06 a.m. | #1
On Fri, Feb 22, 2019 at 04:13:50PM +0800, Jiayu Hu wrote:
> The VIRTIO_RING_F_EVENT_IDX feature of split ring might
> be broken, as the value of signalled_used is unpredictable
> after live migration or start up. This patch fixes it by
> using signalled_used_valid.

Seems you also need to invalidate the signalled_used in e.g.
set_vring_base, as signalled_used may not match last_used_idx
anymore e.g. when guest driver is reloaded.

> 
> In addition, this patch makes the VIRTIO_RING_F_EVENT_IDX
> implementation of split ring match kernel backend to suppress
> more interrupts.
> 
> Fixes: e37ff954405a ("vhost: support virtqueue interrupt/notification suppression")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Jiayu Hu <jiayu.hu@intel.com>
> ---
>  lib/librte_vhost/vhost.h | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
> index fc31796..c4e5e34 100644
> --- a/lib/librte_vhost/vhost.h
> +++ b/lib/librte_vhost/vhost.h
> @@ -633,16 +633,20 @@ vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
>  	if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
>  		uint16_t old = vq->signalled_used;
>  		uint16_t new = vq->last_used_idx;
> +		bool signalled_used_valid = vq->signalled_used_valid;
> +
> +		vq->signalled_used = new;
> +		vq->signalled_used_valid = true;
>  
>  		VHOST_LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
>  			__func__,
>  			vhost_used_event(vq),
>  			old, new);
> -		if (vhost_need_event(vhost_used_event(vq), new, old)
> -			&& (vq->callfd >= 0)) {
> -			vq->signalled_used = vq->last_used_idx;
> +
> +		if ((vhost_need_event(vhost_used_event(vq), new, old) &&
> +					(vq->callfd >= 0)) ||
> +				unlikely(!signalled_used_valid))
>  			eventfd_write(vq->callfd, (eventfd_t) 1);
> -		}
>  	} else {
>  		/* Kick the guest if necessary. */
>  		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
> -- 
> 2.7.4
>
Hu, Jiayu Feb. 27, 2019, 5:38 a.m. | #2
> -----Original Message-----
> From: Bie, Tiwei
> Sent: Monday, February 25, 2019 3:07 PM
> To: Hu, Jiayu <jiayu.hu@intel.com>
> Cc: dev@dpdk.org; maxime.coquelin@redhat.com; stable@dpdk.org
> Subject: Re: [PATCH] vhost: fix interrupt suppression for the split ring
> 
> On Fri, Feb 22, 2019 at 04:13:50PM +0800, Jiayu Hu wrote:
> > The VIRTIO_RING_F_EVENT_IDX feature of split ring might
> > be broken, as the value of signalled_used is unpredictable
> > after live migration or start up. This patch fixes it by
> > using signalled_used_valid.
> 
> Seems you also need to invalidate the signalled_used in e.g.
> set_vring_base, as signalled_used may not match last_used_idx
> anymore e.g. when guest driver is reloaded.

To handle the virtio device reload case, how about setting
signalled_used_valid to false in get_vring_base()?

Thanks,
Jiayu

> 
> >
> > In addition, this patch makes the VIRTIO_RING_F_EVENT_IDX
> > implementation of split ring match kernel backend to suppress
> > more interrupts.
> >
> > Fixes: e37ff954405a ("vhost: support virtqueue interrupt/notification
> suppression")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Jiayu Hu <jiayu.hu@intel.com>
> > ---
> >  lib/librte_vhost/vhost.h | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
> > index fc31796..c4e5e34 100644
> > --- a/lib/librte_vhost/vhost.h
> > +++ b/lib/librte_vhost/vhost.h
> > @@ -633,16 +633,20 @@ vhost_vring_call_split(struct virtio_net *dev,
> struct vhost_virtqueue *vq)
> >  	if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
> >  		uint16_t old = vq->signalled_used;
> >  		uint16_t new = vq->last_used_idx;
> > +		bool signalled_used_valid = vq->signalled_used_valid;
> > +
> > +		vq->signalled_used = new;
> > +		vq->signalled_used_valid = true;
> >
> >  		VHOST_LOG_DEBUG(VHOST_DATA, "%s:
> used_event_idx=%d, old=%d, new=%d\n",
> >  			__func__,
> >  			vhost_used_event(vq),
> >  			old, new);
> > -		if (vhost_need_event(vhost_used_event(vq), new, old)
> > -			&& (vq->callfd >= 0)) {
> > -			vq->signalled_used = vq->last_used_idx;
> > +
> > +		if ((vhost_need_event(vhost_used_event(vq), new, old) &&
> > +					(vq->callfd >= 0)) ||
> > +				unlikely(!signalled_used_valid))
> >  			eventfd_write(vq->callfd, (eventfd_t) 1);
> > -		}
> >  	} else {
> >  		/* Kick the guest if necessary. */
> >  		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
> > --
> > 2.7.4
> >
Tiwei Bie Feb. 27, 2019, 10:55 a.m. | #3
On Wed, Feb 27, 2019 at 01:38:28PM +0800, Hu, Jiayu wrote:
> > -----Original Message-----
> > From: Bie, Tiwei
> > Sent: Monday, February 25, 2019 3:07 PM
> > To: Hu, Jiayu <jiayu.hu@intel.com>
> > Cc: dev@dpdk.org; maxime.coquelin@redhat.com; stable@dpdk.org
> > Subject: Re: [PATCH] vhost: fix interrupt suppression for the split ring
> > 
> > On Fri, Feb 22, 2019 at 04:13:50PM +0800, Jiayu Hu wrote:
> > > The VIRTIO_RING_F_EVENT_IDX feature of split ring might
> > > be broken, as the value of signalled_used is unpredictable
> > > after live migration or start up. This patch fixes it by
> > > using signalled_used_valid.
> > 
> > Seems you also need to invalidate the signalled_used in e.g.
> > set_vring_base, as signalled_used may not match last_used_idx
> > anymore e.g. when guest driver is reloaded.
> 
> To handle the virtio device reload case, how about setting
> signalled_used_valid to false in get_vring_base()?

Sounds good.

> 
> Thanks,
> Jiayu
> 
> > 
> > >
> > > In addition, this patch makes the VIRTIO_RING_F_EVENT_IDX
> > > implementation of split ring match kernel backend to suppress
> > > more interrupts.
> > >
> > > Fixes: e37ff954405a ("vhost: support virtqueue interrupt/notification
> > suppression")
> > > Cc: stable@dpdk.org
> > >
> > > Signed-off-by: Jiayu Hu <jiayu.hu@intel.com>
> > > ---
> > >  lib/librte_vhost/vhost.h | 12 ++++++++----
> > >  1 file changed, 8 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
> > > index fc31796..c4e5e34 100644
> > > --- a/lib/librte_vhost/vhost.h
> > > +++ b/lib/librte_vhost/vhost.h
> > > @@ -633,16 +633,20 @@ vhost_vring_call_split(struct virtio_net *dev,
> > struct vhost_virtqueue *vq)
> > >  	if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
> > >  		uint16_t old = vq->signalled_used;
> > >  		uint16_t new = vq->last_used_idx;
> > > +		bool signalled_used_valid = vq->signalled_used_valid;
> > > +
> > > +		vq->signalled_used = new;
> > > +		vq->signalled_used_valid = true;
> > >
> > >  		VHOST_LOG_DEBUG(VHOST_DATA, "%s:
> > used_event_idx=%d, old=%d, new=%d\n",
> > >  			__func__,
> > >  			vhost_used_event(vq),
> > >  			old, new);
> > > -		if (vhost_need_event(vhost_used_event(vq), new, old)
> > > -			&& (vq->callfd >= 0)) {
> > > -			vq->signalled_used = vq->last_used_idx;
> > > +
> > > +		if ((vhost_need_event(vhost_used_event(vq), new, old) &&
> > > +					(vq->callfd >= 0)) ||
> > > +				unlikely(!signalled_used_valid))
> > >  			eventfd_write(vq->callfd, (eventfd_t) 1);
> > > -		}
> > >  	} else {
> > >  		/* Kick the guest if necessary. */
> > >  		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)
> > > --
> > > 2.7.4
> > >

Patch

diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h
index fc31796..c4e5e34 100644
--- a/lib/librte_vhost/vhost.h
+++ b/lib/librte_vhost/vhost.h
@@ -633,16 +633,20 @@  vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)
 	if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) {
 		uint16_t old = vq->signalled_used;
 		uint16_t new = vq->last_used_idx;
+		bool signalled_used_valid = vq->signalled_used_valid;
+
+		vq->signalled_used = new;
+		vq->signalled_used_valid = true;
 
 		VHOST_LOG_DEBUG(VHOST_DATA, "%s: used_event_idx=%d, old=%d, new=%d\n",
 			__func__,
 			vhost_used_event(vq),
 			old, new);
-		if (vhost_need_event(vhost_used_event(vq), new, old)
-			&& (vq->callfd >= 0)) {
-			vq->signalled_used = vq->last_used_idx;
+
+		if ((vhost_need_event(vhost_used_event(vq), new, old) &&
+					(vq->callfd >= 0)) ||
+				unlikely(!signalled_used_valid))
 			eventfd_write(vq->callfd, (eventfd_t) 1);
-		}
 	} else {
 		/* Kick the guest if necessary. */
 		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)