Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755504Ab2FFJgC (ORCPT ); Wed, 6 Jun 2012 05:36:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10549 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750713Ab2FFJf7 (ORCPT ); Wed, 6 Jun 2012 05:35:59 -0400 Message-ID: <4FCF24DE.5090109@redhat.com> Date: Wed, 06 Jun 2012 17:37:34 +0800 From: Jason Wang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120210 Thunderbird/10.0.1 MIME-Version: 1.0 To: Eric Dumazet CC: netdev@vger.kernel.org, rusty@rustcorp.com.au, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, mst@redhat.com, Stephen Hemminger Subject: Re: [PATCH] virtio-net: fix a race on 32bit arches References: <1338971724.2760.3913.camel@edumazet-glaptop> <1338972341.2760.3944.camel@edumazet-glaptop> In-Reply-To: <1338972341.2760.3944.camel@edumazet-glaptop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1940 Lines: 47 On 06/06/2012 04:45 PM, 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. Thanks for explaing, current virtio-net is safe I think. But the patch is still needed as my patch would update the statistics in irq. > > [1] If done with one instruction, we still have a race, since a reader > might see an even sequence and conclude no writer is inside the critical > section. So read values could be wrong. > > > > -- > 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/ -- 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/