Skip to content

Commit e7ed2ba

Browse files
committed
net: protect NAPI config fields with netdev_lock()
Protect the following members of netdev and napi by netdev_lock: - defer_hard_irqs, - gro_flush_timeout, - irq_suspend_timeout. The first two are written via sysfs (which this patch switches to new lock), and netdev genl which holds both netdev and rtnl locks. irq_suspend_timeout is only written by netdev genl. 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-11-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 53ed308 commit e7ed2ba

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/linux/netdevice.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ struct napi_struct {
384384
int rx_count; /* length of rx_list */
385385
unsigned int napi_id; /* protected by netdev_lock */
386386
struct hrtimer timer;
387-
struct task_struct *thread; /* protected by netdev_lock */
387+
/* all fields past this point are write-protected by netdev_lock */
388+
struct task_struct *thread;
388389
unsigned long gro_flush_timeout;
389390
unsigned long irq_suspend_timeout;
390391
u32 defer_hard_irqs;
391-
/* all fields past this point are write-protected by netdev_lock */
392392
/* control-path-only fields follow */
393393
struct list_head dev_list;
394394
struct hlist_node napi_hash_node;
@@ -2452,7 +2452,8 @@ struct net_device {
24522452
* Drivers are free to use it for other protection.
24532453
*
24542454
* Protects:
2455-
* @napi_list, @net_shaper_hierarchy, @reg_state, @threaded
2455+
* @gro_flush_timeout, @napi_defer_hard_irqs, @napi_list,
2456+
* @net_shaper_hierarchy, @reg_state, @threaded
24562457
*
24572458
* Partially protects (writers must hold both @lock and rtnl_lock):
24582459
* @up

net/core/net-sysfs.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static ssize_t gro_flush_timeout_store(struct device *dev,
450450
if (!capable(CAP_NET_ADMIN))
451451
return -EPERM;
452452

453-
return netdev_store(dev, attr, buf, len, change_gro_flush_timeout);
453+
return netdev_lock_store(dev, attr, buf, len, change_gro_flush_timeout);
454454
}
455455
NETDEVICE_SHOW_RW(gro_flush_timeout, fmt_ulong);
456456

@@ -470,7 +470,8 @@ static ssize_t napi_defer_hard_irqs_store(struct device *dev,
470470
if (!capable(CAP_NET_ADMIN))
471471
return -EPERM;
472472

473-
return netdev_store(dev, attr, buf, len, change_napi_defer_hard_irqs);
473+
return netdev_lock_store(dev, attr, buf, len,
474+
change_napi_defer_hard_irqs);
474475
}
475476
NETDEVICE_SHOW_RW(napi_defer_hard_irqs, fmt_uint);
476477

0 commit comments

Comments
 (0)