]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: team: Annotate reads and writes for mixed lock accessed values
authorMarc Harvey <marcharvey@google.com>
Thu, 9 Apr 2026 02:59:23 +0000 (02:59 +0000)
committerPaolo Abeni <pabeni@redhat.com>
Mon, 13 Apr 2026 13:09:48 +0000 (15:09 +0200)
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>
drivers/net/team/team_core.c
drivers/net/team/team_mode_random.c
include/linux/if_team.h

index 566a5d102c2399840ad164f1b04099cbbf839d6a..becd066279a622f1047000c9baec7caebf905a2b 100644 (file)
@@ -938,7 +938,8 @@ static void team_port_enable(struct team *team,
 {
        if (team_port_enabled(port))
                return;
-       port->index = team->en_port_count++;
+       WRITE_ONCE(port->index, team->en_port_count);
+       WRITE_ONCE(team->en_port_count, team->en_port_count + 1);
        hlist_add_head_rcu(&port->hlist,
                           team_port_index_hash(team, port->index));
        team_adjust_ops(team);
@@ -958,7 +959,7 @@ static void __reconstruct_port_hlist(struct team *team, int rm_index)
        for (i = rm_index + 1; i < team->en_port_count; i++) {
                port = team_get_port_by_index(team, i);
                hlist_del_rcu(&port->hlist);
-               port->index--;
+               WRITE_ONCE(port->index, port->index - 1);
                hlist_add_head_rcu(&port->hlist,
                                   team_port_index_hash(team, port->index));
        }
@@ -973,8 +974,8 @@ static void team_port_disable(struct team *team,
                team->ops.port_disabled(team, port);
        hlist_del_rcu(&port->hlist);
        __reconstruct_port_hlist(team, port->index);
-       port->index = -1;
-       team->en_port_count--;
+       WRITE_ONCE(port->index, -1);
+       WRITE_ONCE(team->en_port_count, team->en_port_count - 1);
        team_queue_override_port_del(team, port);
        team_adjust_ops(team);
        team_lower_state_changed(port);
@@ -1245,7 +1246,7 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
                netif_addr_unlock_bh(dev);
        }
 
-       port->index = -1;
+       WRITE_ONCE(port->index, -1);
        list_add_tail_rcu(&port->list, &team->port_list);
        team_port_enable(team, port);
        netdev_compute_master_upper_features(dev, true);
index 53d0ce34b8ced631bd8e1be8c62a38ffd8753df6..169a7bc865b2a8f624f03c9768ca2c81a0f8b86c 100644 (file)
@@ -16,7 +16,7 @@ static bool rnd_transmit(struct team *team, struct sk_buff *skb)
        struct team_port *port;
        int port_index;
 
-       port_index = get_random_u32_below(team->en_port_count);
+       port_index = get_random_u32_below(READ_ONCE(team->en_port_count));
        port = team_get_port_by_index_rcu(team, port_index);
        if (unlikely(!port))
                goto drop;
index ccb5327de26d08425210111ad3c35efbc65159ad..06f4d7400c1e1425698ce6df1a40e51e7ad000fe 100644 (file)
@@ -77,7 +77,7 @@ static inline struct team_port *team_port_get_rcu(const struct net_device *dev)
 
 static inline bool team_port_enabled(struct team_port *port)
 {
-       return port->index != -1;
+       return READ_ONCE(port->index) != -1;
 }
 
 static inline bool team_port_txable(struct team_port *port)
@@ -272,7 +272,7 @@ static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
        struct hlist_head *head = team_port_index_hash(team, port_index);
 
        hlist_for_each_entry_rcu(port, head, hlist)
-               if (port->index == port_index)
+               if (READ_ONCE(port->index) == port_index)
                        return port;
        return NULL;
 }