Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1121143pxb; Thu, 23 Sep 2021 19:09:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy613c0uSkB0m4IL/Dpb6svVpfGP8d8A1BrvHp+O15VBKW93+qZVm5ASjTtimsVO/YJslao X-Received: by 2002:a6b:610a:: with SMTP id v10mr6693111iob.167.1632449358494; Thu, 23 Sep 2021 19:09:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632449358; cv=none; d=google.com; s=arc-20160816; b=Gy8EDPyAWXbX5d3lZVErAjzahU0J/mC1hgSNFVm44ZncRTwZRMcqKeyqsLAXSC9cYz BtzPNcJpCkV5ITpgMUSguUhOalImwAFVAI6jGMUvHeE4kESyCyFJyA9Q0OlmTdNUNRKf 4UvJAV1N3SrmsxqW0Qix/cLbJr1jjf0UmhcMFnNn1dU3Hvqa2rwFGNCpMLHkSPJMF5mi qMHI/Py7sfELdAG9vNqfocOPs8WjX5bZg40LuesBavhy2ZtcJMl7TURbxFRX5PxkJ5L+ +jGp/GcxZb+qY7uYeAGg4LnF1z+yLbuJ9zOi1tzDWkoYaDUY0vvtlHMBGEgjN8L4RpOE z44g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=bLcTySXrjTtbNqjCHEjf0wnSyOi5vsry20ye6u7nY74=; b=NWEUf2mr3/OU9/ABp9L8WOj21tdSyyzULV6uV+JXNsv8gJ8Gv6JHWzr3D78Rk5PlT7 oDJRBbbtSVmxUu3LnBZbvA21SmN0VyIm1H1V5tVXMijQdWH7E3o68XGNJvQUUvLelPyZ vKlRt1Y6TCDbTkn53JDawcfl3GAeKa6rEx7jnlvtna76i+nUiUNmb5+rx/q4MOCv5pWp a4qNIy3Kj33Mm+x7auFSyH043rm7upQOU4MD1Fs+jFWG/3LPANm1q4BPgKyxckN3+czm LiHNhPH94ixeqqvJvZjOuZ7rv7JX3tZqYlDIJube+ucEXBz7Gz9n2BW1rsZ66GjuKcC/ hRhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si8238384ilg.114.2021.09.23.19.09.03; Thu, 23 Sep 2021 19:09:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243864AbhIXCJp (ORCPT + 99 others); Thu, 23 Sep 2021 22:09:45 -0400 Received: from out30-45.freemail.mail.aliyun.com ([115.124.30.45]:40483 "EHLO out30-45.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243797AbhIXCJp (ORCPT ); Thu, 23 Sep 2021 22:09:45 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0UpNQIdV_1632449291; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UpNQIdV_1632449291) by smtp.aliyun-inc.com(127.0.0.1); Fri, 24 Sep 2021 10:08:11 +0800 Subject: Re: [RFC PATCH] trace: prevent preemption in perf_ftrace_function_call() To: Steven Rostedt Cc: Ingo Molnar , open list References: <2470f39b-aed1-4e19-9982-206007eb0c6a@linux.alibaba.com> <20210923093359.30da8ba6@gandalf.local.home> From: =?UTF-8?B?546L6LSH?= Message-ID: <7f4dfb4a-d271-b3c5-f603-06cc789ba9e9@linux.alibaba.com> Date: Fri, 24 Sep 2021 10:08:10 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20210923093359.30da8ba6@gandalf.local.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/23 下午9:33, Steven Rostedt wrote: [snip] >> --- >> kernel/trace/trace_event_perf.c | 14 +++++++++----- >> 1 file changed, 9 insertions(+), 5 deletions(-) >> >> diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c >> index 6aed10e..5486b18 100644 >> --- a/kernel/trace/trace_event_perf.c >> +++ b/kernel/trace/trace_event_perf.c >> @@ -438,15 +438,17 @@ void perf_trace_buf_update(void *record, u16 type) >> int rctx; >> int bit; >> >> + preempt_disable_notrace(); >> + >> if (!rcu_is_watching()) >> - return; >> + goto out; > > You don't need preemption disabled for the above check. It's better to > disable it here and leave the above return untouched. I found the rcu tree implementation of rcu_is_watching() will check this_cpu_ptr(&rcu_data.dynticks), and after that enable the preemption. If preemption happened after that and before we disable here, there are still possibility that the CPU changed and make the dynticks checking invalid, isn't it? Regards, Michael Wang > > -- Steve > >> >> if ((unsigned long)ops->private != smp_processor_id()) >> - return; >> + goto out; >> >> bit = ftrace_test_recursion_trylock(ip, parent_ip); >> if (bit < 0) >> - return; >> + goto out; >> >> event = container_of(ops, struct perf_event, ftrace_ops); >> >> @@ -468,16 +470,18 @@ void perf_trace_buf_update(void *record, u16 type) >> >> entry = perf_trace_buf_alloc(ENTRY_SIZE, NULL, &rctx); >> if (!entry) >> - goto out; >> + goto out_unlock; >> >> entry->ip = ip; >> entry->parent_ip = parent_ip; >> perf_trace_buf_submit(entry, ENTRY_SIZE, rctx, TRACE_FN, >> 1, ®s, &head, NULL); >> >> -out: >> +out_unlock: >> ftrace_test_recursion_unlock(bit); >> #undef ENTRY_SIZE >> +out: >> + preempt_enable_notrace(); >> } >> >> static int perf_ftrace_function_register(struct perf_event *event)