🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #14511

[PATCH net-next 06/15] batman-adv: dat: annotate last_update with READ/WRITE_ONCE

#14511
From: Simon Wunderlich
Date: Wed, 11 Nov 2026 10:27
79 lines
11888 bytes
From: Sven Eckelmann <sven@narfation.org>

The last_update field for batadv_dat_entry tracks the jiffies value of
the most recent activity and is used to detect timeouts. These accesses are
not consistently protected by a lock, so READ_ONCE/WRITE_ONCE must be used
to prevent data races caused by compiler optimizations.

To avoid an underflow due to an non-strict order read of jiffies vs
last_update, use jiffies_delta_to_msecs instead of jiffies_to_msecs to
evaluate the delta.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-4933a0a0-367e-43b3-8da5-29ae37dfdff3
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/distributed-arp-table.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 0260ed7e828b2..7e82c154c13f8 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -11,6 +11,7 @@
 #include <linux/bitops.h>
 #include <linux/bug.h>
 #include <linux/byteorder/generic.h>
+#include <linux/compiler.h>
 #include <linux/container_of.h>
 #include <linux/err.h>
 #include <linux/errno.h>
@@ -206,7 +207,7 @@ static void batadv_dat_entry_put(struct batadv_dat_entry *dat_entry)
  */
 static bool batadv_dat_to_purge(struct batadv_dat_entry *dat_entry)
 {
-	return batadv_has_timed_out(dat_entry->last_update,
+	return batadv_has_timed_out(READ_ONCE(dat_entry->last_update),
 				    BATADV_DAT_ENTRY_TIMEOUT);
 }
 
@@ -453,7 +454,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,
 	if (dat_entry) {
 		atomic64_set(&dat_entry->mac_addr, u64_mac);
 
-		dat_entry->last_update = jiffies;
+		WRITE_ONCE(dat_entry->last_update, jiffies);
 		batadv_dbg(BATADV_DBG_DAT, bat_priv,
 			   "Entry updated: %pI4 %pM (vid: %d)\n",
 			   &dat_entry->ip, mac_addr,
@@ -468,7 +469,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,
 	dat_entry->ip = ip;
 	dat_entry->vid = vid;
 	atomic64_set(&dat_entry->mac_addr, u64_mac);
-	dat_entry->last_update = jiffies;
+	WRITE_ONCE(dat_entry->last_update, jiffies);
 	kref_init(&dat_entry->refcount);
 
 	kref_get(&dat_entry->refcount);
@@ -940,6 +941,7 @@ batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid,
 			    struct batadv_dat_entry *dat_entry)
 {
 	u8 mac[ETH_ALEN] __aligned(2);
+	unsigned long last_update;
 	u64 u64_mac;
 	int msecs;
 	void *hdr;
@@ -952,7 +954,8 @@ batadv_dat_cache_dump_entry(struct sk_buff *msg, u32 portid,
 
 	genl_dump_check_consistent(cb, hdr);
 
-	msecs = jiffies_to_msecs(jiffies - dat_entry->last_update);
+	last_update = READ_ONCE(dat_entry->last_update);
+	msecs = jiffies_delta_to_msecs(jiffies - last_update);
 	u64_mac = atomic64_read(&dat_entry->mac_addr);
 	u64_to_ether_addr(u64_mac, mac);
 
-- 
2.47.3
Technical Details
Message-ID: <20261111102729.2096241-7-sw@simonwunderlich.de>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360993-linux-kernel-netdev=dewy.ru
References: <20261111102729.2096241-1-sw@simonwunderlich.de>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360993-linux-kernel-netdev=dewy.ru
From: sw@simonwunderlich.de (Simon Wunderlich)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 06/15] batman-adv: dat: annotate last_update with READ/WRITE_ONCE
Date: Wed, 11 Nov 2026 11:27:20 +0100
Organization: Usenet Network
Message-ID: <20261111102729.2096241-7-sw@simonwunderlich.de>
References: <20261111102729.2096241-1-sw@simonwunderlich.de>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="832345"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qLuXnL/KAX1QYHcSizLOE5HMiX4= sha256:MMG3hbo7cwTa7UpEvac/iiCBu7s0+ZxwtZMkX3DEmO4=
	sha1:PA0/nHpP67a7fp0vnrNgaaLzwUQ= sha256:tsFD3Pee2iH9b4AL6cZoNExU7SeYoMs8MAMOWjBFHXM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 89F11113EB7; Wed, 11 Nov 2026 13:39:45 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=simonwunderlich.de
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id FK1wCvOJvsvr;
	Wed, 11 Nov 2026 13:39:41 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-360993-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=simonwunderlich.de
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 34286113EB6; Wed, 11 Nov 2026 13:39:32 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 922533BFDE; Wed, 11 Nov 2026 10:27:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794392862;
	b=3nsgMdwaJtVXr+soyAa6DQWyY5NhGvgyCJ3janMv2clCHsdBKgLzRhHPq5unw3TFs4fC
	 zpvfAAaUAFRHUQkCYMHPjutGD96H3aP/2H1OxCyBSBXD4UeF045TSMJKaN8MT481WyOqG
	 ALm47QT56CKu8SY1EXtI0Y7zfX7imXheCKcF8CWdPP493XHTiAP7BryZ+9c5pA5bZO3h+
	 a5S2nMp6wOKn4kFoRi4zfM4wEtV2I9LppUHLzPKYM6mh8MVGF07VBbNwWI9PO8mrRRhRB
	 7+2h9A6D49DW/wbeyZUD9VqMLZDIRWYj49B2ZyPZlaUry8fkutnevfgYNp0zaOGgf0A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794392862;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=i3zqzKOviMB/7i3MMVHu6vwKrbi96jH7wX2hwfL9yZs=;
	b=lZ5MGSvdUVpUJ88LxvrvqZso2slDs2ye3oKo7lepGJ5OFgiyX3k6NDCRQRTe1pb02mBA
	 vSiqSJ05mr8fvb4/CUa8wXL1BatYQwFroXk6rIm5R9pSHkYpTvPL0m0KWqxOl6yt14NXp
	 xE85btL1K0hJBxyNBqetaKqlp53yLjMmLr4YqZusESHEnJeEYyb+tNlmqYHRRJILkVySk
	 e3yqUGLg1LgX76rblCcilOezm9nWbBKHzf8sgk/QSgaCP3HRWL+XDeXnuZLaxbmjvpnlV
	 5P8LU4s0Wz1jOmYeyg2MIUii/a2aa+qAH9lVdV5YJP0/lAEhJy8nuFA30gTKtjzj1TA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=ketxwRrp;
	dmarc=pass header.from=simonwunderlich.de;
	spf=pass smtp.mailfrom=simonwunderlich.de;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id A5EAE606A89B;
	Wed, 11 Nov 2026 10:27:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=ketxwRrp
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=23.88.38.48
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794392861;
	b=YyDOZ9zez9swtVqhh12NB8qkrSDAKeUb3anN3V+7lulnJuyXZ34rW/Ct/Zj2+aPdCatz
	 xsdVD+wG1Cl4J0ZfowtYh4TznjCvkhAxC5dKItoIkHkxYfh/FikjkGtpMQSLm6H7AJNAP
	 8HTURupa0B8NIye1hLCHlC9DOsqjABmPW1pam7DuDad4c/q3SbIuS7ID+CTjOGOH4SL3P
	 9iradcK68lHscRl/8r2bN6l0t4aRuBjoCsRAsZXLSq9C6bP/yY2yfBEA4BkP2nsPRIlgu
	 Zy7eIKXsVArzuOObu18V0Wv4BB5MNA2FwGI+m/mSxE1tgyizUlBmolTo3Sv3DyD/7tw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794392861;
	h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=i3zqzKOviMB/7i3MMVHu6vwKrbi96jH7wX2hwfL9yZs=;
	b=Iyrs8oHMMg5xE939X0327EV8H8T8YTxl8oBV1+yHZzVzsuwq5rVZK0ZpqRh4ksmImnMK
	 RpukVgxdt4AOoZvTwT2WMbYp1VYi2Rbxhn5EvE0UryOO0yNMSf1Eu46qDMyS9wWGvLjgI
	 qKNBHiWs5gHtmHQLcG4PGVtVlS+8EhnwykX87+IJPvLaASqtdVaKQK63IFXQl1SKeCV0h
	 q7m/N0cT6leQVwhnFhdt2l6eLDJxcsIxRdbCk1c3uPmNKS8nuWPSd9xrdnIsA3Gl6XrBB
	 lwC5pugaY8uLx2nr6Boi2dajcpaPaXdhsuHxpgJSneT095/7OnnnUrsRa5+/rX9xesw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=simonwunderlich.de;
	spf=pass smtp.mailfrom=simonwunderlich.de;
	dkim=pass header.d=simonwunderlich.de header.i=@simonwunderlich.de header.a=rsa-sha256 header.s=09092022 header.b=ketxwRrp;
	arc=none smtp.remote-ip=23.88.38.48
X-Received: from mail.simonwunderlich.de (mail.simonwunderlich.de [23.88.38.48])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 538D6606A883
	for <netdev@vger.kernel.org>; Wed, 11 Nov 2026 10:27:41 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 538D6606A883
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=simonwunderlich.de
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=simonwunderlich.de
X-Received: from kero.packetmixer.de (p200300c59740DeD843BE7E4A980e9C65.dip0.t-ipconnect.de [IPv6:2003:c5:9740:ded8:43be:7e4a:980e:9c65])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mail.simonwunderlich.de (Postfix) with UTF8SMTPSA id F21CBFA1BF;
	Wed, 11 Nov 2026 11:27:35 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=simonwunderlich.de;
	s=09092022; t=1794392856;
	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=i3zqzKOviMB/7i3MMVHu6vwKrbi96jH7wX2hwfL9yZs=;
	b=ketxwRrpYj6dSTh62/2AwYyFHwCu+GS0t11cfu1psnbF3zyXjQ4YOf+ZpEF0OgFdCPEsN1
	26Bv9IkBo9EVXgeYtd+bfM8mmHwvSUB6OplPpQpe98MnpfLDrnjZlWQWWFoq/XS2knsrcK
	ZeAHCW5bQtvNn5KFomqMB/Uxrd4dQtwOiAKk0Ozm6MgO5ObbFVq4abYvDE2JCW3dyEBKv3
	igrzzyZZVrcTj0OGijtVAdrPJoPas+6Lr7Yj22tT7qEgqfJcvKXLnOPGqzY+djxyhv2uW0
	yPT4mXLZAKzVSo8SRah8WsYDkgYds8tXdxu9O+1qb2zuyGAy105ijhNfBq7q8g==
X-Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	b.a.t.m.a.n@lists.open-mesh.org,
	Sven Eckelmann <sven@narfation.org>,
	Sashiko <sashiko-bot@kernel.org>,
	Simon Wunderlich <sw@simonwunderlich.de>
X-Mailer: git-send-email 2.47.3
X-In-Reply-To: <20261111102729.2096241-1-sw@simonwunderlich.de>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list