2013-07-03 12:26:38

by Jason Wang

[permalink] [raw]
Subject: [PATCH net] virtio-net: fix the race between channels setting and refill

Commit 55257d72bd1c51f25106350f4983ec19f62ed1fa (virtio-net: fill only rx queues
which are being used) tries to refill on demand when changing the number of
channels by call try_refill_recv() directly, this may race:

- the refill work who may do the refill in the same time
- the try_refill_recv() called in bh since napi was not disabled

Which may led guest complain during setting channels:

virtio_net virtio0: input.1:id 0 is not a head!

Solve this issue by scheduling a refill work which can guarantee the
serialization of refill.

Cc: Sasha Levin <[email protected]>
Cc: Rusty Russell <[email protected]>
Cc: Michael S. Tsirkin <[email protected]>
Signed-off-by: Jason Wang <[email protected]>
---
drivers/net/virtio_net.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index c9e0038..47b4882 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -901,7 +901,6 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
struct scatterlist sg;
struct virtio_net_ctrl_mq s;
struct net_device *dev = vi->dev;
- int i;

if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ))
return 0;
@@ -915,10 +914,8 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
queue_pairs);
return -EINVAL;
} else {
- for (i = vi->curr_queue_pairs; i < queue_pairs; i++)
- if (!try_fill_recv(&vi->rq[i], GFP_KERNEL))
- schedule_delayed_work(&vi->refill, 0);
vi->curr_queue_pairs = queue_pairs;
+ schedule_delayed_work(&vi->refill, 0);
}

return 0;
--
1.7.1


2013-07-03 23:59:47

by David Miller

[permalink] [raw]
Subject: Re: [PATCH net] virtio-net: fix the race between channels setting and refill

From: Jason Wang <[email protected]>
Date: Wed, 3 Jul 2013 20:15:52 +0800

> Commit 55257d72bd1c51f25106350f4983ec19f62ed1fa (virtio-net: fill only rx queues
> which are being used) tries to refill on demand when changing the number of
> channels by call try_refill_recv() directly, this may race:
>
> - the refill work who may do the refill in the same time
> - the try_refill_recv() called in bh since napi was not disabled
>
> Which may led guest complain during setting channels:
>
> virtio_net virtio0: input.1:id 0 is not a head!
>
> Solve this issue by scheduling a refill work which can guarantee the
> serialization of refill.
>
> Cc: Sasha Levin <[email protected]>
> Cc: Rusty Russell <[email protected]>
> Cc: Michael S. Tsirkin <[email protected]>
> Signed-off-by: Jason Wang <[email protected]>

Michael, please review.

Thanks.

2013-07-04 00:56:53

by Asias He

[permalink] [raw]
Subject: Re: [PATCH net] virtio-net: fix the race between channels setting and refill

On Wed, Jul 03, 2013 at 08:15:52PM +0800, Jason Wang wrote:
> Commit 55257d72bd1c51f25106350f4983ec19f62ed1fa (virtio-net: fill only rx queues
> which are being used) tries to refill on demand when changing the number of
> channels by call try_refill_recv() directly, this may race:
>
> - the refill work who may do the refill in the same time
> - the try_refill_recv() called in bh since napi was not disabled
>
> Which may led guest complain during setting channels:
>
> virtio_net virtio0: input.1:id 0 is not a head!
>
> Solve this issue by scheduling a refill work which can guarantee the
> serialization of refill.
>
> Cc: Sasha Levin <[email protected]>
> Cc: Rusty Russell <[email protected]>
> Cc: Michael S. Tsirkin <[email protected]>
> Signed-off-by: Jason Wang <[email protected]>

Reviewed-by: Asias He <[email protected]>

