diff mbox series

[net-next,2/3] virtio_net: Hold RTNL for NAPI to queue mapping

Message ID 20250110202605.429475-3-jdamato@fastly.com (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series virtio_net: Link queues to NAPIs | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 47 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest pending net-next-2025-01-11--00-00 (tests: 0)

Commit Message

Joe Damato Jan. 10, 2025, 8:26 p.m. UTC
Prepare for NAPI to queue mapping by holding RTNL in code paths where
NAPIs will be mapped to queue IDs and RTNL is not currently held.

Signed-off-by: Joe Damato <jdamato@fastly.com>
---
 drivers/net/virtio_net.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

Comments

Gerhard Engleder Jan. 10, 2025, 10:22 p.m. UTC | #1
On 10.01.25 21:26, Joe Damato wrote:
> Prepare for NAPI to queue mapping by holding RTNL in code paths where
> NAPIs will be mapped to queue IDs and RTNL is not currently held.
> 
> Signed-off-by: Joe Damato <jdamato@fastly.com>
> ---
>   drivers/net/virtio_net.c | 17 ++++++++++++++---
>   1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index cff18c66b54a..4e88d352d3eb 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -2803,11 +2803,17 @@ static void virtnet_napi_do_enable(struct virtqueue *vq,
>   	local_bh_enable();
>   }
>   
> -static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi)
> +static void virtnet_napi_enable_lock(struct virtqueue *vq,
> +				     struct napi_struct *napi)
>   {
>   	virtnet_napi_do_enable(vq, napi);
>   }
>   
> +static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi)
> +{
> +	virtnet_napi_enable_lock(vq, napi);
> +}
> +
>   static void virtnet_napi_tx_enable(struct virtnet_info *vi,
>   				   struct virtqueue *vq,
>   				   struct napi_struct *napi)
> @@ -2844,7 +2850,7 @@ static void refill_work(struct work_struct *work)
>   
>   		napi_disable(&rq->napi);
>   		still_empty = !try_fill_recv(vi, rq, GFP_KERNEL);
> -		virtnet_napi_enable(rq->vq, &rq->napi);
> +		virtnet_napi_enable_lock(rq->vq, &rq->napi);
>   
>   		/* In theory, this can happen: if we don't get any buffers in
>   		 * we will *never* try to fill again.
> @@ -5621,8 +5627,11 @@ static void virtnet_freeze_down(struct virtio_device *vdev)
>   	netif_tx_lock_bh(vi->dev);
>   	netif_device_detach(vi->dev);
>   	netif_tx_unlock_bh(vi->dev);
> -	if (netif_running(vi->dev))
> +	if (netif_running(vi->dev)) {
> +		rtnl_lock();
>   		virtnet_close(vi->dev);
> +		rtnl_unlock();
> +	}
>   }
>   
>   static int init_vqs(struct virtnet_info *vi);
> @@ -5642,7 +5651,9 @@ static int virtnet_restore_up(struct virtio_device *vdev)
>   	enable_rx_mode_work(vi);
>   
>   	if (netif_running(vi->dev)) {
> +		rtnl_lock();
>   		err = virtnet_open(vi->dev);
> +		rtnl_unlock();
>   		if (err)
>   			return err;
>   	}

Reviewed-by: Gerhard Engleder <gerhard@engleder-embedded.com>
diff mbox series

Patch

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index cff18c66b54a..4e88d352d3eb 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -2803,11 +2803,17 @@  static void virtnet_napi_do_enable(struct virtqueue *vq,
 	local_bh_enable();
 }
 
-static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi)
+static void virtnet_napi_enable_lock(struct virtqueue *vq,
+				     struct napi_struct *napi)
 {
 	virtnet_napi_do_enable(vq, napi);
 }
 
+static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi)
+{
+	virtnet_napi_enable_lock(vq, napi);
+}
+
 static void virtnet_napi_tx_enable(struct virtnet_info *vi,
 				   struct virtqueue *vq,
 				   struct napi_struct *napi)
@@ -2844,7 +2850,7 @@  static void refill_work(struct work_struct *work)
 
 		napi_disable(&rq->napi);
 		still_empty = !try_fill_recv(vi, rq, GFP_KERNEL);
-		virtnet_napi_enable(rq->vq, &rq->napi);
+		virtnet_napi_enable_lock(rq->vq, &rq->napi);
 
 		/* In theory, this can happen: if we don't get any buffers in
 		 * we will *never* try to fill again.
@@ -5621,8 +5627,11 @@  static void virtnet_freeze_down(struct virtio_device *vdev)
 	netif_tx_lock_bh(vi->dev);
 	netif_device_detach(vi->dev);
 	netif_tx_unlock_bh(vi->dev);
-	if (netif_running(vi->dev))
+	if (netif_running(vi->dev)) {
+		rtnl_lock();
 		virtnet_close(vi->dev);
+		rtnl_unlock();
+	}
 }
 
 static int init_vqs(struct virtnet_info *vi);
@@ -5642,7 +5651,9 @@  static int virtnet_restore_up(struct virtio_device *vdev)
 	enable_rx_mode_work(vi);
 
 	if (netif_running(vi->dev)) {
+		rtnl_lock();
 		err = virtnet_open(vi->dev);
+		rtnl_unlock();
 		if (err)
 			return err;
 	}