Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 262E5379C2F for ; Mon, 1 Jun 2026 12:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=23.88.38.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780317418; cv=none; b=GSBDPfvN3hgtbZIALjqN1xrEDVxeAatHGfng3KpY+T73Z4Hq/5SKFr0nm8cb/usa7yMlUpY0NwT//8P4TxjVlxaBwHL4zmwEPVoNXG+nb4F7tCbHXeoJvug4HSWg31tZm93hUETz3eUSTuzlzBmI+fF0VIMfoK2sz9dwJx1Epto= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780317418; c=relaxed/simple; bh=z6AHHk6pcyhVzMHzKwOXbJLPIH22QVny3TnICcdEjhs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EiirZOOi1MS+zamd0DdGUrCsdiejnPV77+0TaArMD35rpAJLX1Nv/JwbAgktpGB+W1AwwtR4qex3a/ZkNTmSvia29i204agO8pf5JZJ66LBZNaAc2f+fNxYX+Jnl2boMYvkydTQwECmc0FGjKX1gSduaeDKZgh32fAgN5RBU0iw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de; spf=pass smtp.mailfrom=simonwunderlich.de; dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.b=cKTHiUyL; arc=none smtp.client-ip=23.88.38.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=simonwunderlich.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.b="cKTHiUyL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simonwunderlich.de; s=09092022; t=1780317412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ri4AHRHZCuDHoKH27mQCgD4is/vIvn27vJEihLqUnqo=; b=cKTHiUyLyA8ZXZzltVrKRaGBttu5cooLFMoPX8TNenkCAd7joQkJnSQY3hw9ou05x3ZOeo Gl7VGjwki/eiSiLxgWyuQmmnRoH0+scgs7yMOi2jHpB0CGPPUBKLHqeoWfSbjtDMCCmx74 FNBT0ea12gqtgUbK3jVPfcueWuVxoRoEb5R6DE0C4KGdMFnjp9lkv9Eb07pThsysvMk0x6 BwvtPwtkspr0IPkJduPbWvR+FxXdFGY7KzT3Wj2LQus6lGm2GHRmxBX+U0HPLKelYghEcV 7DjcQTA+6RezUQ3SU0jfaevGlxvc4IUcWa4sQ8XptToiuYPyDgcIAU5NpKZA3g== From: Simon Wunderlich To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , b.a.t.m.a.n@lists.open-mesh.org, Sven Eckelmann , Simon Wunderlich Subject: [PATCH net-next v2 11/15] batman-adv: replace non-atomic packet_size_max with (READ|WRITE)_ONCE Date: Mon, 1 Jun 2026 14:36:25 +0200 Message-ID: <20260601123629.707089-12-sw@simonwunderlich.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260601123629.707089-1-sw@simonwunderlich.de> References: <20260601123629.707089-1-sw@simonwunderlich.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sven Eckelmann The maximum packet size of an meshif is only accessed as plain loads/stores and does not require full atomic_t semantics. Convert to a native integer and replace its users with READ_ONCE()/WRITE_ONCE() to avoid load/store tearing. Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- net/batman-adv/hard-interface.c | 3 +-- net/batman-adv/mesh-interface.c | 2 +- net/batman-adv/translation-table.c | 6 +++--- net/batman-adv/types.h | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 86e7d10864e2f..bb3c31b5f259d 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -7,7 +7,6 @@ #include "hard-interface.h" #include "main.h" -#include #include #include #include @@ -629,7 +628,7 @@ int batadv_hardif_min_mtu(struct net_device *mesh_iface) * overhead). For example, this value is used by TT to compute the * maximum local table size */ - atomic_set(&bat_priv->packet_size_max, min_mtu); + WRITE_ONCE(bat_priv->packet_size_max, min_mtu); /* the real mesh-interface MTU is computed by removing the payload * overhead from the maximum amount of bytes that was just computed. diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c index 7497f307c10db..b6797654b18ab 100644 --- a/net/batman-adv/mesh-interface.c +++ b/net/batman-adv/mesh-interface.c @@ -779,7 +779,7 @@ static int batadv_meshif_init_late(struct net_device *dev) WRITE_ONCE(bat_priv->log_level, 0); #endif WRITE_ONCE(bat_priv->fragmentation, 1); - atomic_set(&bat_priv->packet_size_max, BATADV_MAX_MTU); + WRITE_ONCE(bat_priv->packet_size_max, BATADV_MAX_MTU); atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN); atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN); diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 515f26ff8c269..e319b0796f7c8 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c @@ -649,7 +649,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, /* Ignore the client if we cannot send it in a full table response. */ table_size = batadv_tt_local_table_transmit_size(bat_priv); table_size += batadv_tt_len(1); - packet_size_max = atomic_read(&bat_priv->packet_size_max); + packet_size_max = READ_ONCE(bat_priv->packet_size_max); if (table_size > packet_size_max) { net_ratelimited_function(batadv_info, mesh_iface, "Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n", @@ -3069,7 +3069,7 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv, /* Don't send the response, if larger than fragmented packet. */ tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len; - if (tt_len > atomic_read(&bat_priv->packet_size_max)) { + if (tt_len > READ_ONCE(bat_priv->packet_size_max)) { net_ratelimited_function(batadv_info, bat_priv->mesh_iface, "Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n", res_dst_orig_node->orig); @@ -3932,7 +3932,7 @@ bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv, void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface) { struct batadv_priv *bat_priv = netdev_priv(mesh_iface); - int packet_size_max = atomic_read(&bat_priv->packet_size_max); + int packet_size_max = READ_ONCE(bat_priv->packet_size_max); int table_size, timeout = BATADV_TT_LOCAL_TIMEOUT / 2; bool reduced = false; diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h index 58375c0a643b8..7533d71b73725 100644 --- a/net/batman-adv/types.h +++ b/net/batman-adv/types.h @@ -1570,7 +1570,7 @@ struct batadv_priv { * multiple fragmented skbs or a single frame if fragmentation is * disabled */ - atomic_t packet_size_max; + int packet_size_max; /** * @frag_seqno: incremental counter to identify chains of egress -- 2.47.3