* [PATCH net-next] netdevsim: use u64_stats_t with u64_stats_sync properly
@ 2026-01-23 21:10 David Yang
2026-01-27 5:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: David Yang @ 2026-01-23 21:10 UTC (permalink / raw)
To: netdev
Cc: David Yang, Jakub Kicinski, Andrew Lunn, David S. Miller,
Eric Dumazet, Paolo Abeni, linux-kernel
On 64bit arches, struct u64_stats_sync is empty and provides no help
against load/store tearing. Convert to u64_stats_t to ensure atomic
operations.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/netdevsim/netdevsim.h | 8 ++++----
drivers/net/netdevsim/psp.c | 18 ++++++++++--------
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 46c67983c517..f767fc8a7505 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -109,10 +109,10 @@ struct netdevsim {
int rq_reset_mode;
struct {
- u64 rx_packets;
- u64 rx_bytes;
- u64 tx_packets;
- u64 tx_bytes;
+ u64_stats_t rx_packets;
+ u64_stats_t rx_bytes;
+ u64_stats_t tx_packets;
+ u64_stats_t tx_bytes;
struct u64_stats_sync syncp;
struct psp_dev *dev;
u32 spi;
diff --git a/drivers/net/netdevsim/psp.c b/drivers/net/netdevsim/psp.c
index 727da06101ca..0b4d717253b0 100644
--- a/drivers/net/netdevsim/psp.c
+++ b/drivers/net/netdevsim/psp.c
@@ -72,10 +72,12 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
skb->decrypted = 1;
u64_stats_update_begin(&ns->psp.syncp);
- ns->psp.tx_packets++;
- ns->psp.rx_packets++;
- ns->psp.tx_bytes += skb->len - skb_inner_transport_offset(skb);
- ns->psp.rx_bytes += skb->len - skb_inner_transport_offset(skb);
+ u64_stats_inc(&ns->psp.tx_packets);
+ u64_stats_inc(&ns->psp.rx_packets);
+ u64_stats_add(&ns->psp.tx_bytes,
+ skb->len - skb_inner_transport_offset(skb));
+ u64_stats_add(&ns->psp.rx_bytes,
+ skb->len - skb_inner_transport_offset(skb));
u64_stats_update_end(&ns->psp.syncp);
} else {
struct ipv6hdr *ip6h __maybe_unused;
@@ -183,10 +185,10 @@ static void nsim_get_stats(struct psp_dev *psd, struct psp_dev_stats *stats)
do {
start = u64_stats_fetch_begin(&ns->psp.syncp);
- stats->rx_bytes = ns->psp.rx_bytes;
- stats->rx_packets = ns->psp.rx_packets;
- stats->tx_bytes = ns->psp.tx_bytes;
- stats->tx_packets = ns->psp.tx_packets;
+ stats->rx_bytes = u64_stats_read(&ns->psp.rx_bytes);
+ stats->rx_packets = u64_stats_read(&ns->psp.rx_packets);
+ stats->tx_bytes = u64_stats_read(&ns->psp.tx_bytes);
+ stats->tx_packets = u64_stats_read(&ns->psp.tx_packets);
} while (u64_stats_fetch_retry(&ns->psp.syncp, start));
}
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] netdevsim: use u64_stats_t with u64_stats_sync properly
2026-01-23 21:10 [PATCH net-next] netdevsim: use u64_stats_t with u64_stats_sync properly David Yang
@ 2026-01-27 5:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-27 5:10 UTC (permalink / raw)
To: David Yang
Cc: netdev, kuba, andrew+netdev, davem, edumazet, pabeni,
linux-kernel
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 24 Jan 2026 05:10:55 +0800 you wrote:
> On 64bit arches, struct u64_stats_sync is empty and provides no help
> against load/store tearing. Convert to u64_stats_t to ensure atomic
> operations.
>
> Signed-off-by: David Yang <mmyangfl@gmail.com>
> ---
> drivers/net/netdevsim/netdevsim.h | 8 ++++----
> drivers/net/netdevsim/psp.c | 18 ++++++++++--------
> 2 files changed, 14 insertions(+), 12 deletions(-)
Here is the summary with links:
- [net-next] netdevsim: use u64_stats_t with u64_stats_sync properly
https://git.kernel.org/netdev/net-next/c/5c05b3dbccb1
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-01-27 5:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-23 21:10 [PATCH net-next] netdevsim: use u64_stats_t with u64_stats_sync properly David Yang
2026-01-27 5:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox