From patchwork Fri Nov 18 17:32:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 22411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp333369wrr; Fri, 18 Nov 2022 10:02:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf7CZJWCdGumyuAnr9A8PNdoT5S63pqbRo5K6brsglLcJuXkCnQuIdQBpnVaV846c9Uzpb9G X-Received: by 2002:a17:906:348b:b0:78d:9e04:d8c2 with SMTP id g11-20020a170906348b00b0078d9e04d8c2mr6742756ejb.614.1668794532418; Fri, 18 Nov 2022 10:02:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668794532; cv=none; d=google.com; s=arc-20160816; b=Nn7RrwyzFGMVIFJhC+ukEz5UpawCXiIN6LaQ4wn65xHKjN1dOo/1vq1sphcuKDnv4y 8Y2gZRzwrtkclWZDPb14B5YaclOTcNNEe9wu4gsAm93qVTGR86f9L4XYjD9D7zsdNuV7 QRZiDnAP1NBXfGLgW2aN7lBNRw1KY14lqqJgvCYybfw+ByOfTjMN7UX3AIR1gAcjgxK+ MYRa9fLtDkCTx8xeBrzqiw5kYIaIF88S7T3rKCE7zmv//7ZMmlNoc777ADp1pRPCiZEN PKuWAU59Q6/L5XR/Lg0wHwYXk2Vd74r2gAq1zy6hkQsFT3YZ+UyVnizlZekmYOl1exRg D+bQ== 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=um7o47dkwC3+Xw39j9lUuqY5O+T3nm01Mm5u8aYpugQ=; b=aTIW9LYymtOJqNkRWTAWMN7w/LAxgadlCTcTV3QUW58Z8aQgQEE9LHTGcZDPabE6TJ Fk5cfi96xMBbw9qVeF3IV4W8cjSEsG7F+ZXJ2oMKDBL07yAEGJkTZWRa9ylKRW/pDJp6 hGZlPJvc13BvDA0GhrhrsQAkHRGIF5s7tVrgNoIJsQqKZUvJHJON3+gddCwGUfyzE68B jTE7ibUpE4xgDJFnRBdAbNJbDjUD52kew0uv4a+aZxKw2+P2zbQrJLETGSb31l5PFWSe h8fkBbn/J5w9b79FhfY2PO8n7jWp8aQCXZ6CsdGG4Eng+OGPtdTd0R0AJnxF6g6Zr0gF aH5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bKlIx655; 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 di14-20020a170906730e00b007ae1052555dsi3701115ejc.436.2022.11.18.10.01.24; Fri, 18 Nov 2022 10:02:12 -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=bKlIx655; 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 S241969AbiKRReF (ORCPT + 99 others); Fri, 18 Nov 2022 12:34:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242533AbiKRRdc (ORCPT ); Fri, 18 Nov 2022 12:33:32 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F5E4976E7 for ; Fri, 18 Nov 2022 09:32:33 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id b21so5145453plc.9 for ; Fri, 18 Nov 2022 09:32:33 -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=um7o47dkwC3+Xw39j9lUuqY5O+T3nm01Mm5u8aYpugQ=; b=bKlIx655pe3B+kU4aGQHe83PsarqTSNkJgq+XRCvic+rix3rZvypD7FAQbl8gYsUDD 2dqZGBtB6qVDypNdijaMpfpWr6w3V1lCNGGYMbnLbA65mBemShhEZCqNslu6hoBVgH9y WXM4UVDYWXnn3+7o46j4i9UXJAAji3tVB8cuqQovq73rJGr0HNMVFD/aOkFvchMxaY0H ORKxWsayMeW6gda+HNYq5r/Y550hpY8CvB/o/OoYOEvDY1AvF++rH0nH1tAsrxmIHGF9 uCTu9N9MGMeS0NwwteNRRl39+9BlK7I56LV/O1p4hh2+cWTNLA0GDcKkrGvXwDpZaMBJ hMAg== 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=um7o47dkwC3+Xw39j9lUuqY5O+T3nm01Mm5u8aYpugQ=; b=LkaTZFbwz5MrIS54FyK0pmfR4Vcv7FFSnrRNm58CICeXWkPd+dQSnfW44XW24Ap2E4 nLoB6vnlq0PDIddVKrfdbDV2QgDW7t85dqPgr0eGJmedDX71xR9rObZl7gF05yIVt95T mlGiG9dv7z6uQVqXcV0eIUS5G5itJ/gb9XzmXjJ5hPyjLO1sIB7rlZsYoa4/9pMT30H+ N4K6ZceTGSRIC5cv1HHi9exkE1Fyt8mB8K/By2mFC5dJ2cAedQewXdgKsEznc+CGmOsW b/fBgP64gwHbfWKtLITRl2ydd3IJxnoIYXc5LA22kQSucWX+5Qs9n0SThqBAp/+GQWwl wKMA== X-Gm-Message-State: ANoB5pksatIHaWIR4Pa/Xa8BOx2ppfowE1SXo+j0tCdUndhg//fmh6vc h7kK2i5agjeuylteoznrbMU= X-Received: by 2002:a17:90b:3d90:b0:212:de1c:a007 with SMTP id pq16-20020a17090b3d9000b00212de1ca007mr15291940pjb.30.1668792752983; Fri, 18 Nov 2022 09:32:32 -0800 (PST) Received: from localhost.localdomain ([112.2.231.196]) by smtp.gmail.com with ESMTPSA id u7-20020a656707000000b00476b6b7f339sm3037979pgf.11.2022.11.18.09.32.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 09:32:32 -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 v3 1/2] riscv/ftrace: add ftrace_graph_func Date: Sat, 19 Nov 2022 01:32:16 +0800 Message-Id: <20221118173217.888077-2-suagrfillet@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221118173217.888077-1-suagrfillet@gmail.com> References: <20221118173217.888077-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?1749857895996300003?= X-GMAIL-MSGID: =?utf-8?q?1749857895996300003?= 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 are revised for serving only ftrace_graph_call in the !FTRACE_WITH_REGS version ftrace_caller. Signed-off-by: Song Shuai --- arch/riscv/include/asm/ftrace.h | 13 +++++++++++-- arch/riscv/kernel/ftrace.c | 30 +++++++++++++----------------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index 34b0b523865a..01bebb28eabe 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -107,8 +107,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 8c77f236fc71..651ce5808b77 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -169,32 +169,28 @@ 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 *)®s->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) { - int ret; - - ret = __ftrace_modify_call((unsigned long)&ftrace_graph_call, - (unsigned long)&prepare_ftrace_return, true, 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, 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, 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, false, true); } +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ #endif /* CONFIG_DYNAMIC_FTRACE */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ From patchwork Fri Nov 18 17:32:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 22410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp331643wrr; Fri, 18 Nov 2022 09:58:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf5fOhBwPzxcXlYqhcSnBPcj39JtEwZEO5u2BagzkBAFOawe6Ck8i7c0822XM7fqVcwF3M49 X-Received: by 2002:a17:906:86ca:b0:78d:3341:aa8 with SMTP id j10-20020a17090686ca00b0078d33410aa8mr6827020ejy.96.1668794334655; Fri, 18 Nov 2022 09:58:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668794334; cv=none; d=google.com; s=arc-20160816; b=PPhJPEHVrf/czK6gfbOH0mA9aHff6Df+b47A2V/XnhGbtin2jpf2sBEV9VCFrsswsc KpwiAeRArfwmkZ+td4lwbxb337XvWvoWeycVlRpsSwkWiSwozu3R5ln3CiCj6eLTjvN6 4t2Q0RKlHQzeQxtaftiIeXU5G3Xb9i6cf9QUd8Czijf29nJDDsJzbib0bNEM3Z5ezIbj 6KWjuhGC7E1X91kbIzWRYgubnbmX+gjcqIYAGJeJ+zQGkwvNbPwqPT63tohjHu5HDT3t RlIShk2tmmOWeyPFuWFtc7iglCo8DGNrGBM4fbLWewdNINkDcTPm5xy0zO+cT4pMKQZj 1Zjg== 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=9NBmSk7fBSAJxNI2xlbnnvVbJDd4rleDkNQ22MfWjS4=; b=cewlx5PX5i5q+0IHIRPzs009JBzVWfDoryVg3bA/2UBluzpe+bTd0KoXVb1+5Jb6tk CYpA2l5CjiKXUbJaMnQVSqtLCndfJfrIG0F24svqcg5owHLjCqFgeqd25ISmDYqY/V5p Vg0v+0AEyowKD4GvO0kSJAv6u/W0y10Jn/VJSjydTexxlH3INe0Ae6D44A3+DGYMgIx/ eaC7HErnNIe9TRiULCV24NGzD6j6JUyw1z9FzSwdsoCKaMXgI5XDa1dANIrFoU017WBO 8m/6pdCPK67CHdjDi75ozwBXFiebe06UJU1eHVBW8h7BJuLT3AlbHH0Ke2CsJ2AmK9Ts h2wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=F0LYXy04; 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 xf9-20020a17090731c900b007ad86f97b36si3424851ejb.560.2022.11.18.09.58.27; Fri, 18 Nov 2022 09:58:54 -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=F0LYXy04; 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 S240445AbiKRReM (ORCPT + 99 others); Fri, 18 Nov 2022 12:34:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242541AbiKRRdq (ORCPT ); Fri, 18 Nov 2022 12:33:46 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 023FE99EAA for ; Fri, 18 Nov 2022 09:32:36 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so8908824pjs.4 for ; Fri, 18 Nov 2022 09:32:36 -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=9NBmSk7fBSAJxNI2xlbnnvVbJDd4rleDkNQ22MfWjS4=; b=F0LYXy04+BTUjesxYiznzIMp2EPv6TsAXbgRS7pQaL8OVC5YVDOU5m8FLAC/FIzrky g023O0gv5uUPYMTsf65qv4ardfNDmUcl38ECWjHwojCt7NXtJVG3KJKr1l6WR8RljrFP rtiSJ0hvZ+xve4POcmFgudRMFpS3FTy5EaS4Gp6yEvXM8t7ByKn/EOEiFaG72rgpdwtE Ia1Qz9fLb20rSXAqzcEWosodqLqAhvtnpMJWCkTJmbTsx6dmQL6By1FcxZHnAhuYj8tx Rx9JHHuYX8ZUr+6rVgwnFnQKpG7/Ap36Kcc5H9AbqX6x0fsKxCcuJeXrTC8tCsXKkK0B 4qFw== 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=9NBmSk7fBSAJxNI2xlbnnvVbJDd4rleDkNQ22MfWjS4=; b=PQDNXGMp1BP0t+tE7bj1jE2C1Ae2rYhzcMoM1sQs1hXrC7cl6WhbuOECdCBYRFeLo5 Tce/Kalygsh+kfBJR0GIrvMyS3DYDbmqUzVJB0Weo7WRIxIqaPXZK7wPAdD8INtCnWIN MBinYn0v1jFi1hXSMUhfeKAPkGZ12b06KyQI3GkFzamItTzd+ONEwNEwO4MYvKp3299D OlrcjwUsmI2cH/IiTdp0jJUVrvcYlJfPNlSXnnb4NvGNJUUacfe0IJzLn4igbIA/pG/s qXXPDUI5FNHQ83i+y+m2YAd9Xnlsa2l424ULDp5iN0D+OD5dIx9lZLx77qrDW6zzo+2c EW5w== X-Gm-Message-State: ANoB5plNiKo20L/BY3NmNHGR3iZq3B/LqaV/FvpeH7jhsOCXRO0e+m3p kawnYrKQ1KVk8aSKduFoqSA= X-Received: by 2002:a17:902:cf0e:b0:17c:5b01:f227 with SMTP id i14-20020a170902cf0e00b0017c5b01f227mr620277plg.3.1668792755984; Fri, 18 Nov 2022 09:32:35 -0800 (PST) Received: from localhost.localdomain ([112.2.231.196]) by smtp.gmail.com with ESMTPSA id u7-20020a656707000000b00476b6b7f339sm3037979pgf.11.2022.11.18.09.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 09:32:35 -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 v3 2/2] riscv/ftrace: make ftrace_caller call ftrace_graph_func Date: Sat, 19 Nov 2022 01:32:17 +0800 Message-Id: <20221118173217.888077-3-suagrfillet@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221118173217.888077-1-suagrfillet@gmail.com> References: <20221118173217.888077-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?1749857688013941555?= X-GMAIL-MSGID: =?utf-8?q?1749857688013941555?= 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 supersedes SAVE_ALL by SAVE_ABI_REGS which has an extra option to allow saving only the necessary ABI-related regs for ftrace_caller. ftrace_caller and ftrace_regs_caller save their regs with the respective option of SAVE_ABI_REGS, 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. As the previous patch described, the ftrace_caller remains with its ftrace_graph_call if FTRACE_WITH_REGS isn't defined, For convenience, the original argument setup for the tracing function in ftrace_[regs]_caller is killed and appended to the tail of SAVE_ABI_REGS. Signed-off-by: Song Shuai --- arch/riscv/kernel/mcount-dyn.S | 143 ++++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 38 deletions(-) diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index 64bc79816f5e..c70f04711a2e 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -57,19 +57,55 @@ .endm #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS - .macro SAVE_ALL + +/** +* SAVE_ABI_REGS - 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. +* +* 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 +* +++++++++ +**/ + .macro SAVE_ABI_REGS, all=0 addi sp, sp, -PT_SIZE_ON_STACK REG_S t0, PT_EPC(sp) REG_S x1, PT_RA(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) @@ -78,6 +114,18 @@ REG_S x15, PT_A5(sp) REG_S x16, PT_A6(sp) REG_S x17, PT_A7(sp) + + // save the leftover regs + + .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) @@ -92,19 +140,28 @@ REG_S x29, PT_T4(sp) REG_S x30, PT_T5(sp) REG_S x31, PT_T6(sp) + + // save s0 if FP_TEST defined + + .else +#ifdef HAVE_FUNCTION_GRAPH_FP_TEST + REG_S x8, PT_S0(sp) +#endif + .endif + + // setup 4 args for tracing functions + + addi a0, t0, -FENTRY_RA_OFFSET // ip + la a1, function_trace_op + REG_L a2, 0(a1) // op + REG_L a1, PT_RA(sp) // parent_ip + mv a3, sp // fregs + .endm - .macro RESTORE_ALL + .macro RESTORE_ABI_REGS, all=0 REG_L t0, PT_EPC(sp) REG_L x1, PT_RA(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) @@ -113,6 +170,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) @@ -128,10 +195,16 @@ 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 .endm #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ +#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS ENTRY(ftrace_caller) SAVE_ABI @@ -160,33 +233,27 @@ ftrace_graph_call: jr t0 ENDPROC(ftrace_caller) -#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS +#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ ENTRY(ftrace_regs_caller) - SAVE_ALL - - addi a0, t0, -FENTRY_RA_OFFSET - la a1, function_trace_op - REG_L a2, 0(a1) - REG_L a1, PT_RA(sp) - mv a3, sp + SAVE_ABI_REGS 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_T0(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_ABI_REGS 1 jr t0 ENDPROC(ftrace_regs_caller) + +ENTRY(ftrace_caller) + SAVE_ABI_REGS 0 + +ftrace_call: + .global ftrace_call + call ftrace_stub + + RESTORE_ABI_REGS 0 + jr t0 +ENDPROC(ftrace_caller) #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */