Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp105559rwe; Fri, 26 Aug 2022 01:21:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR7gAqkAIgfp3MtyTXfKeeeSOaIT86d0TaEzX0/Q2MTvg69tCf9hY1omNlBkLj8m1EDeT8zt X-Received: by 2002:a17:907:7da0:b0:734:9bc0:6203 with SMTP id oz32-20020a1709077da000b007349bc06203mr4756281ejc.637.1661502085622; Fri, 26 Aug 2022 01:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661502085; cv=none; d=google.com; s=arc-20160816; b=bnUVdkheDBvsaie8jE/TzRTJxkbF3fPjFYKyEhhlGKsZyZTyTb9ID2aL+C47oQ3Rbd SQkZFsCYcIoN04WQFg4Wg6ObeLFTSKdk5JYQRSdiNlUEO/4PLxRXDgPApYqof372UK7z U4MhbwBFzuGG2UTHQ1uDQV5iREcofMGYuwr2wjp/UWDlOn9KuVtxZCe7T+E7N+kX6iov cZRSv52Tvm2DayQ4pQj8AY1oXA9+Gtc+e0u7RV4swd763K0WYxECVO9Qk90ZH5HhzfPg UBdw3e1p73s+wfgdU0embfEy7m3Oa0KzcxLdlm8SBw6PDZNULqw2n88WSQoTZiOk5pWF GxeA== 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=gfAI3Ji1LBpCDfG8MYCpa5haCTx5x5oGgreqDRBTs08=; b=vWAkdgyWBEtgrozU0Gx5g32fKXz1NsUvWuLuqjTx4Rq9GUiXXZt/qx577QxWTmfEEF btCY09AMyxxnHmsFd+Z/0CaW6mPEF/QB4CzroyBp0w+0wI4Fj89Iufy3n/ASS2YugwQ2 54wHFumsSewVceIOICbTHqBzUNV1hhZl6uOTjS7L6OpSd5QyRf/YNB9VaMyL/luX3mfI vUatSelJCdrmxRtkRE3q2UimWaEOyJC/9xhs2/jeAg0Ok9CB32wr+Y1/+2Qgoir6eMym IXF0NzCdc5UFxFT1mOOOEjEpfstLRa4oZvpKMVpqr94aBOFXIfIdi7bLPMkNq1nJ+uZq XCHQ== 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 go8-20020a1709070d8800b0073d866620b2si1012552ejc.994.2022.08.26.01.21.00; Fri, 26 Aug 2022 01:21:25 -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 S245514AbiHZHc3 (ORCPT + 99 others); Fri, 26 Aug 2022 03:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245443AbiHZHbt (ORCPT ); Fri, 26 Aug 2022 03:31:49 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C9931B02AE for ; Fri, 26 Aug 2022 00:31:25 -0700 (PDT) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxFeLDdghjfjwKAA--.46370S2; Fri, 26 Aug 2022 15:31:15 +0800 (CST) From: Qing Zhang To: Huacai Chen , Steven Rostedt , Ingo Molnar Cc: WANG Xuerui , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, Jiaxun Yang , hejinyang@loongson.cn Subject: [PATCH v2 0/9] LoongArch: Add ftrace support Date: Fri, 26 Aug 2022 15:31:05 +0800 Message-Id: <20220826073114.1515-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8AxFeLDdghjfjwKAA--.46370S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXFyDuw4UKr1ruw17XF1UZFb_yoW5uF15pr W3Zrn3Gr4UGFs3twnxK34rurn5Ar1xCryaq3W3AryrCr42vr1UXr1ktrykXa45t3yfGry0 qF1rWw42gF4UZa7anT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkq14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6r4x MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAI cVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUb3l1PUUUUU== X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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 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/9) Suggested by Jinyang: - Change addu16id to lu12iw and Adjust module_finalize return value (7/9) - Use the "jr" pseudo-instruction where applicable (1/9) - Use the "la.pcrel" instead of "la" (3/9) 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 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 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 | 36 +++ arch/loongarch/include/asm/module.h | 5 +- arch/loongarch/include/asm/module.lds.h | 1 + arch/loongarch/include/asm/unwind.h | 1 + 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 | 10 +- scripts/recordmcount.c | 23 ++ 19 files changed, 936 insertions(+), 3 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.20.1