From patchwork Mon Nov 28 10:12:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 26606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5555409wrr; Mon, 28 Nov 2022 02:13:22 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vE6YTl+z4Oe1QKwloWkWW57pC0b/iaWUC240Qwo4GnPTwtZ6D8zQUIi4HuDncj6yA8/pm X-Received: by 2002:a17:906:b14b:b0:78d:cede:91f4 with SMTP id bt11-20020a170906b14b00b0078dcede91f4mr42195591ejb.764.1669630402398; Mon, 28 Nov 2022 02:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669630402; cv=none; d=google.com; s=arc-20160816; b=XT4qGbmjmf6TFOj4jPONczLySbzsdGKPrgD9PZxWbcot7oB7VK+85p6piMgW7/m/DI sISCoAvr+a3wQpSh3nFhFu3PeVhVNMnbMskC2/42kkgzhg5e7NnC+1QOWYyjTPSWKeH3 ko2/3lzgVHVAWKdlXZVb465Mv/Q67yTP02GqTTHeox9S15VrG+KMRrjUmBPtU22y7/j9 pcpBhkxLr58TKw0/EqI9mqHvr3iKq8t153OwDHL3NDWsq4qsu4RsNVcEaZ2UG6eJD9cW +8UABGeU7Nl5XEeIyeu1nInEerfZsSSmdJIR6w5I/Ku/Fwc1MlcLMKNYR0ZpgdYQwvku YnAA== 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=PPMNXNRRFjH+rDhuT+HcsqCumI+v05trdGcQ/o6yRR4=; b=vRvYRy0gn2WFHYVChrhnsZAx4rBPPdXEozxlKb2JHOOenjX6PJHuqp3AIt290Tu3Tp 4DonmSQyz8nootTy0Y+3QcYWB+nMj00wIMWXUcp++HmVCWuDNvSNni4wCA2iY4oxA4CJ jx/lnWtT8nZzCHNjDnnOyHEMn+cyBw2m5Spsu5JTVEX6em6lVA9YqxWHnCBDeYDrfbtM HJE7kQq2xR7nDG98qbgg37VmYdFUrS8G0m9CHNmtKjoJubgRZTBnnCS9l+yj6aIkRVQI lzQkqUIk2iBtYqz1bfAdy++SU/ct8x0wK0fBp6uUZST86kGqNN2QdIsZtxeeiH6eiw4A qzRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=svOz3bsm; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cn15-20020a0564020caf00b00461d726439asi8958537edb.538.2022.11.28.02.12.59; Mon, 28 Nov 2022 02:13:22 -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=@kernel.org header.s=k20201202 header.b=svOz3bsm; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbiK1KM2 (ORCPT + 99 others); Mon, 28 Nov 2022 05:12:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbiK1KMZ (ORCPT ); Mon, 28 Nov 2022 05:12:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CB3CE96 for ; Mon, 28 Nov 2022 02:12:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 17259B80CB4 for ; Mon, 28 Nov 2022 10:12:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60462C433D7; Mon, 28 Nov 2022 10:12:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669630341; bh=OR1E22SfIW28jaKNXJ/IaUulMe996ymxezMSEdVKYYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=svOz3bsmumYNfOUkFxQf/UNebxKeByl7zQCW8z+bWGmjHi7pbAKwaQmz83I9oTz5w dFzgZfkrSfRYRGOiOWMfH4/rwcHKVgt0WYWszRbYzbEmCxjewVYj10mF86mGvAkVrt ik4WNd1kLRvqQAIvg3AuuMBEMHGdr43GyrPc/gUUhtmq1LXgn5VH6FuzpL1XRngr+6 4o29xwf3MpRIrHqDfsaoxpiuqr+xz3OuQj6aIxnAnWxR2SJW2iPQXYb5Mm6MUH7Nz+ hdMB9ms26bTzJVZyixg9NYLLOQ07WNWZYl8Mi0y43dmr8n/JRgGNsSNCsHGxQT/kGi GyhzJhTtpmLjw== From: guoren@kernel.org To: suagrfillet@gmail.com, guoren@kernel.org Cc: aou@eecs.berkeley.edu, bp@suse.de, jolsa@redhat.com, jpoimboe@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, mark.rutland@arm.com, mhiramat@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, peterz@infradead.org, rostedt@goodmis.org Subject: [PATCH 1/2] riscv: ftrace: Add DYNAMIC_FTRACE_WITH_DIRECT_CALLS support Date: Mon, 28 Nov 2022 05:12:00 -0500 Message-Id: <20221128101201.4144527-1-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1750734368561499916?= X-GMAIL-MSGID: =?utf-8?q?1750734368561499916?= From: Song Shuai This patch adds DYNAMIC_FTRACE_WITH_DIRECT_CALLS support for RISC-V. select the DYNAMIC_FTRACE_WITH_DIRECT_CALLS to provide the register_ftrace_direct[_multi] interfaces allowing users to register the customed trampoline (direct_caller) as the mcount for one or more target functions. And modify_ftrace_direct[_multi] are also provided for modifying direct_caller. To make the direct_caller and the other ftrace hooks (eg. function/fgraph tracer, k[ret]probes) co-exist, a temporary register is nominated to store the address of direct_caller in ftrace_regs_caller. After the setting of the address direct_caller by direct_ops->func and the RESTORE_REGS in ftrace_regs_caller, direct_caller will be jumped to by the `jr` inst. Signed-off-by: Song Shuai Co-developed-by: Guo Ren Signed-off-by: Guo Ren --- Remove modification of mcount-dyn.S. (Guo Ren) --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/ftrace.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 1d0e5838b11b..2828537abfcd 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -278,6 +278,7 @@ config ARCH_RV64I select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8) select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE + select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index 84f856a3286e..d2c159cdfa5c 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -114,6 +114,32 @@ 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 + +static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr) +{ + /* + * Backup origin detour target (t0) in t1, and set t0 with addr. + * + * Here is the sample code for riscv direct_caller: + * + * addi sp,sp,-16 + * move t0,t1 + * ^^^^^^^^^^ + * sd t0,0(sp) + * sd ra,8(sp) + * call my_direct_func1 + * ld t0,0(sp) + * ld ra,8(sp) + * addi sp,sp,16 + * jr t0 + * + * (Set t0 with t1 for continuous detour, because t1 contains origin detour + * target) + */ + regs->t1 = regs->t0; + regs->t0 = addr; +} + #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ #endif /* __ASSEMBLY__ */ From patchwork Mon Nov 28 10:12:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guo Ren X-Patchwork-Id: 26607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5555739wrr; Mon, 28 Nov 2022 02:14:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf7GNbiSIZplxKbbD/XISE1Ic/axt6RzHoywAvp5E5FcklRkPBNSKmZP0vpgykWe0miv0r3X X-Received: by 2002:a17:906:89a3:b0:78d:408a:4a18 with SMTP id gg35-20020a17090689a300b0078d408a4a18mr42824359ejc.261.1669630452126; Mon, 28 Nov 2022 02:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669630452; cv=none; d=google.com; s=arc-20160816; b=xCb5j40aZSTcO0aveivaJD1liupoVdNkX0UfrDsld0ofHq6s2zoYV5pIV9gVTv4xGC raAmlDyD00ORAzNYNXLf8Svm7QS7Tes4K1ym73cTMeTd/koSMpO3EqkggPoz5wn0ZLop bIRokTb20JCq1+fqxQ8a+5h3yrBuImmGJZk//tdvNT/ktqqGXGeBsdhGUivjHqNc1xzT hq3nRpjaPJ1EY9Gf/hAUKU5XXgiPUaD5TTZyCoW7BakLkQbBc75EfG5jiwf1IXH810tK h8b1AXWy/RF2OGFsHdzWJgbomIYZAvN0XGNmXVvK0smNQK9xuJlvL5H/rsYXDFmZtCkp MvHA== 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=1om3VjlS1emuWwVx5GZrW+Gh7MWzH4eHT131WvCrUqE=; b=H37yM1FCgX4rr+WDS65/9xtlRWO4YATTyaN58nNAgvyedrXLDE6MUFSXjIHVXSR0Mu RRSqlMSr2Uj/nz7t9L9mX2YGmJFgB3gn+ijTjIOT/0916GJueAmheFgulcIkB3zJ7h8m O7AyVp+ys3an6HcEy/09E1Y3rbt43z7oNhTM5Z+KRlUZiwmgnyNQNFpEB4KRWlIvQBWG t2RBwiNaSIwhSiNFAswi3g/aphqL1xAwp2N5uzTOIUVlzG65tPdqJrXcf/6gpLIOe5dO xvpD+0JHl7zUe+uZuMSgcoh72d+tt1l/Gt47enbsW+1/va3Z5KjbW+U7xYmHTkDUOb/T KF/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tA71LX2K; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs17-20020a170906dc9100b007b889a69895si9520885ejc.589.2022.11.28.02.13.48; Mon, 28 Nov 2022 02:14: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=@kernel.org header.s=k20201202 header.b=tA71LX2K; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229708AbiK1KMh (ORCPT + 99 others); Mon, 28 Nov 2022 05:12:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbiK1KMb (ORCPT ); Mon, 28 Nov 2022 05:12:31 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B001D8 for ; Mon, 28 Nov 2022 02:12:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3D5B9B80CB4 for ; Mon, 28 Nov 2022 10:12:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E067C433D6; Mon, 28 Nov 2022 10:12:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669630346; bh=u89aOTJopm5tzMbQZRi0aLUZMGuYaAIU5HPAPaFbrYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tA71LX2K+I/jJhM2ALB1Ec6vFXPMSlU1IrsxnPGS5+n2LsZ6j2kLcz7LN7SMTuyk6 9wtMzBJezeEAHf5Ew5IBV8D+wQVL03oD9yts9NtNtTVgXHTdgYVocg8VZ7+cPSyp04 o312tL8/bGzH7xeK3WsLKEDB4w4+QlpGkFxy46Z8jepPCUtGVlhdaOuarSGLGMChsE VEFIJe/NNAqdJPGIZbnOuui9YlBmxM2S1XlWOo0K3REkR2Csy13OSLKntMDHBzgPZV 6vUvyVtcWPQrUN8x8Yq7rkTxxyd/QVSD1YZcj9pok6dU0wgIP9RZDhsdKdHR7ItLbx So8WdNqib+bqg== From: guoren@kernel.org To: suagrfillet@gmail.com, guoren@kernel.org Cc: aou@eecs.berkeley.edu, bp@suse.de, jolsa@redhat.com, jpoimboe@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, mark.rutland@arm.com, mhiramat@kernel.org, palmer@dabbelt.com, paul.walmsley@sifive.com, peterz@infradead.org, rostedt@goodmis.org Subject: [PATCH 2/2] samples: ftrace: Add riscv support for SAMPLE_FTRACE_DIRECT[_MULTI] Date: Mon, 28 Nov 2022 05:12:01 -0500 Message-Id: <20221128101201.4144527-2-guoren@kernel.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221128101201.4144527-1-guoren@kernel.org> References: <20221128101201.4144527-1-guoren@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1750734420549113400?= X-GMAIL-MSGID: =?utf-8?q?1750734420549113400?= From: Song Shuai select HAVE_SAMPLE_FTRACE_DIRECT and HAVE_SAMPLE_FTRACE_DIRECT_MULTI for ARCH_RV64I in arch/riscv/Kconfig. And add riscv asm code for the ftrace-direct*.c files in samples/ftrace/. Signed-off-by: Song Shuai Co-developed-by: Guo Ren Signed-off-by: Guo Ren --- Below is modified by Guo Ren: diff --git a/samples/ftrace/ftrace-direct-modify.c b/samples/ftrace/ftrace-direct-modify.c index 5582d000d803..d970b46ecc4e 100644 --- a/samples/ftrace/ftrace-direct-modify.c +++ b/samples/ftrace/ftrace-direct-modify.c @@ -29,6 +29,7 @@ asm (" .pushsection .text, \"ax\", @progbits\n" " .globl my_tramp1\n" " my_tramp1:\n" " addi sp,sp,-16\n" +" move t0,t1\n" " sd t0,0(sp)\n" " sd ra,8(sp)\n" " call my_direct_func1\n" diff --git a/samples/ftrace/ftrace-direct-multi-modify.c b/samples/ftrace/ftrace-direct-multi-modify.c index 43e02d39c652..9534e18fa6ed 100644 --- a/samples/ftrace/ftrace-direct-multi-modify.c +++ b/samples/ftrace/ftrace-direct-multi-modify.c @@ -28,6 +28,7 @@ asm (" .pushsection .text, \"ax\", @progbits\n" " my_tramp1:\n" " addi sp,sp,-24\n" " sd a0,0(sp)\n" +" move t0,t1\n" " sd t0,8(sp)\n" " sd ra,16(sp)\n" " call my_direct_func1\n" diff --git a/samples/ftrace/ftrace-direct-multi.c b/samples/ftrace/ftrace-direct-multi.c index df91339d3095..2111478b0463 100644 --- a/samples/ftrace/ftrace-direct-multi.c +++ b/samples/ftrace/ftrace-direct-multi.c @@ -23,6 +23,7 @@ asm (" .pushsection .text, \"ax\", @progbits\n" " my_tramp:\n" " addi sp,sp,-24\n" " sd a0,0(sp)\n" +" move t0,t1\n" " sd t0,8(sp)\n" " sd ra,16(sp)\n" " call my_direct_func\n" diff --git a/samples/ftrace/ftrace-direct-too.c b/samples/ftrace/ftrace-direct-too.c index fe3b8c4f3336..e80981d3dc0a 100644 --- a/samples/ftrace/ftrace-direct-too.c +++ b/samples/ftrace/ftrace-direct-too.c @@ -27,6 +27,7 @@ asm (" .pushsection .text, \"ax\", @progbits\n" " sd a0,0(sp)\n" " sd a1,8(sp)\n" " sd a2,16(sp)\n" +" move t0,t1\n" " sd t0,24(sp)\n" " sd ra,32(sp)\n" " call my_direct_func\n" diff --git a/samples/ftrace/ftrace-direct.c b/samples/ftrace/ftrace-direct.c index 0784024b6653..b6cae1b5cb66 100644 --- a/samples/ftrace/ftrace-direct.c +++ b/samples/ftrace/ftrace-direct.c @@ -22,6 +22,7 @@ asm (" .pushsection .text, \"ax\", @progbits\n" " my_tramp:\n" " addi sp,sp,-24\n" " sd a0,0(sp)\n" +" move t0,t1\n" " sd t0,8(sp)\n" " sd ra,16(sp)\n" " call my_direct_func\n" --- arch/riscv/Kconfig | 2 ++ samples/ftrace/ftrace-direct-modify.c | 34 ++++++++++++++++++ samples/ftrace/ftrace-direct-multi-modify.c | 38 +++++++++++++++++++++ samples/ftrace/ftrace-direct-multi.c | 23 +++++++++++++ samples/ftrace/ftrace-direct-too.c | 27 +++++++++++++++ samples/ftrace/ftrace-direct.c | 23 +++++++++++++ 6 files changed, 147 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 2828537abfcd..0a1da03e88c2 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -279,6 +279,8 @@ config ARCH_RV64I select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && $(cc-option,-fpatchable-function-entry=8) select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS + select HAVE_SAMPLE_FTRACE_DIRECT + select HAVE_SAMPLE_FTRACE_DIRECT_MULTI select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION diff --git a/samples/ftrace/ftrace-direct-modify.c b/samples/ftrace/ftrace-direct-modify.c index 39146fa83e20..6a633ff4cf6d 100644 --- a/samples/ftrace/ftrace-direct-modify.c +++ b/samples/ftrace/ftrace-direct-modify.c @@ -22,6 +22,40 @@ extern void my_tramp2(void *); static unsigned long my_ip = (unsigned long)schedule; +#ifdef CONFIG_RISCV + +asm (" .pushsection .text, \"ax\", @progbits\n" +" .type my_tramp1, @function\n" +" .globl my_tramp1\n" +" my_tramp1:\n" +" addi sp,sp,-16\n" +" move t0,t1\n" +" sd t0,0(sp)\n" +" sd ra,8(sp)\n" +" call my_direct_func1\n" +" ld t0,0(sp)\n" +" ld ra,8(sp)\n" +" addi sp,sp,16\n" +" jr t0\n" +" .size my_tramp1, .-my_tramp1\n" + +" .type my_tramp2, @function\n" +" .globl my_tramp2\n" +" my_tramp2:\n" +" addi sp,sp,-16\n" +" sd t0,0(sp)\n" +" sd ra,8(sp)\n" +" call my_direct_func2\n" +" ld t0,0(sp)\n" +" ld ra,8(sp)\n" +" addi sp,sp,16\n" +" jr t0\n" +" .size my_tramp2, .-my_tramp2\n" +" .popsection\n" +); + +#endif /* CONFIG_RISCV */ + #ifdef CONFIG_X86_64 #include diff --git a/samples/ftrace/ftrace-direct-multi-modify.c b/samples/ftrace/ftrace-direct-multi-modify.c index 65aa94d96f4e..9534e18fa6ed 100644 --- a/samples/ftrace/ftrace-direct-multi-modify.c +++ b/samples/ftrace/ftrace-direct-multi-modify.c @@ -20,6 +20,44 @@ void my_direct_func2(unsigned long ip) extern void my_tramp1(void *); extern void my_tramp2(void *); +#ifdef CONFIG_RISCV + +asm (" .pushsection .text, \"ax\", @progbits\n" +" .type my_tramp1, @function\n" +" .globl my_tramp1\n" +" my_tramp1:\n" +" addi sp,sp,-24\n" +" sd a0,0(sp)\n" +" move t0,t1\n" +" sd t0,8(sp)\n" +" sd ra,16(sp)\n" +" call my_direct_func1\n" +" ld a0,0(sp)\n" +" ld t0,8(sp)\n" +" ld ra,16(sp)\n" +" addi sp,sp,24\n" +" jr t0\n" +" .size my_tramp1, .-my_tramp1\n" + +" .type my_tramp2, @function\n" +" .globl my_tramp2\n" +" my_tramp2:\n" +" addi sp,sp,-24\n" +" sd a0,0(sp)\n" +" sd t0,8(sp)\n" +" sd ra,16(sp)\n" +" call my_direct_func2\n" +" ld a0,0(sp)\n" +" ld t0,8(sp)\n" +" ld ra,16(sp)\n" +" addi sp,sp,24\n" +" jr t0\n" +" .size my_tramp2, .-my_tramp2\n" +" .popsection\n" +); + +#endif /* CONFIG_RISCV */ + #ifdef CONFIG_X86_64 #include diff --git a/samples/ftrace/ftrace-direct-multi.c b/samples/ftrace/ftrace-direct-multi.c index 41ded7c615c7..2111478b0463 100644 --- a/samples/ftrace/ftrace-direct-multi.c +++ b/samples/ftrace/ftrace-direct-multi.c @@ -15,6 +15,29 @@ void my_direct_func(unsigned long ip) extern void my_tramp(void *); +#ifdef CONFIG_RISCV + +asm (" .pushsection .text, \"ax\", @progbits\n" +" .type my_tramp, @function\n" +" .globl my_tramp\n" +" my_tramp:\n" +" addi sp,sp,-24\n" +" sd a0,0(sp)\n" +" move t0,t1\n" +" sd t0,8(sp)\n" +" sd ra,16(sp)\n" +" call my_direct_func\n" +" ld a0,0(sp)\n" +" ld t0,8(sp)\n" +" ld ra,16(sp)\n" +" addi sp,sp,24\n" +" jr t0\n" +" .size my_tramp, .-my_tramp\n" +" .popsection\n" +); + +#endif /* CONFIG_RISCV */ + #ifdef CONFIG_X86_64 #include diff --git a/samples/ftrace/ftrace-direct-too.c b/samples/ftrace/ftrace-direct-too.c index 6690468c5cc2..e80981d3dc0a 100644 --- a/samples/ftrace/ftrace-direct-too.c +++ b/samples/ftrace/ftrace-direct-too.c @@ -17,6 +17,33 @@ void my_direct_func(struct vm_area_struct *vma, extern void my_tramp(void *); +#ifdef CONFIG_RISCV + +asm (" .pushsection .text, \"ax\", @progbits\n" +" .type my_tramp, @function\n" +" .globl my_tramp\n" +" my_tramp:\n" +" addi sp,sp,-40\n" +" sd a0,0(sp)\n" +" sd a1,8(sp)\n" +" sd a2,16(sp)\n" +" move t0,t1\n" +" sd t0,24(sp)\n" +" sd ra,32(sp)\n" +" call my_direct_func\n" +" ld a0,0(sp)\n" +" ld a1,8(sp)\n" +" ld a2,16(sp)\n" +" ld t0,24(sp)\n" +" ld ra,32(sp)\n" +" addi sp,sp,40\n" +" jr t0\n" +" .size my_tramp, .-my_tramp\n" +" .popsection\n" +); + +#endif /* CONFIG_RISCV */ + #ifdef CONFIG_X86_64 #include diff --git a/samples/ftrace/ftrace-direct.c b/samples/ftrace/ftrace-direct.c index e8f1e440b9b8..b6cae1b5cb66 100644 --- a/samples/ftrace/ftrace-direct.c +++ b/samples/ftrace/ftrace-direct.c @@ -14,6 +14,29 @@ void my_direct_func(struct task_struct *p) extern void my_tramp(void *); +#ifdef CONFIG_RISCV + +asm (" .pushsection .text, \"ax\", @progbits\n" +" .type my_tramp, @function\n" +" .globl my_tramp\n" +" my_tramp:\n" +" addi sp,sp,-24\n" +" sd a0,0(sp)\n" +" move t0,t1\n" +" sd t0,8(sp)\n" +" sd ra,16(sp)\n" +" call my_direct_func\n" +" ld a0,0(sp)\n" +" ld t0,8(sp)\n" +" ld ra,16(sp)\n" +" addi sp,sp,24\n" +" jr t0\n" +" .size my_tramp, .-my_tramp\n" +" .popsection\n" +); + +#endif /* CONFIG_RISCV */ + #ifdef CONFIG_X86_64 #include