virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio-net: fix a race on 32bit arches
@ 2012-06-06  8:35 Eric Dumazet
  2012-06-06  8:45 ` Eric Dumazet
  2012-06-10 10:25 ` Michael S. Tsirkin
  0 siblings, 2 replies; 32+ messages in thread
From: Eric Dumazet @ 2012-06-06  8:35 UTC (permalink / raw)
  To: Jason Wang; +Cc: mst, netdev, linux-kernel, virtualization, Stephen Hemminger

From: Eric Dumazet <edumazet@google.com>

commit 3fa2a1df909 (virtio-net: per cpu 64 bit stats (v2)) added a race
on 32bit arches.

We must use separate syncp for rx and tx path as they can be run at the
same time on different cpus. Thus one sequence increment can be lost and
readers spin forever.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Stephen Hemminger <shemminger@vyatta.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
---
 drivers/net/virtio_net.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 5214b1e..f18149a 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -42,7 +42,8 @@ module_param(gso, bool, 0444);
 #define VIRTNET_DRIVER_VERSION "1.0.0"
 
 struct virtnet_stats {
-	struct u64_stats_sync syncp;
+	struct u64_stats_sync tx_syncp;
+	struct u64_stats_sync rx_syncp;
 	u64 tx_bytes;
 	u64 tx_packets;
 
@@ -300,10 +301,10 @@ static void receive_buf(struct net_device *dev, void *buf, unsigned int len)
 
 	hdr = skb_vnet_hdr(skb);
 
-	u64_stats_update_begin(&stats->syncp);
+	u64_stats_update_begin(&stats->rx_syncp);
 	stats->rx_bytes += skb->len;
 	stats->rx_packets++;
-	u64_stats_update_end(&stats->syncp);
+	u64_stats_update_end(&stats->rx_syncp);
 
 	if (hdr->hdr.flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
 		pr_debug("Needs csum!\n");
@@ -565,10 +566,10 @@ static unsigned int free_old_xmit_skbs(struct virtnet_info *vi)
 	while ((skb = virtqueue_get_buf(vi->svq, &len)) != NULL) {
 		pr_debug("Sent skb %p\n", skb);
 
-		u64_stats_update_begin(&stats->syncp);
+		u64_stats_update_begin(&stats->tx_syncp);
 		stats->tx_bytes += skb->len;
 		stats->tx_packets++;
-		u64_stats_update_end(&stats->syncp);
+		u64_stats_update_end(&stats->tx_syncp);
 
 		tot_sgs += skb_vnet_hdr(skb)->num_sg;
 		dev_kfree_skb_any(skb);
@@ -703,12 +704,16 @@ static struct rtnl_link_stats64 *virtnet_stats(struct net_device *dev,
 		u64 tpackets, tbytes, rpackets, rbytes;
 
 		do {
-			start = u64_stats_fetch_begin(&stats->syncp);
+			start = u64_stats_fetch_begin(&stats->tx_syncp);
 			tpackets = stats->tx_packets;
 			tbytes   = stats->tx_bytes;
+		} while (u64_stats_fetch_retry(&stats->tx_syncp, start));
+
+		do {
+			start = u64_stats_fetch_begin(&stats->rx_syncp);
 			rpackets = stats->rx_packets;
 			rbytes   = stats->rx_bytes;
-		} while (u64_stats_fetch_retry(&stats->syncp, start));
+		} while (u64_stats_fetch_retry(&stats->rx_syncp, start));
 
 		tot->rx_packets += rpackets;
 		tot->tx_packets += tpackets;

^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2012-06-11  3:23 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-06  8:35 [PATCH] virtio-net: fix a race on 32bit arches Eric Dumazet
2012-06-06  8:45 ` Eric Dumazet
2012-06-06  9:37   ` Jason Wang
2012-06-06 11:13   ` Michael S. Tsirkin
2012-06-06 13:10     ` Eric Dumazet
2012-06-06 14:49       ` Michael S. Tsirkin
2012-06-06 15:14         ` Stephen Hemminger
2012-06-06 15:19         ` Eric Dumazet
2012-06-06 16:17           ` Michael S. Tsirkin
2012-06-06 17:13             ` Eric Dumazet
     [not found]             ` <1339002782.26966.22.camel@edumazet-glaptop>
2012-06-06 18:43               ` Michael S. Tsirkin
2012-06-06 20:06                 ` Eric Dumazet
2012-06-06 20:19                   ` Michael S. Tsirkin
2012-06-06 16:57           ` Michael S. Tsirkin
2012-06-06 20:00             ` Eric Dumazet
     [not found]         ` <20120606081432.6b602065@nehalam.linuxnetplumber.net>
2012-06-06 18:51           ` Michael S. Tsirkin
2012-06-06 19:54             ` Eric Dumazet
     [not found]             ` <1339012441.26966.48.camel@edumazet-glaptop>
2012-06-06 19:58               ` Michael S. Tsirkin
2012-06-06 20:08                 ` Eric Dumazet
2012-06-06 20:16                   ` Michael S. Tsirkin
2012-06-06 20:24                     ` Eric Dumazet
2012-06-06 20:38                       ` Eric Dumazet
2012-06-06 20:35                     ` Ben Hutchings
2012-06-06 20:43                       ` Michael S. Tsirkin
2012-06-06 20:19                   ` Ben Hutchings
     [not found]                   ` <1339013979.2836.52.camel@bwh-desktop.uk.solarflarecom.com>
2012-06-06 20:25                     ` Eric Dumazet
2012-06-10  6:36   ` Rusty Russell
2012-06-10  7:03     ` Michael S. Tsirkin
2012-06-10 10:21       ` Eric Dumazet
2012-06-10 10:22         ` Michael S. Tsirkin
2012-06-10 10:25 ` Michael S. Tsirkin
2012-06-11  3:23   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).