From patchwork Sun Nov 23 03:32:30 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 10276 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id C673BDDDEA for ; Sun, 23 Nov 2008 14:32:45 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755531AbYKWDck (ORCPT ); Sat, 22 Nov 2008 22:32:40 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755411AbYKWDck (ORCPT ); Sat, 22 Nov 2008 22:32:40 -0500 Received: from gw1.cosmosbay.com ([86.65.150.130]:33061 "EHLO gw1.cosmosbay.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755384AbYKWDcj (ORCPT ); Sat, 22 Nov 2008 22:32:39 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) by gw1.cosmosbay.com (8.13.7/8.13.7) with ESMTP id mAN3WUB7001750; Sun, 23 Nov 2008 04:32:31 +0100 Message-ID: <4928CECE.602@cosmosbay.com> Date: Sun, 23 Nov 2008 04:32:30 +0100 From: Eric Dumazet User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: =?ISO-8859-1?Q?Ilpo_J=E4rvinen?= , David Miller CC: Netdev Subject: Re: net-next/unix: BUG: using smp_processor_id() in preemptible References: In-Reply-To: X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (gw1.cosmosbay.com [0.0.0.0]); Sun, 23 Nov 2008 04:32:31 +0100 (CET) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Ilpo Järvinen a écrit : > I got plenty of these from sock_prot_inuse_add: > > BUG: using smp_processor_id() in preemptible [00000000] code: rcS/1146 > > caller is sock_prot_inuse_add+0x24/0x42 > Pid: 1146, comm: rcS Not tainted 2.6.28-rc6-01121-g89a2f15 #76 > Call Trace: > [] debug_smp_processor_id+0xd3/0xe8 > [] sock_prot_inuse_add+0x24/0x42 > [] unix_create1+0x161/0x176 > [] unix_create+0x60/0x6b > [] __sock_create+0x144/0x1bd > [] ? __sock_create+0xb9/0x1bd > [] sock_create+0x2d/0x2f > [] sys_socket+0x29/0x5b > [] system_call_fastpath+0x16/0x1b > > Thanks Ilpo for this report I guess the following is necessary. Once Christopher and Rusty work on percpu variables is finished, the preempt_enable()/disable() wont be necessary anymore, so its a temporary workaround anyway. [PATCH] net: make sock_prot_inuse_add() preempt safe Ilpo Järvinen reported that commit a8076d8db98de6da61394b2e942320e4612643ac (net: af_unix should update its inuse counter) was triggering a warning in smp_processor_id(), being called in a preemptible code. Fix is to make sock_prot_inuse_add() safe in this regard. This fix can be reverted when new percpu infrastructure is ready, allowing a cpu to safely do a increment/decrement on a percpu var. Signed-off-by: Eric Dumazet Tested-by: Ilpo Järvinen diff --git a/net/core/sock.c b/net/core/sock.c index a4e840e..d4f5ad7 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1942,8 +1942,8 @@ 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(); - per_cpu_ptr(net->core.inuse, cpu)->val[prot->inuse_idx] += val; + per_cpu_ptr(net->core.inuse, get_cpu())->val[prot->inuse_idx] += val; + put_cpu(); } EXPORT_SYMBOL_GPL(sock_prot_inuse_add); @@ -1989,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) { + preempt_disable(); __get_cpu_var(prot_inuse).val[prot->inuse_idx] += val; + preempt_enable(); } EXPORT_SYMBOL_GPL(sock_prot_inuse_add);