From: David Yang <mmyangfl@gmail.com>
To: netdev@vger.kernel.org
Cc: David Yang <mmyangfl@gmail.com>, Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
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>,
xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next] xen/netfront: Use u64_stats_t with u64_stats_sync properly
Date: Wed, 21 Jan 2026 16:25:46 +0800 [thread overview]
Message-ID: <20260121082550.2389249-1-mmyangfl@gmail.com> (raw)
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/xen-netfront.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 7c2220366623..0969d5c9f6b7 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -97,8 +97,8 @@ struct netfront_cb {
static DECLARE_WAIT_QUEUE_HEAD(module_wq);
struct netfront_stats {
- u64 packets;
- u64 bytes;
+ u64_stats_t packets;
+ u64_stats_t bytes;
struct u64_stats_sync syncp;
};
@@ -634,8 +634,8 @@ static int xennet_xdp_xmit_one(struct net_device *dev,
notify_remote_via_irq(queue->tx_irq);
u64_stats_update_begin(&tx_stats->syncp);
- tx_stats->bytes += xdpf->len;
- tx_stats->packets++;
+ u64_stats_add(&tx_stats->bytes, xdpf->len);
+ u64_stats_inc(&tx_stats->packets);
u64_stats_update_end(&tx_stats->syncp);
return 0;
@@ -843,8 +843,8 @@ static netdev_tx_t xennet_start_xmit(struct sk_buff *skb, struct net_device *dev
notify_remote_via_irq(queue->tx_irq);
u64_stats_update_begin(&tx_stats->syncp);
- tx_stats->bytes += skb->len;
- tx_stats->packets++;
+ u64_stats_add(&tx_stats->bytes, skb->len);
+ u64_stats_inc(&tx_stats->packets);
u64_stats_update_end(&tx_stats->syncp);
if (!netfront_tx_slot_available(queue))
@@ -1249,8 +1249,8 @@ static int handle_incoming_queue(struct netfront_queue *queue,
}
u64_stats_update_begin(&rx_stats->syncp);
- rx_stats->packets++;
- rx_stats->bytes += skb->len;
+ u64_stats_inc(&rx_stats->packets);
+ u64_stats_add(&rx_stats->bytes, skb->len);
u64_stats_update_end(&rx_stats->syncp);
/* Pass it up. */
@@ -1400,14 +1400,14 @@ static void xennet_get_stats64(struct net_device *dev,
do {
start = u64_stats_fetch_begin(&tx_stats->syncp);
- tx_packets = tx_stats->packets;
- tx_bytes = tx_stats->bytes;
+ tx_packets = u64_stats_read(&tx_stats->packets);
+ tx_bytes = u64_stats_read(&tx_stats->bytes);
} while (u64_stats_fetch_retry(&tx_stats->syncp, start));
do {
start = u64_stats_fetch_begin(&rx_stats->syncp);
- rx_packets = rx_stats->packets;
- rx_bytes = rx_stats->bytes;
+ rx_packets = u64_stats_read(&rx_stats->packets);
+ rx_bytes = u64_stats_read(&rx_stats->bytes);
} while (u64_stats_fetch_retry(&rx_stats->syncp, start));
tot->rx_packets += rx_packets;
--
2.51.0
next reply other threads:[~2026-01-21 8:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 8:25 David Yang [this message]
2026-01-22 12:10 ` [PATCH net-next] xen/netfront: Use u64_stats_t with u64_stats_sync properly patchwork-bot+netdevbpf
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=20260121082550.2389249-1-mmyangfl@gmail.com \
--to=mmyangfl@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jgross@suse.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=pabeni@redhat.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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