Skip to contentSkip to conversation

vhost: fix interrupt suppression for the split ring

PATCH Superseded Jiayu Hu 4 participants 8 messages Feb 22, 2019 – Mar 20, 2019

lore
Share & tools
lore

Jiayu Hu

author
#0 lore raw

PATCH 1/1 vhost: fix interrupt suppression for the split ring

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")
---
 lib/librte_vhost/vhost.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost.h +8 -4
index fc31796..c4e5e34 100644
@@ -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)
Signature · 1 line
2.7.4
#1 lore raw
Quoted 4 lines · Jiayu Hu

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.

Quoted 45 lines

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")
---
 lib/librte_vhost/vhost.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost.h +8 -4
index fc31796..c4e5e34 100644
@@ -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)
Signature · 1 line
2.7.4
author
#2 lore raw
Quoted 10 lines

-----Original Message-----
From: Bie, Tiwei
Sent: Monday, February 25, 2019 3:07 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] vhost: fix interrupt suppression for the split ring

On Fri, Feb 22, 2019 at 04:13:50PM +0800, Jiayu Hu wrote:

Quoted 8 lines
Quoted 4 lines

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

Quoted 49 lines
Quoted 7 lines

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")

lib/librte_vhost/vhost.h vhost_vring_call_split(struct virtio_net *dev,

Quoted 12 lines
---
 lib/librte_vhost/vhost.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost.h +0 -0
index fc31796..c4e5e34 100644
@@ -633,16 +633,20 @@ vhost_vring_call_split(struct virtio_net *dev,

struct vhost_virtqueue *vq)

lib/librte_vhost/vhost.h vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)

Quoted 9 lines
lib/librte_vhost/vhost.h +4 -0
 	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",

Quoted 18 lines
lib/librte_vhost/vhost.h +4 -5
 			__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

#3 lore raw
Quoted 13 lines · Jiayu
Quoted 13 lines

-----Original Message-----
From: Bie, Tiwei
Sent: Monday, February 25, 2019 3:07 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] vhost: fix interrupt suppression for the split ring

Quoted 4 lines · Jiayu Hu

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.

Quoted 6 lines
Quoted 3 lines

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.

Quoted 53 lines

Thanks,
Jiayu

Quoted 49 lines
Quoted 7 lines

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")

lib/librte_vhost/vhost.h vhost_vring_call_split(struct virtio_net *dev,

Quoted 12 lines
---
 lib/librte_vhost/vhost.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost.h +0 -0
index fc31796..c4e5e34 100644
@@ -633,16 +633,20 @@ vhost_vring_call_split(struct virtio_net *dev,

struct vhost_virtqueue *vq)

lib/librte_vhost/vhost.h vhost_vring_call_split(struct virtio_net *dev, struct vhost_virtqueue *vq)

Quoted 9 lines
lib/librte_vhost/vhost.h +4 -0
 	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",

Quoted 18 lines
lib/librte_vhost/vhost.h +4 -5
 			__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

author
#4 lore raw

PATCH v2 1/1 vhost: fix interrupt suppression for the split ring

In reply to Jiayu Hu

The VIRTIO_RING_F_EVENT_IDX feature of split ring might be broken, as the value of signalled_used is invalid after live migration, start up and virtio driver reload. 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")

---
change in v2:
- fix virtio-net driver reload

 lib/librte_vhost/vhost.h      | 12 ++++++++----
 lib/librte_vhost/vhost_user.c |  2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost.h +8 -4
index f008ec4..e9138df 100644
@@ -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)
lib/librte_vhost/vhost_user.c +2 -0
index 36c0c67..01a8d80 100644
@@ -1298,6 +1298,8 @@ vhost_user_get_vring_base(struct virtio_net **pdev,
 
 	vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD;
 
+	vq->signalled_used_valid = false;
+
 	if (dev->dequeue_zero_copy)
 		free_zmbufs(vq);
 	if (vq_is_packed(dev)) {
Signature · 1 line
2.7.4
#5 lore raw

Best Wishes,
Yinan

Quoted 77 lines

-----Original Message-----
From: Hu, Jiayu
Sent: 2019年3月17日 14:39
To: [email protected]
Cc: Bie, Tiwei <[email protected]>; [email protected]; Wang, Yinan <[email protected]>; Hu, Jiayu <[email protected]>; [email protected]
Subject: [PATCH v2] vhost: fix interrupt suppression for the split ring

The VIRTIO_RING_F_EVENT_IDX feature of split ring might be broken, as the value of signalled_used is invalid after live migration, start up and virtio driver reload.
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: [email protected]

---
change in v2:
- fix virtio-net driver reload

 lib/librte_vhost/vhost.h      | 12 ++++++++----
 lib/librte_vhost/vhost_user.c |  2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
lib/librte_vhost/vhost.h index renamed from lib/librte_vhost/vhost.h +0 -0

f008ec4..e9138df 100644

lib/librte_vhost/vhost.h +8 -4
@@ -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 {
lib/librte_vhost/vhost.h +0 -0
 		/* Kick the guest if necessary. */
 		if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT) diff --git

a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 36c0c67..01a8d80 100644

lib/librte_vhost/vhost_user.c +2 -0
@@ -1298,6 +1298,8 @@ vhost_user_get_vring_base(struct virtio_net
 **pdev,
 
 	vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD;
 
+	vq->signalled_used_valid = false;
+
 	if (dev->dequeue_zero_copy)
 		free_zmbufs(vq);

if (vq_is_packed(dev)) {
--
2.7.4

Reviewed-by on v2 1/1
#6 lore raw
In reply to Jiayu Hu
Quoted 12 lines · Jiayu Hu

The VIRTIO_RING_F_EVENT_IDX feature of split ring might be broken, as the value of signalled_used is invalid after live migration, start up and virtio driver reload. 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")
Quoted 8 lines

---
change in v2:
- fix virtio-net driver reload

 lib/librte_vhost/vhost.h      | 12 ++++++++----
 lib/librte_vhost/vhost_user.c |  2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
#7 lore raw
In reply to Jiayu Hu
Quoted 12 lines · Jiayu Hu

The VIRTIO_RING_F_EVENT_IDX feature of split ring might be broken, as the value of signalled_used is invalid after live migration, start up and virtio driver reload. 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")
Quoted 8 lines

---
change in v2:
- fix virtio-net driver reload

  lib/librte_vhost/vhost.h      | 12 ++++++++----
  lib/librte_vhost/vhost_user.c |  2 ++
  2 files changed, 10 insertions(+), 4 deletions(-)

Applied to dpdk-next-virtio/master branch.

Thanks,
Maxime