summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2026-08-12 08:54:39 +0000
committerJakub Kicinski <kuba@kernel.org>2026-08-17 10:27:48 -0700
commit0c6c32a8c854e570998494b8368d314d526ddbd3 (patch)
treecff3777bad39a4f4e9a6342bd8e90bfe79bd570d /include/linux
parent21ef2d065ad3f0cfbf2ae51260bf962a9fa2c643 (diff)
net: add READ_ONCE()/WRITE_ONCE() annotations for dev->num_tc
Several fast-path and control-path lockless readers access dev->num_tc (e.g., skb_tx_hash(), netdev_txq_to_tc(), netdev_get_num_tc(), and qdisc/driver lookups) while concurrent writers update dev->num_tc during TC setup, device reset, or channel configuration. Add READ_ONCE() and WRITE_ONCE() annotations to prevent compiler reordering and load/store tearing when accessing dev->num_tc. Update inline helpers in netdevice.h (netdev_get_num_tc(), netdev_set_prio_tc_map(), and netdev_get_sb_channel()) as well as writers and lockless readers in core networking code and drivers. Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://patch.msgid.link/20260812085440.3917924-3-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/netdevice.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 9d22e6b0df60..fd1916261072 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2678,7 +2678,7 @@ int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
static inline
int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
{
- if (tc >= dev->num_tc)
+ if (tc >= READ_ONCE(dev->num_tc))
return -EINVAL;
dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
@@ -2691,9 +2691,9 @@ int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset);
int netdev_set_num_tc(struct net_device *dev, u8 num_tc);
static inline
-int netdev_get_num_tc(struct net_device *dev)
+int netdev_get_num_tc(const struct net_device *dev)
{
- return dev->num_tc;
+ return READ_ONCE(dev->num_tc);
}
static inline void net_prefetch(void *p)
@@ -2720,7 +2720,7 @@ int netdev_bind_sb_channel_queue(struct net_device *dev,
int netdev_set_sb_channel(struct net_device *dev, u16 channel);
static inline int netdev_get_sb_channel(struct net_device *dev)
{
- return max_t(int, -dev->num_tc, 0);
+ return max_t(int, -READ_ONCE(dev->num_tc), 0);
}
static inline