Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: team: Annotate reads and writes for mixed lock accessed values

The team_port's "index" and the team's "en_port_count" are read in
the hot transmit path, but are only written to when holding the rtnl
lock.

Use READ_ONCE() for all lockless reads of these values, and use
WRITE_ONCE() for all writes.

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Marc Harvey <marcharvey@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260409-teaming-driver-internal-v7-1-f47e7589685d@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Marc Harvey and committed by
Paolo Abeni
3faf0ce6 8806d502

+9 -8
+6 -5
drivers/net/team/team_core.c
··· 938 938 { 939 939 if (team_port_enabled(port)) 940 940 return; 941 - port->index = team->en_port_count++; 941 + WRITE_ONCE(port->index, team->en_port_count); 942 + WRITE_ONCE(team->en_port_count, team->en_port_count + 1); 942 943 hlist_add_head_rcu(&port->hlist, 943 944 team_port_index_hash(team, port->index)); 944 945 team_adjust_ops(team); ··· 959 958 for (i = rm_index + 1; i < team->en_port_count; i++) { 960 959 port = team_get_port_by_index(team, i); 961 960 hlist_del_rcu(&port->hlist); 962 - port->index--; 961 + WRITE_ONCE(port->index, port->index - 1); 963 962 hlist_add_head_rcu(&port->hlist, 964 963 team_port_index_hash(team, port->index)); 965 964 } ··· 974 973 team->ops.port_disabled(team, port); 975 974 hlist_del_rcu(&port->hlist); 976 975 __reconstruct_port_hlist(team, port->index); 977 - port->index = -1; 978 - team->en_port_count--; 976 + WRITE_ONCE(port->index, -1); 977 + WRITE_ONCE(team->en_port_count, team->en_port_count - 1); 979 978 team_queue_override_port_del(team, port); 980 979 team_adjust_ops(team); 981 980 team_lower_state_changed(port); ··· 1246 1245 netif_addr_unlock_bh(dev); 1247 1246 } 1248 1247 1249 - port->index = -1; 1248 + WRITE_ONCE(port->index, -1); 1250 1249 list_add_tail_rcu(&port->list, &team->port_list); 1251 1250 team_port_enable(team, port); 1252 1251 netdev_compute_master_upper_features(dev, true);
+1 -1
drivers/net/team/team_mode_random.c
··· 16 16 struct team_port *port; 17 17 int port_index; 18 18 19 - port_index = get_random_u32_below(team->en_port_count); 19 + port_index = get_random_u32_below(READ_ONCE(team->en_port_count)); 20 20 port = team_get_port_by_index_rcu(team, port_index); 21 21 if (unlikely(!port)) 22 22 goto drop;
+2 -2
include/linux/if_team.h
··· 77 77 78 78 static inline bool team_port_enabled(struct team_port *port) 79 79 { 80 - return port->index != -1; 80 + return READ_ONCE(port->index) != -1; 81 81 } 82 82 83 83 static inline bool team_port_txable(struct team_port *port) ··· 272 272 struct hlist_head *head = team_port_index_hash(team, port_index); 273 273 274 274 hlist_for_each_entry_rcu(port, head, hlist) 275 - if (port->index == port_index) 275 + if (READ_ONCE(port->index) == port_index) 276 276 return port; 277 277 return NULL; 278 278 }