All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: sjur.brandeland@stericsson.com, Ohad Ben-Cohen <ohad@wizery.com>,
	mst@redhat.com
Cc: sjur@brendeland.net, Linus Walleij <linus.walleij@linaro.org>,
	Erwan Yvin <erwan.yvin@stericsson.com>,
	virtualization@lists.linux-foundation.org
Subject: [PATCH 2/3] vringh: don't flag already listening.
Date: Wed, 06 Mar 2013 15:59:20 +1100	[thread overview]
Message-ID: <87ppzdazti.fsf@rustcorp.com.au> (raw)
In-Reply-To: <87sj49azw1.fsf@rustcorp.com.au>

This doesn't work for eventidx:

1) vringh_notify_enable_user() gets called because the ring is empty
   (vrh->last_avail_idx == vrh->vring.avail->idx).
2) It puts vrh->last_avail_idx into vring_avail_event().
3) It sets ->listening to true.
4) Meanwhile, the other side has done more work, updating vrh->vring.avail->idx.
5) It notices vrh->vring.avail->idx has changed, so returns true to
   make us do more work.

But since the value we wrote into vring_avail_event() is past, we
won't get notified.  This happens rarely: only once I'd optimized
add_buf could I trigger this in about 1 in 10 runs.

Since it's so rare, just remove the listening flag: it's fine to do
this twice anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index 8234f2b..d4413d9 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -476,12 +476,6 @@ static inline bool __vringh_notify_enable(struct vringh *vrh,
 {
 	u16 avail;
 
-	/* Already enabled? */
-	if (vrh->listening)
-		return false;
-
-	vrh->listening = true;
-
 	if (!vrh->event_indices) {
 		/* Old-school; update flags. */
 		if (putu16(&vrh->vring.used->flags, 0) != 0) {
@@ -515,11 +509,6 @@ static inline bool __vringh_notify_enable(struct vringh *vrh,
 static inline void __vringh_notify_disable(struct vringh *vrh,
 					   int (*putu16)(u16 *p, u16 val))
 {
-	/* Already disabled? */
-	if (!vrh->listening)
-		return;
-
-	vrh->listening = false;
 	if (!vrh->event_indices) {
 		/* Old-school; update flags. */
 		if (putu16(&vrh->vring.used->flags, VRING_USED_F_NO_NOTIFY)) {
@@ -593,7 +582,6 @@ int vringh_init_user(struct vringh *vrh, u32 features,
 
 	vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX));
 	vrh->weak_barriers = weak_barriers;
-	vrh->listening = false;
 	vrh->completed = 0;
 	vrh->last_avail_idx = 0;
 	vrh->last_used_idx = 0;
@@ -853,7 +841,6 @@ int vringh_init_kern(struct vringh *vrh, u32 features,
 
 	vrh->event_indices = (features & (1 << VIRTIO_RING_F_EVENT_IDX));
 	vrh->weak_barriers = weak_barriers;
-	vrh->listening = false;
 	vrh->completed = 0;
 	vrh->last_avail_idx = 0;
 	vrh->last_used_idx = 0;
diff --git a/include/linux/vringh.h b/include/linux/vringh.h
index ab41185..44b94cd 100644
--- a/include/linux/vringh.h
+++ b/include/linux/vringh.h
@@ -33,9 +33,6 @@ struct vringh {
 	/* Guest publishes used event idx (note: we always do). */
 	bool event_indices;
 
-	/* Have we told the other end we want to be notified? */
-	bool listening;
-
 	/* Can we get away with weak barriers? */
 	bool weak_barriers;

  reply	other threads:[~2013-03-06  4:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-05 13:51 [PATCH vringh] virtio: Introduce vringh wrappers in virtio_config sjur.brandeland
2013-03-06  4:42 ` Rusty Russell
2013-03-06 10:50   ` Sjur Brændeland
2013-03-06 12:16     ` Ohad Ben-Cohen
2013-03-06 12:37       ` Sjur Brændeland
2013-03-06 23:28         ` Sjur Brændeland
2013-03-06  4:46 ` [FYI] vringh fixes Rusty Russell
2013-03-06  4:53   ` [PATCH 1/2] Rusty Russell
2013-03-06  4:54     ` [PATCH 2/2] tools/virtio: make barriers stronger Rusty Russell
2013-03-06 10:20       ` Michael S. Tsirkin
2013-03-07  3:48         ` Rusty Russell
2013-03-07  9:29           ` Michael S. Tsirkin
2013-03-07 23:56             ` Rusty Russell
2013-03-06  4:57   ` [PATCH 1/3] vringh: host-side implementation of virtio rings (v2) Rusty Russell
2013-03-06  4:59     ` Rusty Russell [this message]
2013-03-06  5:02     ` [PATCH 3/3] tools/virtio: add vring_test (v2) Rusty Russell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ppzdazti.fsf@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=erwan.yvin@stericsson.com \
    --cc=linus.walleij@linaro.org \
    --cc=mst@redhat.com \
    --cc=ohad@wizery.com \
    --cc=sjur.brandeland@stericsson.com \
    --cc=sjur@brendeland.net \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.