Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755052Ab2FJKYr (ORCPT ); Sun, 10 Jun 2012 06:24:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7671 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752594Ab2FJKYq (ORCPT ); Sun, 10 Jun 2012 06:24:46 -0400 Date: Sun, 10 Jun 2012 13:25:12 +0300 From: "Michael S. Tsirkin" To: Eric Dumazet Cc: Jason Wang , netdev@vger.kernel.org, rusty@rustcorp.com.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Stephen Hemminger Subject: Re: [PATCH] virtio-net: fix a race on 32bit arches Message-ID: <20120610102512.GB6793@redhat.com> References: <1338971724.2760.3913.camel@edumazet-glaptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1338971724.2760.3913.camel@edumazet-glaptop> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3252 Lines: 91 On Wed, Jun 06, 2012 at 10:35:24AM +0200, Eric Dumazet wrote: > From: Eric Dumazet > > 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 > Cc: Stephen Hemminger > Cc: Michael S. Tsirkin > Cc: Jason Wang I'm still thinking about moving tx to take a xmit lock long term, meanwhile this fix appears appropriate for 3.5. Acked-by: Michael S. Tsirkin Dave, can you pick this up pls? > --- > 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; > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/