Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp972859pxb; Mon, 25 Oct 2021 23:52:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJjccyAXDq1bAa7xVS1uq+pumdwEn+RI7Hu9R4PMMKCI04wr0qW2fFOaiSC1kWptAmaEbr X-Received: by 2002:a17:90b:1d06:: with SMTP id on6mr41292259pjb.119.1635231165823; Mon, 25 Oct 2021 23:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635231165; cv=none; d=google.com; s=arc-20160816; b=P34xSwxwYpjACfu4/nOLLZhYKBMIeKZhC67k2jjS0K7ABR4NQQ6SaDn9bsVYnRqUQf JnviElmJ+RGdeJLkhCT4ZMdZIw+QZEFsa7rZnRvGWkvvyddU2CYVhgpQpL+j3eg6eoam 46Tk3dhpvVl3s9Q30lE/Z3VTfW8P46ePCX15MARMttXSS4pAfW1ZvoMgly/q05Wa44OQ sdNslQMh4h4DC8gwuY19jZbQrd0Dfwz/78GE/1qZpc2DKcVCIQIw+LAUAWJJsZzb7UaX EpIez8z7iCmDMfxYpkBlKkH7jSRNmjYxSXb+RrCRhz5P70qSkJ5ozDr5AMANKMwjOW1k pVdw== 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 :to:subject; bh=pRjd4MJ5F+bgOPrckZRjA6mesYTbghX2dNhDULsWxkE=; b=TFRbO8vQc+Xyk3AiCCM/vm04Wkvz04cNxn+ejcX+hid2qebfeg0lSGc2CyzmPe9qG+ KnKV/dY9X/q1KjckBb0rK8KwnKjimMPOxlxgUdEuHkuBG/ASoE4RHJ5yFonOkMkZBbXM M31/oVVIoxa9YILeWg2lhUTD7mMMHYAsxMagbs4+u61dvAQuxmL12Q+Rf5l3psV4LY8A cpIGBO4XZnsvXOkRAoy8SYMW/tDLXY6bh/gakxCma/fyLPDDeQc57XgarjIpxvPjxfGo A2Y/ATbLlDrnMq3Z6arS43oeaAzY4zN3U+CuQom5YeLGpVQUiyiMxZiT3LPqkXWuiRkm bXNg== 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 e13si29253418pfv.306.2021.10.25.23.52.33; Mon, 25 Oct 2021 23:52:45 -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 S234636AbhJZDSU (ORCPT + 99 others); Mon, 25 Oct 2021 23:18:20 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:40920 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234621AbhJZDSR (ORCPT ); Mon, 25 Oct 2021 23:18:17 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R941e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01424;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=30;SR=0;TI=SMTPD_---0UtjbRA2_1635218146; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UtjbRA2_1635218146) by smtp.aliyun-inc.com(127.0.0.1); Tue, 26 Oct 2021 11:15:48 +0800 Subject: [PATCH v5 2/2] ftrace: do CPU checking after preemption disabled 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: <3ca92dc9-ea04-ddc2-71cd-524bfa5a5721@linux.alibaba.com> From: =?UTF-8?B?546L6LSH?= Message-ID: <5212e96a-29ad-b2e1-5db7-b958f42adcb7@linux.alibaba.com> Date: Tue, 26 Oct 2021 11:15:46 +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: <3ca92dc9-ea04-ddc2-71cd-524bfa5a5721@linux.alibaba.com> 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