From nobody Sun Feb 8 14:57:05 2026 Received: from out198-7.us.a.mail.aliyun.com (out198-7.us.a.mail.aliyun.com [47.90.198.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61B3D334C24 for ; Fri, 9 Jan 2026 12:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.198.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767961415; cv=none; b=gasI0POggOJLpSRS5z8ngkKU9eZitqDV4ZpEcxaFusAuOwZS3d9tIPDnbOYjXKne+hC9EENUTmTGexYbtHpzMqdWcexhaSzd+q/z2cFWUcgUUYtaPMHPSz6x3geLDa3EAly/2UplFURaDD9DOSgCG+e+TxY+YerSfCFABvPypR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767961415; c=relaxed/simple; bh=vGfujkjKtWyDyzzAuYAFqPApaqieFUo+Iq8/mSOmeXc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=RQFMpzuh/fOIN0PFS/Jdn3Oos06ovIgY4pQ6mkfx6xvtVuGtugi7IgaTYOKGZIeA3fL7eFObTedYfF05+s4E3AvA28ZkUQDkCC1xQtPKb1CBi8rx6jO3Xe7TrYci+x+cbph2SO7sOdXDIPPDO8MrLJ53zHY03XYtioZF60K5c5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=PprzgPgV; arc=none smtp.client-ip=47.90.198.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="PprzgPgV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1767961395; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=E4wB7atRTH9/uzWqZL+eIv7EIncCKJBN6KYjddhuqoM=; b=PprzgPgVSVI26Dsk0G7flctL4sYIGz1EN9vf6yQ/yl7F/s0b+MeYuHqAc+H6iHUF6Ux5q2WHLg7fApXPQRphfvJxUucZeEbCroQjo45Vf67JAB/acgwzT7p8AjbKLxTDnPMktoLkHa6jox0BBO6Th36GV6ACxXmIDjKIZ/cbwxQ= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.g2PqCS7_1767961393 cluster:ay29) by smtp.aliyun-inc.com; Fri, 09 Jan 2026 20:23:14 +0800 From: Hou Wenlong To: linux-kernel@vger.kernel.org Cc: Hou Wenlong , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Kees Cook , Josh Poimboeuf , FUJITA Tomonori , Sohil Mehta , "Xin Li (Intel)" , Mostafa Saleh , Alexander Shishkin Subject: [PATCH] x86_64/bug: Handle __WARN_printf() trap in early_fixup_exception() Date: Fri, 9 Jan 2026 20:21:55 +0800 Message-Id: <97dd5c5b5e92d48ffbc95fb1357dfbbbf0d12a1e.1767960698.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The commit 5b472b6e5bd9 ("x86_64/bug: Implement __WARN_printf()") implemented __WARN_printf(), which changed the mechanism to use UD1 instead of UD2. However, it only handles the trap in the runtime IDT handler, while the early booting IDT handler lacks this handling. As a result, the usage of WARN() before the runtime IDT setup can lead to kernel crashes. Since KMSAN is enabled after the runtime IDT setup, it is safe to use handle_bug() directly in early_fixup_exception() to address this issue. Fixes: 5b472b6e5bd9 ("x86_64/bug: Implement __WARN_printf()") Signed-off-by: Hou Wenlong --- arch/x86/include/asm/bug.h | 1 + arch/x86/kernel/traps.c | 2 +- arch/x86/mm/extable.c | 7 ++----- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index 9b4e04690e1a..23e4b235461d 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -153,6 +153,7 @@ struct arch_va_list { struct sysv_va_list args; }; extern void *__warn_args(struct arch_va_list *args, struct pt_regs *regs); +extern noinstr bool handle_bug(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ =20 #define __WARN_bug_entry(flags, format) ({ \ diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index bcf1dedc1d00..aca1eca5daff 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -397,7 +397,7 @@ static inline void handle_invalid_op(struct pt_regs *re= gs) ILL_ILLOPN, error_get_trap_addr(regs)); } =20 -static noinstr bool handle_bug(struct pt_regs *regs) +noinstr bool handle_bug(struct pt_regs *regs) { unsigned long addr =3D regs->ip; bool handled =3D false; diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c index 2fdc1f1f5adb..6b9ff1c6cafa 100644 --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -411,14 +411,11 @@ void __init early_fixup_exception(struct pt_regs *reg= s, int trapnr) return; =20 if (trapnr =3D=3D X86_TRAP_UD) { - if (report_bug(regs->ip, regs) =3D=3D BUG_TRAP_TYPE_WARN) { - /* Skip the ud2. */ - regs->ip +=3D LEN_UD2; + if (handle_bug(regs)) return; - } =20 /* - * If this was a BUG and report_bug returns or if this + * If this was a BUG and handle_bug returns or if this * was just a normal #UD, we want to continue onward and * crash. */ --=20 2.31.1