From patchwork Wed Nov 16 08:07:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhang X-Patchwork-Id: 20773 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp16454wru; Wed, 16 Nov 2022 00:08:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf5WqQ/SjzdzfRbXopB5V/6+kNN9qvUZEXy/o5+mY1iob1ZTqYJpLMrt3YuwvPWGC/ejM45q X-Received: by 2002:a65:664a:0:b0:470:4f30:6d80 with SMTP id z10-20020a65664a000000b004704f306d80mr19424023pgv.285.1668586114945; Wed, 16 Nov 2022 00:08:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668586114; cv=none; d=google.com; s=arc-20160816; b=x12Tvp3cReBrVEo9KbhlpjVCJOpPMAQeNny8fbWNKith6E7zz0Ca3NMqM/KUR/gZOW yB4XlSGucBXFHfK7xo4maccxT7/eDdLAmTAjQ6f6UojmLm0O4x7Irbs0zDgvMgJm6hIk CuqGgA+URvMeqWIIHLpgGl+gLM8Id75Hljxil1sNfMybuWMOWVuJhgTN5Lf0VC7BsPgk Cxy09SXkOFO0hCzNpXxEnixwU+B9mzLPH8MBKAaz/uj1hA+q9wuWTPUWyvZAf1uDNam6 LYaySs5lXhXz84cHAoZ6VfUZ7/CW1gxCM+KcQo2zoJZvojiRF3Zo7RVeYBuNwLRN8t6+ cwGw== 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=yqaaraD41d8yquYs9uvpEzPfvWGxZsexL9BF9lm40No=; b=u+FshLZt0VcMl2MSS2OIOZp6g0Cp/UiOuecLxXKYSx9q+mMChic0EvjbncoJf6KbIN EC8JnK6FgFUGLW6adTmNtT64MDJVz9eE5CixQAInB0+jOpxieLI5NVdAYWNpaN1j7iO9 qxHWcQobo2wdvGNQCJLKnTIgOuvOMvPPcquNwWmKWwS0vMWuXi4xXJK1aO9OBUvfrQ1j bJEOWVNq+hrwHVtHgbl/Tq7lq4SlcevO2JGkkL8i5wcFRPf3dHvz0lKmeqzMp3pPhibU qIxUDw8Rbio1WM3jTFcFqfphpzoD/MmsolXyyouUQ+NsJ1lRzrSOdT6SEkjZ9h7Mg8Rt i65g== 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 u9-20020a170902e80900b001868d5fc27csi17423589plg.254.2022.11.16.00.08.20; Wed, 16 Nov 2022 00:08:34 -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 S238403AbiKPIH7 (ORCPT + 99 others); Wed, 16 Nov 2022 03:07:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233097AbiKPIHl (ORCPT ); Wed, 16 Nov 2022 03:07:41 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 52144BCAD for ; Wed, 16 Nov 2022 00:07:33 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8BxHLdEmnRjM7IHAA--.10834S3; Wed, 16 Nov 2022 16:07:32 +0800 (CST) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx9VY6mnRjQ54UAA--.36317S8; Wed, 16 Nov 2022 16:07:31 +0800 (CST) From: Qing Zhang To: Huacai Chen , Steven Rostedt , Ingo Molnar Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v8 6/9] LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support Date: Wed, 16 Nov 2022 16:07:19 +0800 Message-Id: <20221116080722.4745-7-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221116080722.4745-1-zhangqing@loongson.cn> References: <20221116080722.4745-1-zhangqing@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Dx9VY6mnRjQ54UAA--.36317S8 X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxZrW3XFW3WrykGFWrWw13XFb_yoW5AF1DpF yIy3Z8JF47uFsa9asF9FyUWrs8Zr97u34avayxta4rAF1DXFyUZr1xAr1DXFyUt34kGrWI vFyfKwnIkF45X3JanT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bakYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26rWY6Fy7McIj6I8E 87Iv67AKxVW8Jr0_Cr1UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04 k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC2 0s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI 0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW5JVW7JwCI42IY6xIIjxv2 0xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2js IE14v26F4j6r4UJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIF yTuYvjxUs038UUUUU 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?1749639353904878172?= X-GMAIL-MSGID: =?utf-8?q?1749639353904878172?= 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 e2803582e110..9c3d05c727e3 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 */