From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out28-218.mail.aliyun.com (out28-218.mail.aliyun.com [115.124.28.218]) (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 5680C33D4EA for ; Mon, 12 Jan 2026 08:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.218 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768207131; cv=none; b=UqL4WdXXb3AqrWbedSwYSRBWtFw0T9J2XEMrMAqMKxdxEBe07jmICBF/4AsR5iKkqYf2X9E/p5wVHm7H1LAjyOFcZ04bK2KiUpMlq2fse+WmUuHaKOLIzQ3g3puIXAY8uagkHykx48QH1qdLn6lT0S7+QwgybVpGHqnRQma/iSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768207131; c=relaxed/simple; bh=NO+oUS3K1WqS4HyfdvEfwhmeN6d45yspNamdJuY2Li4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kofNIvjYnnyXkh/dxBEhbeCK9TiTfp46VSzm+me7gpEOwZNuCoszTmDsuYBjS/nCgm3PfaHzgK4mVu4GxEM13jcDVG8nkjDLIq0GeQaG1HIgqvLunhVIpbYDlFDmHdPxqmA1RIAY9hWq2bepgT5mn+6dCZTNJ52b0L6M0XDF//4= 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=AuueKA1p; arc=none smtp.client-ip=115.124.28.218 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="AuueKA1p" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1768207127; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type; bh=exlBl6riUsimBwYSGEmzEUQkLgEiHhVrp/+kNuMOS+A=; b=AuueKA1pFbzj4/NVTCfT1m+S0TlzyOV7ScLhkguXKKOJbU7cCyW+07k70piJ/fCGN+Ta5tHirvqsynl6dK3vaIJL6SX+YgJbS/j51CzKYqTKr0IWlQlS9xfA5S/44xC+bA9Twyxclv2WzMpXwfbVbVKX8Tn2w2k1qjEs0CuYdi0= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.g4Lu7CJ_1768207126 cluster:ay29) by smtp.aliyun-inc.com; Mon, 12 Jan 2026 16:38:46 +0800 Date: Mon, 12 Jan 2026 16:38:46 +0800 From: Hou Wenlong To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andy Lutomirski , Joel Granados , Kees Cook , Sohil Mehta , "Xin Li (Intel)" , Mostafa Saleh , Josh Poimboeuf , Alexander Shishkin Subject: Re: [PATCH v2] x86/bug: Handle __WARN_printf() trap in early_fixup_exception() Message-ID: <20260112083846.GA24143@k08j02272.eu95sqa> References: <97dd5c5b5e92d48ffbc95fb1357dfbbbf0d12a1e.1767960698.git.houwenlong.hwl@antgroup.com> <20260112074428.GA830755@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260112074428.GA830755@noisy.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2010-09-15) On Mon, Jan 12, 2026 at 08:44:28AM +0100, Peter Zijlstra wrote: > On Sat, Jan 10, 2026 at 11:47:37AM +0800, Hou Wenlong wrote: > > 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. > > Urgh, indeed. Clearly I don't see many early WARNs :/ > Uh, I found this accidentally while I was trying to clean up the early_ioremap debug printing, where it uses WARN() for dumpstack. > > 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. > > I'm not sure I understand this. Should it not be that KMSAN is enabled > *before* early IDT to make this a non-issue? > I see that handle_bug() would call kmsan_unpoison_entry_regs(), and I assume that it should be a NOP before kmsan_init_runtime(). Therefore, I think it's safe to use handle_bug() directly in early_fixup_exception(). Additionally, I note that kmsan_init_runtime() is called after trap_init(), which is why I described the commit message this way. Thanks! > > Fixes: 5b472b6e5bd9 ("x86_64/bug: Implement __WARN_printf()") > > Signed-off-by: Hou Wenlong > > --- > > arch/x86/include/asm/traps.h | 2 ++ > > arch/x86/kernel/traps.c | 2 +- > > arch/x86/mm/extable.c | 7 ++----- > > 3 files changed, 5 insertions(+), 6 deletions(-) > > > > diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h > > index 869b88061801..3f24cc472ce9 100644 > > --- a/arch/x86/include/asm/traps.h > > +++ b/arch/x86/include/asm/traps.h > > @@ -25,6 +25,8 @@ extern int ibt_selftest_noendbr(void); > > void handle_invalid_op(struct pt_regs *regs); > > #endif > > > > +noinstr bool handle_bug(struct pt_regs *regs); > > + > > static inline int get_si_code(unsigned long condition) > > { > > if (condition & DR_STEP) > > 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 *regs) > > ILL_ILLOPN, error_get_trap_addr(regs)); > > } > > > > -static noinstr bool handle_bug(struct pt_regs *regs) > > +noinstr bool handle_bug(struct pt_regs *regs) > > { > > unsigned long addr = regs->ip; > > bool handled = 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 *regs, int trapnr) > > return; > > > > if (trapnr == X86_TRAP_UD) { > > - if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) { > > - /* Skip the ud2. */ > > - regs->ip += LEN_UD2; > > + if (handle_bug(regs)) > > return; > > - } > > > > /* > > - * 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. > > */ > > > > base-commit: b7dccac786071bba98b0d834c517fd44a22c50f9 > > -- > > 2.31.1 > >