Re: [PATCH 5 of 5] virtio: expose added descriptors immediately

From: Rusty Russell
Date: Mon Nov 21 2011 - 20:00:28 EST


On Mon, 21 Nov 2011 13:57:04 +0200, "Michael S. Tsirkin" <mst@xxxxxxxxxx> wrote:
> On Mon, Nov 21, 2011 at 12:18:45PM +1030, Rusty Russell wrote:
> > On Wed, 16 Nov 2011 09:18:38 +0200, "Michael S. Tsirkin" <mst@xxxxxxxxxx> wrote:
> > > My unlocked kick patches will trip this warning: they make
> > > virtio-net do add + get without kick.
> >
> > Heh, it's a good sign if they do, since that means you're running really
> > well :)
>
> They don't in fact, in my testing :(. But I think they can with luck.
>
> > > I think block with unlocked kick can trip it too:
> > > add, lock is dropped and then an interrupt can get.
> > >
> > > We also don't need a kick each num - each 2^15 is enough.
> > > Why don't we do this at start of add_buf:
> > > if (vq->num_added >= 0x7fff)
> > > return -ENOSPC;
> >
> > The warning was there in case a driver is never doing a kick, and
> > getting away with it (mostly) because the device is polling. Let's not
> > penalize good drivers to catch bad ones.
> >
> > How about we do this properly, like so:
>
> Absolutely. But I think we also need to handle num_added
> overflow of a 15 bit counter, no? Otherwise the
> vring_need_event logic might give us false negatives ....
> I'm guessing we can just assume we need a kick in that case.

You're right. Thankyou. My immediate reaction of "make it an unsigned
long" doesn't work.

Here's the diff to what I posted before:

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -254,9 +254,10 @@ add_head:
vq->vring.avail->idx++;
vq->num_added++;

- /* If you haven't kicked in this long, you're probably doing something
- * wrong. */
- WARN_ON(vq->num_added > vq->vring.num);
+ /* This is very unlikely, but theoretically possible. Kick
+ * just in case. */
+ if (unlikely(vq->num_added == 65535))
+ virtqueue_kick(_vq);

pr_debug("Added buffer head %i to %p\n", head, vq);
END_USE(vq);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/