From patchwork Wed May 10 10:18:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 92008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3513492vqo; Wed, 10 May 2023 03:31:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7beXpvEWLfzTvhmHYsuBmk0HvM8saQeuDk7tROwSoxLWyTXeG30OIkTgo/aH+EW919FCel X-Received: by 2002:a17:902:7782:b0:1aa:fdef:2a93 with SMTP id o2-20020a170902778200b001aafdef2a93mr15794197pll.7.1683714678553; Wed, 10 May 2023 03:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683714678; cv=none; d=google.com; s=arc-20160816; b=Z5gYlAQDSyhgCuAaiYotWtSdk5x7kH4nRhwJiFlqJbUD8ykSCbez3IkP4nmxXaSazL FgOlo5aiiOvGysidYM1JtKeX+owbfn50W71aaIm+Mn1So8onJ79DcTbYsT6AxlF1mcEC 13t243/SQFBuB1TBE6m+31AYEdQ9NvZwexWkGyh4j5vOy4p/lJxfcwemCV4yQXokQB/6 0DRMDXfwZshKlyopV8dtXRst0uGTcCg0h8p4YwMBj11Cfh8dNxQW756IEDkgTlQ7Yajx 3GKq8Srhhc9PLLLSCpEUDlvUBwQHvtdJmAry82pJEPS6Ng8p4EIW4j3yyK3yzlutcTiB zHFw== 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=z1t0ft/AfuKy/xQMa6et8iuTG4wcZxNYRj+6RIhEHQg=; b=Q1SwJv8ZcHZBiLjuAq47R5s5lxFa+TOv7HcI0BVoUEl78LLXzKbtLnd4oGpRRxa6PU xTY6vg6gd/EzLA1LO9GnDefbP+c1rBt8D/ZFmKr7VIFnyYVmdE9aN2B98z8QWFr/GbCd g3U6n79G5OUoX94jr/Pi/i8Zp4dlEONqSS8ooBDqoLojC+AEpSqSTyKkU/GblliuyHvS 9bS2Kubizoxmy9goEx4eWw3upEYrc5Qf8pN5cv4pRusQtyugTOqRKRMQZoLZJPvEP4MC iYziu2ZIdFvYungO46JMd2aGtZLHx+bYbtxGZ1+Iv7aKHD58BDSCfpeAYroQD7zXj3+S C4aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QIn7qQyG; 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 13-20020a170902c20d00b001ac53744492si3713278pll.2.2023.05.10.03.31.03; Wed, 10 May 2023 03:31:18 -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=QIn7qQyG; 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 S236522AbjEJKT1 (ORCPT + 99 others); Wed, 10 May 2023 06:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjEJKTX (ORCPT ); Wed, 10 May 2023 06:19:23 -0400 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 3E15F213B; Wed, 10 May 2023 03:19:22 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1aae5c2423dso68513475ad.3; Wed, 10 May 2023 03:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683713961; x=1686305961; 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=z1t0ft/AfuKy/xQMa6et8iuTG4wcZxNYRj+6RIhEHQg=; b=QIn7qQyGu9KHA02ujG7t9C/xbo/Tw2O/IeCeYI61VMn9+jgbUaZbg1NtaoLSGqn1Ok Xe90gJ+r3SRKeS34/7oOM6jvIbWyhjhQ/TvzKX6rIy9BTF3CMXtkrrWy8ohl+giADPhq N/uoad4SmyQsBNdlpRe+/e+PFgXOvrjakYFTyPhROB+6YkVl1Jyd8sllHP1QeKv2Q9nD K/19jMnBenBArM/nj0/uPipZfqw5hvKKQZGLnpG5m07w8IEpB2hOqFPpc27RAxFlAgbJ H55faVr/w8momTJ96c0CYKQ74gDk+ttrdT+UYy6xk3yNrVyIkQpf9tAG9gFUZ8c8hv4Z cPrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683713961; x=1686305961; 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=z1t0ft/AfuKy/xQMa6et8iuTG4wcZxNYRj+6RIhEHQg=; b=QFCXtWg3CESiRfjkku2OPmxqCAMqiCGC/85paW9CYzGLc8Sj01Wmy7HgPknZIGJBjo 4MbPf3SF5MX6d2qMHzL0R6r/5QDHpL6pydkajsCVmOa4IC9xrRBz5mdwFReh7hMVitjn bQBabvfZEU25fKTB7WMYJ5I08qFZMf0mbL4FMSPZMDBjJwT4OBp9SQNwyV6stSZjXKkb x/d4cGoB7c3VcgOMC6wfxcKzmPaqCAb3Z8Pilj5JKEsWQz23Au2TEypUPdTDddjjttGo N4p47yLblkcYQ6pzu36nkLi3HlebEYLf6txxTQub/7hamdrN5hqpBpSZCtP8qBHeTpi/ cizQ== X-Gm-Message-State: AC+VfDxJiG93xcWPn6dT6NULFqX6zUL+dvcV1WyMPS8Xxm8r59R0gGyi PVN9sTjMzAEkUPz1RK18Ru0= X-Received: by 2002:a17:902:d3c6:b0:1a9:7e44:17 with SMTP id w6-20020a170902d3c600b001a97e440017mr15067440plb.17.1683713961643; Wed, 10 May 2023 03:19:21 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 03:19:21 -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, =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= Subject: [PATCH V9 1/4] riscv: select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY Date: Wed, 10 May 2023 18:18:54 +0800 Message-Id: <20230510101857.2953955-2-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765502802543767813?= X-GMAIL-MSGID: =?utf-8?q?1765502802543767813?= In RISC-V, -fpatchable-function-entry option is used to support dynamic ftrace in this commit afc76b8b8011 ("riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT"). So recordmcount don't have to be called to create the __mcount_loc section before the vmlinux linking. Here selects FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY to tell Makefile not to run recordmcount. Link: https://lore.kernel.org/linux-riscv/CAAYs2=j3Eak9vU6xbAw0zPuoh00rh8v5C2U3fePkokZFibWs2g@mail.gmail.com/T/#t Link: https://lore.kernel.org/linux-riscv/Y4jtfrJt+%2FQ5nMOz@spud/ Signed-off-by: Song Shuai Tested-by: Guo Ren Signed-off-by: Guo Ren Acked-by: Björn Töpel --- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 348c0fa1fc8c..e0632493482f 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -58,6 +58,7 @@ config RISCV select COMMON_CLK select CPU_PM if CPU_IDLE || HIBERNATION select EDAC_SUPPORT + select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY if DYNAMIC_FTRACE select GENERIC_ARCH_TOPOLOGY select GENERIC_ATOMIC64 if !64BIT select GENERIC_CLOCKEVENTS_BROADCAST if SMP From patchwork Wed May 10 10:18:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 92010 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3520201vqo; Wed, 10 May 2023 03:44:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4aYpS9ODdHmTH3mcYkIs9oJ1I++358BKY6tdlKOIJZYvwWEvEfejxtUV74VSIiOQ9NWduR X-Received: by 2002:a05:6a20:3d09:b0:ee:f290:5b5e with SMTP id y9-20020a056a203d0900b000eef2905b5emr21913908pzi.43.1683715483656; Wed, 10 May 2023 03:44:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683715483; cv=none; d=google.com; s=arc-20160816; b=j8MLabt2rO79x2p+KjH3xbydmu8Q9Jj4RQUpMJsTNzPdCuDd2K9sA4g2sPVSGbLwlN EUL1D9icFW8C4cezEFwlas478jaIbwBVdDQxm5nZ6B1o92YS8iCTU41AIgSq1jpN2uOZ 82b23dWKXv79kg5gugeWWOcoZO+Umy01TNTudFGiWcIe3lpOmLm90dEsvuUaVnR/shnX rXWkDIVnJrsuDSnTQ92+j4r8+vAX6NA26thP00DKKwTA7L/H/owg6NWqUgWtuCxoxQGV XsxI++RSVf+BaIlJS/nP5jLNvBNgNhsiDy+CuNitF/6EDFXEq1wNlJ1XG3M2NGG0J0mF k3Xw== 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=m8PnWPxOmTgqoGmgt89yn/TCaGU0tidyCiXa2X9+A9Y=; b=ltFUuAN2s1M9Ev0+1DpBMoEnbcBsp38uC9r0+7ki0wzoRBN7EOEn2tPMrp/VtB5Te0 ZCXrqCkpF2+hawJcfOlJ8q/1s0Q8Rep59KIpB+aqS6qj5WRzZ+1W7pnxHJJLF+MU53i6 82B3AyJY7A/ftwbO8cUIC2RcArdWLmTXijFSboNmm3rK4yhNuEWKZAwEvf16t4P7wA7I Ak76l+s9xL/5YrLB1qsIWPDJ22pGjaGkHGeVlkltwyQneeeFhuIE2zMX+Zk48AS4DiR+ HonOuuE1t9AA5C3VBrW2BQ3j5th1sUV2epDRI8nnmDOjRy5wPkuZu5smfCEvTU88lSUU f8BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=NG7LekLr; 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 j5-20020a637a45000000b005303a26dbf8si3666827pgn.408.2023.05.10.03.44.28; Wed, 10 May 2023 03:44:43 -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=NG7LekLr; 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 S236571AbjEJKTb (ORCPT + 99 others); Wed, 10 May 2023 06:19:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236534AbjEJKT2 (ORCPT ); Wed, 10 May 2023 06:19:28 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 066AB2716; Wed, 10 May 2023 03:19:26 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6436dfa15b3so4730219b3a.1; Wed, 10 May 2023 03:19:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683713965; x=1686305965; 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=m8PnWPxOmTgqoGmgt89yn/TCaGU0tidyCiXa2X9+A9Y=; b=NG7LekLrGub/XMbXfi3gcSS73gXoq3iSZZWfSXlZPqmSMrHzfFFBIubqDmC8Eefr80 wEqvElqqiPuolBOBiv4wBsXIWbKKlA308XesKY6liA0h+mP8zmKLs24IUzpctt+SG5gS MNWt4pprKn4yBZEDrxeoI4HcPoIbPdwN1KdNUGmN86tF3xDsYjW18X58KbPjw1oglnhe DHJowzV74jSy2dQCs2Zx7N0zEMr2KU1q8gtfolnEdFdsAZYtlXGm9tyf6qPvpxGqB8K+ 9sogzCb89uOGBEmmpJ/dhsAW5Z9zQ1Wr/4y4QoGRMIdKFhKW/bY07Ng70r7mvpguvbR9 qcwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683713965; x=1686305965; 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=m8PnWPxOmTgqoGmgt89yn/TCaGU0tidyCiXa2X9+A9Y=; b=H71UrmvQeVCQ8HWMJtI5DTZRkDM0tMaIqTfZ3waULNvkZaqL3ayrZaIoTY+1FBz/Sh vhbFi+E5Ul1TbdrXgrOpu0uos/E2BYdLdQFzvfaydDAFuL3VX4Mr0pOXOxFVJUhmzUqr EGded6EKqRcZLeExRzjxSYANe7EkY95Cb9p1ZPECJjXG4hUtS0bFfYc1/hfwFSl1+74v s3bSPUfF26HH1ahEEYlLXhOjZ3xxwdy7Mio0LGbMFk5HI2ExjQyLbfUDr/R9sObTefq2 0bohiPp6IbHU1PuCKY4K1icejtuC8sAtbjA9CNcOcZDMOupcU4lQkKkqpPaO+tlY8eko vFWA== X-Gm-Message-State: AC+VfDwTmS1059AGEeQhc3ZyNRDYZvL+ye9gwikK5tjFcbZcEa/th3bm jnV5uzOdC0Fpc2LZm0MsG0o= X-Received: by 2002:a17:902:d505:b0:1a6:dd9a:62c5 with SMTP id b5-20020a170902d50500b001a6dd9a62c5mr21537860plg.10.1683713965388; Wed, 10 May 2023 03:19:25 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 03:19:25 -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 2/4] riscv: ftrace: Add ftrace_graph_func Date: Wed, 10 May 2023 18:18:55 +0800 Message-Id: <20230510101857.2953955-3-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765503646524428746?= X-GMAIL-MSGID: =?utf-8?q?1765503646524428746?= 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 Tested-by: Guo Ren Signed-off-by: Guo Ren Acked-by: Björn Töpel --- arch/riscv/include/asm/ftrace.h | 11 ++- arch/riscv/kernel/ftrace.c | 30 +++--- arch/riscv/kernel/mcount-dyn.S | 166 +++++++++++++++++++++++++++----- 3 files changed, 163 insertions(+), 44 deletions(-) diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index d47d87c2d7e3..84f856a3286e 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -107,7 +107,16 @@ do { \ struct dyn_ftrace; int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); #define ftrace_init_nop ftrace_init_nop -#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 */ diff --git a/arch/riscv/kernel/ftrace.c b/arch/riscv/kernel/ftrace.c index 03a6434a8cdd..f5aa24d9e1c1 100644 --- a/arch/riscv/kernel/ftrace.c +++ b/arch/riscv/kernel/ftrace.c @@ -178,32 +178,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 */ diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index 669b8697aa38..f26e9f6e2fed 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -57,31 +57,150 @@ .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. +* +* 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) + + // always save the ABI regs + + REG_S x10, PT_A0(sp) + REG_S x11, PT_A1(sp) + REG_S x12, PT_A2(sp) + REG_S x13, PT_A3(sp) + REG_S x14, PT_A4(sp) + 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) - save_from_x6_to_x31 + 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) + REG_S x21, PT_S5(sp) + REG_S x22, PT_S6(sp) + REG_S x23, PT_S7(sp) + REG_S x24, PT_S8(sp) + REG_S x25, PT_S9(sp) + REG_S x26, PT_S10(sp) + REG_S x27, PT_S11(sp) + REG_S x28, PT_T3(sp) + 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 .endm - .macro RESTORE_ALL + .macro RESTORE_ABI_REGS, all=0 + REG_L t0, PT_EPC(sp) REG_L x1, PT_RA(sp) + REG_L x10, PT_A0(sp) + REG_L x11, PT_A1(sp) + REG_L x12, PT_A2(sp) + REG_L x13, PT_A3(sp) + REG_L x14, PT_A4(sp) + 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) - /* Restore t0 with PT_EPC */ - REG_L x5, PT_EPC(sp) - restore_from_x6_to_x31 + 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) + REG_L x21, PT_S5(sp) + REG_L x22, PT_S6(sp) + REG_L x23, PT_S7(sp) + REG_L x24, PT_S8(sp) + REG_L x25, PT_S9(sp) + REG_L x26, PT_S10(sp) + REG_L x27, PT_S11(sp) + REG_L x28, PT_T3(sp) + REG_L x29, PT_T4(sp) + 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 + + .macro PREPARE_ARGS + addi a0, t0, -FENTRY_RA_OFFSET // ip + la a1, function_trace_op + REG_L a2, 0(a1) // op + mv a1, ra // parent_ip + mv a3, sp // fregs + .endm + #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ +#ifndef CONFIG_DYNAMIC_FTRACE_WITH_REGS ENTRY(ftrace_caller) SAVE_ABI @@ -110,33 +229,28 @@ 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) - mv a1, ra - mv a3, sp + SAVE_ABI_REGS 1 + PREPARE_ARGS 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 + RESTORE_ABI_REGS 1 + jr t0 +ENDPROC(ftrace_regs_caller) + +ENTRY(ftrace_caller) + SAVE_ABI_REGS 0 + PREPARE_ARGS + +ftrace_call: + .global ftrace_call call ftrace_stub -#endif - RESTORE_ALL + RESTORE_ABI_REGS 0 jr t0 -ENDPROC(ftrace_regs_caller) +ENDPROC(ftrace_caller) #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ From patchwork Wed May 10 10:18:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 92012 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3521818vqo; Wed, 10 May 2023 03:47:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6j4GNA0I4wvv9A1RIdwiH0dp67kvmNzy8OUEl6Ka4Gyg026XP+7yjLtZLzGKWwXnm5Yk8D X-Received: by 2002:a17:902:ed8e:b0:1a9:765c:77ac with SMTP id e14-20020a170902ed8e00b001a9765c77acmr17248683plj.7.1683715676276; Wed, 10 May 2023 03:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683715676; cv=none; d=google.com; s=arc-20160816; b=pJjZJobKyfm5mrgHsMeXou8oMF/IuPsIiBMKT4X0I32NXXSLP4BQ+HGiyShya98L3H KryduZy89IMTnKdrd2kr5b0n/1EZIb/XEv7HgJulA2B7xnhSCWnNHtCR/OY4LVLxQk7D 70BOZTwcoKRg1l4SF6UHMyy84GyqK6xlIC4/nTpblh1jZ3fwY3pnCLbhg901rjGenwsZ SFdIA/fNIcrRf/4XnOvcg41BI851ZPBcrnwStJtC8YThsKx+YjM28zchdWr2l9ZpUOto 99bfxIEfJsRb/cYgY3obghB57koE6jnhEKUzcV37d2Cu1XdZ7945a/GIuHG9FSGA5q/4 gRGw== 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=S5vFEEjmnopDHc0xjFlK98v5d+a6ehUkb1OxTzirFXs=; b=cQTGZBjBwKx9B/l7u5zXvKVhv1KmbpGXnAobH7HiYBW6Vtrc3xw+/EyUOxEb+6GB/f YhmaFAgjpBwzRdeEWNMPEf3Wts0wDHfDpVhjB80qXSAj785aqls+HdHcbwdH0GlMYODu d5wlKqsADZE1LfU5U5xUrayFdlSYFKAZq7ZTOdKhSpfpcVDBjD5PVd9e9TwG9qrYhhxv Udl262Oi5FGPETuTd6fpNhU6lxzxb2VxHXpKDbrYMkhSYdeyHcBrAdEv5x60XTx1dmXp KaR3kgiQqtjslLz+DsoBM9PiCx2+oMsfEQfZZIuHP0C7zyY6/x01/urW62Ve5ICrl8O4 eHHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=MycZHAKq; 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 w1-20020a170902e88100b001a63d07af3csi3935063plg.41.2023.05.10.03.47.41; Wed, 10 May 2023 03:47:56 -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=MycZHAKq; 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 S236538AbjEJKTh (ORCPT + 99 others); Wed, 10 May 2023 06:19:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236566AbjEJKTb (ORCPT ); Wed, 10 May 2023 06:19:31 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3C2176B8; Wed, 10 May 2023 03:19:29 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-52c30fa5271so3617647a12.0; Wed, 10 May 2023 03:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683713969; x=1686305969; 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=S5vFEEjmnopDHc0xjFlK98v5d+a6ehUkb1OxTzirFXs=; b=MycZHAKqtatZ4GlFbUi6sg2PZR12Yb/VQzOokoxdbGJHe+MlTAHBhFPtZ5BKPygoBK B2MeyhOrY0UaP/fmkmLdjUOaHYR6A1E/TdGzjOaXlYa0H2ewEKI2FavlI9UYveb9lbb3 SJJNR5WOBTnan1uhg8+i/AidIcRCJ6WKOryfBJEmkUNiX0Yd70C827SLJFmVRCxlRFUi DKCGIkPzqO5LDRRV9kBNFpQWKxYWqMWV3ZVEV1D6ygubMSAWe1GBwksgIkU2yw038UKb YCuYCnFd2GxkCM4Egf38kWeZV3K/GO7MCzXIRDTa7c0m5ZRgxISdHfOqrN0odure0JmN h0Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683713969; x=1686305969; 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=S5vFEEjmnopDHc0xjFlK98v5d+a6ehUkb1OxTzirFXs=; b=ZQPql6dB+jVSydxAL0PJEUmeTSFqiYUKdUaEtOw0bcQLuSrRgMt+KhXR42+Rp6H/0Z v9Fjv36cSkFXHec8yUWjRiUhKbruQtP8eqKerMkOpeLCU4vFwsJxlFXGgLAY47nCkeb3 omZAmJ0SejDNGkjlgG31PNG8kfYFMusnL2G/iS8ZwYYoYbh++/gxZaya1O1cKi6mnjha 6O/QfTinz2Q6U/RYX7ErZVplbAvIAPbAkr7Qc8Mzs2hAdcTdhfge27EPpLlMhToVte4T W1aaauSzUCjbnbjeB+6R/D97oFdsjL+FOmE+/QlswQSYr0ZssHMtGmzcF3GDe4AVJI57 JjGg== X-Gm-Message-State: AC+VfDzu+WlHVWUYQmRbLK9UtaBOnCgoyNzOlvElcDENNbuFwhDmAhPL FCo+mMMvM0NkKZPT+AEe1ZI= X-Received: by 2002:a17:902:cece:b0:1a8:626:6d9d with SMTP id d14-20020a170902cece00b001a806266d9dmr22665000plg.62.1683713969110; Wed, 10 May 2023 03:19:29 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 03:19:28 -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 3/4] riscv: ftrace: Add DYNAMIC_FTRACE_WITH_DIRECT_CALLS support Date: Wed, 10 May 2023 18:18:56 +0800 Message-Id: <20230510101857.2953955-4-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765503849020077395?= X-GMAIL-MSGID: =?utf-8?q?1765503849020077395?= 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 Tested-by: Guo Ren Signed-off-by: Guo Ren --- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/ftrace.h | 8 ++++++++ arch/riscv/kernel/mcount-dyn.S | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index e0632493482f..fdf0b219a02c 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -144,6 +144,7 @@ config RISCV select UACCESS_MEMCPY if !MMU select ZONE_DMA32 if 64BIT select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE) + select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL select HAVE_FUNCTION_GRAPH_TRACER diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index 84f856a3286e..84904c1e4369 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -114,6 +114,14 @@ 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) +{ + regs->t1 = addr; +} +#define arch_ftrace_set_direct_caller(fregs, addr) \ + __arch_ftrace_set_direct_caller(&(fregs)->regs, addr) #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ #endif /* __ASSEMBLY__ */ diff --git a/arch/riscv/kernel/mcount-dyn.S b/arch/riscv/kernel/mcount-dyn.S index f26e9f6e2fed..9d405baedb52 100644 --- a/arch/riscv/kernel/mcount-dyn.S +++ b/arch/riscv/kernel/mcount-dyn.S @@ -231,6 +231,7 @@ ENDPROC(ftrace_caller) #else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ ENTRY(ftrace_regs_caller) + move t1, zero SAVE_ABI_REGS 1 PREPARE_ARGS @@ -239,7 +240,10 @@ ftrace_regs_call: call ftrace_stub RESTORE_ABI_REGS 1 + bnez t1,.Ldirect jr t0 +.Ldirect: + jr t1 ENDPROC(ftrace_regs_caller) ENTRY(ftrace_caller) @@ -254,3 +258,9 @@ ftrace_call: jr t0 ENDPROC(ftrace_caller) #endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ + +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS +SYM_CODE_START(ftrace_stub_direct_tramp) + jr t0 +SYM_CODE_END(ftrace_stub_direct_tramp) +#endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */ From patchwork Wed May 10 10:18:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Song Shuai X-Patchwork-Id: 92009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3516550vqo; Wed, 10 May 2023 03:36:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7lRcECi6Z6VHx1CtMw+41QfiqorlZXsFxUu7Y8oYxMGjotxW7++nlDwy1pdECI6OxIixB2 X-Received: by 2002:a05:6a00:a82:b0:646:e11c:f602 with SMTP id b2-20020a056a000a8200b00646e11cf602mr8105779pfl.0.1683715014482; Wed, 10 May 2023 03:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683715014; cv=none; d=google.com; s=arc-20160816; b=cWJBJS5nTYDgoi7MGVfdFFKQZtf0w68gNKr6zaDSiVsJemLd20wFmnY7vDVLXabC7p 0SKsq7QelEauMRpS/xqfan8oNNGGtVKeTqUF/4fTXI2OXX2fd0gq1ZJwBqhArls8R3Jz nCMFY38IULUcBtUqUHK9sFT4R3IV2ujTCtuW+SsrZzVlxfn4yUYAZnJKwDzZNl3LLtFZ jZH3wYEnUK1Lk4bSvBgCw67wjEWgzTsYXOuMdNv1l4LPhvyB+ObJZ2NecoF3JRZWMztX fKKYNQE9RfmYxi7FVfy5XqL903G6qGdo84BEK/qhieNlD4Wk6Ltfl8Fm+KswqPDBuXnb zi7g== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c3-20020aa79523000000b00640f04eb323si4659270pfp.62.2023.05.10.03.36.39; Wed, 10 May 2023 03:36:54 -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 S236579AbjEJKUB (ORCPT + 99 others); Wed, 10 May 2023 06:20:01 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765503155082610136?= X-GMAIL-MSGID: =?utf-8?q?1765503155082610136?= 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 Acked-by: Björn Töpel --- 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