Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752573Ab0ARQlf (ORCPT ); Mon, 18 Jan 2010 11:41:35 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751639Ab0ARQlf (ORCPT ); Mon, 18 Jan 2010 11:41:35 -0500 Received: from fg-out-1718.google.com ([72.14.220.154]:54283 "EHLO fg-out-1718.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751995Ab0ARQle (ORCPT ); Mon, 18 Jan 2010 11:41:34 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=eXgQE+er+9Q/pDz9nmW30V4k3qTt6h/+t22oXUVMOcY8yCYI3/+kQ5O27uiQiRZulC inmS8O4rM6rHXW+Chyz4Hq0H/qd4c/IPddh4sK6w5rwqZ+TamoOPszw8dW7B4wYhdY5x CUxKyYqQ+F2rcbQDo5u66rlhN6Q5ZcK8FnJrA= Date: Mon, 18 Jan 2010 17:41:30 +0100 From: Frederic Weisbecker To: Xiao Guangrong Cc: Ingo Molnar , Peter Zijlstra , Paul Mackerras , LKML Subject: Re: [PATCH 1/3] perf_event: fix race in perf_swevent_get_recursion_context() Message-ID: <20100118164128.GI10364@nowhere> References: <4B54654A.4090601@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4B54654A.4090601@cn.fujitsu.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1306 Lines: 42 On Mon, Jan 18, 2010 at 09:42:34PM +0800, Xiao Guangrong wrote: > It only disable preemption in perf_swevent_get_recursion_context() > it can't avoid race of hard-irq and NMI > > In this patch, we use atomic operation to avoid it and reduce > cpu_ctx->recursion size, it also make this patch no need diable > preemption > > Signed-off-by: Xiao Guangrong I don't understand what is racy in what we have currently. > int perf_swevent_get_recursion_context(void) > { > - struct perf_cpu_context *cpuctx = &get_cpu_var(perf_cpu_context); > + struct perf_cpu_context *cpuctx = &__get_cpu_var(perf_cpu_context); > int rctx; > > if (in_nmi()) > @@ -3933,13 +3933,8 @@ int perf_swevent_get_recursion_context(void) > else > rctx = 0; > > - if (cpuctx->recursion[rctx]) { > - put_cpu_var(perf_cpu_context); > + if (test_and_set_bit(rctx, &cpuctx->recursion)) > return -1; This looks broken. We don't call back perf_swevent_put_recursion_context in fail case, so the bit won't ever be cleared once we recurse. -- 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/