Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752138Ab2FJHDh (ORCPT ); Sun, 10 Jun 2012 03:03:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32327 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751090Ab2FJHDf (ORCPT ); Sun, 10 Jun 2012 03:03:35 -0400 Date: Sun, 10 Jun 2012 10:03:27 +0300 From: "Michael S. Tsirkin" To: Rusty Russell Cc: Eric Dumazet , Jason Wang , netdev@vger.kernel.org, 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: <20120610070325.GA14010@redhat.com> References: <1338971724.2760.3913.camel@edumazet-glaptop> <1338972341.2760.3944.camel@edumazet-glaptop> <87ipezhdvx.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87ipezhdvx.fsf@rustcorp.com.au> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1790 Lines: 46 On Sun, Jun 10, 2012 at 04:06:34PM +0930, Rusty Russell wrote: > On Wed, 06 Jun 2012 10:45:41 +0200, Eric Dumazet wrote: > > On Wed, 2012-06-06 at 10:35 +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 > > > --- > > > > Just to make clear : even using percpu stats/syncp, we have no guarantee > > that write_seqcount_begin() is done with one instruction. [1] > > > > It is OK on x86 if "incl" instruction is generated by the compiler, but > > on a RISC cpu, the "load memory,%reg ; inc %reg ; store %reg,memory" can > > be interrupted. > > > > So if you are 100% sure all paths are safe against preemption/BH, then > > this patch is not needed, but a big comment in the code would avoid > > adding possible races in the future. > > Too fragile; let's keep them separate as per this patch. > > Acked-by: Rusty Russell > > Thanks, > Rusty. One question though: do we want to lay the structure out so that the rx sync structure precedes the rx counters? -- MST -- 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/