]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: designate queue -> napi linking as "ops protected"
authorJakub Kicinski <kuba@kernel.org>
Mon, 24 Mar 2025 22:45:32 +0000 (15:45 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 25 Mar 2025 17:06:49 +0000 (10:06 -0700)
netdev netlink is the only reader of netdev_{,rx_}queue->napi,
and it already holds netdev->lock. Switch protection of
the writes to netdev->lock to "ops protected".

The expectation will be now that accessing queue->napi
will require netdev->lock for "ops locked" drivers, and
rtnl_lock for all other drivers.

Current "ops locked" drivers don't require any changes.
gve and netdevsim use _locked() helpers right next to
netif_queue_set_napi() so they must be holding the instance
lock. iavf doesn't call it. bnxt is a bit messy but all paths
seem locked.

Acked-by: Stanislav Fomichev <sdf@fomichev.me>
Link: https://patch.msgid.link/20250324224537.248800-7-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/netdevice.h
include/net/netdev_lock.h
include/net/netdev_rx_queue.h
net/core/dev.c

index 60ef367d857569cbb8b8b9c92d5b0f37af39276a..fa79145518d1eb845ada659165c2d95fad53d343 100644 (file)
@@ -710,7 +710,7 @@ struct netdev_queue {
  * slow- / control-path part
  */
        /* NAPI instance for the queue
-        * Readers and writers must hold RTNL
+        * "ops protected", see comment about net_device::lock
         */
        struct napi_struct      *napi;
 
@@ -2526,7 +2526,8 @@ struct net_device {
         * Double ops protects:
         *      @real_num_rx_queues, @real_num_tx_queues
         *
-        * Also protects some fields in struct napi_struct.
+        * Also protects some fields in:
+        *      struct napi_struct, struct netdev_queue, struct netdev_rx_queue
         *
         * Ordering: take after rtnl_lock.
         */
index efd302375ef2a19ac13410e37a4d4b2826b0fc67..1c0c9a94cc224ae592ab6227babd0c59c119529f 100644 (file)
@@ -56,6 +56,14 @@ static inline void netdev_ops_assert_locked(const struct net_device *dev)
                ASSERT_RTNL();
 }
 
+static inline void
+netdev_ops_assert_locked_or_invisible(const struct net_device *dev)
+{
+       if (dev->reg_state == NETREG_REGISTERED ||
+           dev->reg_state == NETREG_UNREGISTERING)
+               netdev_ops_assert_locked(dev);
+}
+
 static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,
                                     const struct lockdep_map *b)
 {
index af40842f229d9aa93b2fe4ccf7a985480581894a..b2238b551dced53fc907c1e1b611110cf0213e4a 100644 (file)
@@ -24,7 +24,7 @@ struct netdev_rx_queue {
        struct xsk_buff_pool            *pool;
 #endif
        /* NAPI instance for the queue
-        * Readers and writers must hold RTNL
+        * "ops protected", see comment about net_device::lock
         */
        struct napi_struct              *napi;
        struct pp_memory_provider_params mp_params;
index 2d9be3ecd5e6a5e3c68063569830b4beea4231da..ab74e1f005d2ec85c7e12f2de846b65e5e7b55be 100644 (file)
@@ -6901,8 +6901,7 @@ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
 
        if (WARN_ON_ONCE(napi && !napi->dev))
                return;
-       if (dev->reg_state >= NETREG_REGISTERED)
-               ASSERT_RTNL();
+       netdev_ops_assert_locked_or_invisible(dev);
 
        switch (type) {
        case NETDEV_QUEUE_TYPE_RX: