Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp599863pxb; Wed, 27 Oct 2021 08:48:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdi3JFI5WD835Wu9DNhcimi6k3QaBuGtNKTarqNGmcxFPVi4GOGeAi8SmmhL7zZfte86m3 X-Received: by 2002:a17:906:2f16:: with SMTP id v22mr39863073eji.334.1635349716556; Wed, 27 Oct 2021 08:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635349716; cv=none; d=google.com; s=arc-20160816; b=mIs1yUKD3FVF1kF8qRhJKiGJvMlQno7HT2hicL5aBoLvlW2+7NeeLi5HMVeuMwOV4e +bdH8qu3mVb5WqfnkTlUQ+MncRTIM+pg+Nx/wPPEg4BF5rLSj1SbDYck/OQ/5V4/NpBV J0dzwJ4EyEiFtnt8qs7theAUt77PF8iViC17MmtD6hOXiB/9qRSOwLQfLw9qyHMHLwX9 2ktP5OHsbwx1rddqAsLFdlGOQGYOD9PpC1fEa3oyxdyOvsyXBNR4DYtNsakxNGCDe/fp sDPzVsjYaxUU3aks12EBER7Vdf+4aURpH5vlMMB7RMDleFUullpGlfgF6x9GOISUA8Cz 3oQg== 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:references:to :from:subject; bh=pRjd4MJ5F+bgOPrckZRjA6mesYTbghX2dNhDULsWxkE=; b=R/am4RUXpNEkhqcTBDmu0IQ4y0Y5AnjOnLWTunmPLxoDxrqUJLL/uRlMegQmWCHLA6 quIj7ReHFeqwVp8BhGsNc3oe9W27z0F1dXbhgI9/CuTuRsH1KIXrmNZ9SPvS8geo13S6 lVsnexYluqdAznsvD2dqcJK/jozASIXr3q4+0NL35X98oz6dIgR2bf6f+QcA4/dorxsd mGa+19xYk2sl0XRcy4WniHv0QZaLvYhCcXXcDsmkQlwVAbDIThBKq+FN0b8xL3kngSsi UxLg0lVePqKERlAC0rTMkSRNxKR6MwBZsGvbmy1b2SGGsqjzxszRqXZNEXFq7tSghyvX gXrg== 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 k9si217550eje.548.2021.10.27.08.48.12; Wed, 27 Oct 2021 08:48:36 -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 S238510AbhJ0ChO (ORCPT + 99 others); Tue, 26 Oct 2021 22:37:14 -0400 Received: from out30-43.freemail.mail.aliyun.com ([115.124.30.43]:57034 "EHLO out30-43.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238415AbhJ0ChJ (ORCPT ); Tue, 26 Oct 2021 22:37:09 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R921e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=30;SR=0;TI=SMTPD_---0UtpxLpr_1635302077; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UtpxLpr_1635302077) by smtp.aliyun-inc.com(127.0.0.1); Wed, 27 Oct 2021 10:34:39 +0800 Subject: [PATCH v6 2/2] ftrace: do CPU checking after preemption disabled From: =?UTF-8?B?546L6LSH?= To: Guo Ren , Steven Rostedt , 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 , 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: Message-ID: <444d3576-4160-be9e-36c0-8061bf1242fb@linux.alibaba.com> Date: Wed, 27 Oct 2021 10:34:37 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With CONFIG_DEBUG_PREEMPT we observed reports like: BUG: using smp_processor_id() in preemptible caller is perf_ftrace_function_call+0x6f/0x2e0 CPU: 1 PID: 680 Comm: a.out Not tainted Call Trace: dump_stack_lvl+0x8d/0xcf check_preemption_disabled+0x104/0x110 ? optimize_nops.isra.7+0x230/0x230 ? text_poke_bp_batch+0x9f/0x310 perf_ftrace_function_call+0x6f/0x2e0 ... __text_poke+0x5/0x620 text_poke_bp_batch+0x9f/0x310 This telling us the CPU could be changed after task is preempted, and the checking on CPU before preemption will be invalid. Since now ftrace_test_recursion_trylock() will help to disable the preemption, this patch just do the checking after trylock() to address the issue. CC: Steven Rostedt Reported-by: Abaci Signed-off-by: Michael Wang --- kernel/trace/trace_event_perf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index 6aed10e..fba8cb7 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -441,13 +441,13 @@ void perf_trace_buf_update(void *record, u16 type) if (!rcu_is_watching()) return; - if ((unsigned long)ops->private != smp_processor_id()) - return; - bit = ftrace_test_recursion_trylock(ip, parent_ip); if (bit < 0) return; + if ((unsigned long)ops->private != smp_processor_id()) + goto out; + event = container_of(ops, struct perf_event, ftrace_ops); /* -- 1.8.3.1