net: designate XSK pool pointers in queues as "ops protected"
authorJakub Kicinski <kuba@kernel.org>
Tue, 8 Apr 2025 19:59:49 +0000 (12:59 -0700)
committerJakub Kicinski <kuba@kernel.org>
Thu, 10 Apr 2025 00:01:51 +0000 (17:01 -0700)
Read accesses go via xsk_get_pool_from_qid(), the call coming
from the core and gve look safe (other "ops locked" drivers
don't support XSK).

Write accesses go via xsk_reg_pool_at_qid() and xsk_clear_pool_at_qid().
Former is already under the ops lock, latter is not (both coming from
the workqueue via xp_clear_dev() and NETDEV_UNREGISTER via xsk_notifier()).

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250408195956.412733-3-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/netdevice.h
include/net/netdev_rx_queue.h
net/xdp/xsk_buff_pool.c

index 8e9be80bc1670a9ba89bfab74e043dc6afb6c684..7242fb8a22fc5aa78c046d600c72248978f9a55e 100644 (file)
@@ -688,6 +688,7 @@ struct netdev_queue {
        /* Subordinate device that the queue has been assigned to */
        struct net_device       *sb_dev;
 #ifdef CONFIG_XDP_SOCKETS
+       /* "ops protected", see comment about net_device::lock */
        struct xsk_buff_pool    *pool;
 #endif
 
index b2238b551dced53fc907c1e1b611110cf0213e4a..8cdcd138b33f2d713a34c2886eae388da42be22e 100644 (file)
@@ -20,12 +20,12 @@ struct netdev_rx_queue {
        struct net_device               *dev;
        netdevice_tracker               dev_tracker;
 
+       /* All fields below are "ops protected",
+        * see comment about net_device::lock
+        */
 #ifdef CONFIG_XDP_SOCKETS
        struct xsk_buff_pool            *pool;
 #endif
-       /* NAPI instance for the queue
-        * "ops protected", see comment about net_device::lock
-        */
        struct napi_struct              *napi;
        struct pp_memory_provider_params mp_params;
 } ____cacheline_aligned_in_smp;
index 25a76c5ce0f12878dd3bdf5877cf14d2ef63e3b2..cbf2129e808b30f525c22e47bdf5a6fea1ce5113 100644 (file)
@@ -266,13 +266,17 @@ int xp_assign_dev_shared(struct xsk_buff_pool *pool, struct xdp_sock *umem_xs,
 
 void xp_clear_dev(struct xsk_buff_pool *pool)
 {
+       struct net_device *netdev = pool->netdev;
+
        if (!pool->netdev)
                return;
 
+       netdev_lock_ops(netdev);
        xp_disable_drv_zc(pool);
        xsk_clear_pool_at_qid(pool->netdev, pool->queue_id);
-       dev_put(pool->netdev);
        pool->netdev = NULL;
+       netdev_unlock_ops(netdev);
+       dev_put(netdev);
 }
 
 static void xp_release_deferred(struct work_struct *work)