Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp69022rwd; Mon, 15 May 2023 20:15:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4jxT2BqEKvGKhMZ/bV9ymV75walTE7v/s7ojtqKlSNQ8znQSsZn6kiS14FUhwxoMy6UmGY X-Received: by 2002:a17:902:bc8b:b0:1ae:a44:841c with SMTP id bb11-20020a170902bc8b00b001ae0a44841cmr8620374plb.42.1684206939968; Mon, 15 May 2023 20:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684206939; cv=none; d=google.com; s=arc-20160816; b=jcN3qbXJ4pKYEQlaZGu8gFG/CXJJjNL4QCj982tXxTLqO7YfVIgdnLDCL05Omh08Oi aJ9MRAFB3B8bbdo3FiO1uanGZmTBFLTlzmf+/FLqYDYoeUgrrDHslZ7BrDxwLONlzPRN RJz8SKHbNaPnjEotHttpKb71mfyJjjzN6uQ7mpjxpmhPpEunV0/ZmV1omSvnqiqiIv0h oapaJpG352/Otc6WhyEsp0zFUirVljoICgCG5XC3G8ereUeO0YMrWFdjCNIOtFBpfEbg NSMWbbOQzjf3vxP+vo169NmoiJSHw4pPWs7RalhiodM77R7awAiWM/AeaE7jpyIIgmCc V+rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xRflamDYeWG+dwnKCN6fDmXchdmQ0hXXUg/f9uPeMuY=; b=dXKWGkPkLhIngyQHZzxHZlhrBEY2CyzDpzosXKxk2G1Zmq+yeWRDS90EmuUNFRqx3q O8C5rK40Fldv2zOZgUiEUHmnfhZ8GV1yXVUh/YI/srWEnXHKylkzdMGY9KLZUSqVv8FY 68EHR08wLwoMtfqXorCSlejoI/UTyc/e9S5fcw4FCrC53SLy1RJF+lTPGh1RtYD1QZkX aiTy1h0XJDDOoCLh47SdB9GHqbMhxp0aEoKYIgc0+770NMSmq9hmphr+FbenKNpglNj7 jG5Rx0cc1rethXJexYlaXhEVtRX4vpN5uX3xWbCtAwQnjNttp0gazKr7ffKTgErjXfCl Jj2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="Qm/1ER7w"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a170902e5cf00b001a9b9c32ab7si19146522plf.624.2023.05.15.20.15.27; Mon, 15 May 2023 20:15:39 -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="Qm/1ER7w"; 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 S229896AbjEPDDG (ORCPT + 99 others); Mon, 15 May 2023 23:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjEPDCn (ORCPT ); Mon, 15 May 2023 23:02:43 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F63B6581; Mon, 15 May 2023 20:02:40 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-50bcb229adaso24679600a12.2; Mon, 15 May 2023 20:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684206159; x=1686798159; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xRflamDYeWG+dwnKCN6fDmXchdmQ0hXXUg/f9uPeMuY=; b=Qm/1ER7wHWb0P4lNl5uRyhGhPoafIXVefvVQ587Pbjiog1kXtVz6ACLNM06p+XOYSU smFyGvGg+cr6vN7ET8xBmyz31UGOcw5o/y6eRzo4Ll8mvQsT8t/jGmwLODRpHIV1IJau F1DNEkUsphDSLw4P0Eg/qW5rS3WO5n1V5QRybYRUK3RHhjj8E4DyrQNDAG1pjEiSoJmj kx1oypv1r2QHylMPFhgOT3N/kT0pyWVvhrZGwLFVE6b5PCXmgvxswpFQSp2Y6jpkiMjW EBEigNKekJJIOQVExsYyVn17jIlhMZuA6JVsTYRLPcUvc6WBw3kZbq8ZEEJnrRxRyWh4 ZiXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684206159; x=1686798159; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xRflamDYeWG+dwnKCN6fDmXchdmQ0hXXUg/f9uPeMuY=; b=MjB+TvKCBimTjpFGQo3DW9uqpa6lQnCCLpGi6YJwHxTyreNg/bV55JMBsPB/kJAI3s GP2MDZfS/GTLGlh5+uJPnMwIF5dcQjjg8loXyp0AqguXe4iimEzr+KR3u9AAxdko9a65 XgiylvEKbxbHERRm8r7WDPKCAozmfI9t0NqkVsbKy3N7jNOxhUjPrxLuucOI+s3+8j4Q v+DjublUzJZsr4u48DaH3s96omzgZHf169f91R5ooBicX9hy7XBEsxJWnye20QFQpNGD c8dUTsCu02OTZ3wBxHyrBC8PWdxX1Hnq7lCQN04tcRV4lOSZRWyWhM/AHkWjc6X/uITP htwA== X-Gm-Message-State: AC+VfDzJMD5PKhS2KKBQMypkOX9Qgwq9GeQBmZb2Y2noCCCGI7+J/3ru bQ4q55z5A5jjPO1T6PIJg1rQhQhiLbkLUm70q0k= X-Received: by 2002:a17:906:da86:b0:960:ddba:e5c3 with SMTP id xh6-20020a170906da8600b00960ddbae5c3mr28508381ejb.32.1684206159081; Mon, 15 May 2023 20:02:39 -0700 (PDT) MIME-Version: 1.0 References: <6c428b9f74090b2780b67ca498c45aa5e8c38c44.1684120990.git.zegao@tencent.com> <20230515212546.7a467a1f@gandalf.local.home> In-Reply-To: <20230515212546.7a467a1f@gandalf.local.home> From: Ze Gao Date: Tue, 16 May 2023 11:02:27 +0800 Message-ID: Subject: Re: [PATCH 2/4] fprobe: make fprobe_kprobe_handler recursion free To: Steven Rostedt Cc: Masami Hiramatsu , Ze Gao , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Hi Steven, On Tue, May 16, 2023 at 9:25=E2=80=AFAM Steven Rostedt wrote: > > On Mon, 15 May 2023 11:26:39 +0800 > Ze Gao wrote: > > > 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. > > > > Refactor the common part out of fprobe_kprobe_handler and fprobe_ > > handler and call ftrace recursion detection at the very beginning, > > and also mark these functions notrace so that the whole fprobe_k- > > probe_handler is free from recusion. And > > > > Signed-off-by: Ze Gao > > --- > > kernel/trace/fprobe.c | 61 +++++++++++++++++++++++++++++++------------ > > 1 file changed, 45 insertions(+), 16 deletions(-) > > > > diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c > > index 9abb3905bc8e..ad9a36c87ad9 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 *fr= egs) > > +static inline notrace void __fprobe_handler(unsigned long ip, unsigned= long > > > FYI, if you look in kernel/trace/Makefile you'll see: > > ccflags-remove-$(CONFIG_FUNCTION_TRACER) +=3D $(CC_FLAGS_FTRACE) > > Which removes the flags to add tracing. So there's no reason to add > "notrace" here, as all functions in this directory are by default "notrac= e". Thanks for your valuable info, which I missed before. I'll send v2 to remove those unnecessary notrace annotations, and use the same trick for rethook too. BTW, I think we can mark rethook routines decls notrace in include/linux/rethook.h, which helps to remind developers of other arch(s) this important info. What do you think of it? Regards, Ze