Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp304003rwb; Wed, 16 Nov 2022 00:23:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf5d1h9vwTzPANKrn9V64ae1GhF53ZmklFxzrhjQzDqzp3eSq1XKeCv7t0jO8lWYmtDRSx8g X-Received: by 2002:a17:906:b1d7:b0:7ae:4373:c8aa with SMTP id bv23-20020a170906b1d700b007ae4373c8aamr17300550ejb.466.1668587032465; Wed, 16 Nov 2022 00:23:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668587032; cv=none; d=google.com; s=arc-20160816; b=aVjZpv9H8NlTOBBHAPWAo3Iy2o7k8Wh7XoUOKJPnA6o4JTQphg9EikyUkQvXp19IeW VRYRRpWXNDwstHpT55a6dOwUdWXLKcz0O/xuLcYtw65PBigQ9BuucxpOlrvzBwzbaJft 54RmguWZXboC6cMIR+qopl8IrpMTyChhma7cPuSVJcW3WfFSJaRekozWJUPjT5cgzau3 HAXQKlVf/XyZvR3akaDJk6PIxHuwN00oM3n9XNJF9VPsy5Y4nG7k+Js3f9rQdomR9Orx VEisXUQ+I6eHuanEGb31NVC2Bt5gOhux+CB3GCuMC36c2eLfQaqZvtNW/9tbz2eW1V1u Z/dg== 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=76MGcKXKOdnXnj7ZJ7tcxKnQsBuySsC4GvISxJFl9iU=; b=ddDA8nzvLlmdSqjXZRm0wLXQYFupORQ5o5O83d2A39PGUWv7bPrIbF7qSB9N0D+bNh PKXbyAipRnMXsxplTSWoQNBS70ovWZ608E1GNK9j9cy8m3PYTB7eWj9AVp1vKcup1h0L BL6RTgnJIook7vmlbNzwB6dIA5/zJ1/avRMMWL1Kk2yojY2KLczQqPGdkqO5y0yp3wQV 9wSzZx6JSlc9fBPwS2h5IPaeqmNbBDncH8qNcT5C73TqJ/GxfuhWSxUXMHZ+mGACij5C Czhu1045tPvhKB0VK55zHuqhBHHEr6nZwy56bWYaSYJVEn0I4+9o7lpW9Wq4qktTplJF Ii4w== 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 hq34-20020a1709073f2200b0078334ccc570si14275723ejc.328.2022.11.16.00.23.31; Wed, 16 Nov 2022 00:23:52 -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 S233101AbiKPIH3 (ORCPT + 90 others); Wed, 16 Nov 2022 03:07:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233094AbiKPIH1 (ORCPT ); Wed, 16 Nov 2022 03:07:27 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F33CB9FFA for ; Wed, 16 Nov 2022 00:07:24 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Bxfdo7mnRjEbIHAA--.22941S3; Wed, 16 Nov 2022 16:07:23 +0800 (CST) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx9VY6mnRjQ54UAA--.36317S2; Wed, 16 Nov 2022 16:07:23 +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 0/9] LoongArch: Add ftrace support Date: Wed, 16 Nov 2022 16:07:13 +0800 Message-Id: <20221116080722.4745-1-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Dx9VY6mnRjQ54UAA--.36317S2 X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxXFyDuw4UKr1ruw17XF1UZFb_yoWrGFy8pr W3ZFn3Gr4UCFs3KwnxK34rurn5Ar1xGryag3W3JryrCr47Zr1UXw1ktrykXa45t393Gry0 qF1rWw42gF4DZa7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU baxYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E 87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw2 8IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I 3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxV WUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8I cVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aV AFwI0_Cr0_Gr1UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZF pf9x07jbDGOUUUUU= 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 Changes in v8: - remove useless macro judgment and modify the return location - move some code to Patch-3 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 | 59 +++++ 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, 919 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