Skip to content

Commit 53ed308

Browse files
committed
net: protect napi->irq with netdev_lock()
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>
1 parent 1bb86cf commit 53ed308

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

include/linux/netdevice.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ struct napi_struct {
388388
unsigned long gro_flush_timeout;
389389
unsigned long irq_suspend_timeout;
390390
u32 defer_hard_irqs;
391+
/* all fields past this point are write-protected by netdev_lock */
391392
/* control-path-only fields follow */
392393
struct list_head dev_list;
393394
struct hlist_node napi_hash_node;
@@ -2706,11 +2707,18 @@ static inline void netdev_assert_locked_or_invisible(struct net_device *dev)
27062707
netdev_assert_locked(dev);
27072708
}
27082709

2709-
static inline void netif_napi_set_irq(struct napi_struct *napi, int irq)
2710+
static inline void netif_napi_set_irq_locked(struct napi_struct *napi, int irq)
27102711
{
27112712
napi->irq = irq;
27122713
}
27132714

2715+
static inline void netif_napi_set_irq(struct napi_struct *napi, int irq)
2716+
{
2717+
netdev_lock(napi->dev);
2718+
netif_napi_set_irq_locked(napi, irq);
2719+
netdev_unlock(napi->dev);
2720+
}
2721+
27142722
/* Default NAPI poll() weight
27152723
* Device drivers are strongly advised to not use bigger value
27162724
*/

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6957,7 +6957,7 @@ void netif_napi_add_weight_locked(struct net_device *dev,
69576957
*/
69586958
if (dev->threaded && napi_kthread_create(napi))
69596959
dev->threaded = false;
6960-
netif_napi_set_irq(napi, -1);
6960+
netif_napi_set_irq_locked(napi, -1);
69616961
}
69626962
EXPORT_SYMBOL(netif_napi_add_weight_locked);
69636963

0 commit comments

Comments
 (0)