]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: protect napi->irq with netdev_lock()
authorJakub Kicinski <kuba@kernel.org>
Wed, 15 Jan 2025 03:53:17 +0000 (19:53 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 16 Jan 2025 03:13:34 +0000 (19:13 -0800)
Take netdev_lock() in netif_napi_set_irq(). All NAPI "control fields"
are now protected by that lock (most of the other ones are set during
napi add/del). The napi_hash_node is fully protected by the hash
spin lock, but close enough for the kdoc...

Reviewed-by: Joe Damato <jdamato@fastly.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250115035319.559603-10-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/netdevice.h
net/core/dev.c

index 20e773bbd1819fdf8720db418599c6225f2ceb55..a47ff20365f928b837e91eccea4507c1ee85bba1 100644 (file)
@@ -388,6 +388,7 @@ struct napi_struct {
        unsigned long           gro_flush_timeout;
        unsigned long           irq_suspend_timeout;
        u32                     defer_hard_irqs;
+       /* all fields past this point are write-protected by netdev_lock */
        /* control-path-only fields follow */
        struct list_head        dev_list;
        struct hlist_node       napi_hash_node;
@@ -2706,11 +2707,18 @@ static inline void netdev_assert_locked_or_invisible(struct net_device *dev)
                netdev_assert_locked(dev);
 }
 
-static inline void netif_napi_set_irq(struct napi_struct *napi, int irq)
+static inline void netif_napi_set_irq_locked(struct napi_struct *napi, int irq)
 {
        napi->irq = irq;
 }
 
+static inline void netif_napi_set_irq(struct napi_struct *napi, int irq)
+{
+       netdev_lock(napi->dev);
+       netif_napi_set_irq_locked(napi, irq);
+       netdev_unlock(napi->dev);
+}
+
 /* Default NAPI poll() weight
  * Device drivers are strongly advised to not use bigger value
  */
index 34db90f345d54d5a9b89590400ac12f137149d35..b6722ed9767a9e8ec0232e9b4f2f5e6408453fe2 100644 (file)
@@ -6957,7 +6957,7 @@ void netif_napi_add_weight_locked(struct net_device *dev,
         */
        if (dev->threaded && napi_kthread_create(napi))
                dev->threaded = false;
-       netif_napi_set_irq(napi, -1);
+       netif_napi_set_irq_locked(napi, -1);
 }
 EXPORT_SYMBOL(netif_napi_add_weight_locked);