Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7080735rwr; Wed, 10 May 2023 03:43:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Jo+PjbWbnIdSoUlp7R659oyUqyVsE2vfp6q2uUjhrPr5H8hd5SG7aDI1UCPhDg2/Wbkph X-Received: by 2002:a17:902:e549:b0:1ac:a661:a4b0 with SMTP id n9-20020a170902e54900b001aca661a4b0mr4676936plf.57.1683715425925; Wed, 10 May 2023 03:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683715425; cv=none; d=google.com; s=arc-20160816; b=Z+FBZNLs789qD8MtQbmAqL2c0x+v27EQpnUM0pnkKUGYSjNQgx+esmeml5QK9iI3ik ltj6QO48SGdg0T//92asvKoPsXuW5uIFAvyqECuiyCokijfHO+tsbg7MPiWgzgel9byN jhI7neB1yqFejGj0tVyUhQBQGnDwCYv25LqGQ/pe4gbxoVfWHq3uC/dmwfZ1DjGFC2t+ TC0rBJPNNXu3atTyGweKqq6PqQMeH5bm1+NMPkAMrcScVxXItwKA2YAnZqV9UxD0jutk pVDBfKuN3jieOLtRrDBHT+eHCAWNLcYi28LaQ13oH0pJDAYaxv6iaQxp7zQf6cpgQ55I mM2Q== 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=N85teQqBhV1VEodsjY4znoRaG/yAfuSF6nM7iLcKOvw=; b=ULynJSyFum1g34bRrVMNsiYxMPU+1QkMNkSPVo1Tn7Me3Q/+PcKAhN4ceox3SSnL2v KvJkLVjBZ7iHu+iWImCztbOzwF5k6qgZBhJ3LMwqNM3yW3lv322pLyv608ibbxkSqtma nrrYwoxryuoQPBTGgz1qmnUp9F9sM+hQw/KPRih0rUNNEex7pOb7HSrz/YSv4c1uXUyI x2wu06e4BfB4l73l9ubtVif+6lvHvl1DMFMM/o0gRspO9Rks3lpXL0glvjtGFMExFjKt xcOuV/LIxK3IRuOoUVwoj4PAwx6JyElpPVjN86UA/v0dQ4unfEuiaVlPUL80Eqwb9yBL ymFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JBQ0T3lw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a63340f000000b00527d158ec6dsi3613190pga.406.2023.05.10.03.43.31; Wed, 10 May 2023 03:43:45 -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; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JBQ0T3lw; 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 S236577AbjEJKUA (ORCPT + 99 others); Wed, 10 May 2023 06:20:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236555AbjEJKTm (ORCPT ); Wed, 10 May 2023 06:19:42 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B4AD7D8C; Wed, 10 May 2023 03:19:33 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-643990c5319so4972196b3a.2; Wed, 10 May 2023 03:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683713973; x=1686305973; 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=N85teQqBhV1VEodsjY4znoRaG/yAfuSF6nM7iLcKOvw=; b=JBQ0T3lwKLhK0PsZBb1kYBcphNzpqyyl3v8068U4Z25lbu7323vNcfTbAT08d7SanU bIcbzIgLfJZAfqyswNxbuXkFGvvji93jpJPKad8THrO7Y8/yKBV+sN6MQNAqHUCmsK0E bNO02zLALN25h9l8gRv6obdQayaRZZ5ZdZlaNPrhBCB+t2kzo9TaJNzrKMV1ZNgE5KPV c3V8HbeSB3KldLQcjhTN1zty3I9nNAphJR9M6QAKpYnMaY1RDEPnpU9kCZHQkb+ezb7K 4OOHTo++3s5vtGe9yVzy8qxpwdH/3c1bP/DOT2nykZbsZWtMhyupmlaQNOnPh2cyhwFg rv5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683713973; x=1686305973; 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=N85teQqBhV1VEodsjY4znoRaG/yAfuSF6nM7iLcKOvw=; b=QVxyjf2VW8w12Yt/eNqBJ0VIONFRrRkfKLsSSJP0EWH+KoPPp93ChTA7BoZ9TkOGWy +IxDymbubcsQ4z7Da9APXoVg/kITDZPpYDQCDAUd/d9HKhWCfX4drBkFlD5T+JlB7wGs bZWTILZ9D/g7BFiLD9zq2f4XLO2HwMY0I8UUu0tnMJZPio2lB+zgiNWK50KNq4fWVj4G jSWc2HQ0zmlnvFp9fCTiZJE6uka3RYxkZNCWGPNhDEQsOnU5XxUJp4iTLHbI//e83mTb dObntgrlyKZYGbqoPAyBGW4CEgERs+A4eJo4nCYUfX1dPdnmzV+GLv6qxNF13JjrHlFy RBvA== X-Gm-Message-State: AC+VfDzLfZoyUccDfTDmlc1fchoNWvbYzCRYel9pSj5kCDnvAwM5kjBe dM7glIR6p9JVxljX/NRNhDk= X-Received: by 2002:a17:902:e752:b0:1ac:7072:cfc with SMTP id p18-20020a170902e75200b001ac70720cfcmr13862334plf.16.1683713972979; Wed, 10 May 2023 03:19:32 -0700 (PDT) Received: from localhost.localdomain ([221.226.144.218]) by smtp.gmail.com with ESMTPSA id p16-20020a170902e75000b001aadd0d7364sm3393419plf.83.2023.05.10.03.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 03:19:32 -0700 (PDT) From: Song Shuai To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, rostedt@goodmis.org, mhiramat@kernel.org, mark.rutland@arm.com, guoren@kernel.org, suagrfillet@gmail.com, jszhang@kernel.org, e.shatokhin@yadro.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH V9 4/4] samples: ftrace: Add riscv support for SAMPLE_FTRACE_DIRECT[_MULTI] Date: Wed, 10 May 2023 18:18:57 +0800 Message-Id: <20230510101857.2953955-5-suagrfillet@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230510101857.2953955-1-suagrfillet@gmail.com> References: <20230510101857.2953955-1-suagrfillet@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE 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 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/. Link: https://lore.kernel.org/linux-riscv/c68bac83-5c88-80b1-bac9-e1fd4ea8f07e@yadro.com/T/#ma13012560331c66b051b580b3ab4a04ba44455ec Tested-by: Evgenii Shatokhin Signed-off-by: Song Shuai Tested-by: Guo Ren Signed-off-by: Guo Ren --- arch/riscv/Kconfig | 2 ++ samples/ftrace/ftrace-direct-modify.c | 33 +++++++++++++++++ samples/ftrace/ftrace-direct-multi-modify.c | 39 +++++++++++++++++++++ samples/ftrace/ftrace-direct-multi.c | 23 ++++++++++++ samples/ftrace/ftrace-direct-too.c | 26 ++++++++++++++ samples/ftrace/ftrace-direct.c | 22 ++++++++++++ 6 files changed, 145 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index fdf0b219a02c..cb94ef086f0c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -121,6 +121,8 @@ config RISCV select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RSEQ + select HAVE_SAMPLE_FTRACE_DIRECT + select HAVE_SAMPLE_FTRACE_DIRECT_MULTI select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select IRQ_DOMAIN diff --git a/samples/ftrace/ftrace-direct-modify.c b/samples/ftrace/ftrace-direct-modify.c index 06d889149012..b355e6994c5c 100644 --- a/samples/ftrace/ftrace-direct-modify.c +++ b/samples/ftrace/ftrace-direct-modify.c @@ -22,6 +22,39 @@ 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" +" 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 62f6b681999e..6a4ee86d1f70 100644 --- a/samples/ftrace/ftrace-direct-multi-modify.c +++ b/samples/ftrace/ftrace-direct-multi-modify.c @@ -20,6 +20,45 @@ 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" +" sd t0,8(sp)\n" +" sd ra,16(sp)\n" +" mv a0,t0\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" +" mv a0,t0\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 5482cf616b43..e00a33b7d3c2 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" +" sd t0,8(sp)\n" +" sd ra,16(sp)\n" +" mv a0,t0\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 a05bc2cc2261..af0b90c4d6d5 100644 --- a/samples/ftrace/ftrace-direct-too.c +++ b/samples/ftrace/ftrace-direct-too.c @@ -17,6 +17,32 @@ 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" +" 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 06879bbd3399..47977e262291 100644 --- a/samples/ftrace/ftrace-direct.c +++ b/samples/ftrace/ftrace-direct.c @@ -14,6 +14,28 @@ 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" +" 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 -- 2.20.1