From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 8C49631B131 for ; Mon, 12 Jan 2026 07:44:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203885; cv=none; b=eF8OlvyEMibNUol26EfjHs+7+wcVDI7ImuJsF22wSvptT7lR2k8tr0QTOi4brskjnYz6zjRgbW5P2/cmkJa0XMNIS011MUzR2p9hTmPzJJi79o6Bki1uYgAvNhe/37AJhgiB1KjXL6ntXTLgKOv1VSxauZbPbOqZKVYJ2OsIjsQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768203885; c=relaxed/simple; bh=5Ab/qFJ4SLjcVfXMM6TI6cfysQ/lnSiuKaPWr/ggWxw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yeb8eRKSSVhsyGHULLfxQ9TKz2P1JzK7NkgiZUYNFG1PxjUV8EXS4gr/r0wOwBYJxYB2fknQeUZ8pkZSdGd1zdYf1/F5vWyUIeVWqgwtw+aHAh7IIK9EDsV+RfX+7cvVxSyEHTJlv3w2FVgU6sTJwlQa6IiEwEPxwdwfYkn0uv4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=P6U+i8TH; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="P6U+i8TH" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xnN8WTw6SlamuR6sfGAszetsyT+RIS4YFpOqCTeOTaw=; b=P6U+i8THxLhJ0pI6HscDY1J8Qh ePjEOVEDX8HeYvYszdTQVl05zb0bweqQ61ZVLy/wuvzxWHpLqT/4Jkx81HvAslwM+0GtkBDR6mXmn KlbkEMYdLhARJJAF/wqNy6SND4FOcSMmpgCKrZ7EzbeIsmonFLVLJ3g6tbVv+BaVAVUvvS5iZmjh7 7Lzmq2e3E43eqSryFu26hF5L2PF+RmuGwy0Bg/2G7i+fNZ+cmPzjxuy7EU4jq7bE9BkIBF9li39nF kMihp5rVX5tjX9x6mLHtYFari+nUtNH8ddOIA1HZs+hXGxP/aiARYnKqA/KppAyn7ePWMOW9IJMWd e2eh1gxQ==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vfCbF-00000000Bpk-3Z3P; Mon, 12 Jan 2026 07:44:30 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id AC7F9302D3E; Mon, 12 Jan 2026 08:44:28 +0100 (CET) Date: Mon, 12 Jan 2026 08:44:28 +0100 From: Peter Zijlstra To: Hou Wenlong 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: <20260112074428.GA830755@noisy.programming.kicks-ass.net> References: <97dd5c5b5e92d48ffbc95fb1357dfbbbf0d12a1e.1767960698.git.houwenlong.hwl@antgroup.com> 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: 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 :/ > 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? > 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 >