Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756708AbYGaOe4 (ORCPT ); Thu, 31 Jul 2008 10:34:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753148AbYGaOeq (ORCPT ); Thu, 31 Jul 2008 10:34:46 -0400 Received: from ecfrec.frec.bull.fr ([129.183.4.8]:40226 "EHLO ecfrec.frec.bull.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752332AbYGaOep (ORCPT ); Thu, 31 Jul 2008 10:34:45 -0400 Date: Thu, 31 Jul 2008 16:35:15 +0200 From: Sebastien Dugue To: Peter Zijlstra Cc: John Kacur , Chirag Jog , J?rgen Mell , Thomas Gleixner , LKML , rt-users , Steven Rostedt , Clark Williams , Josh Triplett , "Timothy R. Chavez" Subject: Re: [PATCH] Fix Bug messages Message-ID: <20080731163515.4a992060@bull.net> In-Reply-To: <1217512907.8157.91.camel@twins> References: <200807301101.32417.j.mell@t-online.de> <20080730171842.GB3420@linux.vnet.ibm.com> <20080731100023.0221ec2b@bull.net> <520f0cf10807310313q45599221q3db1b6fd7e7c722f@mail.gmail.com> <20080731132336.362bd487@bull.net> <520f0cf10807310649l1083e29bmf0f704e13dee96c@mail.gmail.com> <1217512907.8157.91.camel@twins> X-Mailer: Claws Mail 3.2.0 (GTK+ 2.12.2; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2988 Lines: 87 Hi Peter, On Thu, 31 Jul 2008 16:01:47 +0200 Peter Zijlstra wrote: > On Thu, 2008-07-31 at 15:49 +0200, John Kacur wrote: > > Signed-off-by: John Kacur > > Index: linux-2.6.26-rt1/net/core/sock.c > > =================================================================== > > --- linux-2.6.26-rt1.orig/net/core/sock.c > > +++ linux-2.6.26-rt1/net/core/sock.c > > @@ -1986,11 +1986,12 @@ static __init int net_inuse_init(void) > > > > core_initcall(net_inuse_init); > > #else > > -static DEFINE_PER_CPU(struct prot_inuse, prot_inuse); > > +static DEFINE_PER_CPU_LOCKED(struct prot_inuse, prot_inuse); > > > > void sock_prot_inuse_add(struct net *net, struct proto *prot, int val) > > { > > - __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val; > > + int cpu = 0; > > + __get_cpu_var_locked(prot_inuse, cpu).val[prot->inuse_idx] += val; > > } > > EXPORT_SYMBOL_GPL(sock_prot_inuse_add); > > > > @@ -2000,7 +2001,7 @@ int sock_prot_inuse_get(struct net *net, > > int res = 0; > > > > for_each_possible_cpu(cpu) > > - res += per_cpu(prot_inuse, cpu).val[idx]; > > + res += per_cpu_var_locked(prot_inuse, cpu).val[idx]; > > > > return res >= 0 ? res : 0; > > } > > This doesn't look good. You declare it as a PER_CPU_LOCKED, but then > never use the extra lock to synchronize data. > > Given that sock_proc_inuse_get() is a racy read anyway, the 'right' fix > would be to do something like: > > diff --git a/net/core/sock.c b/net/core/sock.c > index 91f8bbc..5a8ace4 100644 > --- a/net/core/sock.c > +++ b/net/core/sock.c > @@ -1941,8 +1941,9 @@ static DECLARE_BITMAP(proto_inuse_idx, PROTO_INUSE_NR); > #ifdef CONFIG_NET_NS > void sock_prot_inuse_add(struct net *net, struct proto *prot, int val) > { > - int cpu = smp_processor_id(); > + int cpu = get_cpu(); > per_cpu_ptr(net->core.inuse, cpu)->val[prot->inuse_idx] += val; > + put_cpu(); > } > EXPORT_SYMBOL_GPL(sock_prot_inuse_add); > > @@ -1988,7 +1989,9 @@ static DEFINE_PER_CPU(struct prot_inuse, prot_inuse); > > void sock_prot_inuse_add(struct net *net, struct proto *prot, int val) > { > - __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val; > + int cpu = get_cpu(); > + per_cpu(prot_inuse, cpu).val[prot->inuse_idx] += val; > + put_cpu(); > } > EXPORT_SYMBOL_GPL(sock_prot_inuse_add); > > This disables preemption, but only for a very short time - so it doesn't > hurt the preempt-latency. > > The alternative is to take a lock, do the inc, and drop the lock again, > which is much more expensive. This does indeed seem to fix the problem, no more BUGs appearing on the console with 2.6.26-rt1 now. Thanks, Sebastien. -- 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/