Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp574163rdb; Thu, 15 Feb 2024 08:39:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVDAyRT7s6FcMweKPuF6kRBju8gNemtMC6p6is/XTlsXo+D6oQKE1/NYxAXRvnUZ2pSsLRsoMTFOWjp0Y7NlJJwfL8cg2mhJx4W2qFsHw== X-Google-Smtp-Source: AGHT+IFM4rBU6/yfL0Y9bLlsCbh8SN8JW39Pw7SuJzWe/iWAWOREcdn7z2o90E7KdrdFta5cFm/x X-Received: by 2002:a17:90a:cb8b:b0:296:8eac:b4a1 with SMTP id a11-20020a17090acb8b00b002968eacb4a1mr1924770pju.27.1708015184797; Thu, 15 Feb 2024 08:39:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708015184; cv=pass; d=google.com; s=arc-20160816; b=cAIL8S+Bt9x0MNmQhxyldhAOdxsFn2kyAaRmqIl9FtXTCUGmJ57PNEQV6C0P791oxI 9uaUsH9V6LTVRzSgh5PS2OlB7jPlntsZ+GVKDIwP0Nh31cyK/DwePBvYdy1pYPGbnMgu 0sxAOLNQ9Tm+5IAoP1Dk8Kb7o2qiw8m8dNZTMqdP90OHJjMrEUE7LCEGASCaeaSYNQ97 UcmMm4gts3C3PFBE5Dta2cIC2oeOsORq9OCjGeaIo+xlGH+FMB+MdSDfhJPHNEsDCSXu ipcrBOqkfHBTRJoIDc2zvgI5IcF628Nkm0AVOAytIcuaVR81WSGTZe4jRZyDfrOkMU3C Xmfg== 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=28GJHVXpkKvjGHRZVISo+Uzq4VKiDWow1dU0zxY7eEk=; fh=VaF/w+FGpk/prTFLJfCoV+GJDmV0Sd6dt8EMZrBTbz0=; b=GNqLLSe49H4LVelpQ754wshgc0Ym7HH0mkCkGP76wE6Ill6vfczMn6A+GYs6w1QxDU tHzg6YcujUrx0vxYJ66QGNZ5A8M5jW/jOPdUngOpG2D2oBSwuhUoh669RKA8tAqu3pmc x1HVh+T6yLMDy/JBfYLKNOf1S3G+klQAxn1EFlq52ZCs56lQ4t0Xr8L4Bb5ecA5OXQvI 6VDn8hyyuTYWt6nrk9fCtM0hS69kh/dspE8VWoCh09LDBYFKD7vomx1zyt1BF4QKOX/v KmwNKIj8IFfN4lDsc0t59XxadaD+lJPC4q7WF5JQERe/jOKSU4GN3/NqDg5Wp/dj+6sz 1ktg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-67288-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67288-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id na13-20020a17090b4c0d00b002992c45455fsi111307pjb.30.2024.02.15.08.39.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 08:39:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67288-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-67288-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67288-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 53E092824AF for ; Thu, 15 Feb 2024 16:14:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 060D41350CF; Thu, 15 Feb 2024 16:08:51 +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 777B51339A9; Thu, 15 Feb 2024 16:08:50 +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=1708013330; cv=none; b=MCIhCiy/YuLBqBdCm2gV2TMh3BDWi6oGvXWVvSJIqVBDW4DOBBmw8B+38YrQb36H2hHJE/Ug9B/yCEjcYE0apqqF1r3zybRC/2U2RBMX/gIoIbWKvugYVKVe1sXpg7jizXrTa9ZhlBewogS0dI/T+jx7lSbxgWAqJSKt4U8LAVw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708013330; c=relaxed/simple; bh=oG6XQpiguIejDhBna2Kjxoiz9TbXaIQMa+9CRNJEo5k=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=god0upz6gD373yJSEVVNhb+AbDghSGqRUUiiTLDhUQtrzQpjIr3SxItGP8L7yy2T3f+JvtCk2dQzZJ1+Wsp2VUixoXw+dCfK44wkqh1VDZ8ZKmmviLVEx1GrHh9x6sqnsZZhufQty5ar8qHjucVVXlK5MBUrLY7HnNWYa/kWy4A= 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 2F360C433F1; Thu, 15 Feb 2024 16:08:48 +0000 (UTC) Date: Thu, 15 Feb 2024 11:10:21 -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 25/36] arm64: ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Message-ID: <20240215111021.05163ba1@gandalf.local.home> In-Reply-To: <170723232647.502590.10808588686838195094.stgit@devnote2> References: <170723204881.502590.11906735097521170661.stgit@devnote2> <170723232647.502590.10808588686838195094.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:12:06 +0900 "Masami Hiramatsu (Google)" wrote: > From: Masami Hiramatsu (Google) > > Enable CONFIG_HAVE_FUNCTION_GRAPH_FREGS on arm64. Note that this > depends on HAVE_DYNAMIC_FTRACE_WITH_ARGS which is enabled if the > compiler supports "-fpatchable-function-entry=2". If not, it > continue to use ftrace_ret_regs. > > Signed-off-by: Masami Hiramatsu (Google) > --- > Changes in v3: > - Newly added. > --- > arch/arm64/Kconfig | 2 ++ > arch/arm64/include/asm/ftrace.h | 6 ++++++ > arch/arm64/kernel/entry-ftrace.S | 28 ++++++++++++++++++++++++++++ > 3 files changed, 36 insertions(+) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index aa7c1d435139..34becd41ae66 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -194,6 +194,8 @@ config ARM64 > select HAVE_DYNAMIC_FTRACE > select HAVE_DYNAMIC_FTRACE_WITH_ARGS \ > if $(cc-option,-fpatchable-function-entry=2) > + select HAVE_FUNCTION_GRAPH_FREGS \ > + if HAVE_DYNAMIC_FTRACE_WITH_ARGS > select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS \ > if DYNAMIC_FTRACE_WITH_ARGS && DYNAMIC_FTRACE_WITH_CALL_OPS > select HAVE_DYNAMIC_FTRACE_WITH_CALL_OPS \ > diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h > index ab158196480c..efd5dbf74dd6 100644 > --- a/arch/arm64/include/asm/ftrace.h > +++ b/arch/arm64/include/asm/ftrace.h > @@ -131,6 +131,12 @@ ftrace_regs_set_return_value(struct ftrace_regs *fregs, > fregs->regs[0] = ret; > } > > +static __always_inline unsigned long > +ftrace_regs_get_frame_pointer(struct ftrace_regs *fregs) > +{ > + return fregs->fp; > +} > + > static __always_inline void > ftrace_override_function_with_return(struct ftrace_regs *fregs) > { > diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S > index f0c16640ef21..d87ccdb9e678 100644 > --- a/arch/arm64/kernel/entry-ftrace.S > +++ b/arch/arm64/kernel/entry-ftrace.S > @@ -328,6 +328,33 @@ SYM_FUNC_END(ftrace_stub_graph) > * Run ftrace_return_to_handler() before going back to parent. > * @fp is checked against the value passed by ftrace_graph_caller(). > */ > +#ifdef CONFIG_HAVE_FUNCTION_GRAPH_FREGS > +SYM_CODE_START(return_to_handler) > + /* save ftrace_regs except for PC */ > + sub sp, sp, #FREGS_SIZE > + stp x0, x1, [sp, #FREGS_X0] > + stp x2, x3, [sp, #FREGS_X2] > + stp x4, x5, [sp, #FREGS_X4] > + stp x6, x7, [sp, #FREGS_X6] > + str x8, [sp, #FREGS_X8] > + str x29, [sp, #FREGS_FP] > + str x9, [sp, #FREGS_LR] > + str x10, [sp, #FREGS_SP] Here too. The above is just garbage. Let's not fill in garbarge registers. The above is useless on return of a function. Heck, adding zeros is better than this. But really, we need to have ftrace regs to have some kind of flag that can state what it holds. Right now I see three states: 1 - holds all regs and pt_regs can be retrieved 2 - only holds function entry regs (parameters and stack) 3 - only holds function exit regs (return value and stack) Don't save anything else unless needed. -- Steve > + > + mov x0, sp > + bl ftrace_return_to_handler // addr = ftrace_return_to_hander(fregs); > + mov x30, x0 // restore the original return address > + > + /* restore return value regs */ > + ldp x0, x1, [sp, #FREGS_X0] > + ldp x2, x3, [sp, #FREGS_X2] > + ldp x4, x5, [sp, #FREGS_X4] > + ldp x6, x7, [sp, #FREGS_X6] > + add sp, sp, #FREGS_SIZE > + > + ret > +SYM_CODE_END(return_to_handler) > +#else /* !CONFIG_HAVE_FUNCTION_GRAPH_FREGS */ > SYM_CODE_START(return_to_handler) > /* save return value regs */ > sub sp, sp, #FGRET_REGS_SIZE > @@ -350,4 +377,5 @@ SYM_CODE_START(return_to_handler) > > ret > SYM_CODE_END(return_to_handler) > +#endif /* CONFIG_HAVE_FUNCTION_GRAPH_FREGS */ > #endif /* CONFIG_FUNCTION_GRAPH_TRACER */