From patchwork Tue Nov 15 02:55:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhang X-Patchwork-Id: 20154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2485217wru; Mon, 14 Nov 2022 18:59:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf66B7WYJ5+5OWSgZmREarfO7hguvvh08loFvWusW0ycv35EYrCqW/SODazQlwqeZdtx6Fky X-Received: by 2002:a05:6402:144c:b0:45f:b9d8:9514 with SMTP id d12-20020a056402144c00b0045fb9d89514mr13616656edx.204.1668481170148; Mon, 14 Nov 2022 18:59:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668481170; cv=none; d=google.com; s=arc-20160816; b=OMtGh8iuLDoe7DZPvXX0EEHjCjjqqMkZw0H4Mcx6sdv25EQZEz1SuXCtyp78I5vKG0 7WLj+WGeQBOubqK7XF5DPZM1gB7p9YXpCJN+JhpeVll5ctlpmHouK7XZX0ct1ECC0DIC qAP7TWQB6cBH2gmFxOfG11yWHfHQA084CTYh2mpEXwRsPM2/ByHw5tigplS5I5QUsVDm KQZWpBBGwBOwOZWUGho+p0fshB31nZpSWby2LlmKBKFpOUglcj2HEPqvJUHzZXrTshms tVJ9mcKcrZse6S2JeR61xqXklV/exdPlnF0E7Fh5URYAyOzGjRhVewvof3hpL5cT9/Td wlrw== 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; bh=8SySSvrM2OZpMsn8J9LlhyOa72oKwGWd6tTphSgiZlI=; b=aS0OtIZTxs8Gvv+Q9a7/ZW6Tj8FH73nRMTtiK8QTlU6yv6HHszBpaj9WvtxyHLAw3l bhZM/g8ebqpNG4x/AuKEHSfVZE/acY2pJ1Pcdnw82IcowJHXzMipfDIkeHaDqz+xYE5H QOI36AVanRb2/5dc1Es3VbVvwxl2K6Y2N8rD5+HW5g3PpKy7B2BgP7xhV+YKqVdevCY/ v20OrtLG1SSNdaCKX/0M9M4MgR3Sw/wiyGe3YZe62ZqjPRcqqzHnl+IgVg1AoHDg5Fk+ AdNWFCHZXKaPMdSu7yi+u4HO7pepSF7VuLi4Ff8KXvFWylPWcntBHYS58OhzC9Bn2VQY Iz7g== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di9-20020a170906730900b007b271fa8e7asi111707ejc.197.2022.11.14.18.59.06; Mon, 14 Nov 2022 18:59:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232238AbiKOC5p (ORCPT + 99 others); Mon, 14 Nov 2022 21:57:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235613AbiKOC5A (ORCPT ); Mon, 14 Nov 2022 21:57:00 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7DBE11EC63 for ; Mon, 14 Nov 2022 18:55:37 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Dx_Nik_3JjgB8HAA--.21143S3; Tue, 15 Nov 2022 10:55:32 +0800 (CST) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxLuKf_3JjmywTAA--.51398S8; Tue, 15 Nov 2022 10:55:32 +0800 (CST) From: Qing Zhang To: Huacai Chen , Steven Rostedt , Ingo Molnar Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v6 6/9] LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support Date: Tue, 15 Nov 2022 10:55:24 +0800 Message-Id: <20221115025527.13382-7-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221115025527.13382-1-zhangqing@loongson.cn> References: <20221115025527.13382-1-zhangqing@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxLuKf_3JjmywTAA--.51398S8 X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxZrW3XFW3WrykGFWrWw13XFb_yoW5AF1DpF yIy3Z8JF47uFsa9asF9Fy5Wrs8Xr97u34avayxJa4rAF1DXFyUZr1xAr1DXFyUt3s7GrWI vFyrKwnIkF45X3JanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b3AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26rWY6Fy7McIj6I8E 87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2Iq xVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r 126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY 6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67 AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuY vjxUVCD7UUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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?1749529311587157623?= X-GMAIL-MSGID: =?utf-8?q?1749529311587157623?= Allow for arguments to be passed in to ftrace_regs by default, If this is set, then arguments and stack can be found from the pt_regs. 1. HAVE_DYNAMIC_FTRACE_WITH_ARGS don't need special hook for graph tracer entry point, but instead we can use graph_ops::func function to install the return_hooker. 2. Livepatch requires this option in the future. Signed-off-by: Qing Zhang --- arch/loongarch/Kconfig | 1 + arch/loongarch/include/asm/ftrace.h | 17 +++++++++++++++++ arch/loongarch/kernel/ftrace_dyn.c | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 12e3e91a68ae..5c4f1dc87f84 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -90,6 +90,7 @@ config LOONGARCH select HAVE_DEBUG_STACKOVERFLOW select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE + select HAVE_DYNAMIC_FTRACE_WITH_ARGS select HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_EBPF_JIT select HAVE_EXIT_THREAD diff --git a/arch/loongarch/include/asm/ftrace.h b/arch/loongarch/include/asm/ftrace.h index a3f974a7a5ce..5cc13ae48164 100644 --- a/arch/loongarch/include/asm/ftrace.h +++ b/arch/loongarch/include/asm/ftrace.h @@ -15,6 +15,23 @@ extern void _mcount(void); #define mcount _mcount #endif +#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +struct ftrace_ops; + +struct ftrace_regs { + struct pt_regs regs; +}; + +static __always_inline struct pt_regs *arch_ftrace_get_regs(struct ftrace_regs *fregs) +{ + return &fregs->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 + #ifdef CONFIG_DYNAMIC_FTRACE static inline unsigned long ftrace_call_adjust(unsigned long addr) { diff --git a/arch/loongarch/kernel/ftrace_dyn.c b/arch/loongarch/kernel/ftrace_dyn.c index ec3d951be50c..f538829312d7 100644 --- a/arch/loongarch/kernel/ftrace_dyn.c +++ b/arch/loongarch/kernel/ftrace_dyn.c @@ -144,6 +144,17 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent) *parent = return_hooker; } +#ifdef CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS +void ftrace_graph_func(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *op, struct ftrace_regs *fregs) +{ + struct pt_regs *regs = &fregs->regs; + unsigned long *parent = (unsigned long *)®s->regs[1]; + + prepare_ftrace_return(ip, (unsigned long *)parent); +} +#else + static int ftrace_modify_graph_caller(bool enable) { unsigned long pc, func; @@ -170,4 +181,5 @@ int ftrace_disable_ftrace_graph_caller(void) { return ftrace_modify_graph_caller(false); } +#endif /* CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS */ #endif /* CONFIG_FUNCTION_GRAPH_TRACER */