From patchwork Wed May 17 03:45:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 95035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp858267vqo; Tue, 16 May 2023 20:54:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7GUwsWf0vHwctvE+ozziL9mvXl2S3xZkF+p8hb/Q14XWBMMrX6qaxr3L4H5MGoZ9+kOOqf X-Received: by 2002:a17:902:b946:b0:1aa:f6f2:46b7 with SMTP id h6-20020a170902b94600b001aaf6f246b7mr36836543pls.34.1684295667178; Tue, 16 May 2023 20:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684295667; cv=none; d=google.com; s=arc-20160816; b=bcq9l6KKatRUkGiOsbpa3wZ0/ddwx+0BMk12+9XnIqzczWxsZXKlNIapwh/Tjy3hCg cnfKX7BQp3jGCA9PiBTfUPotnh7TqcLI9TuEet97+m64WSqbmXJmqTgGJmnYs499DUty ZE8RPE3sYkjsgZ+ZYUu0qE5HijkopnppR2RHm0pdnPkxihMoQMtJfRSNOmsIcvas6H+D T0mEYRET744BXt9tMOjk3BahRBeyQWi5m9X7AfOSiQabYUIdngA6DtJ/vO41eBQq1rxX ckFWH4Y1vLB3M49AkQUoCCa34mD/z2B0/mXQfSfxfic7waQ5I/yNd8B5KFOhMiLwR00L HT8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2uMSZdlVzbxeM11qsVcr0sdcteuxEXHjRqP1IVvopNU=; b=NVdEtv1k5MC2jV0+xb/dkZp6a/8RFNKCgEtzcForZWfDjdP2yx5V44rbsIMOIQm/FT Ot5aq6duue8ytgYgPjs9AgrKm9IGcmPjB1wXSGLhhU8PbwE8EkgvnYVJhh9WJ3WNqFfk UzQ4aNOEDncR9qKHoed1Jx2lpJN3x1NsocwLaRcV9JniuxRIHdFg5j9zB6wqRZ1eAQz1 DL87dcgBeZOHDzkWbIquQtR6e8b5IByndbQzt0x9P+73y/iY0D6ttHu7sm9f+SVqg1Ya exa39C53pbP8/y08uQ/IuWb6lgNarV8oqH80RnPJgolZuqwm22Ty+COqV5MVvhLfN+HD 5JjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NaiABcWC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a170902be0900b001aaf7a9d7aasi18792187pls.126.2023.05.16.20.54.13; Tue, 16 May 2023 20:54:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NaiABcWC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232548AbjEQDpc (ORCPT + 99 others); Tue, 16 May 2023 23:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232532AbjEQDp1 (ORCPT ); Tue, 16 May 2023 23:45:27 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9920430E8; Tue, 16 May 2023 20:45:26 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1ae454844edso2995535ad.1; Tue, 16 May 2023 20:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684295126; x=1686887126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2uMSZdlVzbxeM11qsVcr0sdcteuxEXHjRqP1IVvopNU=; b=NaiABcWCkvK2DCfRgsRBZ/BumHoPpPMfbt+vLGTc6mJZBbSsqJ0Qfs1mqA7kr8myUo s7kSI/PYlCeuqR4ZbKL9S1vhuAY+ZO32SdCRVFiTtC3/xKk1CUQDuNXIMAh3wyt3/G64 rQWz6cmVHkWp9jnZhxAKMfX2GMLup8u+aKqErt2ZO3RuFuVlpDjKXH4tL2d1zxJYDeRP ECA8Kbi6BULm0yKVVaAKuR3xEaYyCpEWicvFRD1kFGuO1KsnamVYvfWDtne7SmUss8Bi uvPjR3V/VweHcFPDZkGddzvzmyH6a+8PLhXzZqGWD0Fq589AY6UlUaV1QRpGrKEEYisb 4R5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684295126; x=1686887126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2uMSZdlVzbxeM11qsVcr0sdcteuxEXHjRqP1IVvopNU=; b=J4BMx1ya4BmdmL60ryHoZmFvThJnrJXVEsA4vdF+wvjX71fsKpl64LeKeqnxFlOyVq QEUQOs0rJDItpbkNRvO+3x0+tWwkz/AQwIQDnRGtJ9ui79RLcyIG6vN20E7FiaN1sP7T 5SrOkl+Zz7d6If6NC1Vbnc4kBMmQF27lwNUtHit1JJL187YnhZWUoKwF1Edz/yeos7P6 myzJKHEae5nFuj9f7REe7tTz9POnjw031fjJjoj11L+O2oaAuetDEnWmy9jV4U8O8g6u ACC0fT7y76A52gcmAdI5MZCnQoRu5Cgcszo9AXpOxjkUOWURQ1QPXI4MsILLiSqPV7rn gfAg== X-Gm-Message-State: AC+VfDyjoN6lbjda/o5PRHkG9YQOxIoPx17PieAjPcXwOqyS+OrOcx1u fVN1woXYoNTgCG1Q9EEA3kA= X-Received: by 2002:a17:903:32c5:b0:1aa:e5cd:647a with SMTP id i5-20020a17090332c500b001aae5cd647amr54727835plr.23.1684295126019; Tue, 16 May 2023 20:45:26 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.83]) by smtp.googlemail.com with ESMTPSA id t2-20020a170902e84200b001a19196af48sm16336746plg.64.2023.05.16.20.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 20:45:25 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Steven Rostedt , Masami Hiramatsu Cc: Albert Ou , Alexander Gordeev , Alexei Starovoitov , Borislav Petkov , Christian Borntraeger , Dave Hansen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Palmer Dabbelt , Paul Walmsley , Sven Schnelle , Thomas Gleixner , Vasily Gorbik , x86@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Conor Dooley , Jiri Olsa , Yonghong Song , Ze Gao , stable@vger.kernel.org Subject: [PATCH v3 1/4] rethook: use preempt_{disable, enable}_notrace in rethook_trampoline_handler Date: Wed, 17 May 2023 11:45:06 +0800 Message-Id: <20230517034510.15639-2-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230517034510.15639-1-zegao@tencent.com> References: <20230517034510.15639-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766112013254641015?= X-GMAIL-MSGID: =?utf-8?q?1766112013254641015?= This patch replaces preempt_{disable, enable} with its corresponding notrace version in rethook_trampoline_handler so no worries about stack recursion or overflow introduced by preempt_count_{add, sub} under fprobe + rethook context. Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook") Signed-off-by: Ze Gao Acked-by: Masami Hiramatsu (Google) Cc: Link: https://lore.kernel.org/linux-trace-kernel/20230516071830.8190-2-zegao@tencent.com --- kernel/trace/rethook.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c index 32c3dfdb4d6a..60f6cb2b486b 100644 --- a/kernel/trace/rethook.c +++ b/kernel/trace/rethook.c @@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, * These loops must be protected from rethook_free_rcu() because those * are accessing 'rhn->rethook'. */ - preempt_disable(); + preempt_disable_notrace(); /* * Run the handler on the shadow stack. Do not unlink the list here because @@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, first = first->next; rethook_recycle(rhn); } - preempt_enable(); + preempt_enable_notrace(); return correct_ret_addr; } From patchwork Wed May 17 03:45:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 95039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp872704vqo; Tue, 16 May 2023 21:36:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ78DM3fqBrGlM+cLPz14LMsqBDzfNCGWGBzt6CvEX9pvT1iNZ9McfYMWbuYQehSQmSx5+zs X-Received: by 2002:a17:903:230e:b0:1ab:1b45:7972 with SMTP id d14-20020a170903230e00b001ab1b457972mr47956964plh.0.1684298166363; Tue, 16 May 2023 21:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684298166; cv=none; d=google.com; s=arc-20160816; b=vtKLdumd77dbNTRolP+Tn/YphJUdsJpMYA6+fNDDQGtY1kUkBctRVqfAXVlrsVDNTt pWf8wX+xirfT6n5ExlxDSG4/IvdyhXPWsPsbn86wXOU3PoI3fZhlIuvJTFKFCgmi0YsK mLo3CnjX5RkzkK46x91t2He1yvSFbH2Mj1rEgV8Ib71+0rRDskMz+raFV2FncQDKiyxY Zpm/PiRgkc5I3A/POlsJnTbKBCJ88eKXTaXZt4bpJmm8n6+E614vufa65YR0833GZiet sUJGGiua4xvA6B6fZxmcZcG4ZRJMyA9CwcTJLILNsRNgLRJ7XXAxhYWZI55uOTsIQgIS OJWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qGFBel0XWHMPBOQVpTEFEgbDNqzL0utWuk4Q5TTOH0I=; b=rDjrnRSPVAl+b+aO2sVyvtA8NqZL7WZSEVlxZnNyEo4JjEtBz4PIdKUn+Km7hPKzBL QCup8p6QK9Z+1Y7K7wKIt/jQ45zXnNV6P4LKmJKMdsft1N5emZqxfSL9T7aaUeSLMRKG lZ521MUKAUz46tXeaUgcxuZkuDz9VxqR+LWonEAkqZSI8vPdAFKvDt3O+IkLflMyAMZ4 OtYTnotzlnVK/MDMQ2s1mkDhzXbEZ49Mx/m6Fm8d+mlaUBVIkcuajt7ziccxamYd9FfG Dvcbp/GDKT6AR7koKP9okFntrqKvHt/0tarRt4R9QamAMEbGyekjsuCRhS1hwrvJ/GOd 5AEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mnJfkgKp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d23-20020a170902729700b001a637201992si18785988pll.488.2023.05.16.21.35.54; Tue, 16 May 2023 21:36:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mnJfkgKp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232237AbjEQDpu (ORCPT + 99 others); Tue, 16 May 2023 23:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232532AbjEQDpf (ORCPT ); Tue, 16 May 2023 23:45:35 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB4EA46AE; Tue, 16 May 2023 20:45:32 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1ae3ed1b08eso4283735ad.0; Tue, 16 May 2023 20:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684295132; x=1686887132; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qGFBel0XWHMPBOQVpTEFEgbDNqzL0utWuk4Q5TTOH0I=; b=mnJfkgKpTPVHwlmswT6XPsXRmkE2FWCwvioj+muJ+uq/kD9S+KoY7Oqkt6AmGwLc/z XybyjbtWhNsEukNAJTd2qEGYk9Q5aG8qQhF8Z4c8fxEuhIHJSB7pGjzeyBHZ7eLCJ0ws Hu70LM7ImU/s5A9/ULM7FjA2T3Cgn6aORaqGmDC7TbFFn0Bjdn8aMd7V1ebFyyUDDS+/ ijzbOIGTn234aKxai/0GSHN1oxWvmXwJgoQ3LE8py0PO78r1+r5FrFv/U8FACfsqgf2s 1dsyFbjtjgmr6jCqTC1Vroc6QGGr3250tlPm4Rp5GQjBasJ1Y6NSlI+mvnKXJhm6Sq/g MJ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684295132; x=1686887132; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qGFBel0XWHMPBOQVpTEFEgbDNqzL0utWuk4Q5TTOH0I=; b=i/7IHYjqFFrgqfnXsIpp8niZUr9k0YacnK+jL/ifglWQRtJ5hYNGKPlNj/pchbf7kG GLFNF71CO+mwzeSnKayBqJEKIs7q/id4s9IpjHQCeop+lqqEMwrkzFD3TXwey8nqKPhT zN95yPmFa1mM1qXrDylaF7sX3JBBo4MPH4FXVSJBEKfHfUzLdBqZ8oc2BY3dWqAPNWf3 XngveA4HvSp6YqToaoD1vLbAcAxuSejr6DOuB9pkj+h0rnskDlqWHv96b7hWVU5PA3ag yNzO9S5TTJ/tOoi0ig9EMJqmzzR+D2SXJSwkLQFXuNUHVRW9ZCcr4gWs2EsAAMtM6uph SX6g== X-Gm-Message-State: AC+VfDxVg2Jyt6KfTI9mSUP+x4ZffeLEPT2TPzjq+yDeW49LLTmTK84F 5+YoqYnDHV5UnUp00hJnlgI= X-Received: by 2002:a17:902:d507:b0:1ac:310d:872d with SMTP id b7-20020a170902d50700b001ac310d872dmr52041365plg.52.1684295132086; Tue, 16 May 2023 20:45:32 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.83]) by smtp.googlemail.com with ESMTPSA id t2-20020a170902e84200b001a19196af48sm16336746plg.64.2023.05.16.20.45.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 20:45:31 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Steven Rostedt , Masami Hiramatsu Cc: Albert Ou , Alexander Gordeev , Alexei Starovoitov , Borislav Petkov , Christian Borntraeger , Dave Hansen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Palmer Dabbelt , Paul Walmsley , Sven Schnelle , Thomas Gleixner , Vasily Gorbik , x86@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Conor Dooley , Jiri Olsa , Yonghong Song , Ze Gao Subject: [PATCH v3 2/4] fprobe: make fprobe_kprobe_handler recursion free Date: Wed, 17 May 2023 11:45:07 +0800 Message-Id: <20230517034510.15639-3-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230517034510.15639-1-zegao@tencent.com> References: <20230517034510.15639-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766114634478160653?= X-GMAIL-MSGID: =?utf-8?q?1766114634478160653?= Current implementation calls kprobe related functions before doing ftrace recursion check in fprobe_kprobe_handler, which opens door to kernel crash due to stack recursion if preempt_count_{add, sub} is traceable in kprobe_busy_{begin, end}. Things goes like this without this patch quoted from Steven: " fprobe_kprobe_handler() { kprobe_busy_begin() { preempt_disable() { preempt_count_add() { <-- trace fprobe_kprobe_handler() { [ wash, rinse, repeat, CRASH!!! ] " By refactoring the common part out of fprobe_kprobe_handler and fprobe_handler and call ftrace recursion detection at the very beginning, the whole fprobe_kprobe_handler is free from recursion. Signed-off-by: Ze Gao Acked-by: Masami Hiramatsu (Google) Link: https://lore.kernel.org/linux-trace-kernel/20230516071830.8190-3-zegao@tencent.com --- kernel/trace/fprobe.c | 59 ++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 9abb3905bc8e..097c740799ba 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -20,30 +20,22 @@ struct fprobe_rethook_node { char data[]; }; -static void fprobe_handler(unsigned long ip, unsigned long parent_ip, - struct ftrace_ops *ops, struct ftrace_regs *fregs) +static inline void __fprobe_handler(unsigned long ip, unsigned long + parent_ip, struct ftrace_ops *ops, struct ftrace_regs *fregs) { struct fprobe_rethook_node *fpr; struct rethook_node *rh = NULL; struct fprobe *fp; void *entry_data = NULL; - int bit, ret; + int ret; fp = container_of(ops, struct fprobe, ops); - if (fprobe_disabled(fp)) - return; - - bit = ftrace_test_recursion_trylock(ip, parent_ip); - if (bit < 0) { - fp->nmissed++; - return; - } if (fp->exit_handler) { rh = rethook_try_get(fp->rethook); if (!rh) { fp->nmissed++; - goto out; + return; } fpr = container_of(rh, struct fprobe_rethook_node, node); fpr->entry_ip = ip; @@ -61,23 +53,60 @@ static void fprobe_handler(unsigned long ip, unsigned long parent_ip, else rethook_hook(rh, ftrace_get_regs(fregs), true); } -out: +} + +static void fprobe_handler(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *ops, struct ftrace_regs *fregs) +{ + struct fprobe *fp; + int bit; + + fp = container_of(ops, struct fprobe, ops); + if (fprobe_disabled(fp)) + return; + + /* recursion detection has to go before any traceable function and + * all functions before this point should be marked as notrace + */ + bit = ftrace_test_recursion_trylock(ip, parent_ip); + if (bit < 0) { + fp->nmissed++; + return; + } + __fprobe_handler(ip, parent_ip, ops, fregs); ftrace_test_recursion_unlock(bit); + } NOKPROBE_SYMBOL(fprobe_handler); static void fprobe_kprobe_handler(unsigned long ip, unsigned long parent_ip, struct ftrace_ops *ops, struct ftrace_regs *fregs) { - struct fprobe *fp = container_of(ops, struct fprobe, ops); + struct fprobe *fp; + int bit; + + fp = container_of(ops, struct fprobe, ops); + if (fprobe_disabled(fp)) + return; + + /* recursion detection has to go before any traceable function and + * all functions called before this point should be marked as notrace + */ + bit = ftrace_test_recursion_trylock(ip, parent_ip); + if (bit < 0) { + fp->nmissed++; + return; + } if (unlikely(kprobe_running())) { fp->nmissed++; return; } + kprobe_busy_begin(); - fprobe_handler(ip, parent_ip, ops, fregs); + __fprobe_handler(ip, parent_ip, ops, fregs); kprobe_busy_end(); + ftrace_test_recursion_unlock(bit); } static void fprobe_exit_handler(struct rethook_node *rh, void *data, From patchwork Wed May 17 03:45:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 95037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp868926vqo; Tue, 16 May 2023 21:25:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6RrIM4+T4EUtDGoXQ8FKUqAeexY524mPhc0CD9yHou4vc3NxSXYbieuHhO/9S8fgeY7Xzd X-Received: by 2002:a05:6a20:8429:b0:107:3db4:1666 with SMTP id c41-20020a056a20842900b001073db41666mr3806161pzd.23.1684297514052; Tue, 16 May 2023 21:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684297514; cv=none; d=google.com; s=arc-20160816; b=OZofr50jQS8fl6J4f0iUcjZdlOp2ycsUpcj2M11fnn67V2i/KHasqGg925sPPs0opk 1R7tlzte4gRC2kpVocXZVNjGpasjpGmofMMIi8UWiprQ34b8s3trFSg/XDKxTlq5BNBH eOYvehxd6k7pu73K0Hnqr0TmQXp7UrZAApYD4Yl8OpNNgDcN+A/XayNU9/5W2nyWqbXi Z+A7IXl/cfxJMCN3CiBC4iC2aNdmC0sf+APc+VKJJytJ/e5Sq9kB0rXhpAIe4ZphZfk+ tzEWK2ToHoFFIxP718MP7EJgETwx635YdPVLs6U0X67reCnuLH3uPsaSvLvPYqfkXWF0 TqVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TpQR3cccQnkFxa/VBlSDTBSv5SyL5gibvWrL1LrLMho=; b=brfmiiueTnNRMh/7GlbM0L7Nd7cbx2eXhJQReHa/gtdfM46eYnGo28TX9aOpQUzRv5 scb/BHsFQ0uaXR8/r+YS6EuZ/iHBAxpcaCjroKv6sGta5lNe/NUKBHV4x2G+bLP57iMw tec16Z4v9/+6EDpCBQ0R8irFU9RP7l7PO5pNfHalkW2XhDSNTqK9E/a+/srfE8CAh335 CHgCwNSAZmo3DSJzmvr9QPd1ALRhQJ1jGQ+Bg7z68uSE64cZuGihhqRlOjB8R+WmVf52 40ItYxGCWd1mPPzU/9f/Pt+eNQv7vBuLHQlHDa/fnF9SWoO+/VCEFLE9eF2zMbaM74u0 dq3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=UERCSL4J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a63db58000000b00528c16e927dsi20566856pgi.22.2023.05.16.21.24.42; Tue, 16 May 2023 21:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=UERCSL4J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232613AbjEQDqC (ORCPT + 99 others); Tue, 16 May 2023 23:46:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232577AbjEQDps (ORCPT ); Tue, 16 May 2023 23:45:48 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DC804ECF; Tue, 16 May 2023 20:45:38 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1ae3fe67980so4102875ad.3; Tue, 16 May 2023 20:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684295138; x=1686887138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TpQR3cccQnkFxa/VBlSDTBSv5SyL5gibvWrL1LrLMho=; b=UERCSL4JnKxWSII93BWPVPBBwK6uL6PmIwlr8ZXOKLlNtpxo5SuSIG9NCdRoUWZOoZ +hYxmrQqH/Q8Nn729aEESqAHFErEnG5gxcYEkikRN8HovztUkVCPnfidYHdjmfJn+l6e gPuj5+IyFNkSWsVE10FucW4qXqClKG6/w9Wcd6mq92qXTmFiEFyl9MK0fjfWsOjlNaiE QByDM+aLJ9R3qtw1YAJQhEHVvBAURJgNELbn6b65JIvslmWs6VSBHTubnpB57vEVbPCm +o0szfsEnOcquAkSel2xOZHbDEFVqFPW+K6B6MfoBO6zQxqzqLXJyy1b1eY7ngteuAgP EiJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684295138; x=1686887138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TpQR3cccQnkFxa/VBlSDTBSv5SyL5gibvWrL1LrLMho=; b=RKdobhXpfuoQxTdnrJmdVxhPJ5Dnkh+KCUsJx/VqgEgSySy9ABMHXM8j8mhkkD86Go 5baR2bC9Wb4rPYXMhs5ow9mNWZvArVb+Z+/RV57UL7X0SZuae3ksSzMwhze7m0cgzXdC nfJbN2exVCNCXSgPYI8cdO/OSNRX9XO2C7u2T/bQ1w/5ZNVJR3YN595/dTbImC+9f/XA 7dZg7AcYENfDT3h1JYUWp1oq+FOjHrf1oofDu9rjUTWsE51+ejzQvmiHXrKKZFZvO8QQ zdqdYXDAlIOt8he4OSXhKRce58sm12cbzUJxkKs/B80WsxsehK9NNB3dOYEte3RbU5M7 s8UA== X-Gm-Message-State: AC+VfDx6Jx39R1Cu8ClguI54YsgEJJQX6HALFPazakLttX7p5B3uXQFb bP9uZinnmhyyl2qVWN4bHpI= X-Received: by 2002:a17:902:9897:b0:1ab:253e:6906 with SMTP id s23-20020a170902989700b001ab253e6906mr37006175plp.67.1684295138247; Tue, 16 May 2023 20:45:38 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.83]) by smtp.googlemail.com with ESMTPSA id t2-20020a170902e84200b001a19196af48sm16336746plg.64.2023.05.16.20.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 20:45:37 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Steven Rostedt , Masami Hiramatsu Cc: Albert Ou , Alexander Gordeev , Alexei Starovoitov , Borislav Petkov , Christian Borntraeger , Dave Hansen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Palmer Dabbelt , Paul Walmsley , Sven Schnelle , Thomas Gleixner , Vasily Gorbik , x86@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Conor Dooley , Jiri Olsa , Yonghong Song , Ze Gao , stable@vger.kernel.org Subject: [PATCH v3 3/4] fprobe: add recursion detection in fprobe_exit_handler Date: Wed, 17 May 2023 11:45:08 +0800 Message-Id: <20230517034510.15639-4-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230517034510.15639-1-zegao@tencent.com> References: <20230517034510.15639-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766113950333466633?= X-GMAIL-MSGID: =?utf-8?q?1766113950333466633?= fprobe_hander and fprobe_kprobe_handler has guarded ftrace recursion detection but fprobe_exit_handler has not, which possibly introduce recursive calls if the fprobe exit callback calls any traceable functions. Checking in fprobe_hander or fprobe_kprobe_handler is not enough and misses this case. So add recursion free guard the same way as fprobe_hander. Since ftrace recursion check does not employ ip(s), so here use entry_ip and entry_parent_ip the same as fprobe_handler. Fixes: 5b0ab78998e3 ("fprobe: Add exit_handler support") Signed-off-by: Ze Gao Cc: stable@vger.kernel.org Acked-by: Masami Hiramatsu (Google) Link: https://lore.kernel.org/linux-trace-kernel/20230516071830.8190-4-zegao@tencent.com --- kernel/trace/fprobe.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 097c740799ba..281b58c7dd14 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -17,6 +17,7 @@ struct fprobe_rethook_node { struct rethook_node node; unsigned long entry_ip; + unsigned long entry_parent_ip; char data[]; }; @@ -39,6 +40,7 @@ static inline void __fprobe_handler(unsigned long ip, unsigned long } fpr = container_of(rh, struct fprobe_rethook_node, node); fpr->entry_ip = ip; + fpr->entry_parent_ip = parent_ip; if (fp->entry_data_size) entry_data = fpr->data; } @@ -114,14 +116,26 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data, { struct fprobe *fp = (struct fprobe *)data; struct fprobe_rethook_node *fpr; + int bit; if (!fp || fprobe_disabled(fp)) return; fpr = container_of(rh, struct fprobe_rethook_node, node); + /* + * we need to assure no calls to traceable functions in-between the + * end of fprobe_handler and the beginning of fprobe_exit_handler. + */ + bit = ftrace_test_recursion_trylock(fpr->entry_ip, fpr->entry_parent_ip); + if (bit < 0) { + fp->nmissed++; + return; + } + fp->exit_handler(fp, fpr->entry_ip, regs, fp->entry_data_size ? (void *)fpr->data : NULL); + ftrace_test_recursion_unlock(bit); } NOKPROBE_SYMBOL(fprobe_exit_handler); From patchwork Wed May 17 03:45:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ze Gao X-Patchwork-Id: 95040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp872788vqo; Tue, 16 May 2023 21:36:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4l3nN4gLBTxPCGcHtd9Vo3Q+TfiMx1S3/5ScqccZ9Skayc4HXajVr2ktwOU6FAsTkBKGeg X-Received: by 2002:a05:6a20:8f09:b0:100:6f8f:7793 with SMTP id b9-20020a056a208f0900b001006f8f7793mr45364996pzk.3.1684298178538; Tue, 16 May 2023 21:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684298178; cv=none; d=google.com; s=arc-20160816; b=S4D17JCWXKfgAROdNV/HNlrTjsdQUYRxuphjYmimur5aGbUoFiRFl8WaZvoOPDrvqs lPpRsEW6Ccb+X3JXZRkjK3NNuxzh4QcXDsqFJYiVXMxVrJg6/y7sGh1CIRNZ/n1IGUvj 5EUQzdgXmEeB561ttYhdZToogyx+ChZE7cTCkOxOaoE77nfsVHRShS7tPISzOREuEw/O ySnfu7Z/MzTAlsXeZqefeVHm+rmce2vBhgpm5+IU5d0YSCH+6RiNDQE0yOfE061XwnxF hcMWprK6cFKK7NCTUs0kc+QOj142IxaYURvSgayfIYSweTp9dncCj0u8A1LNGPI94nPW N/jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0tAjWrmzrXGyO7rim5mWO1xH9wWB24VwxwxXjgy9nqY=; b=a8BmOxsXZD2ZdndKa91EpRlpezX6c71P7nx1Fi0v0ozXM5j9RAX9ytKevAicqb5OEY r4V7+LomPGGF3jiGbnWMGtIrIoNAk8HH8NvSRJ5QQD2mRzuJDhLPmybnY1LxzkYOabiX qlZHfKaho8eFfLcZxme5wwKTA80JoSILIQVv4TQc9xVYCD17iOlVNOwD6KMTDN8w3Jae cToXc4t0seIqQbMZ0OmCWz7z+iKyt7zvQg1qNvPQbNjjmxJnpD2CT8pOhfzV1dEy0p8t n2ogWoK+qb6uLyah8GUzIuAABcv0XrmjmMM0cPSTt4jIDCWYGT7qZuRJjPdYuYCvaCMH S1ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=IXqKz9k5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fy12-20020a17090b020c00b0024bda568513si828082pjb.123.2023.05.16.21.36.01; Tue, 16 May 2023 21:36:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=IXqKz9k5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbjEQDq3 (ORCPT + 99 others); Tue, 16 May 2023 23:46:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232565AbjEQDp5 (ORCPT ); Tue, 16 May 2023 23:45:57 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0956D526E; Tue, 16 May 2023 20:45:44 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1ab1b79d3a7so2945855ad.3; Tue, 16 May 2023 20:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684295144; x=1686887144; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0tAjWrmzrXGyO7rim5mWO1xH9wWB24VwxwxXjgy9nqY=; b=IXqKz9k5vSycU5LcG+OjyO4IGbHD5KIhty+95sowy/bKSzZa6tVax2mkeL31D/yJXY zZ1ImDoihBfW8G988jhG7sfn7iDKErXUynFJTStUSB5InW+x9v4xALBs6IRvfWppMBCb Fw9RijMCj0KacaPY0rt1opW3J+Q1n1/ewB/QVr0B2wcDg8nvSsTgVbY876opBh2vwXh9 RdhfyRMJ1vqrv7dawirsMEnJkbkG/ZpErcsyRoOUyhNEV0o8vS66V1QEbsBQGpKlVvqz 882Rda4fpgf0Ayg1p+FBxlEBJO9Q5Ee1eINQYzfKeZjacQZhCSJaPRU+age+OA6o6P6Q 1ILA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684295144; x=1686887144; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0tAjWrmzrXGyO7rim5mWO1xH9wWB24VwxwxXjgy9nqY=; b=Mf2pAA5GywEimpHyglZ/yVF02LoBun5PT+++n5d/jWy2rKfFAmBOOum/TU8ms6uR7m CbZ1aWn/HLL9UQ2DhE47+m/o2IRX2rVx1h3ux9D4nzs+cEHul+6HJVgrlnbV0IPf3jDH Rx7EqCQbsr6/RsaD0INfXsQuEn3Xd8uziYCg52ljH6sRjmMwVPpspijAXqKmZBOK6J+q TSpqUJucdpRe92IK6mrAj2ZfUfuauLdrWEyPClewxCnNvEXBgUvrS8MPJNmJ5M/Zn9w9 CwTvKe4PcxhKV4CV3mTs+miv98O0IesFUzuj07/81d1uekX91uYowZA/78lGFTmWF8Dz k5WA== X-Gm-Message-State: AC+VfDzBQ2qllEOApQ6DfgU8cQYODEzHleZJY9bknmGblfLEWbBfPXC3 G+hnUAQ+3Clp2f1ntQqa0KhSSk3eYGWUnA== X-Received: by 2002:a17:902:dace:b0:1ac:6e1f:d1bd with SMTP id q14-20020a170902dace00b001ac6e1fd1bdmr44584262plx.19.1684295144122; Tue, 16 May 2023 20:45:44 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.83]) by smtp.googlemail.com with ESMTPSA id t2-20020a170902e84200b001a19196af48sm16336746plg.64.2023.05.16.20.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 20:45:43 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Steven Rostedt , Masami Hiramatsu Cc: Albert Ou , Alexander Gordeev , Alexei Starovoitov , Borislav Petkov , Christian Borntraeger , Dave Hansen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Palmer Dabbelt , Paul Walmsley , Sven Schnelle , Thomas Gleixner , Vasily Gorbik , x86@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Conor Dooley , Jiri Olsa , Yonghong Song , Ze Gao Subject: [PATCH v3 4/4] rethook, fprobe: do not trace rethook related functions Date: Wed, 17 May 2023 11:45:09 +0800 Message-Id: <20230517034510.15639-5-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230517034510.15639-1-zegao@tencent.com> References: <20230517034510.15639-1-zegao@tencent.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766114646626703956?= X-GMAIL-MSGID: =?utf-8?q?1766114646626703956?= These functions are already marked as NOKPROBE to prevent recursion and we have the same reason to blacklist them if rethook is used with fprobe, since they are beyond the recursion-free region ftrace can guard. Signed-off-by: Ze Gao Reviewed-by: Steven Rostedt (Google) Acked-by: Masami Hiramatsu (Google) Link: https://lore.kernel.org/linux-trace-kernel/20230516071830.8190-5-zegao@tencent.com --- arch/riscv/kernel/probes/Makefile | 2 ++ arch/s390/kernel/Makefile | 1 + arch/x86/kernel/Makefile | 1 + 3 files changed, 4 insertions(+) diff --git a/arch/riscv/kernel/probes/Makefile b/arch/riscv/kernel/probes/Makefile index c40139e9ca47..8265ff497977 100644 --- a/arch/riscv/kernel/probes/Makefile +++ b/arch/riscv/kernel/probes/Makefile @@ -4,3 +4,5 @@ obj-$(CONFIG_RETHOOK) += rethook.o rethook_trampoline.o obj-$(CONFIG_KPROBES_ON_FTRACE) += ftrace.o obj-$(CONFIG_UPROBES) += uprobes.o decode-insn.o simulate-insn.o CFLAGS_REMOVE_simulate-insn.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook_trampoline.o = $(CC_FLAGS_FTRACE) diff --git a/arch/s390/kernel/Makefile b/arch/s390/kernel/Makefile index 8983837b3565..6b2a051e1f8a 100644 --- a/arch/s390/kernel/Makefile +++ b/arch/s390/kernel/Makefile @@ -10,6 +10,7 @@ CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE) # Do not trace early setup code CFLAGS_REMOVE_early.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_rethook.o = $(CC_FLAGS_FTRACE) endif diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index dd61752f4c96..4070a01c11b7 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -17,6 +17,7 @@ CFLAGS_REMOVE_ftrace.o = -pg CFLAGS_REMOVE_early_printk.o = -pg CFLAGS_REMOVE_head64.o = -pg CFLAGS_REMOVE_sev.o = -pg +CFLAGS_REMOVE_rethook.o = -pg endif KASAN_SANITIZE_head$(BITS).o := n