From nobody Wed Apr 1 23:51:46 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 863672E8E09 for ; Wed, 1 Apr 2026 06:05:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775023544; cv=none; b=DSFL06kcWCnPiqJ5aKl1R6WXNk4LNmnPcgdLue687NOm4U9YvN12aAqEbs/9ySCZI2hoicXZ8CORpQ8T+zQUalt8QufsnN2CxJgu0N/ArR/1UxA6qnhPCVDL1XDQ1IsYk1+IqXaZOSRVUspWQxlET5zx61x3b8trvuTvwB3So0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775023544; c=relaxed/simple; bh=riyU8vHNfE+1WJo560BCnv4d01q2x8dxI6Sfshs/X8I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BUEyGQ7X7q0jhKBnyXybg40SVAmyh69MyVtNBVTiZUeGoZKFW5JeGMqJbuJNm9yMMdIQg9FflnFy5+gnRwvXgvtAn1vYVlFDucoTPn3VUIdb7ryOdm3XYN7s+dxga0sbdY0z2w9W5jZ1uCJWzKrB60jUw32AxBLJK/rLgIiVK7Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--marcharvey.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rLLJ5WXi; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--marcharvey.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rLLJ5WXi" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-128d59030d0so26270708c88.0 for ; Tue, 31 Mar 2026 23:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775023542; x=1775628342; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9ankry/lV9AonDaqBDI1RKEvyyWLrtwB+yzkL/8QxFk=; b=rLLJ5WXiDy2sUQhI1Px8GzwBkmfZZrpK5yQhHR2I60Rel13DArIDTetWhagkYXA1Ct GnF902c3YmJE89X5JH9kgJ0Eic48jUBZhPWCt7aw1DOlTOGd1PpaxjCw/0Qnri6I76iR yXG6OySPVT5uo6LBdOyI6ao1exIUQFnzO5VTgQUSuXPh57iqoTw2fGIQS+iSq3DOaGom kvr2XFc7Fh45HMah+H58MTDkuGVBrHmo+11TD5Y8wLhMyQFJtcl2XlsLep1y6nUAQOx/ xRMVrv0bDmPO3K2AhFdrUxX6ZKrDibrCRVuY21SO/AB2pn8zub8SJxYM8AdYi43c4Pcb dmwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775023542; x=1775628342; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9ankry/lV9AonDaqBDI1RKEvyyWLrtwB+yzkL/8QxFk=; b=iA+XNEME8VZ4QRF17+FOji5hMyctrHKUiqbQqJwJlmNL71Wz9WLVaAJkUUdRsyxjJZ AT2VoUr0B2SlV5bAW0Ect0G7VLsRbtb24fP/qlQGMzmEzm9BW5GRZ5idllCvbRrrj6gU YFzpDUYNg9ZNnJz0xCV/tMVNFEKQWLaNNi5hCopN9oBGtIS1f4s/naaxfCCjw1fqPf2C Gai7gTmH2bh7ITrBp4EdGW9WVrxgvnd6sPbzJtDtUJa9j4hsv92WhXVxmlHOlPTe+Uov 5Cl0nzdRroYjuDCoMcM9MvcbpyMibZ+LSeWZ07WvErGfXAFFRIzdOCH7eAW3qBle+kay mkDw== X-Forwarded-Encrypted: i=1; AJvYcCWFoiVqy+zb/DJ7zku7deDY2Iy/thpw714tIWuF5+1or2UZdKDh25M8EwRM3TloBcUOSDU6Ylm2wXZEqnk=@vger.kernel.org X-Gm-Message-State: AOJu0YwDEwDWdVa8FieK+D6Z5Bj+eYZ055+4uyg7b6u1BA3vJnub5kC8 TA96xmF23ck13dKvSdVRjrve8FhyT7CW5+aiFMzedrz2mFkkiPTkBPaluwnTiCLkKdVbvXXdaTa vWxSEaopcvgSTqhyndQZ7Gg== X-Received: from dlea18-n2.prod.google.com ([2002:a05:701b:4212:20b0:128:dd22:12cd]) (user=marcharvey job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:670f:b0:128:bae9:c069 with SMTP id a92af1059eb24-12be654bc86mr1474279c88.33.1775023541385; Tue, 31 Mar 2026 23:05:41 -0700 (PDT) Date: Wed, 01 Apr 2026 06:05:25 +0000 In-Reply-To: <20260401-teaming-driver-internal-v2-0-f80c1291727b@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260401-teaming-driver-internal-v2-0-f80c1291727b@google.com> X-Developer-Key: i=marcharvey@google.com; a=ed25519; pk=OzOeciadbfF5Bug/4/hyEAwfrruSY4tn0Q0LocyYUL0= X-Developer-Signature: v=1; a=ed25519-sha256; t=1775023538; l=3665; i=marcharvey@google.com; s=20260401; h=from:subject:message-id; bh=riyU8vHNfE+1WJo560BCnv4d01q2x8dxI6Sfshs/X8I=; b=e2Y6yARA2z8bZQKESrRpOLOxdHQcqYmWWB5p0Dl3ZHngh6oIVov5Cz5wfvs7aXHGgx5lkyvNl WgKwxdB3BopAAqgA0zp8YZW9xuE3SQQiiSUfDCEamE0S4NCwjkNhtjA X-Mailer: b4 0.14.3 Message-ID: <20260401-teaming-driver-internal-v2-1-f80c1291727b@google.com> Subject: [PATCH net-next v2 1/7] net: team: Annotate reads and writes for mixed lock accessed values From: Marc Harvey To: Jiri Pirko , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan , Simon Horman Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Marc Harvey Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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. Signed-off-by: Marc Harvey --- Changes in v2: - None --- drivers/net/team/team_core.c | 11 ++++++----- drivers/net/team/team_mode_random.c | 2 +- include/linux/if_team.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/net/team/team_core.c b/drivers/net/team/team_core.c index 566a5d102c23..becd066279a6 100644 --- a/drivers/net/team/team_core.c +++ b/drivers/net/team/team_core.c @@ -938,7 +938,8 @@ static void team_port_enable(struct team *team, { if (team_port_enabled(port)) return; - port->index =3D 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 =3D rm_index + 1; i < team->en_port_count; i++) { port =3D 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 =3D -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 ne= t_device *port_dev, netif_addr_unlock_bh(dev); } =20 - port->index =3D -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); diff --git a/drivers/net/team/team_mode_random.c b/drivers/net/team/team_mo= de_random.c index 53d0ce34b8ce..169a7bc865b2 100644 --- a/drivers/net/team/team_mode_random.c +++ b/drivers/net/team/team_mode_random.c @@ -16,7 +16,7 @@ static bool rnd_transmit(struct team *team, struct sk_buf= f *skb) struct team_port *port; int port_index; =20 - port_index =3D get_random_u32_below(team->en_port_count); + port_index =3D get_random_u32_below(READ_ONCE(team->en_port_count)); port =3D team_get_port_by_index_rcu(team, port_index); if (unlikely(!port)) goto drop; diff --git a/include/linux/if_team.h b/include/linux/if_team.h index ccb5327de26d..06f4d7400c1e 100644 --- a/include/linux/if_team.h +++ b/include/linux/if_team.h @@ -77,7 +77,7 @@ static inline struct team_port *team_port_get_rcu(const s= truct net_device *dev) =20 static inline bool team_port_enabled(struct team_port *port) { - return port->index !=3D -1; + return READ_ONCE(port->index) !=3D -1; } =20 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 =3D team_port_index_hash(team, port_index); =20 hlist_for_each_entry_rcu(port, head, hlist) - if (port->index =3D=3D port_index) + if (READ_ONCE(port->index) =3D=3D port_index) return port; return NULL; } --=20 2.53.0.1118.gaef5881109-goog