Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp651893pxb; Wed, 27 Oct 2021 09:42:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK/ayExcmPew+u2eiEjF8WPxw7YdL+Ls5dd1hruEiTkGLJgv96BksRgtXYjyUxJs6ST79d X-Received: by 2002:a05:6a00:174e:b0:47b:d4d6:3b9e with SMTP id j14-20020a056a00174e00b0047bd4d63b9emr29965562pfc.21.1635352964206; Wed, 27 Oct 2021 09:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635352964; cv=none; d=google.com; s=arc-20160816; b=s4PiQocB3tIti9nNHReuyiSHwIjKa/SBER4auEw/aZy+xlvg2YuiMVSUaAzNp2hPbk sPpgvUqVXa8MjAs44SyCJ04f2nydKTeSBiKhqRKp5VEM2saJMGxBgRT8I5EeUZxXaAHy ToagrXYIBaUFcuLwFzn6dXbYhytje6o2bjQJMCyIgFRTVdBYhK5o/OEUgOQqV8zPQ7Tb 5HxKM4iFc2TU7YKZZV6v5P5sLrOnwG+P9w2Zj9GL2LU+TrTUZYDUfy1ZnYlMpPAKlrHc 9Rn2DjuSYRr5rRREMtR7T8JBXd6qsRh+chD5mwB6dG+6r3fhlp93OXjnyXnW43SSI3kR 32Bg== 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 :mime-version:user-agent:date:message-id:subject:from:to; bh=0ECZLXE5SVgw7b8ZtO+xnJN1qKc1qP5aKBSVtRF/bX0=; b=jH1QiQJX+X3NaIoxNO+1XC3BMW5qtFnvyAfN9xqHnqmcYTQKaXG+rZW86WHC3csewK oQ+FS9LmOYoicQtX7pJ8D2OBa4LMbnhnVoufR4FYbStq+m9DTCgWdRTk9I9cISIPBaUI 496vXYy7F2LxqdRuDrbuFjGXiEBTkS2tSkMUoSLcHiLj8kdJ5RaQuWF1g04O6IzbpWsP R3IJN+A9B80mhAmL6gt8DT0OMEXprlHWrApVb3eGyAdqoFXMlgyLSJsZnN955ssci7v4 6F2o9uIT1cac3NU2g8BEqk4ns0Z7st+3rh+a9GSmltXv6rw7W/4F6vXjeMnXki3zcBJ9 mkVQ== 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 d184si512952pgc.536.2021.10.27.09.42.05; Wed, 27 Oct 2021 09:42:44 -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 S238901AbhJ0DQ3 (ORCPT + 99 others); Tue, 26 Oct 2021 23:16:29 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:39699 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237793AbhJ0DQ1 (ORCPT ); Tue, 26 Oct 2021 23:16:27 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R901e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=30;SR=0;TI=SMTPD_---0UtqDHde_1635304435; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UtqDHde_1635304435) by smtp.aliyun-inc.com(127.0.0.1); Wed, 27 Oct 2021 11:13:56 +0800 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 From: =?UTF-8?B?546L6LSH?= Subject: [PATCH v7 0/2] fix & prevent the missing preemption disabling Message-ID: Date: Wed, 27 Oct 2021 11:13:55 +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 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 The testing show that perf_ftrace_function_call() are using smp_processor_id() with preemption enabled, all the checking on CPU could be wrong after preemption. As Peter point out, the section between ftrace_test_recursion_trylock/unlock() pair require the preemption to be disabled as 'Documentation/trace/ftrace-uses.rst' explained, but currently the work is done outside of the helpers. And since the internal using of trace_test_and_set_recursion() and trace_clear_recursion() also require preemption to be disabled, we can just merge the logical together. Patch 1/2 will make sure preemption disabled when recursion lock succeed, patch 2/2 will do smp_processor_id() checking after trylock() to address the issue. v1: https://lore.kernel.org/all/8c7de46d-9869-aa5e-2bb9-5dbc2eda395e@linux.alibaba.com/ v2: https://lore.kernel.org/all/b1d7fe43-ce84-0ed7-32f7-ea1d12d0b716@linux.alibaba.com/ v3: https://lore.kernel.org/all/609b565a-ed6e-a1da-f025-166691b5d994@linux.alibaba.com/ V4: https://lore.kernel.org/all/32a36348-69ee-6464-390c-3a8d6e9d2b53@linux.alibaba.com/ V5: https://lore.kernel.org/all/3ca92dc9-ea04-ddc2-71cd-524bfa5a5721@linux.alibaba.com/ V6: https://lore.kernel.org/all/df8e9b3e-504c-635d-4e92-99cdf9f05479@linux.alibaba.com/ Michael Wang (2): ftrace: disable preemption when recursion locked ftrace: do CPU checking after preemption disabled arch/csky/kernel/probes/ftrace.c | 2 -- arch/parisc/kernel/ftrace.c | 2 -- arch/powerpc/kernel/kprobes-ftrace.c | 2 -- arch/riscv/kernel/probes/ftrace.c | 2 -- arch/x86/kernel/kprobes/ftrace.c | 2 -- include/linux/trace_recursion.h | 11 ++++++++++- kernel/livepatch/patch.c | 13 +++++++------ kernel/trace/ftrace.c | 15 +++++---------- kernel/trace/trace_event_perf.c | 6 +++--- kernel/trace/trace_functions.c | 5 ----- 10 files changed, 25 insertions(+), 35 deletions(-) -- 1.8.3.1