Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1233784rdb; Mon, 19 Feb 2024 08:19:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWAKEzNIIu0/t1xvQRsmSOxwoLoZ2yBTsUWez9FQHC8LwJ9c1AYCOMRtjKPCj7FlkRRo0wkd50C7xKGsa5WV7QyMn2I+WrEt6RPkNCGgg== X-Google-Smtp-Source: AGHT+IE/gCwqtLVgd5TUJOLy4P4SE+eunuEE2TdmvK1VWYWv5LfTdRTqMqdsbbYMxerkjcA+wzAG X-Received: by 2002:a05:6a21:2d06:b0:19e:67b0:9ac6 with SMTP id tw6-20020a056a212d0600b0019e67b09ac6mr19435452pzb.1.1708359546916; Mon, 19 Feb 2024 08:19:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708359546; cv=pass; d=google.com; s=arc-20160816; b=dCt8k/U1QtsoBCKt7WyYeDddBv4h1oQEjhZ6UAx+euYXeZh1yzDR2rL+NiZ9wW4gaS fCA87N8G1QN3QY+OPagEm9XY1Rh0h21EU+7kn2+ClUBgCN+MUE+X+/6ZZALhFduDmgjT eKe43D/2mrvTPjoGfRpiSuzUerLj+CZUdYJEow0iIA3oE8+4MIFgquM0NHVjblAdUYS8 5oQAXW6x6qv89ydy2CzVWlZuXFJF+YhU/bDmYqTRkd7GWMqEnmzwdpftuGUWUsVVpgT2 YiIhs6znhRNBi3Ximuc0ZzQvSgIoSsF8o+lrr90muto3SC8LtyaZVnxuHOUk2UsVn8Nu 56Hw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=rS3EnGHwbKv3vS5p9nX/vjWw8/mfx/GmrHWXplcCuKA=; fh=VaF/w+FGpk/prTFLJfCoV+GJDmV0Sd6dt8EMZrBTbz0=; b=PBCwptFki+tni1rILzuror/8nU5UQMlXDsEhTpfE/IpLfXSVwX9OSENc5ufg9WX9zw zSvUNQoT/j4lX2wniW3jpaGSROdCaz8MlgXARoViKOMHZivfBsFjFph7k2Wr5Ipves/a hLO7lINd9UoOnpNH97lYH6uZ9/iGH6HzA2BYUT/NSMMtJmXfmzMVGI7ShuP9uB6cwiyj rRniTGUKkBqK4O6uizwqepCPEgN1z2O2nxnMOOSHCBEQeWmDQtWVMM3P8K5ulj52UkrS Ms4er6yxy+D4ypMKtbSRKREKooHPkongj+VpLOkJjC+Ad56sF8HXHZWDbFEvvO+q3b3/ sPRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-71637-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71637-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s20-20020a056a00195400b006dffc180954si4702401pfk.398.2024.02.19.08.19.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 08:19:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71637-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-71637-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71637-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 01739B25751 for ; Mon, 19 Feb 2024 16:05:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 207D23C082; Mon, 19 Feb 2024 16:05:25 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B2573A8FB; Mon, 19 Feb 2024 16:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708358724; cv=none; b=MX+8E0ND/AboiToynBW2/al1k5z3GQtBi/fYCP651u/xd+7MubxpxVCQxk84r+ivtWyVGxkLeoQfT1IsDpZQopc4EAc5AnbbQcRW0BNo8L9XJadsG3RCM0lDm0NHNXE8jjiUh+H16UkkY/rXLrCbcE6xEQZVlkfOcPS3kIDXktQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708358724; c=relaxed/simple; bh=/dckHxJU8Um9rSbczYrIkkwQ4W5d5/C4/kuOUKIhTok=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=txD7BYYttdKICxqutmsqG/Np+7T9JXzRaGhnaI5qN0LwadVKuYXnSxywGonn0xfMCI/QvUTWarLYpr5C0DBPKk8yb3LtHohLEXF36BQLs6gUQZ7s6vhbAmgBKk2wkWx3TuAda2kg3PMfOowHo/MzAOP+7D/rHcTV+IstNLJAm2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87B9FC433C7; Mon, 19 Feb 2024 16:05:22 +0000 (UTC) Date: Mon, 19 Feb 2024 11:07:05 -0500 From: Steven Rostedt To: "Masami Hiramatsu (Google)" Cc: Alexei Starovoitov , Florent Revest , linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH v7 22/36] function_graph: Add a new entry handler with parent_ip and ftrace_regs Message-ID: <20240219110705.0c1ffa9c@gandalf.local.home> In-Reply-To: <170723229401.502590.8644663781359457778.stgit@devnote2> References: <170723204881.502590.11906735097521170661.stgit@devnote2> <170723229401.502590.8644663781359457778.stgit@devnote2> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 7 Feb 2024 00:11:34 +0900 "Masami Hiramatsu (Google)" wrote: > From: Masami Hiramatsu (Google) > > Add a new entry handler to fgraph_ops as 'entryregfunc' which takes > parent_ip and ftrace_regs. Note that the 'entryfunc' and 'entryregfunc' > are mutual exclusive. You can set only one of them. > > Signed-off-by: Masami Hiramatsu (Google) > --- > Changes in v3: > - Update for new multiple fgraph. > --- > arch/arm64/kernel/ftrace.c | 2 + > arch/loongarch/kernel/ftrace_dyn.c | 2 + > arch/powerpc/kernel/trace/ftrace.c | 2 + > arch/powerpc/kernel/trace/ftrace_64_pg.c | 10 ++++--- > arch/x86/kernel/ftrace.c | 42 ++++++++++++++++-------------- > include/linux/ftrace.h | 19 +++++++++++--- > kernel/trace/fgraph.c | 30 +++++++++++++++++---- > 7 files changed, 72 insertions(+), 35 deletions(-) > > diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c > index b96740829798..779b975f03f5 100644 > --- a/arch/arm64/kernel/ftrace.c > +++ b/arch/arm64/kernel/ftrace.c > @@ -497,7 +497,7 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, > return; > > if (!function_graph_enter_ops(*parent, ip, frame_pointer, > - (void *)frame_pointer, gops)) > + (void *)frame_pointer, fregs, gops)) I would like to replace that second frame_pointer with fregs. > *parent = (unsigned long)&return_to_handler; > > ftrace_test_recursion_unlock(bit); > diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c > index 81d18b911cc1..45d26c6e6564 100644 > --- a/arch/loongarch/kernel/ftrace_dyn.c > +++ b/arch/loongarch/kernel/ftrace_dyn.c > @@ -250,7 +250,7 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, > > old = *parent; > > - if (!function_graph_enter_ops(old, ip, 0, parent, gops)) > + if (!function_graph_enter_ops(old, ip, 0, parent, fregs, gops)) That is, to replace the parent with fregs, as the parent can be retrieved from fregs. We should add a fregs helper (something like): unsigned long *fregs_caller_addr(fregs) { return (unsigned long *)(kernel_stack_pointer(fregs->regs) + PT_R1); } That returns the address that points to the parent caller on the stack. This was on my todo list to do. That is, replace the passing of the parent of the stack with fregs as it is redundant information. > *parent = return_hooker; > } > #else > diff --git a/arch/powerpc/kernel/trace/ftrace.c b/arch/powerpc/kernel/trace/ftrace.c > index 4ef8bf480279..eeaaa798f4f9 100644 > --- a/arch/powerpc/kernel/trace/ftrace.c > +++ b/arch/powerpc/kernel/trace/ftrace.c > @@ -423,7 +423,7 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, > if (bit < 0) > goto out; > > - if (!function_graph_enter_ops(parent_ip, ip, 0, (unsigned long *)sp, gops)) > + if (!function_graph_enter_ops(parent_ip, ip, 0, (unsigned long *)sp, fregs, gops)) > parent_ip = ppc_function_entry(return_to_handler); > > ftrace_test_recursion_unlock(bit); > diff --git a/arch/powerpc/kernel/trace/ftrace_64_pg.c b/arch/powerpc/kernel/trace/ftrace_64_pg.c > index 7b85c3b460a3..43f6cfaaf7db 100644 > --- a/arch/powerpc/kernel/trace/ftrace_64_pg.c > +++ b/arch/powerpc/kernel/trace/ftrace_64_pg.c > @@ -795,7 +795,8 @@ int ftrace_disable_ftrace_graph_caller(void) > * in current thread info. Return the address we want to divert to. > */ > static unsigned long > -__prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp) > +__prepare_ftrace_return(unsigned long parent, unsigned long ip, unsigned long sp, > + struct ftrace_regs *fregs) And sp shouldn't need to be passed in either, as hat should be part of the fregs. I really like to consolidate the parameters and not just keep adding to them. This all slows down the logic to load the parameters. -- Steve > { > unsigned long return_hooker; > int bit;