From patchwork Tue Nov 15 06:15:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 20203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2547796wru; Mon, 14 Nov 2022 22:24:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf6h0TZ82LibyKdCLZCOOTL6IQCbmjUlsLkVNwvvDi+K2i6o8NLSzpl+1IcPrWyEgb+zQZEL X-Received: by 2002:a17:906:c10:b0:7ad:caf4:9e92 with SMTP id s16-20020a1709060c1000b007adcaf49e92mr12471402ejf.510.1668493478680; Mon, 14 Nov 2022 22:24:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668493478; cv=none; d=google.com; s=arc-20160816; b=wpkSppJvK7XElkNX1zHXe9oHbiWehL5fbPLdzyU9cmFUZ/ylywMj4RNePi85TU/X+M Dp9qzclnDHFMB5rBR3JHi2GWI8BHzurpW2n1R1l5IpzAn7YPfLGMZrJpf3kf40KTulUc p2uEndMS+9fpg4om51/gSKM1QWVHn8DmFWPjWwE8cpzlpKaJvWZARv4WmYqun6vuqBaF Vip2H/hGxZGNK+HH0WSA90wgd6Lw15iNOu+sz1JfqbeIC2yPP7tAeIi+UImuF4cNVvXG Ib00jyeCBnICWkEgQ6qrOC7BVCnhP0USBuYaSSAIf1NtMbMcAhA8x1dzE7G1z7o8iiqc XYlw== 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=7bUagvGYVwuH85x9VGCmZe8w6n24dTZmrFkDrBOEYew=; b=n/isDvqioJnDDTonXgf+FVXT9m4NmZILeD745iKMTp2FYpTX60JNwfpUBSRwF34o5o oOuQ6hY8uGUzd/VBd9DQsxx/wIm2bPUuTzCa2JrjI85bUg2KqhAIu2cWUuWKQY4nLk0s kLryyfKrmb5/b1SJsgaLYygwx5PdO+ZW24rIHsei0SFcDao9SLEhgaNk7MCNVBCwHN1C VwmLN5yxaA+6+XBw/LuuwI5YAU0epEEkYLlTo936QJx1/nEvZNRfF+Z9mXNausNnhw3S kVvwniMGx2yKcK+y01ZwO31qD27NhSkPbpsqoGI5nGTN7LOHtxazbfPj13XSltHxH7b8 fMzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=emPzmYPz; 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 be10-20020a1709070a4a00b00780e022dfb8si4429412ejc.494.2022.11.14.22.24.14; Mon, 14 Nov 2022 22:24:38 -0800 (PST) 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=20210112 header.b=emPzmYPz; 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 S231136AbiKOGPp (ORCPT + 99 others); Tue, 15 Nov 2022 01:15:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbiKOGPk (ORCPT ); Tue, 15 Nov 2022 01:15:40 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04360140D9 for ; Mon, 14 Nov 2022 22:15:40 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id k15so13235210pfg.2 for ; Mon, 14 Nov 2022 22:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=7bUagvGYVwuH85x9VGCmZe8w6n24dTZmrFkDrBOEYew=; b=emPzmYPzC6EXM7lNu8jzs6I/yUKvaSt7SnmUL5TAeEXq0fw3Ob0z4XAtUxLFOepNMC XVF8aJYgJtHALPKGRj2e5BA53YXB+8R1VkH2Nv89Lwj39rnsyQdHsfWvV0GPwpOnm6PN k873s4evosXjprSwTXprETDMQjXww2qUupywX5KjZiSiepdML8s6kssXBwiS+W7kqzud 8BJD9iRMGKuxB3+/2DW1RJ/Kd8PA6nvNh+PRfopHi8i65nqhSRZZ1pDY9HujtnikiDH9 PfvjXW/k2UUJWGC0pdq/79C+W8afoMQgwsX+UA4V/6yapLx6Hev/64V6UB1kCyn5ZR7P q95Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=7bUagvGYVwuH85x9VGCmZe8w6n24dTZmrFkDrBOEYew=; b=uzslvchFp1fivFzvvmom6YpmnyO4aVHqBgbGANHFsxUsJNAKTn/IU3AddLlvLejWtk akeQ71Uxw95Ky/YaJygAwSfJa9xf47ULt8y7PK/+9PRVAtY3sMrjZz/iPhdm7fb8bYXo 3x9IPYwRmCiccZBKtiuEiOMxJQZupZOpXe4WgZDWnN7kgnXQUQUpka6E0+vetvC1Qbw3 C3n/nHLidu5Y+pQCqq3kfgAqkXyVXmURj5tZvIXZ4aI5u+aSs1TaS9sK82MTKiKAdwRT Uyx0RNcGvAmyRzucEZAwcb8zKffkbECjFHNyacK0p2YYFzx1i1hpkCPewJNZfK7LxO6J 3SPQ== X-Gm-Message-State: ANoB5pnNdyOt1PwnqTl8gESeFXmH9XH6oq3tHh0010kim+tz/2qhuWWJ NIMqMZQWQz3sn72EXmYgkXQ= X-Received: by 2002:a63:4a0f:0:b0:476:837c:1bdf with SMTP id x15-20020a634a0f000000b00476837c1bdfmr6945742pga.587.1668492939465; Mon, 14 Nov 2022 22:15:39 -0800 (PST) Received: from localhost.localdomain ([221.226.144.218]) by smtp.gmail.com with ESMTPSA id p9-20020a1709027ec900b0017f57787a4asm8736769plb.229.2022.11.14.22.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 22:15:39 -0800 (PST) From: Song Shuai To: guoren@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Song Shuai Subject: [PATCH 1/3] riscv/ftrace: add ftrace_graph_func Date: Tue, 15 Nov 2022 14:15:23 +0800 Message-Id: <20221115061525.112757-2-suagrfillet@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221115061525.112757-1-suagrfillet@gmail.com> References: <20221115061525.112757-1-suagrfillet@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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?1749542218078214271?= X-GMAIL-MSGID: =?utf-8?q?1749542218078214271?= Here implements ftrace_graph_func as the function graph tracing function with FTRACE_WITH_REGS defined. function_graph_func gets the point of the parent IP and the frame pointer from fregs and call prepare_ftrace_return for function graph tracing. If FTRACE_WITH_REGS isn't defined, the enable/disable helpers of ftrace_graph_[regs]_call remain for serving the !FTRACE_WITH_REGS version ftrace_caller. Signed-off-by: Song Shuai --- arch/riscv/include/asm/ftrace.h | 13 +++++++++++-- arch/riscv/kernel/ftrace.c | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index 04dad3380041..b33c98070972 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -81,8 +81,17 @@ do { \ struct dyn_ftrace; int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); #define ftrace_init_nop ftrace_init_nop -#endif -#endif +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +struct ftrace_ops; +struct ftrace_regs; +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs); +#define ftrace_graph_func ftrace_graph_func +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ + +#endif /* __ASSEMBLY__ */ + +#endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* _ASM_RISCV_FTRACE_H */ diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index 2086f6585773..2d7ce77d4f33 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -196,6 +196,20 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr, } #ifdef CONFIG_DYNAMIC_FTRACE + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS + +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs) +{ + struct pt_regs *regs = arch_ftrace_get_regs(fregs); + unsigned long *parent = (unsigned long *)&(regs->ra); + + prepare_ftrace_return(parent, ip, frame_pointer(regs)); +} + +#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ + extern void ftrace_graph_call(void); extern void ftrace_graph_regs_call(void); int ftrace_enable_ftrace_graph_caller(void) @@ -223,5 +237,7 @@ int ftrace_disable_ftrace_graph_caller(void) return __ftrace_modify_call((unsigned long)&ftrace_graph_regs_call, (unsigned long)&prepare_ftrace_return, false); } +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ + #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ From patchwork Tue Nov 15 06:15:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 20204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2548508wru; Mon, 14 Nov 2022 22:27:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5GbH/guntJjUAswWAs7itnZYYo+sApv6dBNftmErHzJSZkeUQo/e4RD0ysFB4OeRJaMzqZ X-Received: by 2002:a17:906:24d9:b0:7ad:2da5:36e1 with SMTP id f25-20020a17090624d900b007ad2da536e1mr11855717ejb.548.1668493653665; Mon, 14 Nov 2022 22:27:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668493653; cv=none; d=google.com; s=arc-20160816; b=mxRwwJFbUEyiIUFgh6SE6BK4Out8xMziliF5vSGd+TZOj5mmQOLeL/XeTVFMIhpr+R tbngc8TBoCjYBEpF/bJX0k/P3fRxpiRU3ptuqNA+eYonvT2mxsQwOvfFDfR6Ru/Ynt3g DQ7B6Hi0sxYPsfSfOacUWSOrZQ4AMMJAD3IkRcq1F8cm5YC8eOZhqbRTsUcO+8DXdA1u crFRZqz8Nml8yNE4KoG3ZY5RTsaz8esSPTHcoFG0KH0353WJKDHN+zQNZRNgw5IN8Sfq KUHOMoIDTB4S36xEtCaYwHJl16OZobCq6LluIQ22tBlQQnJShXOeQHj1BEwIH+Kfpi5P N5cw== 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=A3Sgd0SU9M6CpUSRStE6vDvg0DHGGT+ouTzN5zX360k=; b=hLyrp3I60oAEb22f/ugpqF9bd9WcJtTMrftgmnf6dn80jNjxOtiTj0jOjJ2EvZoSH0 abRxc3paSyRLQEjoBcg5+166g+WV7hSzJ7olcfLH2SAxWquQSeByYZJH+3NiOwtFocCr of8Kn4azHr9osW2ZYIQb+6yiqzOVRDPBqkYczLY1DX1Tm4nL/c1HO8+wXBksQE5qyHY+ WpFUak8jDkv8wCkoTnWGo4aVtktqWtVM40cY9ivVWVxVBKq0tbPc12mZ8yTX3eIUgale B/bw0YzJW7rmlys13GFS+ELbwo4m+XCqmJ2PiywfxjAoygjHWTjscKTZ3gM4nL5H0BVI YEeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RLvkKCG7; 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 by24-20020a170906a2d800b007adb388df38si7746610ejb.706.2022.11.14.22.27.09; Mon, 14 Nov 2022 22:27:33 -0800 (PST) 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=20210112 header.b=RLvkKCG7; 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 S230517AbiKOGPs (ORCPT + 99 others); Tue, 15 Nov 2022 01:15:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230262AbiKOGPp (ORCPT ); Tue, 15 Nov 2022 01:15:45 -0500 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DD5A140DE for ; Mon, 14 Nov 2022 22:15:44 -0800 (PST) Received: by mail-pg1-x52a.google.com with SMTP id v3so12390005pgh.4 for ; Mon, 14 Nov 2022 22:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=A3Sgd0SU9M6CpUSRStE6vDvg0DHGGT+ouTzN5zX360k=; b=RLvkKCG7nrm/wgdAHq4lZ8n3IHVY4pu4Hdmp7J6S4MWjYEnvIB5iQiZcu+fMgb2KOW UTdU3Q60wS1YYu/au7tQbG9UG1EhfqQZ22tWLShxUgzW0ugwqJltj9uWQtZcH6s8agN6 y6/fy6ZSjw5oFCY9I3PYRKJpR8rU6tIbHrxgP9Wd+ZwMe/02I5TdFv4YiGT4Od7yX2Sh w7WWAUBVI5P48QF/OGcIr18vO+aK4IAWXE1mNn8SDZYEIdKNIpFXv6UdtYh1PsQvEPKN ZgPyNbyGKpQkFTYtmRhkl4ZEh7yEbNxnq1FmwL9htoRK9Akta4BU8MUCumq9axOUv0bv BzmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=A3Sgd0SU9M6CpUSRStE6vDvg0DHGGT+ouTzN5zX360k=; b=kw61YTUhY4H2dQ9/dq0Z9Elka/Q8W4NoCQJXdjVGhsklJVkfm+2yaRQcQqsTtcEfod NLW1lVW/wyE7lhPVaSY62O4u+BP0u39o7swjKXgzRgJYPBkRkydQQBWrcm3SOP1G7XhT L/fTy3S5dAsrJGqYIIeJTlTlhy40rgfuyXJdToTRirSV8vzp/rzy/+ikjPucsnJLiMDN nnAFT6mECsf2ggC9TxFOYlz9WZPaEVMOLa9dvMB29iQ3x8lIBUbh6u5uPratPscDJWOo o/S71xcIIT3t0KRozX5Gg7cXScFNGWFllbFH07/G1HdntW6+l4PnsUuzi/xDNLK9x5J9 7HFA== X-Gm-Message-State: ANoB5plpS1RY3aiXk/niPYqFOLxtem5TpzNmyx74mWZ/770kadkcf1w2 NCYMYZzbRatgjvNvIONXu40= X-Received: by 2002:a63:181e:0:b0:470:f0c:96da with SMTP id y30-20020a63181e000000b004700f0c96damr14267453pgl.544.1668492943688; Mon, 14 Nov 2022 22:15:43 -0800 (PST) Received: from localhost.localdomain ([221.226.144.218]) by smtp.gmail.com with ESMTPSA id p9-20020a1709027ec900b0017f57787a4asm8736769plb.229.2022.11.14.22.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 22:15:43 -0800 (PST) From: Song Shuai To: guoren@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Song Shuai Subject: [PATCH 2/3] riscv/ftrace: SAVE_ALL supports lightweight save Date: Tue, 15 Nov 2022 14:15:24 +0800 Message-Id: <20221115061525.112757-3-suagrfillet@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221115061525.112757-1-suagrfillet@gmail.com> References: <20221115061525.112757-1-suagrfillet@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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?1749542401229312177?= X-GMAIL-MSGID: =?utf-8?q?1749542401229312177?= In order to make the function graph use ftrace directly, ftrace_caller should be adjusted to save the necessary regs against the pt_regs layout so it can call ftrace_graph_func reasonably. SAVE_ALL now saves all the regs according to the pt_regs struct. Here introduces a lightweight option for SAVE_ALL to save only the necessary regs for ftrace_caller. For convenience, the original argument setup for the tracing function in ftrace_[regs]_caller is killed and appended to the tail of SAVE_ALL. Signed-off-by: Song Shuai --- arch/riscv/kernel/mcount-dyn.S | 110 +++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 18 deletions(-) diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index d171eca623b6..2f0a280bd7a0 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -56,7 +56,51 @@ .endm #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - .macro SAVE_ALL + +/** +* SAVE_ALL - save regs against the pt_regs struct +* +* @all: tell if saving all the regs +* +* If all is set, all the regs will be saved, otherwise only ABI +* related regs (a0-a7,epc,ra and optional s0) will be saved. +* +* For convenience the argument setup for tracing function is appended here. +* Especially $sp is passed as the 4th argument of the tracing function. +* +* After the stack is established, +* +* 0(sp) stores the PC of the traced function which can be accessed +* by &(fregs)->regs->epc in tracing function. Note that the real +* function entry address should be computed with -FENTRY_RA_OFFSET. +* +* 8(sp) stores the function return address (i.e. parent IP) that +* can be accessed by &(fregs)->regs->ra in tracing function. +* +* The other regs are saved at the respective localtion and accessed +* by the respective pt_regs member. +* +* Here is the layout of stack for your reference. +* +* +* ========= +* | pip | +* PT_SIZE_ON_STACK -> ========= +* + ..... + +* + t3-t6 + +* + s2-s11+ +* + a0-a7 + --++++-> ftrace_caller saved +* + s1 + + +* + s0 + --+ +* + t0-t2 + + +* + tp + + +* + gp + + +* + sp + + +* + ra + --+ // parent IP +* sp -> + epc + --+ // PC of the traced function +* +++++++++ +**/ + .macro SAVE_ALL, all=0 addi sp, sp, -SZREG addi sp, sp, -PT_SIZE_ON_STACK @@ -67,14 +111,8 @@ REG_S x1, PT_RA(sp) REG_L x1, PT_EPC(sp) - REG_S x2, PT_SP(sp) - REG_S x3, PT_GP(sp) - REG_S x4, PT_TP(sp) - REG_S x5, PT_T0(sp) - REG_S x6, PT_T1(sp) - REG_S x7, PT_T2(sp) - REG_S x8, PT_S0(sp) - REG_S x9, PT_S1(sp) + /* always save the ABI regs */ + REG_S x10, PT_A0(sp) REG_S x11, PT_A1(sp) REG_S x12, PT_A2(sp) @@ -83,6 +121,18 @@ REG_S x15, PT_A5(sp) REG_S x16, PT_A6(sp) REG_S x17, PT_A7(sp) + + /* save leftover regs for ftrace_regs_caller*/ + + .if \all == 1 + REG_S x2, PT_SP(sp) + REG_S x3, PT_GP(sp) + REG_S x4, PT_TP(sp) + REG_S x5, PT_T0(sp) + REG_S x6, PT_T1(sp) + REG_S x7, PT_T2(sp) + REG_S x8, PT_S0(sp) + REG_S x9, PT_S1(sp) REG_S x18, PT_S2(sp) REG_S x19, PT_S3(sp) REG_S x20, PT_S4(sp) @@ -97,22 +147,31 @@ REG_S x29, PT_T4(sp) REG_S x30, PT_T5(sp) REG_S x31, PT_T6(sp) + .else + + /* save s0 for ftrace_caller if FP_TEST defined */ + +#ifdef HAVE_FUNCTION_GRAPH_FP_TEST + REG_S x8, PT_S0(sp) +#endif + .endif + + /* setup 4 args for tracing functions */ + + addi a0, ra, -FENTRY_RA_OFFSET // ip + la a1, function_trace_op + REG_L a2, 0(a1) // op + REG_L a1, PT_SIZE_ON_STACK(sp) // parent_ip + mv a3, sp // fregs .endm - .macro RESTORE_ALL + .macro RESTORE_ALL, all=0 REG_L x1, PT_RA(sp) addi sp, sp, PT_SIZE_ON_STACK REG_S x1, (sp) addi sp, sp, -PT_SIZE_ON_STACK REG_L x1, PT_EPC(sp) - REG_L x2, PT_SP(sp) - REG_L x3, PT_GP(sp) - REG_L x4, PT_TP(sp) - REG_L x5, PT_T0(sp) - REG_L x6, PT_T1(sp) - REG_L x7, PT_T2(sp) - REG_L x8, PT_S0(sp) - REG_L x9, PT_S1(sp) + REG_L x10, PT_A0(sp) REG_L x11, PT_A1(sp) REG_L x12, PT_A2(sp) @@ -121,6 +180,16 @@ REG_L x15, PT_A5(sp) REG_L x16, PT_A6(sp) REG_L x17, PT_A7(sp) + + .if \all == 1 + REG_L x2, PT_SP(sp) + REG_L x3, PT_GP(sp) + REG_L x4, PT_TP(sp) + REG_L x5, PT_T0(sp) + REG_L x6, PT_T1(sp) + REG_L x7, PT_T2(sp) + REG_L x8, PT_S0(sp) + REG_L x9, PT_S1(sp) REG_L x18, PT_S2(sp) REG_L x19, PT_S3(sp) REG_L x20, PT_S4(sp) @@ -136,6 +205,11 @@ REG_L x30, PT_T5(sp) REG_L x31, PT_T6(sp) + .else +#ifdef HAVE_FUNCTION_GRAPH_FP_TEST + REG_L x8, PT_S0(sp) +#endif + .endif addi sp, sp, PT_SIZE_ON_STACK addi sp, sp, SZREG .endm From patchwork Tue Nov 15 06:15:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 20205 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2549036wru; Mon, 14 Nov 2022 22:29:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf5eS2WJyAhhioRn/Kkufe5vXPx6GzvEjwpxLdLNUxcNDvfckvSkYKxfTnqsdT3HXQtJ1faO X-Received: by 2002:a17:906:b6d3:b0:7ae:4236:bfb5 with SMTP id ec19-20020a170906b6d300b007ae4236bfb5mr11973571ejb.428.1668493761884; Mon, 14 Nov 2022 22:29:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668493761; cv=none; d=google.com; s=arc-20160816; b=liGNDpLY8h4sD41dQdh87VRKy0aCzIHb/Fgi7bk1Fj78cuIKu0zSJnESBGnIQzBHY7 HK2VYL3j/vI0FTzRpBalskphT2hvC0wq4I5Tj4CQWYYgHEZdd7JNjkYrBDzQSonuv0es /xQsDRpxlSMwcaIrzJq0nCxumNEz3cPIBRHVFAm0OokI4+tJfbSDSTPrk8pjtZoY+93i gTshWZdh9gvVNXITIvvIRmfpBdudIDMV4U/9uDFPJ3pYDWsilk01eOQpFPTRXcJywoda 12QcYcQInPGafnKCR5fBgVKpQt12nfk0HjbDIvAS0l55Msa1afa7h3O/2v4fNLu3nkKB HZBg== 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=ui8airw69h4AUo9oSmUgv1gkgt+KqV79d7fg2QkBl5M=; b=HPPQaQkX+LIYT+XivXtyrDDpdxnAb21qvhl7BFj1NLxo0KElIfWw1TypLDrmRZyhAF QYFP0SzJku68RTgri5yEo5SpqzPF+PmzNy2QIxcGEHFBLldXa8L1wRPSsSwDWaENplo/ N32grPzMwM8+G9hLWWlK3nhtYyjv2RLZI2T+W+v8BaORonx1N3mXdOMdMKsdUWSTzl07 TLWiQG52jCAiQZCOe12WVleKZQIdn2eMym1YyW9FNy4cb90qY9sJUWkTnlr/xUrw0INJ LaRFqAAVXuNjKqPUtzTZq3dCFRFWfeWX+NtD/CKI1rsxMLMhKEw1U9TX/DcoeCrDuZBv fhBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qjXR2fiv; 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 z16-20020a1709060f1000b007806a130086si9026888eji.302.2022.11.14.22.28.57; Mon, 14 Nov 2022 22:29:21 -0800 (PST) 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=20210112 header.b=qjXR2fiv; 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 S232196AbiKOGP6 (ORCPT + 99 others); Tue, 15 Nov 2022 01:15:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbiKOGPu (ORCPT ); Tue, 15 Nov 2022 01:15:50 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 398D71EC56 for ; Mon, 14 Nov 2022 22:15:48 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id b1-20020a17090a7ac100b00213fde52d49so12918093pjl.3 for ; Mon, 14 Nov 2022 22:15:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=ui8airw69h4AUo9oSmUgv1gkgt+KqV79d7fg2QkBl5M=; b=qjXR2fiv4kg9+omGG4vO16S+uSEZ7V3D5muYTI2e+cCxJKqZZpOed+6egG+gp1pCoX pMjy/kZeJ51sujHaYgIFrywHsdJWPuUEjfll30uxR63zU44uRf+jA9fLF2bW9eq2DBXd rXT6rpuM6BTdIrnC9l3j06dlpTwwr56h3qwrUbFTYaN461zWfipD9qMnGJFF0FlFoNgp w8Qh2rcNICYacRmDfFHyoxT5ebblLdWKa6DTY5pjRq8jGiV6KU9E1CrVvEcQJoJYDDP7 IQS9IKNrsTM+6a2ohqm0uqAzVykK1ku3PBuu+o7yguxGhUDggkiWEe27PEGe0Xqs/D8n 7HlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ui8airw69h4AUo9oSmUgv1gkgt+KqV79d7fg2QkBl5M=; b=o3VIa+b7GgqB6Ur7eR1X89jSJFhB5KYQeAebAj9elhnqLFLO3XZ+njvJ25M5iux3Yo fiVxVpT0kVRjw1n0QpQ1Yca+q0MjFYFl8WopJWJ22PDiUfwY63OyKaXBnoE0X/l8n6dy iW3hGRwTDCKR3fiWbHivtulixICdQF/Eq53O511CqaPF7WRzJPybDCAx8i7eFAhGSQ1p XlVvuQtBXoXamRWSDRMXnWuJF6ZQkdPesGUB3e3HMcm0EYjJdGHwQrFfYXJOAp7RxzHx YrUBWsNcZFrydazmvbCpCr2K33uZ3LqoJsJXMEcF1ud0vXbbZtx4r/isGvayV6ES6ogx UmGA== X-Gm-Message-State: ANoB5pmJpWTlHb5DVUUgzewtjE6A6pJM0MPtMsq+hXupyxqsoKjlfEUG h7stzkSBWd7TJWUfZCfdr2A= X-Received: by 2002:a17:90a:5b08:b0:213:7030:b2ec with SMTP id o8-20020a17090a5b0800b002137030b2ecmr687621pji.95.1668492947682; Mon, 14 Nov 2022 22:15:47 -0800 (PST) Received: from localhost.localdomain ([221.226.144.218]) by smtp.gmail.com with ESMTPSA id p9-20020a1709027ec900b0017f57787a4asm8736769plb.229.2022.11.14.22.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 22:15:47 -0800 (PST) From: Song Shuai To: guoren@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Song Shuai Subject: [PATCH 3/3] riscv/ftrace: cleanup ftrace_caller and ftrace_regs_caller Date: Tue, 15 Nov 2022 14:15:25 +0800 Message-Id: <20221115061525.112757-4-suagrfillet@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221115061525.112757-1-suagrfillet@gmail.com> References: <20221115061525.112757-1-suagrfillet@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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?1749542514628168626?= X-GMAIL-MSGID: =?utf-8?q?1749542514628168626?= ftrace_caller and ftrace_regs_caller save their regs with the respective option of SAVE_ALL, then call the tracing function, especially graph_ops's ftrace_graph_func. So the ftrace_graph_[regs]_call labels aren't needed anymore if FTRACE_WITH_REGS is defined. If FTRACE_WITH_REGS isn't defined, the !FTRACE_WITH_REGS version ftrace_caller remains with the ftrace_graph_call. So the enable/disable helpers are revised for serving only this ftrace_graph_call. Signed-off-by: Song Shuai --- arch/riscv/kernel/ftrace.c | 19 ++---------------- arch/riscv/kernel/mcount-dyn.S | 35 +++++++++++++++------------------- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index 2d7ce77d4f33..974732207c1f 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -211,30 +211,15 @@ void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, #else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ extern void ftrace_graph_call(void); -extern void ftrace_graph_regs_call(void); int ftrace_enable_ftrace_graph_caller(void) { - int ret; - - ret = __ftrace_modify_call((unsigned long)&ftrace_graph_call, - (unsigned long)&prepare_ftrace_return, true); - if (ret) - return ret; - - return __ftrace_modify_call((unsigned long)&ftrace_graph_regs_call, + return __ftrace_modify_call((unsigned long)&ftrace_graph_call, (unsigned long)&prepare_ftrace_return, true); } int ftrace_disable_ftrace_graph_caller(void) { - int ret; - - ret = __ftrace_modify_call((unsigned long)&ftrace_graph_call, - (unsigned long)&prepare_ftrace_return, false); - if (ret) - return ret; - - return __ftrace_modify_call((unsigned long)&ftrace_graph_regs_call, + return __ftrace_modify_call((unsigned long)&ftrace_graph_call, (unsigned long)&prepare_ftrace_return, false); } #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index 2f0a280bd7a0..9e4097c6793d 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -215,6 +215,7 @@ .endm #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ +#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS ENTRY(ftrace_caller) SAVE_ABI @@ -243,33 +244,27 @@ ftrace_graph_call: ret ENDPROC(ftrace_caller) -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ ENTRY(ftrace_regs_caller) - SAVE_ALL - - addi a0, ra, -FENTRY_RA_OFFSET - la a1, function_trace_op - REG_L a2, 0(a1) - REG_L a1, PT_SIZE_ON_STACK(sp) - mv a3, sp + SAVE_ALL 1 ftrace_regs_call: .global ftrace_regs_call call ftrace_stub -#ifdef CONFIG_FUNCTION_GRAPH_TRACER - addi a0, sp, PT_RA - REG_L a1, PT_EPC(sp) - addi a1, a1, -FENTRY_RA_OFFSET -#ifdef HAVE_FUNCTION_GRAPH_FP_TEST - mv a2, s0 -#endif -ftrace_graph_regs_call: - .global ftrace_graph_regs_call - call ftrace_stub -#endif - RESTORE_ALL + RESTORE_ALL 1 ret ENDPROC(ftrace_regs_caller) + +ENTRY(ftrace_caller) + SAVE_ALL 0 + +ftrace_call: + .global ftrace_call + call ftrace_stub + + RESTORE_ALL 0 + ret +ENDPROC(ftrace_caller) #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */