Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3016833pxb; Tue, 12 Oct 2021 19:07:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXATcsMTJSZ8VDpPRw640bpvMQK23FUIAqGsKBg+Ca0WX+RfbQPqvLLs5W976lKxgRdSsa X-Received: by 2002:a05:6402:411:: with SMTP id q17mr5320094edv.35.1634090824832; Tue, 12 Oct 2021 19:07:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634090824; cv=none; d=google.com; s=arc-20160816; b=Nyr6ZWlR1REaAsdLeC/vfT9z3vhY6Lt8moCKAlo5WGzb0p+sy51hn3b4KrPDv5YPtx 8pdjzSUIRKUdFEpCdLvVQmHFM/+7+FoqEbb90ieGbotGi14vK21l+jUnbRjUcg7sxjPS vf3/G6rAAGOQBinpXhZM6Ub7I5Zj5Bd8F7OB3yK7CJAMcBexjYHT/Zo8CcPqbr9ROy6R etPJhcbrL7UwD6w2faSt7J0dfcwLwyODlxQVCuJXL3K29nkA/w8KlBP/z9QYm6GRGgLO 2E6j7oNehcv3tASkrdEb7F09UBoJDnt/HtzfA1qren7M5LDoMqF7dcq90CBy1b0BnN/v 9nag== 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=HWEVhkNs4bs77BUZZiTOR9bIN8mzxvzhzaEjZ6Qtjc8=; b=RxEE9g57EKLo5l+1sqsnJWTE43CGkzZhoVvbPPPFnG1MEnWR4reT8VbfKfrsZSENwd KTi5C1+tYnUtrIXO8wHN7ISv8VCl8EWDW9XE1qhaNv0VNe1dsRWHMBoJS/OYekM96gue +46CKezHbuzs+DHeflEemRojm0uTDHDQqMDvRu0GMDrLEqNWp6FWDBvcY2ZQw9e1ZXKd fJXBInpRTHKUX4fAL9jKr0bXotmEQJwgJDtTL/n3B3v5eZvwK9wNaSiqtbMJknzw+d54 X/42ZbE0OBXWa02ROZq/mLzocWrsyGniOsp15MsUk6bU7RcIoZyQDA2WRgTGw48JwfHK MVAQ== 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 x17si17014350edi.396.2021.10.12.19.06.40; Tue, 12 Oct 2021 19:07:04 -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 S234381AbhJMCHC (ORCPT + 99 others); Tue, 12 Oct 2021 22:07:02 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:59482 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbhJMCHC (ORCPT ); Tue, 12 Oct 2021 22:07:02 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;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=31;SR=0;TI=SMTPD_---0UrdlKN._1634090692; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UrdlKN._1634090692) by smtp.aliyun-inc.com(127.0.0.1); Wed, 13 Oct 2021 10:04:54 +0800 Subject: Re: [PATCH 1/2] ftrace: disable preemption on the testing of recursion To: Steven Rostedt Cc: Guo Ren , Ingo Molnar , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , Colin Ian King , Masami Hiramatsu , "Peter Zijlstra (Intel)" , Nicholas Piggin , Jisheng Zhang , linux-csky@vger.kernel.org, linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, live-patching@vger.kernel.org References: <8c7de46d-9869-aa5e-2bb9-5dbc2eda395e@linux.alibaba.com> <20211012084331.06b8dd23@gandalf.local.home> From: =?UTF-8?B?546L6LSH?= Message-ID: <1eab20c1-d69b-f94b-92ff-4329d0aff6a2@linux.alibaba.com> Date: Wed, 13 Oct 2021 10:04:52 +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: <20211012084331.06b8dd23@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/10/12 δΈ‹εˆ8:43, Steven Rostedt wrote: > On Tue, 12 Oct 2021 13:40:08 +0800 > ηŽ‹θ΄‡ wrote: > >> --- a/include/linux/trace_recursion.h >> +++ b/include/linux/trace_recursion.h >> @@ -214,7 +214,14 @@ static __always_inline void trace_clear_recursion(int bit) >> static __always_inline int ftrace_test_recursion_trylock(unsigned long ip, >> unsigned long parent_ip) >> { >> - return trace_test_and_set_recursion(ip, parent_ip, TRACE_FTRACE_START, TRACE_FTRACE_MAX); >> + int bit; >> + >> + preempt_disable_notrace(); > > The recursion test does not require preemption disabled, it uses the task > struct, not per_cpu variables, so you should not disable it before the test. > > bit = trace_test_and_set_recursion(ip, parent_ip, TRACE_FTRACE_START, TRACE_FTRACE_MAX); > if (bit >= 0) > preempt_disable_notrace(); > > And if the bit is zero, it means a recursion check was already done by > another caller (ftrace handler does the check, followed by calling perf), > and you really don't even need to disable preemption in that case. > > if (bit > 0) > preempt_disable_notrace(); > > And on the unlock, have: > > static __always_inline void ftrace_test_recursion_unlock(int bit) > { > if (bit) > preempt_enable_notrace(); > trace_clear_recursion(bit); > } > > But maybe that's over optimizing ;-) I see, while the user can still check smp_processor_id() after trylock return bit 0... I guess Peter's point at very beginning is to prevent such cases, since kernel for production will not have preemption debug on, and such issue won't get report but could cause trouble which really hard to trace down , way to eliminate such issue once for all sounds attractive, isn't it? Regards, Michael Wang > > -- Steve > > >> + bit = trace_test_and_set_recursion(ip, parent_ip, TRACE_FTRACE_START, TRACE_FTRACE_MAX); >> + if (bit < 0) >> + preempt_enable_notrace(); >> + >> + return bit; >> }