From: Dor Laor <dor.laor@gmail.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
kvm-devel <kvm-devel@lists.sourceforge.net>,
netdev@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: Re: [kvm-devel] [PATCH resent] virtio_net: Fix stalled inbound trafficon early packets
Date: Wed, 12 Dec 2007 17:48:55 +0200 [thread overview]
Message-ID: <476002E7.5050301@qumranet.com> (raw)
In-Reply-To: <200712121239.51435.borntraeger@de.ibm.com>
Christian Borntraeger wrote:
>
> Am Mittwoch, 12. Dezember 2007 schrieb Rusty Russell:
> > On Wednesday 12 December 2007 00:16:12 Christian Borntraeger wrote:
> > > That would also work. We already have VRING_AVAIL_F_NO_INTERRUPT in
> > > virtio_ring.c - maybe we can use that. Its hidden in callback and
> > > restart handling, what about adding an explicit startup?
> >
> > Yes, I debated whether to make this a separate hook or not; the current
> > method reduces the number of function calls without having two ways of
> > disabling callbacks.
> >
> > In this case, simply starting devices with callbacks disabled and
> > renaming 'restart' to 'enable' (or something) and calling it at the
> > beginning is probably sufficient?
>
> So you suggest something like the following patch? It seems to work but
> there is still a theoretical race at startup. Therefore, I tend to agree
> with Dor that a separate hook seems prefereable, so I am not fully sure if
> the patch is the final solution:
>
I think the change below handles the race. Otherwise please detail the
use case.
>
> ps: Its ok to answer that after your vacation.
>
> ---
> drivers/block/virtio_blk.c | 3 ++-
> drivers/net/virtio_net.c | 5 ++++-
> drivers/virtio/virtio_ring.c | 9 ++++-----
> include/linux/virtio.h | 4 ++--
> 4 files changed, 12 insertions(+), 9 deletions(-)
>
> Index: kvm/drivers/virtio/virtio_ring.c
> ===================================================================
> --- kvm.orig/drivers/virtio/virtio_ring.c
> +++ kvm/drivers/virtio/virtio_ring.c
> @@ -220,7 +220,7 @@ static void *vring_get_buf(struct virtqu
> return ret;
> }
>
> -static bool vring_restart(struct virtqueue *_vq)
> +static bool vring_enable(struct virtqueue *_vq)
> {
> struct vring_virtqueue *vq = to_vvq(_vq);
>
> @@ -264,7 +264,7 @@ static struct virtqueue_ops vring_vq_ops
> .add_buf = vring_add_buf,
> .get_buf = vring_get_buf,
> .kick = vring_kick,
> - .restart = vring_restart,
> + .enable = vring_enable,
> .shutdown = vring_shutdown,
> };
>
> @@ -299,9 +299,8 @@ struct virtqueue *vring_new_virtqueue(un
> vq->in_use = false;
> #endif
>
> - /* No callback? Tell other side not to bother us. */
> - if (!callback)
> - vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
> + /* disable interrupts until we enable them */
> + vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
>
> /* Put everything in free lists. */
> vq->num_free = num;
> Index: kvm/include/linux/virtio.h
> ===================================================================
> --- kvm.orig/include/linux/virtio.h
> +++ kvm/include/linux/virtio.h
> @@ -41,7 +41,7 @@ struct virtqueue
> * vq: the struct virtqueue we're talking about.
> * len: the length written into the buffer
> * Returns NULL or the "data" token handed to add_buf.
> - * @restart: restart callbacks after callback returned false.
> + * @enable: restart callbacks after callback returned false.
> * vq: the struct virtqueue we're talking about.
> * This returns "false" (and doesn't re-enable) if there are pending
> * buffers in the queue, to avoid a race.
> @@ -65,7 +65,7 @@ struct virtqueue_ops {
>
> void *(*get_buf)(struct virtqueue *vq, unsigned int *len);
>
> - bool (*restart)(struct virtqueue *vq);
> + bool (*enable)(struct virtqueue *vq);
>
> void (*shutdown)(struct virtqueue *vq);
> };
> Index: kvm/drivers/net/virtio_net.c
> ===================================================================
> --- kvm.orig/drivers/net/virtio_net.c
> +++ kvm/drivers/net/virtio_net.c
> @@ -201,7 +201,7 @@ again:
> /* Out of packets? */
> if (received < budget) {
> netif_rx_complete(vi->dev, napi);
> - if (unlikely(!vi->rvq->vq_ops->restart(vi->rvq))
> + if (unlikely(!vi->rvq->vq_ops->enable(vi->rvq))
> && netif_rx_reschedule(vi->dev, napi))
> goto again;
> }
> @@ -292,6 +292,9 @@ static int virtnet_open(struct net_devic
> return -ENOMEM;
>
> napi_enable(&vi->napi);
> +
> + vi->rvq->vq_ops->enable(vi->rvq);
> + vi->svq->vq_ops->enable(vi->svq);
>
If you change it to:
if (!vi->rvq->vq_ops->enable(vi->rvq))
vi->rvq->vq_ops->kick(vi->rvq);
if (!vi->rvq->vq_ops->enable(vi->svq))
vi->rvq->vq_ops->kick(vi->svq);
You solve the race of packets already waiting in the queue without
triggering the irq.
The same for the block device.
Regards,
Dor.
>
> return 0;
> }
>
> Index: kvm/drivers/block/virtio_blk.c
> ===================================================================
> --- kvm.orig/drivers/block/virtio_blk.c
> +++ kvm/drivers/block/virtio_blk.c
> @@ -183,7 +183,8 @@ static int virtblk_probe(struct virtio_d
> err = PTR_ERR(vblk->vq);
> goto out_free_vblk;
> }
> -
> + /* enable interrupts */
> + vblk->vq->vq_ops->enable(vblk->vq);
> vblk->pool = mempool_create_kmalloc_pool(1,sizeof(struct
> virtblk_req));
> if (!vblk->pool) {
> err = -ENOMEM;
>
next prev parent reply other threads:[~2007-12-12 15:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-11 11:42 [PATCH resent] virtio_net: Fix stalled inbound traffic on early packets Christian Borntraeger
[not found] ` <200712111242.28843.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-12-11 12:48 ` [PATCH resent] virtio_net: Fix stalled inbound trafficon " Dor Laor
[not found] ` <475E8716.2010500-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-11 12:57 ` Dor Laor
[not found] ` <475E892D.9060400-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-11 13:16 ` Christian Borntraeger
2007-12-12 1:54 ` [kvm-devel] " Rusty Russell
2007-12-12 11:39 ` Christian Borntraeger
2007-12-12 15:48 ` Dor Laor [this message]
[not found] ` <476002E7.5050301-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-12-12 18:14 ` Christian Borntraeger
[not found] ` <200712121914.38135.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-12-13 13:24 ` Dor Laor
2007-12-13 18:30 ` [kvm-devel] " Christian Borntraeger
[not found] ` <200712131930.31602.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-12-18 6:54 ` Rusty Russell
2007-12-11 13:19 ` [kvm-devel] " Christian Borntraeger
2007-12-11 15:27 ` Christian Borntraeger
[not found] ` <200712111627.21364.borntraeger-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-12-11 23:34 ` Dor Laor
2007-12-12 11:27 ` [kvm-devel] " Christian Borntraeger
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=476002E7.5050301@qumranet.com \
--to=dor.laor@gmail.com \
--cc=borntraeger@de.ibm.com \
--cc=dor.laor@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=netdev@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).