From patchwork Tue Nov 15 02:55:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhang X-Patchwork-Id: 20149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2485022wru; Mon, 14 Nov 2022 18:58:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf4dvNcMO+DvN8TYt0LXOR/qFwLvI59AnhZSh7V5nKlBA7dBDjpxTaHtmRrZJ9BIzV3Q9l1I X-Received: by 2002:a05:6402:17c2:b0:459:443a:faf4 with SMTP id s2-20020a05640217c200b00459443afaf4mr13398517edy.297.1668481122471; Mon, 14 Nov 2022 18:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668481122; cv=none; d=google.com; s=arc-20160816; b=mSXp9BJKn2zXLvclkaI7UO4lbeaDbgtcHPSIr6y9yCA3l2n2rJYJ12OBc2Zdh1G48G 6BLY81G6ZQfHWx2C+BYQb6dJJnfmRGDXupwvN0K8ccKxHu7H720KI7yzJujKIe9AGPuv JBKJqitt/MJulczStXF/EHsqtwd7ej0jc9dAYFH3pQbf6GCWjja8/F5+3VKnlJ2YIgB9 pohl+VKJV5NJRJTs66SZ/c47L9OYBBy3eYF02i/bgYh+vH46y2K60S6iNinrv/IARVGd sdD4oUD5Pv4i5m0DN0YwCC2ZiBDuXb+dIQvteL7l3NbVPYG/wyfzFpseC5BXY68IJbKr NOfA== 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=Dx/HmnaBFGSk3AqSC8wiGn1e2AIocHqL1euJgzGG4Vk=; b=s9vG/E3SVtaNXteveFGd41Us1ecKWRQP7uHwb5fmQERcYUSpgvuoVRnEDw64CaNNOK b0klIZglmyjz8kRlSmFoVir77jSupop1kMHNnR1vexVJBacwtZ6mpwobI2TWMdA9es4g fuOKvediWG+iMApM+oO4ALgdQc7BmRGg2KVjaAuRcN5gYElhH+rW6EYghGdfWBOlv8zt qgxUDv6XniZ0/M0TladbXWysiwrH9TvjbYHt7ORkkbUK0/DWJxK5qUVOx82Nw56QB1UW fiSu4klRGpGcibAw9tCcI8UUUTd9E4OoMCEutpLGRz0pmXQv/Yj5HZ5VtsnlJwzku6oD D4jA== 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 wu10-20020a170906eeca00b0078d27c1b499si10702745ejb.500.2022.11.14.18.58.18; Mon, 14 Nov 2022 18:58:42 -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 S237761AbiKOC5Z (ORCPT + 99 others); Mon, 14 Nov 2022 21:57:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237783AbiKOC45 (ORCPT ); Mon, 14 Nov 2022 21:56:57 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B14B21EC55 for ; Mon, 14 Nov 2022 18:55:35 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Bxfdqj_3Jjbx8HAA--.21782S3; Tue, 15 Nov 2022 10:55:31 +0800 (CST) Received: from localhost.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxLuKf_3JjmywTAA--.51398S4; Tue, 15 Nov 2022 10:55:30 +0800 (CST) From: Qing Zhang To: Huacai Chen , Steven Rostedt , Ingo Molnar Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v6 2/9] LoongArch/ftrace: Add recordmcount support Date: Tue, 15 Nov 2022 10:55:20 +0800 Message-Id: <20221115025527.13382-3-zhangqing@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221115025527.13382-1-zhangqing@loongson.cn> References: <20221115025527.13382-1-zhangqing@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8CxLuKf_3JjmywTAA--.51398S4 X-CM-SenderInfo: x2kd0wptlqwqxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxGr4UXFWrZr4xAFy8ury8Zrb_yoW5CrWDpr 4qvFyrJFs2qryfG3ZIy348ur15Zas7Kr4Svryfta1FyFyDXrZ5Gr47JrnrWFyUCrykJ34x WF4F9ry8ua1UJw7anT9S1TB71UUUUjUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b3AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JF0_JFyl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l n4kS14v26r1Y6r17M2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6x ACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E 87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82 IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l4IxYO2xFxVAFwI0_Jrv_JF1lx2Iq xVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r 126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY 6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67 AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuY vjxU4OzVUUUUU 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?1749529261795383487?= X-GMAIL-MSGID: =?utf-8?q?1749529261795383487?= Recordmcount utility under scripts is run, after compiling each object, to find out all the locations of calling _mcount() and put them into specific seciton named __mcount_loc. Then linker collects all such information into a table in the kernel image (between __start_mcount_loc and __stop_mcount_loc) for later use by ftrace. This patch adds loongarch specific definitions to identify such locations. On loongarch, only C version is used to build the kernel now that CONFIG_HAVE_C_RECORDMCOUNT is on. Signed-off-by: Qing Zhang --- arch/loongarch/Kconfig | 2 ++ scripts/recordmcount.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 92c4ec8c8527..e6b1defca1f1 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -86,11 +86,13 @@ config LOONGARCH select HAVE_ARCH_TRANSPARENT_HUGEPAGE select HAVE_ASM_MODVERSIONS select HAVE_CONTEXT_TRACKING_USER + select HAVE_C_RECORDMCOUNT select HAVE_DEBUG_STACKOVERFLOW select HAVE_DMA_CONTIGUOUS select HAVE_EBPF_JIT select HAVE_EXIT_THREAD select HAVE_FAST_GUP + select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER select HAVE_GENERIC_VDSO diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c index cce12e1971d8..ae42f9c5dc42 100644 --- a/scripts/recordmcount.c +++ b/scripts/recordmcount.c @@ -38,6 +38,13 @@ #define R_AARCH64_ABS64 257 #endif +#ifndef EM_LOONGARCH +#define EM_LOONGARCH 258 +#define R_LARCH_64 2 +#define R_LARCH_MARK_LA 20 +#define R_LARCH_SOP_PUSH_PLT_PCREL 29 +#endif + #define R_ARM_PC24 1 #define R_ARM_THM_CALL 10 #define R_ARM_CALL 28 @@ -441,6 +448,17 @@ static int arm64_is_fake_mcount(Elf64_Rel const *rp) return ELF64_R_TYPE(w8(rp->r_info)) != R_AARCH64_CALL26; } +static int LARCH64_is_fake_mcount(Elf64_Rel const *rp) +{ + switch (ELF64_R_TYPE(w(rp->r_info))) { + case R_LARCH_MARK_LA: + case R_LARCH_SOP_PUSH_PLT_PCREL: + return 0; + } + + return 1; +} + /* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40] @@ -558,6 +576,7 @@ static int do_file(char const *const fname) break; case EM_IA_64: reltype = R_IA64_IMM64; break; case EM_MIPS: /* reltype: e_class */ break; + case EM_LOONGARCH: /* reltype: e_class */ break; case EM_PPC: reltype = R_PPC_ADDR32; break; case EM_PPC64: reltype = R_PPC64_ADDR64; break; case EM_S390: /* reltype: e_class */ break; @@ -610,6 +629,10 @@ static int do_file(char const *const fname) Elf64_r_info = MIPS64_r_info; is_fake_mcount64 = MIPS64_is_fake_mcount; } + if (w2(ghdr->e_machine) == EM_LOONGARCH) { + reltype = R_LARCH_64; + is_fake_mcount64 = LARCH64_is_fake_mcount; + } if (do64(ghdr, fname, reltype) < 0) goto out; break;