Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp93983rwb; Tue, 15 Nov 2022 19:49:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Pw1D+iuHvnS/ylAcwW3v20fMKlQvpSRX+jWD7gBwM3RreUQxQdbX2xendEO5gFI8wmS6C X-Received: by 2002:a05:6402:40a:b0:461:a5ac:61d4 with SMTP id q10-20020a056402040a00b00461a5ac61d4mr17676947edv.340.1668570571498; Tue, 15 Nov 2022 19:49:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668570571; cv=none; d=google.com; s=arc-20160816; b=io8BAwt3Jeqsn2L+n7KrrN0VXaFN+rrZEzClgP97gxC20aRMVz9r+SEqYM2daU0Jrm OmJniGufX7uDLogf/bKRlnST3dWqcZJC228ImJxHqfiBwb8CjFs0Rzxw05+1M02Bt4qN cXxH80P5i/7uAHrT+HrFyztoUopAeD/eQZexKmMXZyLsHO49NlZtUACL5yFLXCss9l3s 8i3iW/lVW6VUkgT4n/v7CamGYZtxyS04mPrbO1iduVTuZxsSk+AiLGUGUKq1Q38hML/Y 2HCxgJW/ortHyXbGlTCAgrcKb/9mEvBUYsEh/UDYo/HQllqY2ep8+6zxL58LRNTje8L7 ikEQ== 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 :message-id:date:subject:cc:to:from; bh=mkCk5G23SCIb3+e/8/tkfeIPwJ7r4zWqn10VBp9Js9M=; b=Pzj5K3B/JmICR6zatK4r23IFfUK3izQ/UmCny/6yQIEwA8Tb0pOfz5TOVjWPPbLlja wxdq5rzgA77Q2W4WSTwRq6zMbRUJoer2sURPX8+pTjsgXmCyusBJihI/g9f+dChGd9Bb OPlYGDPyGiu8PHKJLAh/wnUrZdqKaTkJIwZ10JhQKT4nLVcE7dYokMtot+T49mTbex96 YV2Cx29tZDAjJZ+rMlNQGr+7dXovzExvNwWCEkLx0RdANdY6l3snM7wzmtiGoEoomhJB OY+uP+UfM1KyL8PmKzG1A1Y0/sVZ0u7mKDKtoHdSh7/peJ2W8JTZNivfqvtN0jc6PZqF Lbqw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gy23-20020a170906f25700b007ae2368c8b7si10567318ejb.138.2022.11.15.19.49.09; Tue, 15 Nov 2022 19:49:31 -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 S231708AbiKPCxb (ORCPT + 90 others); Tue, 15 Nov 2022 21:53:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbiKPCx3 (ORCPT ); Tue, 15 Nov 2022 21:53:29 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 39C62F0B for ; Tue, 15 Nov 2022 18:53:27 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8DxvrelUHRjcJEHAA--.17346S3; Wed, 16 Nov 2022 10:53:25 +0800 (CST) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx9VakUHRjO1MUAA--.35612S2; Wed, 16 Nov 2022 10:53:24 +0800 (CST) From: Qing Zhang To: Huacai Chen , Steven Rostedt , Ingo Molnar Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v7 0/9] LoongArch: Add ftrace support Date: Wed, 16 Nov 2022 10:53:15 +0800 Message-Id: <20221116025324.1624-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Dx9VakUHRjO1MUAA--.35612S2 X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxXFyDuw4UKr1ruw17XF1UZFb_yoWrJFW7pr W3ZFn3Gr4UCFs3KwnIg34rurn5Ar1xGryaq3W3JryrCr47Zr1UXw1ktrykXa45t393Gry0 qF1rWw42gF4qva7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b3kYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW8JVW5JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E 87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2Iq xVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r 126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY 6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67 AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x 07jFa0PUUUUU= 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 This patch series to support basic and dynamic ftrace. 1) -pg Use `-pg` makes stub like a child function `void _mcount(void *ra)`. Thus, it can be seen store RA and open stack before `call _mcount`. Find `open stack` at first, and then find `store RA`. 2) -fpatchable-function-entry=2 The compiler has inserted 2 NOPs before the regular function prologue. T series registers are available and safe because of LoongArch psABI. At runtime, replace nop with bl to enable ftrace call and replace bl with nop to disable ftrace call. The bl requires us to save the original RA value, so here it saves RA at t0. details are: | Compiled | Disabled | Enabled | +------------+------------------------+------------------------+ | nop | move t0, ra | move t0, ra | | nop | nop | bl ftrace_caller | | func_body | func_body | func_body | The RA value will be recovered by ftrace_regs_entry, and restored into RA before returning to the regular function prologue. When a function is not being traced, the move t0, ra is not harmful. performs a series of startup tests on ftrace and The test cases in selftests has passed on LoongArch. Changes in v2: - Remove patch "LoongArch: ftrace: Add CALLER_ADDRx macros" there are other better ways Suggested by Steve: - Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support (6/10) Suggested by Jinyang: - Change addu16id to lu12iw and Adjust module_finalize return value (7/10) - Use the "jr" pseudo-instruction where applicable (1/10) - Use the "la.pcrel" instead of "la" (3/10) Changes in v3: Reported by Jeff: - Fix unwind state when option func_stack_trace (10/10) Changes in v4: - No comments. Just resend the series. - Rebased onto v6.0.0-rc4. Changes in v5: - Modify the indentation of Kconfig and small changes Changes in v6: Suggested by Huacai: - Adjusting the patch Sequence - renamed mcount-dyn.S for consistency Changes in v7: - delete redefinition Qing Zhang (9): LoongArch/ftrace: Add basic support LoongArch/ftrace: Add recordmcount support LoongArch/ftrace: Add dynamic function tracer support LoongArch/ftrace: Add dynamic function graph tracer support LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_REGS support LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support LoongArch/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support LoongArch: modules/ftrace: Initialize PLT at load time LoongArch: Enable CONFIG_KALLSYMS_ALL and CONFIG_DEBUG_FS arch/loongarch/Kconfig | 7 + arch/loongarch/Makefile | 5 + arch/loongarch/configs/loongson3_defconfig | 2 + arch/loongarch/include/asm/ftrace.h | 61 +++++ arch/loongarch/include/asm/inst.h | 15 ++ arch/loongarch/include/asm/module.h | 5 +- arch/loongarch/include/asm/module.lds.h | 1 + arch/loongarch/include/asm/unwind.h | 3 +- arch/loongarch/kernel/Makefile | 13 + arch/loongarch/kernel/ftrace.c | 74 ++++++ arch/loongarch/kernel/ftrace_dyn.c | 264 +++++++++++++++++++++ arch/loongarch/kernel/inst.c | 127 ++++++++++ arch/loongarch/kernel/mcount.S | 94 ++++++++ arch/loongarch/kernel/mcount_dyn.S | 154 ++++++++++++ arch/loongarch/kernel/module-sections.c | 11 + arch/loongarch/kernel/module.c | 22 ++ arch/loongarch/kernel/unwind_guess.c | 4 +- arch/loongarch/kernel/unwind_prologue.c | 46 +++- scripts/recordmcount.c | 23 ++ 19 files changed, 921 insertions(+), 10 deletions(-) create mode 100644 arch/loongarch/include/asm/ftrace.h create mode 100644 arch/loongarch/kernel/ftrace.c create mode 100644 arch/loongarch/kernel/ftrace_dyn.c create mode 100644 arch/loongarch/kernel/mcount.S create mode 100644 arch/loongarch/kernel/mcount_dyn.S -- 2.36.0