Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2101335rwl; Thu, 30 Mar 2023 06:08:58 -0700 (PDT) X-Google-Smtp-Source: AKy350bQc28B5GppmlIsAPyL8fE3Khr0ApvP4bqfvmID6sgZv3Bd08ElDJ0ZkMMptJyJk2uRoSuG X-Received: by 2002:a17:902:fa50:b0:1a1:d395:e85c with SMTP id lb16-20020a170902fa5000b001a1d395e85cmr2266026plb.0.1680181737811; Thu, 30 Mar 2023 06:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680181737; cv=none; d=google.com; s=arc-20160816; b=fQXGT5zxKdAm6Yx9Z7cPovuzCnEUUb8HfAefs2KC2FdpMby/wXnJ63M03U6BnFM9/7 m3/jRlSoHKM7Hzk6K/NryLpu8OMHe2QYVpLeTesnpZ+FCs97SLa4YMVyWBB57Yqd/U1G lX3PlBLrvjCi4pvrDfF3hNqVedlbi4AzK8q9CR8XAUMT6Q+3vjLOTEnNL7AXgK3T6Gfk KEWRkUOzI8/v6IrHNxkHpxT3CPl0CpZeZEm0BW9m1lRfFLIm2LxYz2KGNQgQc/KPnCoj TbxyGqhxJhXYDhObHGu4kEIJxIQc//dwMPvBBhnrKf4DyGVnqeCanm6dJBEtfl9DT7X7 MGPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=31GyjEEsPhwJ+BKrgkvSxNeXde4/jtP+q5sJTKPFGzo=; b=U/rTo+/3SLkVKVWZeOn8B04vk36Ey6bKS3WNLhU+hsoe8rQfGKeJ+FA0KTZfmaV2ui kkDT3jYANk5wVOjjyLZOl1c4SRS6yxwGT1UkYaX6c5glBMnWmatpFRvTV+BBgJvFaxWQ q25V+8BtTRMg8AHOyfvPJQfmErr+XV8xsGHnGN7sHvL9Y14ZKtL6ZXiQtZlPetHCTGoH f+29ZvW1UcckdMcl7zCJU4CLufoXrjxuYffxHGBhyjcZ/DCFAb34dYVVGvmRBruVj+rU HYvPogjM2EZAcmEpix53/4RmejUGM5l66DuDc0Hl5LSOZvPHGheyS3fuRu8mWcQgz7q1 vxgQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a170903024c00b00189efa12957si36219736plh.126.2023.03.30.06.08.42; Thu, 30 Mar 2023 06:08:57 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbjC3NIH (ORCPT + 99 others); Thu, 30 Mar 2023 09:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231367AbjC3NIG (ORCPT ); Thu, 30 Mar 2023 09:08:06 -0400 Received: from mail-m118111.qiye.163.com (mail-m118111.qiye.163.com [115.236.118.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6ABB7ED9; Thu, 30 Mar 2023 06:08:02 -0700 (PDT) Received: from [10.128.10.193] (unknown [117.133.56.22]) by mail-m118111.qiye.163.com (Hmail) with ESMTPA id 1FD3D5802D6; Thu, 30 Mar 2023 21:07:46 +0800 (CST) Message-ID: Date: Thu, 30 Mar 2023 21:07:42 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v9 7/8] LoongArch: ftrace: Enable HAVE_FUNCTION_GRAPH_RETVAL Content-Language: en-US To: Huacai Chen Cc: mhiramat@kernel.org, rostedt@goodmis.org, linux@armlinux.org.uk, mark.rutland@arm.com, will@kernel.org, catalin.marinas@arm.com, rmk+kernel@armlinux.org.uk, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, tglx@linutronix.de, dave.hansen@linux.intel.com, x86@kernel.org, bp@alien8.de, hpa@zytor.com, zhangqing@loongson.cn, kernel@xen0n.name, mingo@redhat.com, peterz@infradead.org, xiehuan09@gmail.com, dinghui@sangfor.com.cn, huangcun@sangfor.com.cn, dolinux.peng@gmail.com, linux-trace-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: From: Donglin Peng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVkZGkgZVh0YQ00YTxpPTE0dGFUTARMWGhIXJBQOD1 lXWRgSC1lBWUpKTFVKSEhVTk1VSUlZV1kWGg8SFR0UWUFZT0tIVUpKS0hKTFVKS0tVS1kG X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PVE6PCo6OT0LH08YUSsTSR0V GgEwFDRVSlVKTUNLSkNKTU1MTEhOVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSkpMVUpISFVOTVVJSVlXWQgBWUFCSExMNwY+ X-HM-Tid: 0a8732a1a59b2eb7kusn1fd3d5802d6 X-HM-MType: 1 X-Spam-Status: No, score=-0.0 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 On 2023/3/30 20:48, Huacai Chen wrote: > Hi, Donglin, > > On Thu, Mar 30, 2023 at 7:39 PM Donglin Peng wrote: >> >> The previous patch ("function_graph: Support recording and printing >> the return value of function") has laid the groundwork for the for >> the funcgraph-retval, and this modification makes it available on >> the LoongArch platform. >> >> We introduce a new structure called fgraph_ret_regs for the LoongArch >> platform to hold return registers and the frame pointer. We then fill >> its content in the return_to_handler and pass its address to the >> function ftrace_return_to_handler to record the return value. >> >> Signed-off-by: Donglin Peng >> --- >> v9: >> - Fix stack pointer align issues >> - Update the commit message >> >> v8: >> - Modify the control range of CONFIG_HAVE_FUNCTION_GRAPH_RETVAL >> --- >> arch/loongarch/Kconfig | 1 + >> arch/loongarch/include/asm/ftrace.h | 20 ++++++++++++++++++++ >> arch/loongarch/kernel/asm-offsets.c | 12 ++++++++++++ >> arch/loongarch/kernel/mcount.S | 14 ++++++++------ >> arch/loongarch/kernel/mcount_dyn.S | 15 ++++++++------- >> 5 files changed, 49 insertions(+), 13 deletions(-) >> >> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig >> index 7fd51257e0ed..4bf60132869b 100644 >> --- a/arch/loongarch/Kconfig >> +++ b/arch/loongarch/Kconfig >> @@ -99,6 +99,7 @@ config LOONGARCH >> select HAVE_FAST_GUP >> select HAVE_FTRACE_MCOUNT_RECORD >> select HAVE_FUNCTION_ARG_ACCESS_API >> + select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER >> select HAVE_FUNCTION_GRAPH_TRACER >> select HAVE_FUNCTION_TRACER >> select HAVE_GENERIC_VDSO >> diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h >> index 3418d32d4fc7..01e7f92de03c 100644 >> --- a/arch/loongarch/include/asm/ftrace.h >> +++ b/arch/loongarch/include/asm/ftrace.h >> @@ -63,4 +63,24 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, >> >> #endif /* CONFIG_FUNCTION_TRACER */ >> >> +#ifndef __ASSEMBLY__ >> +struct fgraph_ret_regs { >> + /* a0 - a1 */ >> + unsigned long regs[2]; >> + >> + unsigned long fp; >> + unsigned long __unused; >> +}; >> + >> +static inline unsigned long fgraph_ret_regs_return_value(struct fgraph_ret_regs *ret_regs) >> +{ >> + return ret_regs->regs[0]; >> +} >> + >> +static inline unsigned long fgraph_ret_regs_frame_pointer(struct fgraph_ret_regs *ret_regs) >> +{ >> + return ret_regs->fp; >> +} >> +#endif >> + >> #endif /* _ASM_LOONGARCH_FTRACE_H */ >> diff --git a/arch/loongarch/kernel/asm-offsets.c b/arch/loongarch/kernel/asm-offsets.c >> index 4bdb203fc66e..fab5bcddeb23 100644 >> --- a/arch/loongarch/kernel/asm-offsets.c >> +++ b/arch/loongarch/kernel/asm-offsets.c >> @@ -12,6 +12,7 @@ >> #include >> #include >> #include >> +#include >> >> void output_ptreg_defines(void) >> { >> @@ -60,6 +61,17 @@ void output_ptreg_defines(void) >> BLANK(); >> } >> >> + >> +void output_fgraph_ret_regs_defines(void) >> +{ >> + COMMENT(" LoongArch fgraph_ret_regs offsets. "); > No space needed at the beginning, and I prefer to move this function > to the end of this file. > Yes, I will fix it. I copy it from output_pbe_defines, and it has a space at the beginning, so I will fix it too. > Huacai >> + OFFSET(FGRET_REGS_A0, fgraph_ret_regs, regs[0]); >> + OFFSET(FGRET_REGS_A1, fgraph_ret_regs, regs[1]); >> + OFFSET(FGRET_REGS_FP, fgraph_ret_regs, fp); >> + DEFINE(FGRET_REGS_SIZE, sizeof(struct fgraph_ret_regs)); >> + BLANK(); >> +} >> + >> void output_task_defines(void) >> { >> COMMENT("LoongArch task_struct offsets."); >> diff --git a/arch/loongarch/kernel/mcount.S b/arch/loongarch/kernel/mcount.S >> index 8cdc1563cd33..cb8e5803de4b 100644 >> --- a/arch/loongarch/kernel/mcount.S >> +++ b/arch/loongarch/kernel/mcount.S >> @@ -79,18 +79,20 @@ SYM_FUNC_START(ftrace_graph_caller) >> SYM_FUNC_END(ftrace_graph_caller) >> >> SYM_FUNC_START(return_to_handler) >> - PTR_ADDI sp, sp, -2 * SZREG >> - PTR_S a0, sp, 0 >> - PTR_S a1, sp, SZREG >> + PTR_ADDI sp, sp, -FGRET_REGS_SIZE >> + PTR_S a0, sp, FGRET_REGS_A0 >> + PTR_S a1, sp, FGRET_REGS_A1 >> + PTR_S zero, sp, FGRET_REGS_FP >> >> + move a0, sp >> bl ftrace_return_to_handler >> >> /* Restore the real parent address: a0 -> ra */ >> move ra, a0 >> >> - PTR_L a0, sp, 0 >> - PTR_L a1, sp, SZREG >> - PTR_ADDI sp, sp, 2 * SZREG >> + PTR_L a0, sp, FGRET_REGS_A0 >> + PTR_L a1, sp, FGRET_REGS_A1 >> + PTR_ADDI sp, sp, FGRET_REGS_SIZE >> jr ra >> SYM_FUNC_END(return_to_handler) >> #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ >> diff --git a/arch/loongarch/kernel/mcount_dyn.S b/arch/loongarch/kernel/mcount_dyn.S >> index bbabf06244c2..ec24ae1de741 100644 >> --- a/arch/loongarch/kernel/mcount_dyn.S >> +++ b/arch/loongarch/kernel/mcount_dyn.S >> @@ -131,18 +131,19 @@ SYM_CODE_END(ftrace_graph_caller) >> >> SYM_CODE_START(return_to_handler) >> /* Save return value regs */ >> - PTR_ADDI sp, sp, -2 * SZREG >> - PTR_S a0, sp, 0 >> - PTR_S a1, sp, SZREG >> + PTR_ADDI sp, sp, -FGRET_REGS_SIZE >> + PTR_S a0, sp, FGRET_REGS_A0 >> + PTR_S a1, sp, FGRET_REGS_A1 >> + PTR_S zero, sp, FGRET_REGS_FP >> >> - move a0, zero >> + move a0, sp >> bl ftrace_return_to_handler >> move ra, a0 >> >> /* Restore return value regs */ >> - PTR_L a0, sp, 0 >> - PTR_L a1, sp, SZREG >> - PTR_ADDI sp, sp, 2 * SZREG >> + PTR_L a0, sp, FGRET_REGS_A0 >> + PTR_L a1, sp, FGRET_REGS_A1 >> + PTR_ADDI sp, sp, FGRET_REGS_SIZE >> >> jr ra >> SYM_CODE_END(return_to_handler) >> -- >> 2.25.1 >>