From patchwork Wed Apr 2 07:42:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: WangYuli X-Patchwork-Id: 14035619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C8A8BC28B20 for ; Wed, 2 Apr 2025 07:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=xs8oJIFC02RAL3duIL2mk7TWHAI7MqzXeYARLJBbpRc=; b=F4rxJ0gWCxEk04 vKi4tUnTW/+zB4LbSCaPlIn4TbnVJxdjnmfmaBF20YuxRdKm+psFCfdNTCzGUW2N9KSu+L0GqIoTi gEGw7SV5XtmGTISMIEYEsoSDH9ObaxFXyKr0h8ARNjh9CT7zCD/H7hVYmrdJYGujLkB/UHsgkV8a6 JaR93E86sIT+CV5E3ZnOCRPgDuN2zhbSj/yRh+8tFBNXSeYSq8N0Omk/AdwwLK6rIdMt8MAYS8HvW 78HGZsR2fwwDE1RksYi9XEqfuFk0LFooMiMQAV1NKryHB+EgkiVWNm4YnA+6lQJbuXLu5+Zovo9r5 Ki6nyrEWGYliGLrbk6Rw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzsqs-00000005QrW-3HRh; Wed, 02 Apr 2025 07:49:34 +0000 Received: from smtpbguseast2.qq.com ([54.204.34.130]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1tzsli-00000005Q2g-2gHR for linux-riscv@lists.infradead.org; Wed, 02 Apr 2025 07:44:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1743579783; bh=IdRmZ2JBex4jUMOaecKtPJHj559XDfi8d/7kI9nzLXE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=NTMll+tpcwyLZdU10Ew5UEXtQneoMxVjPHgE4HA+Od3B1WCziO3hhfrTNL9gsrsta HALDNqp0CYYOcKWzVwcoSDnrO4rbg78/e98sqgwD/d7sBd/exubnxW3xY++EMG780h bUumJynnowbRmVrosHX8jBY9poCJv2UkjxoajTtw= X-QQ-mid: bizesmtpip3t1743579772tmnkz9o X-QQ-Originating-IP: VXfI5PZC7A5F6pu2hcWgPmH22j/MPc1MoA5fwl1MiuU= Received: from localhost.localdomain ( [localhost]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 02 Apr 2025 15:42:50 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 18110157691820490132 EX-QQ-RecipientCnt: 14 From: WangYuli To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr Cc: wangyuli@uniontech.com, chenhuacai@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, vincent.chen@sifive.com, palmerdabbelt@google.com, zhanjun@uniontech.com, niecheng1@uniontech.com, guanwentao@uniontech.com, Huacai Chen Subject: [PATCH v2] riscv: KGDB: Do not inline arch_kgdb_breakpoint() Date: Wed, 2 Apr 2025 15:42:47 +0800 Message-ID: <330B3BAFC6FDB763+20250402074247.64483-1-wangyuli@uniontech.com> X-Mailer: git-send-email 2.49.0 MIME-Version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1Cn+G/+mA2BrYHCvQcwvC6Wk+3r/ikqaqeySpcv/kKAVPN+fSJfpqg9 tjirjWAg== X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= X-QQ-RECHKSPAM: 0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250402_004415_181976_4F110FA7 X-CRM114-Status: UNSURE ( 9.22 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The arch_kgdb_breakpoint() function defines the kgdb_compiled_break symbol using inline assembly. There's a potential issue where the compiler might inline arch_kgdb_breakpoint(), which would then define the kgdb_breakinst symbol multiple times, leading to fail to link vmlinux.o. This isn't merely a potential compilation problem. The intent here is to determine the global symbol address of kgdb_compiled_break, and if this function is inlined multiple times, it would logically be a grave error. Link: https://lore.kernel.org/all/4b4187c1-77e5-44b7-885f-d6826723dd9a@sifive.com/ Fixes: fe89bd2be866 ("riscv: Add KGDB support") Co-developed-by: Huacai Chen Signed-off-by: Huacai Chen Signed-off-by: WangYuli --- Changelog: *v1->v2: Add the missing __ASSEMBLY__ check and substitute ".option rvc/norvc" with ".option push/pop". --- arch/riscv/include/asm/kgdb.h | 9 +-------- arch/riscv/kernel/kgdb.c | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/riscv/include/asm/kgdb.h b/arch/riscv/include/asm/kgdb.h index 46677daf708b..d9f6a8fc387f 100644 --- a/arch/riscv/include/asm/kgdb.h +++ b/arch/riscv/include/asm/kgdb.h @@ -19,16 +19,9 @@ #ifndef __ASSEMBLY__ +extern void arch_kgdb_breakpoint(void); extern unsigned long kgdb_compiled_break; -static inline void arch_kgdb_breakpoint(void) -{ - asm(".global kgdb_compiled_break\n" - ".option norvc\n" - "kgdb_compiled_break: ebreak\n" - ".option rvc\n"); -} - #endif /* !__ASSEMBLY__ */ #define DBG_REG_ZERO "zero" diff --git a/arch/riscv/kernel/kgdb.c b/arch/riscv/kernel/kgdb.c index 2e0266ae6bd7..5873d3970360 100644 --- a/arch/riscv/kernel/kgdb.c +++ b/arch/riscv/kernel/kgdb.c @@ -254,6 +254,14 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc) regs->epc = pc; } +noinline void arch_kgdb_breakpoint(void) +{ + asm(".global kgdb_compiled_break\n" + ".option push\n" + "kgdb_compiled_break: ebreak\n" + ".option pop\n"); +} + void kgdb_arch_handle_qxfer_pkt(char *remcom_in_buffer, char *remcom_out_buffer) {