Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1613620rwn; Thu, 15 Sep 2022 20:04:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4iZO58iSG3/3w3CHDeVPHuFcSF+Ss65pB0UKCprfBaAUddKtWdEZTdeKgIwcZyc17Wove3 X-Received: by 2002:a62:e80c:0:b0:54a:817b:a6ac with SMTP id c12-20020a62e80c000000b0054a817ba6acmr2363304pfi.59.1663297476920; Thu, 15 Sep 2022 20:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663297476; cv=none; d=google.com; s=arc-20160816; b=Kt46drddawwzBTTLhiu8c6n5Qg+laAyVV7r5ASNKAd6nAXmkpQa9PZrfZstI0hpFrV m2F5Ljis1tA/lLg+zoquFKDHPOz+8n1hOQ5s1WGetVIkddr6VefCrP2Wy2/C2QRq5M6m 2xJIUNzg8Pu5Eem0yadSeAiOWOBVli0iWLyJWnM1G7/uPShlURjxWxFbxxegnkiRsw+k 5wi2ZgxSvzWwEc5dSa8dyoqq7qdKb/QHv/AFnN4/gJ/4rOb9Hx0Y3tTNwWpC4aBJIdSh 0ypc7xfuYCkoDqMeGCYy2crhyxTgm/JAICkOF4bfWFmpe3ESAueT3VeTtQeqUbTmi86o U7VQ== 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=AVTczSPIHpYaG0Aq26Kp/7K89F2vUi87mBlOIlPfm9c=; b=P43oInwFrKsM553qfglVarccm+FucWW6CbDVDZi8cpDw3Pnm+SXWAJkbDTYBfSKin4 El6tMe3rLmLxAIu4Zqt9croNpQoaaJM0HcmJV7EncuumWzDb42KllnQiDIxkrbHLSeCQ pZ+68ebf7c9JtbISFWSuuf60MguvsYzK4TJkvzIyqrm8liKHqgQS4YiD/KEIXtVX2mMW U5RUQs6+WoFKxijqOOrdytt8qSOaUxtDy4IHO2drry25XtDlBLRnNTjPckkgzX5cTqjB ecTMUFaHbBr6YSoNTvfzpo96NbgoozDUpD1id6UAbRZ2UCIHDCdXiRjbvZCzExv6tyBX e+cA== 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 e2-20020a63db02000000b0043882f3e747si20189678pgg.619.2022.09.15.20.04.23; Thu, 15 Sep 2022 20:04:36 -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; 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 S229625AbiIPCzx (ORCPT + 99 others); Thu, 15 Sep 2022 22:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbiIPCzs (ORCPT ); Thu, 15 Sep 2022 22:55:48 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2D84A99266 for ; Thu, 15 Sep 2022 19:55:46 -0700 (PDT) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxbWul5SNj08gaAA--.56059S2; Fri, 16 Sep 2022 10:55:34 +0800 (CST) From: Qing Zhang To: Huacai Chen , Steven Rostedt , Ingo Molnar Cc: WANG Xuerui , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v4 00/10] LoongArch: Add ftrace support Date: Fri, 16 Sep 2022 10:55:23 +0800 Message-Id: <20220916025533.18771-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxbWul5SNj08gaAA--.56059S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXFyDuw4UKr1ruw17XF1UZFb_yoW5KF1kpr W3ZFn3Gr4UCFs3twnxK34rurn5Ar4xGryag3W3JryrCr47Zr1UXr1vyrykXa45t393Gry0 qF1rWw47KF4qva7anT9S1TB71UUUUbUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBab7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjc xK6I8E87Iv6xkF7I0E14v26rxl6s0DM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY 62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7V C2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkF 7I0En4kS14v26r126r1DMxkIecxEwVAFwVW8JwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4 IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUAVWUtwC20s026c02F40E14v26r1j6r18MI8I 3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIx AIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAI cVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07bwl1PUUUUU= X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ 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. Qing Zhang (10): 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 DYNAMIC_FTRACE_WITH_REGS support LoongArch/ftrace: Add HAVE_DYNAMIC_FTRACE_WITH_ARGS support LoongArch: modules/ftrace: Initialize PLT at load time LoongArch/ftrace: Add HAVE_FUNCTION_GRAPH_RET_ADDR_PTR support LoongArch: Enable CONFIG_KALLSYMS_ALL and CONFIG_DEBUG_FS LoongArch/ftrace: Fix unwind state when option func_stack_trace 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 | 18 ++ 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/entry_dyn.S | 154 ++++++++++++ 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/module-sections.c | 11 + arch/loongarch/kernel/module.c | 47 ++++ arch/loongarch/kernel/unwind_guess.c | 4 +- arch/loongarch/kernel/unwind_prologue.c | 44 +++- scripts/recordmcount.c | 23 ++ 19 files changed, 947 insertions(+), 10 deletions(-) create mode 100644 arch/loongarch/include/asm/ftrace.h create mode 100644 arch/loongarch/kernel/entry_dyn.S 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 -- 2.36.1