From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1F41C433F5 for ; Fri, 24 Sep 2021 02:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B97B660F6F for ; Fri, 24 Sep 2021 02:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243876AbhIXCJq (ORCPT ); Thu, 23 Sep 2021 22:09:46 -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)