> ---
> drivers/net/virtio_net.c | 5 +----
> 1 files changed, 1 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index c9e0038..47b4882 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -901,7 +901,6 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
> struct scatterlist sg;
> struct virtio_net_ctrl_mq s;
> struct net_device *dev = vi->dev;
> - int i;
>
> if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ))
> return 0;
> @@ -915,10 +914,8 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
> queue_pairs);
> return -EINVAL;
> } else {
> - for (i = vi->curr_queue_pairs; i < queue_pairs; i++)
> - if (!try_fill_recv(&vi->rq[i], GFP_KERNEL))
> - schedule_delayed_work(&vi->refill, 0);
> vi->curr_queue_pairs = queue_pairs;
> + schedule_delayed_work(&vi->refill, 0);
> }

Also, this is not on the data path, it is simpler this way.

>
> return 0;
> --
> 1.7.1
>
> _______________________________________________
> Virtualization mailing list
> [email protected]
> https://lists.linuxfoundation.org/mailman/listinfo/virtualization

--
Asias

2013-07-04 02:25:11

by Rusty Russell

[permalink] [raw]
Subject: Re: [PATCH net] virtio-net: fix the race between channels setting and refill

Jason Wang <[email protected]> writes:
> Commit 55257d72bd1c51f25106350f4983ec19f62ed1fa (virtio-net: fill only rx queues
> which are being used) tries to refill on demand when changing the number of
> channels by call try_refill_recv() directly, this may race:
>
> - the refill work who may do the refill in the same time
> - the try_refill_recv() called in bh since napi was not disabled
>
> Which may led guest complain during setting channels:
>
> virtio_net virtio0: input.1:id 0 is not a head!
>
> Solve this issue by scheduling a refill work which can guarantee the
> serialization of refill.
>
> Cc: Sasha Levin <[email protected]>
> Cc: Rusty Russell <[email protected]>
> Cc: Michael S. Tsirkin <[email protected]>
> Signed-off-by: Jason Wang <[email protected]>

Thanks.

Applied,
Rusty.

2013-07-04 08:22:24

by Michael S. Tsirkin

[permalink] [raw]
Subject: Re: [PATCH net] virtio-net: fix the race between channels setting and refill

On Wed, Jul 03, 2013 at 08:15:52PM +0800, Jason Wang wrote:
> Commit 55257d72bd1c51f25106350f4983ec19f62ed1fa (virtio-net: fill only rx queues
> which are being used) tries to refill on demand when changing the number of
> channels by call try_refill_recv() directly, this may race:
>
> - the refill work who may do the refill in the same time
> - the try_refill_recv() called in bh since napi was not disabled
>
> Which may led guest complain during setting channels:
>
> virtio_net virtio0: input.1:id 0 is not a head!
>
> Solve this issue by scheduling a refill work which can guarantee the
> serialization of refill.
>
> Cc: Sasha Levin <[email protected]>
> Cc: Rusty Russell <[email protected]>
> Cc: Michael S. Tsirkin <[email protected]>
> Signed-off-by: Jason Wang <[email protected]>

Acked-by: Michael S. Tsirkin <[email protected]>

> ---
> drivers/net/virtio_net.c | 5 +----
> 1 files changed, 1 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index c9e0038..47b4882 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -901,7 +901,6 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
> struct scatterlist sg;
> struct virtio_net_ctrl_mq s;
> struct net_device *dev = vi->dev;
> - int i;
>
> if (!vi->has_cvq || !virtio_has_feature(vi->vdev, VIRTIO_NET_F_MQ))
> return 0;
> @@ -915,10 +914,8 @@ static int virtnet_set_queues(struct virtnet_info *vi, u16 queue_pairs)
> queue_pairs);
> return -EINVAL;
> } else {
> - for (i = vi->curr_queue_pairs; i < queue_pairs; i++)
> - if (!try_fill_recv(&vi->rq[i], GFP_KERNEL))
> - schedule_delayed_work(&vi->refill, 0);
> vi->curr_queue_pairs = queue_pairs;
> + schedule_delayed_work(&vi->refill, 0);
> }
>
> return 0;
> --
> 1.7.1