[net] virtio-net: disable NAPI only when enabled during XDP set
diff mbox series

Message ID 1519813204-10002-1-git-send-email-jasowang@redhat.com
State New, archived
Headers show
Series
  • [net] virtio-net: disable NAPI only when enabled during XDP set
Related show

Commit Message

Jason Wang Feb. 28, 2018, 10:20 a.m. UTC
We try to disable NAPI to prevent a single XDP TX queue being used by
multiple cpus. But we don't check if device is up (NAPI is enabled),
this could result stall because of infinite wait in
napi_disable(). Fixing this by checking device state through
netif_running() before.

Fixes: 4941d472bf95b ("virtio-net: do not reset during XDP set")
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/net/virtio_net.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Michael S. Tsirkin Feb. 28, 2018, 3:27 p.m. UTC | #1
On Wed, Feb 28, 2018 at 06:20:04PM +0800, Jason Wang wrote:
> We try to disable NAPI to prevent a single XDP TX queue being used by
> multiple cpus. But we don't check if device is up (NAPI is enabled),
> this could result stall because of infinite wait in
> napi_disable(). Fixing this by checking device state through
> netif_running() before.
> 
> Fixes: 4941d472bf95b ("virtio-net: do not reset during XDP set")
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
>  drivers/net/virtio_net.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index 9bb9e56..2d54123 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2185,8 +2185,9 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
>  	}
>  
>  	/* Make sure NAPI is not using any XDP TX queues for RX. */
> -	for (i = 0; i < vi->max_queue_pairs; i++)
> -		napi_disable(&vi->rq[i].napi);
> +	if (netif_running(dev))
> +		for (i = 0; i < vi->max_queue_pairs; i++)
> +			napi_disable(&vi->rq[i].napi);
>  
>  	netif_set_real_num_rx_queues(dev, curr_qp + xdp_qp);
>  	err = _virtnet_set_queues(vi, curr_qp + xdp_qp);
> @@ -2205,7 +2206,8 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
>  		}
>  		if (old_prog)
>  			bpf_prog_put(old_prog);
> -		virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
> +		if (netif_running(dev))
> +			virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
>  	}
>  
>  	return 0;
> -- 
> 2.7.4
David Miller Feb. 28, 2018, 5:22 p.m. UTC | #2
From: Jason Wang <jasowang@redhat.com>
Date: Wed, 28 Feb 2018 18:20:04 +0800

> We try to disable NAPI to prevent a single XDP TX queue being used by
> multiple cpus. But we don't check if device is up (NAPI is enabled),
> this could result stall because of infinite wait in
> napi_disable(). Fixing this by checking device state through
> netif_running() before.
> 
> Fixes: 4941d472bf95b ("virtio-net: do not reset during XDP set")
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Yes, mis-paired NAPI enable/disable are really a pain.

Probably, we can do something in the interfaces or mechanisms to make
this less error prone and less fragile.

Anyways, applied and queued up for -stable, thanks!
Ben Greear Feb. 28, 2018, 7:02 p.m. UTC | #3
On 02/28/2018 09:22 AM, David Miller wrote:
> From: Jason Wang <jasowang@redhat.com>
> Date: Wed, 28 Feb 2018 18:20:04 +0800
>
>> We try to disable NAPI to prevent a single XDP TX queue being used by
>> multiple cpus. But we don't check if device is up (NAPI is enabled),
>> this could result stall because of infinite wait in
>> napi_disable(). Fixing this by checking device state through
>> netif_running() before.
>>
>> Fixes: 4941d472bf95b ("virtio-net: do not reset during XDP set")
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>
> Yes, mis-paired NAPI enable/disable are really a pain.
>
> Probably, we can do something in the interfaces or mechanisms to make
> this less error prone and less fragile.
>
> Anyways, applied and queued up for -stable, thanks!


I just hit a similar bug in ath10k.  It seems like napi has plenty
of free bit flags so it could keep track of 'is-enabled' state and
allow someone to call napi_disable multiple times w/out deadlocking.

Thanks,
Ben

Patch
diff mbox series

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 9bb9e56..2d54123 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2185,8 +2185,9 @@  static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 	}
 
 	/* Make sure NAPI is not using any XDP TX queues for RX. */
-	for (i = 0; i < vi->max_queue_pairs; i++)
-		napi_disable(&vi->rq[i].napi);
+	if (netif_running(dev))
+		for (i = 0; i < vi->max_queue_pairs; i++)
+			napi_disable(&vi->rq[i].napi);
 
 	netif_set_real_num_rx_queues(dev, curr_qp + xdp_qp);
 	err = _virtnet_set_queues(vi, curr_qp + xdp_qp);
@@ -2205,7 +2206,8 @@  static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 		}
 		if (old_prog)
 			bpf_prog_put(old_prog);
-		virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
+		if (netif_running(dev))
+			virtnet_napi_enable(vi->rq[i].vq, &vi->rq[i].napi);
 	}
 
 	return 0;