From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>,
Sabrina Dubroca <sd@queasysnail.net>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Nikolay Aleksandrov <razor@blackwall.org>,
Ido Schimmel <idosch@nvidia.com>, Simon Horman <horms@kernel.org>,
Aaron Conole <aconole@redhat.com>,
Eelco Chaudron <echaudro@redhat.com>,
Ilya Maximets <i.maximets@ovn.org>,
Shigeru Yoshida <syoshida@redhat.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Breno Leitao <leitao@debian.org>,
Carolina Jubran <cjubran@nvidia.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
Guillaume Nault <gnault@redhat.com>,
linux-kernel@vger.kernel.org, bridge@lists.linux.dev,
dev@openvswitch.org
Subject: [PATCH net-next v2 1/7] u64_stats: Introduce u64_stats_reads()
Date: Sat, 24 Jan 2026 00:21:33 +0800 [thread overview]
Message-ID: <20260123162159.2877941-2-mmyangfl@gmail.com> (raw)
In-Reply-To: <20260123162159.2877941-1-mmyangfl@gmail.com>
The following pattern was observed in the code tree:
do {
start = u64_stats_fetch_begin(&pstats->syncp);
memcpy(&temp, &pstats->stats, sizeof(temp));
} while (u64_stats_fetch_retry(&pstats->syncp, start));
On 64bit arches, struct u64_stats_sync is empty and provides no help
against load/store tearing. memcpy() or struct copying does not
guarantee tear free, although compilers never generate such instructions
in practice.
Theoretically the affected code should convert to u64_stats_t, or use
atomic operations properly.
However since there are needs to copy chunks of statistics, instead of
writing loops everywhere, we provide a safe memcpy() variant for that
purpose.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
include/linux/u64_stats_sync.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/linux/u64_stats_sync.h b/include/linux/u64_stats_sync.h
index 457879938fc1..15ea4db2a77b 100644
--- a/include/linux/u64_stats_sync.h
+++ b/include/linux/u64_stats_sync.h
@@ -79,6 +79,14 @@ static inline u64 u64_stats_read(const u64_stats_t *p)
return local64_read(&p->v);
}
+static inline void *u64_stats_reads(void *dst, const void *src, size_t len)
+{
+ BUILD_BUG_ON(len % sizeof(u64_stats_t));
+ for (size_t i = 0; i < len; i += sizeof(u64_stats_t))
+ *(u64 *)(dst + i) = u64_stats_read((const u64_stats_t *)(src + i));
+ return dst;
+}
+
static inline void u64_stats_set(u64_stats_t *p, u64 val)
{
local64_set(&p->v, val);
@@ -110,6 +118,7 @@ static inline bool __u64_stats_fetch_retry(const struct u64_stats_sync *syncp,
}
#else /* 64 bit */
+#include <linux/string.h>
typedef struct {
u64 v;
@@ -120,6 +129,12 @@ static inline u64 u64_stats_read(const u64_stats_t *p)
return p->v;
}
+static inline void *u64_stats_reads(void *dst, const void *src, size_t len)
+{
+ BUILD_BUG_ON(len % sizeof(u64_stats_t));
+ return memcpy(dst, src, len);
+}
+
static inline void u64_stats_set(u64_stats_t *p, u64 val)
{
p->v = val;
--
2.51.0
next prev parent reply other threads:[~2026-01-23 16:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-23 16:21 [PATCH net-next v2 0/7] u64_stats: Introduce u64_stats_reads() David Yang
2026-01-23 16:21 ` David Yang [this message]
2026-01-23 16:21 ` [PATCH net-next v2 2/7] u64_stats: Doc incorrect usage with plain variables David Yang
2026-01-23 16:21 ` [PATCH net-next v2 3/7] net: bridge: mcast: fix memcpy with u64_stats David Yang
2026-01-23 16:21 ` [PATCH net-next v2 4/7] net: openvswitch: fix load tearing " David Yang
2026-01-24 0:49 ` kernel test robot
2026-01-26 12:25 ` Ilya Maximets
2026-01-26 18:29 ` David Laight
2026-01-26 18:35 ` Eric Dumazet
2026-01-26 19:18 ` David Laight
2026-01-23 16:21 ` [PATCH net-next v2 5/7] macsec: fix memcpy " David Yang
2026-01-23 16:21 ` [PATCH net-next v2 6/7] mpls: Fix load tearing " David Yang
2026-01-23 16:21 ` [PATCH net-next v2 7/7] vxlan: vnifilter: fix memcpy " David Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260123162159.2877941-2-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=aconole@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=bridge@lists.linux.dev \
--cc=cjubran@nvidia.com \
--cc=davem@davemloft.net \
--cc=dev@openvswitch.org \
--cc=echaudro@redhat.com \
--cc=edumazet@google.com \
--cc=gnault@redhat.com \
--cc=horms@kernel.org \
--cc=i.maximets@ovn.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
--cc=sd@queasysnail.net \
--cc=sdf@fomichev.me \
--cc=syoshida@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox