From nobody Fri Dec 19 01:37:41 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 2F0AE3112C4 for ; Mon, 10 Nov 2025 11:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775927; cv=none; b=pyrQHeyRR2+KuIWTCAGVRLn/JIjM2hxoiOx62zGT90J37RLKexoMLGlOazG2tb/dXp3rlVKX4qMyIZzhaE5lMTK0gMosznAtQIq+zDFB4qI9MhfbNQLkRfJdm9h7tQ7uqIOThnV1gNJpDVqDR3T6EYGonKP8uXMOUdqUjgUeozw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775927; c=relaxed/simple; bh=IoMasXSjoGE6KxKLUtaZikrwv5hFbj5+u+bcqqIO1gM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gnpDCFL+J0WUQHppKpneCC7xefSd/2rCSyZcPZhyrFG2P0VjZSDZsqnXh+q/0yJbReD88GwUfzK4fLs1dDdqc1ocGFqnsD2R7jFAUiXUhKEXxrwbddBBu88LeiEJawVHPUtIiaf9KzyvZNaCGmrkgH0v9j8m0yxHr9J54KMUHqs= 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=BwVmIbTp; arc=none smtp.client-ip=90.155.50.34 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="BwVmIbTp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=VA1KlApxh8zgmd9WY7nC8+VHpN+PuUfxe0ZBfHHHypo=; b=BwVmIbTp6mZyP71S+GyKiemLNX m7oagC+6aeS5USJmV3VRBnq9hEXJD3/+anFJmgaGYxYpIDN3BAZArpYql+QUzgTATwNvRrnsn55lr feKu1U1jkl2F7DAtj/Vqrv/kqtE9X1+tSgGfJ35wXRc0N+RPRPFmsgvGoaS0gOyrynWh2RpISl1ye x8xL25rhHc56w/ZIFho7gXSumhSLhLML1rNjpMXfROs2fCU9hLNV8lnzdLhGAb3/4pNPZ2BwfAogr iOnqfc/Sov08uCa+aRD/6yXWGCha88lj0aMV4HWHR/99V6b7HTVnjerO+ZhXl2ZbCZYP4OOJEmETk WcEm1SOQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQXa-0000000EP7Y-3z4z; Mon, 10 Nov 2025 11:58:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 3BA3F3002BE; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.111187573@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:34 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 01/12] x86: Rework __bug_table helpers References: <20251110114633.202485143@infradead.org> 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" Rework the __bug_table helpers such that extension becomes easier. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/bug.h | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -37,39 +37,42 @@ #ifdef CONFIG_GENERIC_BUG =20 #ifdef CONFIG_X86_32 -# define __BUG_REL(val) ".long " val +#define __BUG_REL(val) ".long " val #else -# define __BUG_REL(val) ".long " val " - ." +#define __BUG_REL(val) ".long " val " - ." #endif =20 #ifdef CONFIG_DEBUG_BUGVERBOSE -#define __BUG_ENTRY(file, line, flags) \ - "2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ +#define __BUG_ENTRY_VERBOSE(file, line) \ "\t" __BUG_REL(file) "\t# bug_entry::file\n" \ - "\t.word " line "\t# bug_entry::line\n" \ - "\t.word " flags "\t# bug_entry::flags\n" + "\t.word " line "\t# bug_entry::line\n" #else -#define __BUG_ENTRY(file, line, flags) \ - "2:\t" __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ - "\t.word " flags "\t# bug_entry::flags\n" +#define __BUG_ENTRY_VERBOSE(file, line) #endif =20 +#define __BUG_ENTRY(file, line, flags) \ + __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ + __BUG_ENTRY_VERBOSE(file, line) \ + "\t.word " flags "\t# bug_entry::flags\n" + #define _BUG_FLAGS_ASM(ins, file, line, flags, size, extra) \ "1:\t" ins "\n" \ - ".pushsection __bug_table,\"aw\"\n" \ + ".pushsection __bug_table,\"aw\"\n\t" \ ANNOTATE_DATA_SPECIAL \ + "2:\n\t" \ __BUG_ENTRY(file, line, flags) \ "\t.org 2b + " size "\n" \ ".popsection\n" \ extra =20 -#define _BUG_FLAGS(cond_str, ins, flags, extra) \ -do { \ - asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c0", \ - "%c1", "%c2", "%c3", extra) \ - : : "i" (WARN_CONDITION_STR(cond_str) __FILE__), "i" (__LINE__), \ - "i" (flags), \ - "i" (sizeof(struct bug_entry))); \ +#define _BUG_FLAGS(cond_str, ins, flags, extra) \ +do { \ + asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c0", \ + "%c1", "%c2", "%c3", extra) \ + : : "i" (WARN_CONDITION_STR(cond_str) __FILE__), \ + "i" (__LINE__), \ + "i" (flags), \ + "i" (sizeof(struct bug_entry))); \ } while (0) =20 #define ARCH_WARN_ASM(file, line, flags, size) \ From nobody Fri Dec 19 01:37:41 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 29F6D310629 for ; Mon, 10 Nov 2025 11:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775925; cv=none; b=iYxw1sG3LxOs9/y6yMO6Z4EUWbGSyG49f8XoTPzjS3vitTi48r35bG4qMo9qY/Mjy8uTo3bOTbajoEDP7ejt70TtqVKrZ0N8vYsjvr5smzDPBAx+FcI4Q3t0wqPpf3LazFzmjO7qt8QcKq8jloR3A6FtKyEiYZPOIKGP3T9s02k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775925; c=relaxed/simple; bh=v8zMrrx+Vd9rz29sYzyrTFcl+yNwirp1jzZuIPvgIiA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sPHQNBLt0oSIf5/zCYj6ze+5/OhMTLlkRMpz1hw2g8MDkUUavxCBlnLuDNRFg4elsWp3sLODBMYd0+0Tm1RM4nohfyCfKh3ufo1AgYBH45JsNQkWUaE6lBEwPkEZx3z1k5FgSvUS9qje7QSBRmxOMZIk7Yzo+Zn5/hT2KN3MjxU= 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=D7HJqHTy; arc=none smtp.client-ip=90.155.50.34 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="D7HJqHTy" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=43gEQOf5Sh+lovVXtaC9R0dz67eHKXNxBmPliUUAKWs=; b=D7HJqHTyzxmV97s+/s+Y3vE+Dy 829a9WLcm2j5fR5SXD88l1tSmTEeTs/eyGt9q6l5kTC+Q+DHRdM4Xj4nr0TUQGhIgkrhdNA0c5Vhp jSHGxlPV1B+sr7RYAly9tg/i14qlMukJKl3iFH2j9kMV2x4g7uE8VqMNAJ+ZYYZdcQIIdXJwbKzab xueeK7jAmoXRmeJZCCaPtiiNaaYqZEWS0ClG8YDmVheJ0lfJQ38MZfy1J782CcYbSff8Ywcd7EeGm 1TS2yYwUptxi0H8wWWFpdQnjWOcJWXxUBVKedN1RT1rOpYjqOH8K9THJ341pWEuWgJ0S+cCckHmLv S08usosg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQXa-0000000EP7W-3tkC; Mon, 10 Nov 2025 11:58:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 4092C300323; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.223371452@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:35 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 02/12] bug: Add BUG_FORMAT infrastructure References: <20251110114633.202485143@infradead.org> 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" Add BUG_FORMAT; an architecture opt-in feature that allows adding the WARN_printf() format string to the bug_entry table. Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/bug.h | 7 +++++++ lib/bug.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 7 deletions(-) --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -36,6 +36,13 @@ struct bug_entry { #else signed int bug_addr_disp; #endif +#ifdef HAVE_ARCH_BUG_FORMAT +#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS + const char *format; +#else + signed int format_disp; +#endif +#endif #ifdef CONFIG_DEBUG_BUGVERBOSE #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS const char *file; --- a/lib/bug.c +++ b/lib/bug.c @@ -139,6 +139,19 @@ void bug_get_file_line(struct bug_entry #endif } =20 +static const char *bug_get_format(struct bug_entry *bug) +{ + const char *format =3D NULL; +#ifdef HAVE_ARCH_BUG_FORMAT +#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS + format =3D (const char *)&bug->format_disp + bug->format_disp; +#else + format =3D bug->format; +#endif +#endif + return format; +} + struct bug_entry *find_bug(unsigned long bugaddr) { struct bug_entry *bug; @@ -150,11 +163,19 @@ struct bug_entry *find_bug(unsigned long return module_find_bug(bugaddr); } =20 +static void __warn_printf(const char *fmt) +{ + if (!fmt) + return; + + printk("%s", fmt); +} + static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_re= gs *regs) { - struct bug_entry *bug; - const char *file; - unsigned line, warning, once, done; + bool warning, once, done, no_cut, has_args; + const char *file, *fmt; + unsigned line; =20 if (!is_valid_bugaddr(bugaddr)) return BUG_TRAP_TYPE_NONE; @@ -166,10 +187,12 @@ static enum bug_trap_type __report_bug(u disable_trace_on_warning(); =20 bug_get_file_line(bug, &file, &line); + fmt =3D bug_get_format(bug); =20 - warning =3D (bug->flags & BUGFLAG_WARNING) !=3D 0; - once =3D (bug->flags & BUGFLAG_ONCE) !=3D 0; - done =3D (bug->flags & BUGFLAG_DONE) !=3D 0; + warning =3D bug->flags & BUGFLAG_WARNING; + once =3D bug->flags & BUGFLAG_ONCE; + done =3D bug->flags & BUGFLAG_DONE; + no_cut =3D bug->flags & BUGFLAG_NO_CUT_HERE; =20 if (warning && once) { if (done) @@ -187,8 +210,10 @@ static enum bug_trap_type __report_bug(u * "cut here" line now. WARN() issues its own "cut here" before the * extra debugging message it writes before triggering the handler. */ - if ((bug->flags & BUGFLAG_NO_CUT_HERE) =3D=3D 0) + if (!no_cut) { printk(KERN_DEFAULT CUT_HERE); + __warn_printf(fmt); + } =20 if (warning) { /* this is a WARN_ON rather than BUG/BUG_ON */ From nobody Fri Dec 19 01:37:41 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 48AA63115A1 for ; Mon, 10 Nov 2025 11:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775927; cv=none; b=T2g1UHjrQti1mYJbOpfK/wvZRAKVLpwwbWZhnPruV+clr9SukbCrp6NA14+O2lp6M8RUJFl8aBo4IrstGZwpJ3jO1IguZsh3AjXLzwmebd+7o3xe3jR1WMcVtQW49W1HZX4tNmUTjgbTUSN55RepWWhWlQacTb6UFtt3q7HyjRo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775927; c=relaxed/simple; bh=XHgjdAC2laFSG+IeNK9oonkhCgzlsiBnhP07D4n+jTk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=FDiXN3gownDDhAjG4XvlwsBbYwtos9C7qyTafcFmSJD5CvoAynQAm5HyLVCAmCCETecYjQzPF+0bI6uVB55w0DSyv2gva2BfvQGx3nDxeylEQuxzlkus03jLvYJwz6a1swxBfhm0EG+xffDyJr1cmAoq5VNUFM39MxBCGHnqulE= 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=ldGXshFt; arc=none smtp.client-ip=90.155.50.34 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="ldGXshFt" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=FsgPCWOPtMXCOiGM5hTLthezRlLHddx6RHfFUZthv0I=; b=ldGXshFtWyJ1KOzr3eIISmTFTx xdnkylo0EuCm445bjLZiRWjS5Qm4kP7BEz1nd+jGQzzB01ds/WwNb62BrAMtkgQ7lH/C0jyuSI/70 HAtafu7VltIKkGJMGLGAqWcOoJ9HtISO/lGFnL+loM17DfHioA8yOd3uqN+0CtkAQHQFw5dWt1eW4 NKQ44j7jhJ09I1ZGnk4iGiLg079dEp41wfCfMIh/FjXa4RcwtbekVYPjmX/r53naxiyrxrEqcOYC5 qlMjvV/q3U0V65zvfxnfqI+bc2U8V7Km6Ru4N3R1NIv24wqvsgSoyR9LtOMoTbdPOwuk8jflkaGKY UjZta7JQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQXa-0000000EP7X-3qWt; Mon, 10 Nov 2025 11:58:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 45400300325; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.341703850@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:36 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 03/12] bug: Clean up CONFIG_GENERIC_BUG_RELATIVE_POINTERS References: <20251110114633.202485143@infradead.org> 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" Three repeated CONFIG_GENERIC_BUG_RELATIVE_POINTERS #ifdefs right after one another yields unreadable code. Add a helper. Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/bug.h | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -30,26 +30,20 @@ void __warn(const char *file, int line, =20 #ifdef CONFIG_BUG =20 -#ifdef CONFIG_GENERIC_BUG -struct bug_entry { #ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS - unsigned long bug_addr; +#define BUG_REL(type, name) type name #else - signed int bug_addr_disp; +#define BUG_REL(type, name) signed int name##_disp #endif + +#ifdef CONFIG_GENERIC_BUG +struct bug_entry { + BUG_REL(unsigned long, bug_addr); #ifdef HAVE_ARCH_BUG_FORMAT -#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS - const char *format; -#else - signed int format_disp; -#endif + BUG_REL(const char *, format); #endif #ifdef CONFIG_DEBUG_BUGVERBOSE -#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS - const char *file; -#else - signed int file_disp; -#endif + BUG_REL(const char *, file); unsigned short line; #endif unsigned short flags; From nobody Fri Dec 19 01:37:41 2025 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 7757D30C36F for ; Mon, 10 Nov 2025 11:58:40 +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=1762775921; cv=none; b=jd2bf2b3P1HZNMArA/XeZOAwV3TEjowZFKTW3byOUOmC8WeCfaCK7SwEQydsW/pTdhbqGReOU60SNJkx7o5av2NEoELexeChH9yLFgSqTUnP8nNyF2QbEU4aKxx/0PvqcBN6jYZO4R+oW77yHLy2IyMUUs6l4At4LcqgZzTLmRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775921; c=relaxed/simple; bh=bvzPl/K+tGdRuxnSs4jCh9Mtfh9hDwOZoQ9j5n6ecec=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=fyhImB2Wdyxke3TfkrV74U34H0uE+v8h4Uiu0cPNz6q/4zP9x+F5rRa1UgvPpS70x50dR52hZpkA3a0LCVNcRjwOVAl5RqLSNNy9TPtlp1ecppS+vkHbWQNR18MZAuZtSQ5YaqoULkHL0yEQDBPlEz1oH9Wk2JWnTsTwEuV3uhM= 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=Mk61G/TA; 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="Mk61G/TA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=4BupnHa0sKslSms4QWZa2Ba2ZbtsDMMo1DuTgRU2pls=; b=Mk61G/TA/gq9vZyHHBw+lV3SbQ SAthwTHTzrccA0s2FNwbsmUnPodkbhT+sjqwRf4Oc6C8qrqP3uOnZWXOqiGvjFtW5S8kiU+y+ZZLz fMqudxztpKmYfWguozKAE60r4fBCfSU5MLfTePa8PosFH0a/LV0qffF+xarziUZ0wd92AmZVqWwog qhLo/SaFZ3jiByRYTsZWcBBYJym99kpiQhZi8HuWy2A59V8wbeiJE/K/RFodXZqFo8o1MVBrNszWE lq3iOdkY9I8lnrKrSUaNP/5xPc5vORIQabvhuIDtOLPBPeEexwgvl+/V6QxTc6kNyQrIuZ/sFaKtg 14lcRSZQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIPfv-0000000AZeR-03w5; Mon, 10 Nov 2025 11:03:07 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 49AAC300BD1; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.457339417@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:37 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 04/12] bug: Add BUG_FORMAT_ARGS infrastructure References: <20251110114633.202485143@infradead.org> 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" Add BUG_FORMAT_ARGS; when an architecture is able to provide a va_list given pt_regs, use this to print format arguments. Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/bug.h | 1 + lib/bug.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -13,6 +13,7 @@ #define BUGFLAG_ONCE (1 << 1) #define BUGFLAG_DONE (1 << 2) #define BUGFLAG_NO_CUT_HERE (1 << 3) /* CUT_HERE already sent */ +#define BUGFLAG_ARGS (1 << 4) #define BUGFLAG_TAINT(taint) ((taint) << 8) #define BUG_GET_TAINT(bug) ((bug)->flags >> 8) #endif --- a/lib/bug.c +++ b/lib/bug.c @@ -163,11 +163,23 @@ struct bug_entry *find_bug(unsigned long return module_find_bug(bugaddr); } =20 -static void __warn_printf(const char *fmt) +static void __warn_printf(const char *fmt, struct pt_regs *regs) { if (!fmt) return; =20 +#ifdef HAVE_ARCH_BUG_FORMAT_ARGS + if (regs) { + struct arch_va_list _args; + va_list *args =3D __warn_args(&_args, regs); + + if (args) { + vprintk(fmt, *args); + return; + } + } +#endif + printk("%s", fmt); } =20 @@ -193,6 +205,7 @@ static enum bug_trap_type __report_bug(u once =3D bug->flags & BUGFLAG_ONCE; done =3D bug->flags & BUGFLAG_DONE; no_cut =3D bug->flags & BUGFLAG_NO_CUT_HERE; + has_args =3D bug->flags & BUGFLAG_ARGS; =20 if (warning && once) { if (done) @@ -212,7 +225,7 @@ static enum bug_trap_type __report_bug(u */ if (!no_cut) { printk(KERN_DEFAULT CUT_HERE); - __warn_printf(fmt); + __warn_printf(fmt, has_args ? regs : NULL); } =20 if (warning) { From nobody Fri Dec 19 01:37:41 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 2EFC1310782 for ; Mon, 10 Nov 2025 11:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775926; cv=none; b=PLsGSWLTaRT1665cLS2Od0RqnH5uPzQXCvotsEPS5VY7lJ5xyez//6MbfuK7oW3kYm4APZlYVg3EE3t05UCoFackQFgNAD6ll9BhcMbm+rs5MyMz8SkTmiM3oL84CjnZmFJUNHcbafomthrymYeJCfPNbFGR0nxizDSxsjR1aos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775926; c=relaxed/simple; bh=hygQNXQ+xhB4b9/63ywu2opaPSkxb9cfn8zgZzY10U0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=fEtUHU7pte/gG+t3bE1B9TvTYUrZyjHope68QG5lU/1Y6FIFtClIzLPQnDVaiNt1VEV35Ls8D4OgOuA9FgVdpvfM8L4LE7cHT7qF0s7ppIMb9q3h6AsXNiY6Rh2+FPm6Yzpsw2wbNBtvl4zQ3sxUWyW1Zar6goF2UVdmktzxiYI= 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=XJZD/75H; arc=none smtp.client-ip=90.155.50.34 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="XJZD/75H" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=o64h18BSiLruIN1YC6ldxQoJNaHV4cyR4p9OeFqd4Ag=; b=XJZD/75H/9GlsxrlMmoq1TbpLz gOs9yQjPRRFzvXt295DXIingtUrQ7U35GDIYL1kgYkBGuyyo1ER8fst7SleiodsSEcLmipWiCmchu DNoD6k3u5zpgdU7q3bWTcUyqHDpjEEu7xHwxQG3//BDOCiaTtOAz2oiuoaVjEXN39WeQkwTsV5UBq vbSuPALHsDjYJ/ymBmRKY4Nj1GrswmBRe4KMpGghfBn13S5Mf3bkKYVx26bXA6ynNUs8WcBxyJr7B OQ+ub4tKv5TQA5togF/J78o38KD9PvD5adP71h7NJPPEv1hHsJuh+5cbGurg0w4ju/euYtW8EbrAo tvgRco7w==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQXb-0000000EPAj-2c6a; Mon, 10 Nov 2025 11:58:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 4EC98301185; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.575795595@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:38 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 05/12] bug: Add report_bug_entry() References: <20251110114633.202485143@infradead.org> 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" Add a report_bug() variant where the bug_entry is already known. This is useful when the exception instruction is not instantiated per-site. But instead has a single instance. In such a case the bug_entry address might be passed along in a known register or something. Signed-off-by: Peter Zijlstra (Intel) --- include/linux/bug.h | 1 + lib/bug.c | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -42,6 +42,7 @@ void bug_get_file_line(struct bug_entry struct bug_entry *find_bug(unsigned long bugaddr); =20 enum bug_trap_type report_bug(unsigned long bug_addr, struct pt_regs *regs= ); +enum bug_trap_type report_bug_entry(struct bug_entry *bug, struct pt_regs = *regs); =20 /* These are defined by the architecture */ int is_valid_bugaddr(unsigned long addr); --- a/lib/bug.c +++ b/lib/bug.c @@ -183,18 +183,20 @@ static void __warn_printf(const char *fm printk("%s", fmt); } =20 -static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_re= gs *regs) +static enum bug_trap_type __report_bug(struct bug_entry *bug, unsigned lon= g bugaddr, struct pt_regs *regs) { bool warning, once, done, no_cut, has_args; const char *file, *fmt; unsigned line; =20 - if (!is_valid_bugaddr(bugaddr)) - return BUG_TRAP_TYPE_NONE; - - bug =3D find_bug(bugaddr); - if (!bug) - return BUG_TRAP_TYPE_NONE; + if (!bug) { + if (!is_valid_bugaddr(bugaddr)) + return BUG_TRAP_TYPE_NONE; + + bug =3D find_bug(bugaddr); + if (!bug) + return BUG_TRAP_TYPE_NONE; + } =20 disable_trace_on_warning(); =20 @@ -244,13 +246,25 @@ static enum bug_trap_type __report_bug(u return BUG_TRAP_TYPE_BUG; } =20 +enum bug_trap_type report_bug_entry(struct bug_entry *bug, struct pt_regs = *regs) +{ + enum bug_trap_type ret; + bool rcu =3D false; + + rcu =3D warn_rcu_enter(); + ret =3D __report_bug(bug, 0, regs); + warn_rcu_exit(rcu); + + return ret; +} + enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs) { enum bug_trap_type ret; bool rcu =3D false; =20 rcu =3D warn_rcu_enter(); - ret =3D __report_bug(bugaddr, regs); + ret =3D __report_bug(NULL, bugaddr, regs); warn_rcu_exit(rcu); =20 return ret; From nobody Fri Dec 19 01:37:41 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 29E56310624 for ; Mon, 10 Nov 2025 11:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775925; cv=none; b=u3GFtDZZmXtXBspDcMVo7W8OAK5JJ7O17r1/ZF22lvoFws2iWVD0pptqrUqBhY6aZwlLxyHYnPndxGGvNGkd6YtmwvfEK4ZBo6xyY7TtNMQoinQTHo2QUjSTnKeOl8UxORuw1z0iWwwVU06UDmaRKspomN+tAjfAwAnGfDwhmCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775925; c=relaxed/simple; bh=WtA1JCoGG66vGlW/CyH2TrNoV0lBhThLggqaXOWNdhQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=SjoP7WJGsJkiilTcfqqGiTrGNkalRSWBuHARi6zDAGUXz6YQ6vOgNNyu+VtoHBs83vL1fw2PCtyyAQYeAagt7+u5Qee6FZXQV/0BmSAUghRrN5GihT9OdcooktQB9s5X4COerxhzBkw1i93vpmzcr91o29FJ15Ook8gjdGkIiH8= 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=LTF0bYxW; arc=none smtp.client-ip=90.155.50.34 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="LTF0bYxW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=GIfqOc8Lp2Lf6hr4PQNWDBlZLxdBIQ7Nk6BPMG3El9s=; b=LTF0bYxWBGdjRM1wfxVEFchGxJ ayAG0hfV5Kp048+vgibLoNlWbY+C0NpiIMZOHfPbVFQQ3zuEY7G6RUGqndCeVCSTCwck4VDQLCa3T qLL2Q7isz0vTkSSAbfVI1EH9AiA3/2O3dY7VULMb8x8t3/6EFCZ2J34ThpiO4f/iEfOK3/SLQNt1U n1Lw3OnGabsmRVblCh97SIbfY8E86fUR7MN+J0zRjHyGP1bQIDedAol4btvXGfQXtJDBFzrA0A2Eu sD1kirh31k5sUzz1iFCfTb91bllP5dfcIvUJvt0x1fQKinc96/sKkIvosJz1BlSdETPz5kn6ToTjb o2PQW0Fw==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQXb-0000000EPAn-2iil; Mon, 10 Nov 2025 11:58:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 538EE302E03; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.690999560@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:39 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 06/12] bug: Implement WARN_ON() using __WARN_FLAGS() References: <20251110114633.202485143@infradead.org> 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" This completes 3bc3c9c3ab6d ("bugs/core: Pass down the condition string of WARN_ON_ONCE(cond) warnings to __WARN_FLAGS()") and makes WARN_ON() and WARN_ON_ONCE() behaviour consistent. Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/bug.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -109,19 +109,29 @@ extern __printf(1, 2) void __warn_printk } while (0) #else #define __WARN() __WARN_FLAGS("", BUGFLAG_TAINT(TAINT_WARN)) + #define __WARN_printf(taint, arg...) do { \ instrumentation_begin(); \ __warn_printk(arg); \ __WARN_FLAGS("", BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\ instrumentation_end(); \ } while (0) -#define WARN_ON_ONCE(condition) ({ \ - int __ret_warn_on =3D !!(condition); \ - if (unlikely(__ret_warn_on)) \ - __WARN_FLAGS("["#condition"] ", \ - BUGFLAG_ONCE | \ - BUGFLAG_TAINT(TAINT_WARN)); \ - unlikely(__ret_warn_on); \ + +#define WARN_ON(condition) ({ \ + int __ret_warn_on =3D !!(condition); \ + if (unlikely(__ret_warn_on)) \ + __WARN_FLAGS("["#condition"] ", \ + BUGFLAG_TAINT(TAINT_WARN)); \ + unlikely(__ret_warn_on); \ +}) + +#define WARN_ON_ONCE(condition) ({ \ + int __ret_warn_on =3D !!(condition); \ + if (unlikely(__ret_warn_on)) \ + __WARN_FLAGS("["#condition"] ", \ + BUGFLAG_ONCE | \ + BUGFLAG_TAINT(TAINT_WARN)); \ + unlikely(__ret_warn_on); \ }) #endif From nobody Fri Dec 19 01:37:41 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 29EDA310627 for ; Mon, 10 Nov 2025 11:58:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775925; cv=none; b=G2sRBNXfsLzBpswN2Ni4+1wTf2p/lDlg3/BaePph30BSCL83k2PPydOoDWHfRC6qnYNrHN4j9IOOJ8yQs/DKVZ03Rteqz/suFGKf+u1MTCIm0hBa25538JOHHyj3tQzfXhg4SWlkm9A/2VQzLDNrHJPR2kdzHlUkvACubY6OkSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775925; c=relaxed/simple; bh=y/ROBjRr11C2c2LyZsNZnTDY8QeuGoouvKdG48e3kxw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=TKGuPsTttxK6Pzhllw9ba7tHrNOw1CykiYwY+tgwiefJNmhNygHiQu2LGK8Hlnjyeks0Qh8Uie557WaeR3zrRSSP/5wWYgXMYGuItphaRJnHb76KwNS3/yEyekWmZkEVFGu00s1MBWZOtJi2mKi5dKr/OQF+xLCsONQndk5FFyI= 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=Re/t147S; arc=none smtp.client-ip=90.155.50.34 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="Re/t147S" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=pR5La9IbimsFE5rS0LQqtTCVTAHz0m5FmUgLJFwqOCA=; b=Re/t147SCChaJwCC8YCd32hAxH P8FSeirdy8ol0aUQW78gqe5CgsMFvYeiHfyeC/PLjV5ee8u3IJ6EbUPX/z69wPZV02/UBhFMJ44FU LS3sKgpErFZLDpgXFVVi9sRghJFI92UuIcmv70u3rFYEH7NqPqxZGZT2vGlwWivOcxphRqxgpVSCq K8P6Q/tmd86cEvh0BbiNQJqWm9gcA/rztpg+YuzXByLZTLP9KQI5XpqnR3u2/JvnLvxJ93AniMg0M stV5F7Xg/c5oYOnkjhON/tuXbfwjacS4bkF9gN/+qzrRj2LMFAsUACncKMMofrnGvC4EuURZWzY1R r8TsqZhQ==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQXb-0000000EPAo-2dlo; Mon, 10 Nov 2025 11:58:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 57BE6302FD9; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.807154591@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:40 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 07/12] bug: Allow architectures to provide __WARN_printf() References: <20251110114633.202485143@infradead.org> 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" In addition to providing __WARN_FLAGS(), allow an architecture to also provide __WARN_printf(). Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/bug.h | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -100,23 +100,9 @@ void warn_slowpath_fmt(const char *file, const char *fmt, ...); extern __printf(1, 2) void __warn_printk(const char *fmt, ...); =20 -#ifndef __WARN_FLAGS -#define __WARN() __WARN_printf(TAINT_WARN, NULL) -#define __WARN_printf(taint, arg...) do { \ - instrumentation_begin(); \ - warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \ - instrumentation_end(); \ - } while (0) -#else +#ifdef __WARN_FLAGS #define __WARN() __WARN_FLAGS("", BUGFLAG_TAINT(TAINT_WARN)) =20 -#define __WARN_printf(taint, arg...) do { \ - instrumentation_begin(); \ - __warn_printk(arg); \ - __WARN_FLAGS("", BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\ - instrumentation_end(); \ - } while (0) - #define WARN_ON(condition) ({ \ int __ret_warn_on =3D !!(condition); \ if (unlikely(__ret_warn_on)) \ @@ -135,6 +121,27 @@ extern __printf(1, 2) void __warn_printk }) #endif =20 +#if defined(__WARN_FLAGS) && !defined(__WARN_printf) +#define __WARN_printf(taint, arg...) do { \ + instrumentation_begin(); \ + __warn_printk(arg); \ + __WARN_FLAGS("", BUGFLAG_NO_CUT_HERE | BUGFLAG_TAINT(taint));\ + instrumentation_end(); \ + } while (0) +#endif + +#ifndef __WARN_printf +#define __WARN_printf(taint, arg...) do { \ + instrumentation_begin(); \ + warn_slowpath_fmt(__FILE__, __LINE__, taint, arg); \ + instrumentation_end(); \ + } while (0) +#endif + +#ifndef __WARN +#define __WARN() __WARN_printf(TAINT_WARN, NULL) +#endif + /* used internally by panic.c */ =20 #ifndef WARN_ON From nobody Fri Dec 19 01:37:41 2025 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 D1EF921B918 for ; Mon, 10 Nov 2025 11:58:39 +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=1762775921; cv=none; b=JJSv30k0DAxxhFfLTOxHn+2/ah2t/8VCSvff/YJAvcQOEgcG6xqujDpjwolm5hDYAK3s5Zeksx+i85yRcChYKwN9g635InxWDi0sKNl/rpn4qq5EBeQ/r0lsf2NoCG8YfUO0i3cAtHS4RQ0sOO12X9qp0hW5nVH8gvXSqXpD+w8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775921; c=relaxed/simple; bh=gpUkrpK6WLsk7dAjWEA0Rw7KSK8kJq1N0OJrpJ5CgbY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=h6p1mKv+ucRrx+jpHU14Xi7lBmUWyhCZw2tVR8LGXCYzXciO/OKyLwUFipgIoB7iVhl6H1d0Hn+o2ntsZtElWAUUL38XlTm6vDt9Fffn5yfo4CD1mlECfFCcAwUHhqR1isPyXzqtMofE0bNI+GqLrrMKRNDV6U8jKKi7I7PxyIo= 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=WBtMvl07; 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="WBtMvl07" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=RXB/rxtxG13G057ERTR24i5C8ULS0BJYqSPj5oJfR8g=; b=WBtMvl07213PwHrJ7o3SrWAEuZ lEsSEyjFseCAeik+E/+9O5ZeezfVLl7hgyVaupj3J6BwJddnKSiOjgI/ene3zzuBLuJxd49Twppl8 NpxXoUCt+5e7aGKcrSd/4mlC3uZ0PlvIFtGZjXr53RJWDeiq1BIKroXRDUBOhDwrMIYkHwoeb/h/G br4zNyU5k3xf3zIsE/Cncud8AMPvz4H/Ki2nOso/202dZZH9tBky7hYiK6xUW1Z8WGFZLc69zJwu+ e5Z58koEgqPbrE4BCFBnMWnNRmwMw5DL/TnpXTSP+xIZbiw+JzA+afkS/DJeuhkowWC95zZ6mx2WS QIudPT8Q==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIPfv-0000000AZej-3Idt; Mon, 10 Nov 2025 11:03:08 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 5BC03303004; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115757.980264454@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:41 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 08/12] x86/bug: Add BUG_FORMAT basics References: <20251110114633.202485143@infradead.org> 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" Opt-in to BUG_FORMAT for x86_64, adjust the BUGTABLE helper and for now, just store NULL pointers. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/bug.h | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -50,33 +50,44 @@ #define __BUG_ENTRY_VERBOSE(file, line) #endif =20 -#define __BUG_ENTRY(file, line, flags) \ +#if defined(CONFIG_X86_64) || defined(CONFIG_DEBUG_BUGVERBOSE_DETAILED) +#define HAVE_ARCH_BUG_FORMAT +#define __BUG_ENTRY_FORMAT(format) \ + "\t" __BUG_REL(format) "\t# bug_entry::format\n" +#else +#define __BUG_ENTRY_FORMAT(format) +#endif + +#define __BUG_ENTRY(format, file, line, flags) \ __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ + __BUG_ENTRY_FORMAT(format) \ __BUG_ENTRY_VERBOSE(file, line) \ "\t.word " flags "\t# bug_entry::flags\n" =20 -#define _BUG_FLAGS_ASM(ins, file, line, flags, size, extra) \ +#define _BUG_FLAGS_ASM(ins, format, file, line, flags, size, extra) \ "1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n\t" \ ANNOTATE_DATA_SPECIAL \ "2:\n\t" \ - __BUG_ENTRY(file, line, flags) \ + __BUG_ENTRY(format, file, line, flags) \ "\t.org 2b + " size "\n" \ ".popsection\n" \ extra =20 #define _BUG_FLAGS(cond_str, ins, flags, extra) \ do { \ - asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c0", \ - "%c1", "%c2", "%c3", extra) \ - : : "i" (WARN_CONDITION_STR(cond_str) __FILE__), \ - "i" (__LINE__), \ - "i" (flags), \ - "i" (sizeof(struct bug_entry))); \ + asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c[fmt]", "%c[file]", \ + "%c[line]", "%c[fl]", \ + "%c[size]", extra) \ + : : [fmt] "i" (NULL), \ + [file] "i" (WARN_CONDITION_STR(cond_str) __FILE__), \ + [line] "i" (__LINE__), \ + [fl] "i" (flags), \ + [size] "i" (sizeof(struct bug_entry))); \ } while (0) =20 #define ARCH_WARN_ASM(file, line, flags, size) \ - _BUG_FLAGS_ASM(ASM_UD2, file, line, flags, size, "") + _BUG_FLAGS_ASM(ASM_UD2, "NULL", file, line, flags, size, "") =20 #else From nobody Fri Dec 19 01:37:41 2025 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 2F1793112C9 for ; Mon, 10 Nov 2025 11:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775926; cv=none; b=CyXZJ6zx3kSX1LDp0zWKsAoFZidJn+nwYnuUD/X+5FwlCee6UiAR10d5bw+Mfskl+LGHbpsYD7CIl4Gltuf2ZvVobt3EUt5y7s+2X1KY6QKsP4LVqefkb6SbSWBVnO1QdMF+vM+D6ov3uZIdGKfG2nTVQY8ZPBZAdYe0ir+Nwg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775926; c=relaxed/simple; bh=LP6wuQEXYX4QjbUpdcvxVSBFfEtJ0I/6g9QorY7tuR8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Gej1xsHzu6fPdPW3uLuhRfV+BkCaCNK2FfSZUyA4K4bnMF7i94a1sH2fPS4VZU6QhYZHOn8tj4+3PFcNnytWaCNbiKMrnTKa405kZVtj3K+lVZlN4hTjjG9RWAvTk0cPEG12tcYPXs3CpncWpSTzWtFe5jHtaJEiQ3VKjAiJUWg= 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=qWvIwGa2; arc=none smtp.client-ip=90.155.50.34 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="qWvIwGa2" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=N+AZaDtRc8FPTpKgpo1rqntKZ+vvKgrVjj5UuVMZhVM=; b=qWvIwGa2syYDxURinepOKWa5xA 6cI/cutfJveBXJLWZDszW6ZVAz1EU14MhlohVchYszU3iNHdQ9yjJIZGLZkEjasE4JhrwKpRUy+i3 qpgbhYSxlTuKaJS+UuDgko7U8Rw/itlNOgI7TjH0D1kljHxWbwI/6xgVYRnNK5YajiaVAx+ZAIC2e hDlZUWBGEqaDQ3u1cqNZcbO4XjbN/GSyzRdxsyRHNnf+xFUTLJEzi/U0IBy4gSflt+UuD1UZsljlz PHqyN0pjHqv+Q5H5aC+jWGJi9XVZfkAlWxeT2IyThUepzTpL6vXCQ9NW/gwBVu7HZ6F7ZNQTSlTM2 +Rg0XYAA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIQXb-0000000EPAp-2fVp; Mon, 10 Nov 2025 11:58:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 60365303031; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115758.097401406@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:42 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 09/12] x86/bug: Use BUG_FORMAT for DEBUG_BUGVERBOSE_DETAILED References: <20251110114633.202485143@infradead.org> 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" Since we have an explicit format string, use it for the condition string instead of frobbing it in the file string. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/bug.h | 10 ++++++++-- include/asm-generic/bug.h | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -74,13 +74,19 @@ ".popsection\n" \ extra =20 +#ifdef CONFIG_DEBUG_BUGVERBOSE_DETAILED +#define WARN_CONDITION_STR(cond_str) cond_str +#else +#define WARN_CONDITION_STR(cond_str) NULL +#endif + #define _BUG_FLAGS(cond_str, ins, flags, extra) \ do { \ asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c[fmt]", "%c[file]", \ "%c[line]", "%c[fl]", \ "%c[size]", extra) \ - : : [fmt] "i" (NULL), \ - [file] "i" (WARN_CONDITION_STR(cond_str) __FILE__), \ + : : [fmt] "i" (WARN_CONDITION_STR(cond_str)), \ + [file] "i" (__FILE__), \ [line] "i" (__LINE__), \ [fl] "i" (flags), \ [size] "i" (sizeof(struct bug_entry))); \ --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -18,11 +18,13 @@ #define BUG_GET_TAINT(bug) ((bug)->flags >> 8) #endif =20 +#ifndef WARN_CONDITION_STR #ifdef CONFIG_DEBUG_BUGVERBOSE_DETAILED -# define WARN_CONDITION_STR(cond_str) cond_str +# define WARN_CONDITION_STR(cond_str) "[" cond_str "] " #else # define WARN_CONDITION_STR(cond_str) #endif +#endif /* WARN_CONDITION_STR */ =20 #ifndef __ASSEMBLY__ #include @@ -106,7 +108,7 @@ extern __printf(1, 2) void __warn_printk #define WARN_ON(condition) ({ \ int __ret_warn_on =3D !!(condition); \ if (unlikely(__ret_warn_on)) \ - __WARN_FLAGS("["#condition"] ", \ + __WARN_FLAGS(#condition, \ BUGFLAG_TAINT(TAINT_WARN)); \ unlikely(__ret_warn_on); \ }) @@ -114,7 +116,7 @@ extern __printf(1, 2) void __warn_printk #define WARN_ON_ONCE(condition) ({ \ int __ret_warn_on =3D !!(condition); \ if (unlikely(__ret_warn_on)) \ - __WARN_FLAGS("["#condition"] ", \ + __WARN_FLAGS(#condition, \ BUGFLAG_ONCE | \ BUGFLAG_TAINT(TAINT_WARN)); \ unlikely(__ret_warn_on); \ From nobody Fri Dec 19 01:37:41 2025 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 58BA1309EFF for ; Mon, 10 Nov 2025 11:58:39 +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=1762775921; cv=none; b=ej76z7Snvujq17wX0paKa65R93PErsbvRcD6XAb/UmHfF0alU8HkQwij9ug0z+FfX5a5xFtnmRXvi6P7SEQ/sW94l8xO8n7vW9A2cOA0WsNh9XxioNh6dkLcbjmCW+v/yZpG6IV304qM+R3iIph8birbY3UYuyX4R7vQgGiigLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775921; c=relaxed/simple; bh=/JZxy1HGcM7cgpfx0YBlh4EuElgBFjdyunBC8J8MqeQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=WJ7lrIazBGl3GUjhvuNyTLTZnwzw8OdoMZ8UpH7L0dhyBtBSN9tlxQRv/Y5BpNmxD1L9nIbdh2jZ8F1cvzyqvszVhMQsXQfX0Pn+0WORIkbAS2+eBLUBNXOhK8+2exohQRCZtwJT7CEDP5XJ2I15doYK7sMk0Bzp7/PO23z3V9E= 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=nbOQBLHU; 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="nbOQBLHU" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=MRqwt0l5ljcBnQcjFs/lzNyhQMr3eZJJv7/K6l0LrOg=; b=nbOQBLHUfSEM2w8KoJCtA7jlOE 59q9E5T3ec2q/MVasFGojZznLwjewhDnwwBEEVDuzIpU0OJzmprjwZYrfB3g4jnCAh9Bt50EwZTD2 BOwpmrej9vlY0g/xdHleTezza6T9539DvPGtPlus4Bx6teji1ZHhdHlMyRBKGX3ktvENWsfyazy6m fnR4p24/8laS7od0UbcPYMKsG18vSBFWokwb1PQPktbh/CfuMUIrcQ3qXX/g31Ovk77JOmQW8tWsU +Gr4mbLyy94UKVZAQ8GRaX/lo1959z7vK4M+V/dvyU0FsSg7LJ5ioM0o2FO9NQDev1n+DhJvUWtwf WSHbBfcg==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIPfv-0000000AZek-3Nq2; Mon, 10 Nov 2025 11:03:07 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 64D1A30303E; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115758.213813530@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:43 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 10/12] x86_64/bug: Implement __WARN_printf() References: <20251110114633.202485143@infradead.org> 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 basic idea is to have __WARN_printf() be a vararg function such that the compiler can do the optimal calling convention for us. This function body will be a #UD and then set up a va_list in the exception from pt_regs. But because the trap will be in a called function, the bug_entry must be passed in. Have that be the first argument, with the format tucked away inside the bug_entry. The comments should clarify the real fun details. The big downside is that all WARNs will now show: RIP: 0010:__WARN_trap:+0 One possible solution is to simply discard the top frame when unwinding. A follow up patch takes care of this slightly differently by abusing the x86 static_call implementation. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/entry/entry.S | 8 +++ arch/x86/include/asm/bug.h | 60 +++++++++++++++++++++-- arch/x86/kernel/traps.c | 115 ++++++++++++++++++++++++++++++++++++++++= ----- 3 files changed, 168 insertions(+), 15 deletions(-) --- a/arch/x86/entry/entry.S +++ b/arch/x86/entry/entry.S @@ -32,6 +32,14 @@ SYM_FUNC_END(write_ibpb) /* For KVM */ EXPORT_SYMBOL_GPL(write_ibpb); =20 +SYM_FUNC_START(__WARN_trap) + ANNOTATE_NOENDBR + ANNOTATE_REACHABLE + ud1 (%ecx), %_ASM_ARG1 + RET +SYM_FUNC_END(__WARN_trap) +EXPORT_SYMBOL(__WARN_trap) + .popsection =20 /* --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -31,6 +31,7 @@ #define BUG_UD2 0xfffe #define BUG_UD1 0xfffd #define BUG_UD1_UBSAN 0xfffc +#define BUG_UD1_WARN 0xfffb #define BUG_UDB 0xffd6 #define BUG_LOCK 0xfff0 =20 @@ -58,14 +59,17 @@ #define __BUG_ENTRY_FORMAT(format) #endif =20 +#ifdef CONFIG_X86_64 +#define HAVE_ARCH_BUG_FORMAT_ARGS +#endif + #define __BUG_ENTRY(format, file, line, flags) \ __BUG_REL("1b") "\t# bug_entry::bug_addr\n" \ __BUG_ENTRY_FORMAT(format) \ __BUG_ENTRY_VERBOSE(file, line) \ "\t.word " flags "\t# bug_entry::flags\n" =20 -#define _BUG_FLAGS_ASM(ins, format, file, line, flags, size, extra) \ - "1:\t" ins "\n" \ +#define _BUG_FLAGS_ASM(format, file, line, flags, size, extra) \ ".pushsection __bug_table,\"aw\"\n\t" \ ANNOTATE_DATA_SPECIAL \ "2:\n\t" \ @@ -82,7 +86,8 @@ =20 #define _BUG_FLAGS(cond_str, ins, flags, extra) \ do { \ - asm_inline volatile(_BUG_FLAGS_ASM(ins, "%c[fmt]", "%c[file]", \ + asm_inline volatile("1:\t" ins "\n" \ + _BUG_FLAGS_ASM("%c[fmt]", "%c[file]", \ "%c[line]", "%c[fl]", \ "%c[size]", extra) \ : : [fmt] "i" (WARN_CONDITION_STR(cond_str)), \ @@ -93,7 +98,8 @@ do { \ } while (0) =20 #define ARCH_WARN_ASM(file, line, flags, size) \ - _BUG_FLAGS_ASM(ASM_UD2, "NULL", file, line, flags, size, "") + "1:\t " ASM_UD2 "\n" \ + _BUG_FLAGS_ASM("NULL", file, line, flags, size, "") =20 #else =20 @@ -126,6 +132,52 @@ do { \ instrumentation_end(); \ } while (0) =20 +#ifdef HAVE_ARCH_BUG_FORMAT_ARGS + +#ifndef __ASSEMBLY__ +struct bug_entry; +extern void __WARN_trap(struct bug_entry *bug, ...); + +struct pt_regs; +struct sysv_va_list { /* from AMD64 System V ABI */ + unsigned int gp_offset; + unsigned int fp_offset; + void *overflow_arg_area; + void *reg_save_area; +}; +struct arch_va_list { + unsigned long regs[6]; + struct sysv_va_list args; +}; +extern void *__warn_args(struct arch_va_list *args, struct pt_regs *regs); +#endif /* __ASSEMBLY__ */ + +#define __WARN_bug_entry(flags, format) ({ \ + struct bug_entry *bug; \ + asm_inline volatile("lea (2f)(%%rip), %[addr]\n1:\n" \ + _BUG_FLAGS_ASM("%c[fmt]", "%c[file]", \ + "%c[line]", "%c[fl]", \ + "%c[size]", "") \ + : [addr] "=3Dr" (bug) \ + : [fmt] "i" (format), \ + [file] "i" (__FILE__), \ + [line] "i" (__LINE__), \ + [fl] "i" (flags), \ + [size] "i" (sizeof(struct bug_entry))); \ + bug; }) + +#define __WARN_print_arg(flags, format, arg...) \ +do { \ + int __flags =3D (flags) | BUGFLAG_WARNING | BUGFLAG_ARGS ; \ + __WARN_trap(__WARN_bug_entry(__flags, format), ## arg); \ + asm (""); /* inhibit tail-call optimization */ \ +} while (0) + +#define __WARN_printf(taint, fmt, arg...) \ + __WARN_print_arg(BUGFLAG_TAINT(taint), fmt, ## arg) + +#endif /* HAVE_ARCH_BUG_FORMAT_ARGS */ + #include =20 #endif /* _ASM_X86_BUG_H */ --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -102,25 +102,37 @@ __always_inline int is_valid_bugaddr(uns * UBSan{0}: 67 0f b9 00 ud1 (%eax),%eax * UBSan{10}: 67 0f b9 40 10 ud1 0x10(%eax),%eax * static_call: 0f b9 cc ud1 %esp,%ecx + * __WARN_trap: 67 48 0f b9 39 ud1 (%ecx),%reg * - * Notably UBSAN uses EAX, static_call uses ECX. + * Notable, since __WARN_trap can use all registers, the distinction betwe= en + * UD1 users is through R/M. */ __always_inline int decode_bug(unsigned long addr, s32 *imm, int *len) { unsigned long start =3D addr; + u8 v, reg, rm, rex =3D 0; + int type =3D BUG_UD1; bool lock =3D false; - u8 v; =20 if (addr < TASK_SIZE_MAX) return BUG_NONE; =20 - v =3D *(u8 *)(addr++); - if (v =3D=3D INSN_ASOP) + for (;;) { v =3D *(u8 *)(addr++); + if (v =3D=3D INSN_ASOP) + continue; =20 - if (v =3D=3D INSN_LOCK) { - lock =3D true; - v =3D *(u8 *)(addr++); + if (v =3D=3D INSN_LOCK) { + lock =3D true; + continue; + } + + if ((v & 0xf0) =3D=3D 0x40) { + rex =3D v; + continue; + } + + break; } =20 switch (v) { @@ -156,18 +168,33 @@ __always_inline int decode_bug(unsigned if (X86_MODRM_MOD(v) !=3D 3 && X86_MODRM_RM(v) =3D=3D 4) addr++; /* SIB */ =20 + reg =3D X86_MODRM_REG(v) + 8*!!X86_REX_R(rex); + rm =3D X86_MODRM_RM(v) + 8*!!X86_REX_B(rex); + /* Decode immediate, if present */ switch (X86_MODRM_MOD(v)) { case 0: if (X86_MODRM_RM(v) =3D=3D 5) - addr +=3D 4; /* RIP + disp32 */ + addr +=3D 4; /* RIP + disp32 */ + + if (rm =3D=3D 0) /* (%eax) */ + type =3D BUG_UD1_UBSAN; + + if (rm =3D=3D 1) { /* (%ecx) */ + *imm =3D reg; + type =3D BUG_UD1_WARN; + } break; =20 case 1: *imm =3D *(s8 *)addr; addr +=3D 1; + if (rm =3D=3D 0) /* (%eax) */ + type =3D BUG_UD1_UBSAN; break; =20 case 2: *imm =3D *(s32 *)addr; addr +=3D 4; + if (rm =3D=3D 0) /* (%eax) */ + type =3D BUG_UD1_UBSAN; break; =20 case 3: break; @@ -176,12 +203,73 @@ __always_inline int decode_bug(unsigned /* record instruction length */ *len =3D addr - start; =20 - if (X86_MODRM_REG(v) =3D=3D 0) /* EAX */ - return BUG_UD1_UBSAN; + return type; +} =20 - return BUG_UD1; +static inline unsigned long pt_regs_val(struct pt_regs *regs, int nr) +{ + int offset =3D pt_regs_offset(regs, nr); + if (WARN_ON_ONCE(offset < -0)) + return 0; + return *((unsigned long *)((void *)regs + offset)); } =20 +#ifdef HAVE_ARCH_BUG_FORMAT_ARGS +/* + * Create a va_list from an exception context. + */ +void *__warn_args(struct arch_va_list *args, struct pt_regs *regs) +{ + /* + * Register save area; populate with function call argument registers + */ + args->regs[0] =3D regs->di; + args->regs[1] =3D regs->si; + args->regs[2] =3D regs->dx; + args->regs[3] =3D regs->cx; + args->regs[4] =3D regs->r8; + args->regs[5] =3D regs->r9; + + /* + * From the ABI document: + * + * @gp_offset - the element holds the offset in bytes from + * reg_save_area to the place where the next available general purpose + * argument register is saved. In case all argument registers have + * been exhausted, it is set to the value 48 (6*8). + * + * @fp_offset - the element holds the offset in bytes from + * reg_save_area to the place where the next available floating point + * argument is saved. In case all argument registers have been + * exhausted, it is set to the value 176 (6*8 + 8*16) + * + * @overflow_arg_area - this pointer is used to fetch arguments passed + * on the stack. It is initialized with the address of the first + * argument passed on the stack, if any, and then always updated to + * point to the start of the next argument on the stack. + * + * @reg_save_area - the element points to the start of the register + * save area. + * + * Notably the vararg starts with the second argument and there are no + * floating point arguments in the kernel. + */ + args->args.gp_offset =3D 1*8; + args->args.fp_offset =3D 6*8 + 8*16; + args->args.reg_save_area =3D &args->regs; + args->args.overflow_arg_area =3D (void *)regs->sp; + + /* + * If the exception came from __WARN_trap, there is a return + * address on the stack, skip that. This is why any __WARN_trap() + * caller must inhibit tail-call optimization. + */ + if ((void *)regs->ip =3D=3D &__WARN_trap) + args->args.overflow_arg_area +=3D 8; + + return &args->args; +} +#endif /* HAVE_ARCH_BUG_FORMAT */ =20 static nokprobe_inline int do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str, @@ -334,6 +422,11 @@ static noinstr bool handle_bug(struct pt raw_local_irq_enable(); =20 switch (ud_type) { + case BUG_UD1_WARN: + if (report_bug_entry((void *)pt_regs_val(regs, ud_imm), regs) =3D=3D BUG= _TRAP_TYPE_WARN) + handled =3D true; + break; + case BUG_UD2: if (report_bug(regs->ip, regs) =3D=3D BUG_TRAP_TYPE_WARN) { handled =3D true; From nobody Fri Dec 19 01:37:41 2025 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 ECDB530C37A for ; Mon, 10 Nov 2025 11:58:38 +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=1762775921; cv=none; b=DmqkQ6jd6VsMXzGUwkZcRwvHXJteKkrOmZUMPHrj8HAFxdOtdxzAtP2r7q2nqErI9DGAtzdS6hE4DiFXFSP/PLPPORS5zu86sU79MVXE2L4yMjtzX+o6rHj2wlP659zN1EH8oxiFBZcVpcneL+XgxCBHXjF1ExcILOy0KoQ2grA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775921; c=relaxed/simple; bh=jv50UUcxEyqfqF9uFRD7OvWr/dXultcIfCRsaBDCQUs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=az/ZdkijrvKqMV2NThmbm/U548mMmC0lkkoVzL41z3srl/887XQSKy0TOLfewUiTPROirFMtXpuNsnlsCTXyUsk40Ux0vggqVQudcT37RlfUBuYTzodkoAVxAYzhgJQSFHRoh5XeBiimTKeGuQQccCXd/3owujFofKNHyriENBg= 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=Bwfc+6cg; 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="Bwfc+6cg" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=AunU+fA9b71Eyx5ksFHxLbJWEddIQ60YwA7g3UFMIZ4=; b=Bwfc+6cgG7HrjcyAhv6KFnVS0v NPZ8akbEkyrYXwu5pfknQCeY1T/Nyq5XPLF0143QMwPJuZ5kZ0p8A6aEgHM32FfGHHQX6mycw3/aD u++yWI7MMbxw4lgrEJMjftc/BQMvDLi2x9/ibzEIUtd1yRmcqP4SPKFIybFtu0b+vFA+isb7pnUxW 1g1SF51o1GJIY3zWqW04u+FokT8h2dtkTIOxZM1xD7wpP02KCf9C12AnMgu4nFY97ohb3Cv1hIxgS 73F6JphRBMTh2wbyYewJt5ooWMyfxviCbTr6CR0gmjAXTQbDDk3A0OT2trWLQQ7kcjh6dVtgAULgW AdEV2y6w==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIPfv-0000000AZem-3cAB; Mon, 10 Nov 2025 11:03:08 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 6904F30305C; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115758.339309119@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:44 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 11/12] x86/bug: Implement WARN_ONCE() References: <20251110114633.202485143@infradead.org> 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" Implement WARN_ONCE like WARN using BUGFLAG_ONCE. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/bug.h | 9 +++++++++ include/asm-generic/bug.h | 2 ++ 2 files changed, 11 insertions(+) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -176,6 +176,15 @@ do { \ #define __WARN_printf(taint, fmt, arg...) \ __WARN_print_arg(BUGFLAG_TAINT(taint), fmt, ## arg) =20 +#define WARN_ONCE(cond, format, arg...) ({ \ + int __ret_warn_on =3D !!(cond); \ + if (unlikely(__ret_warn_on)) { \ + __WARN_print_arg(BUGFLAG_ONCE|BUGFLAG_TAINT(TAINT_WARN),\ + format, ## arg); \ + } \ + __ret_warn_on; \ +}) + #endif /* HAVE_ARCH_BUG_FORMAT_ARGS */ =20 #include --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -176,8 +176,10 @@ extern __printf(1, 2) void __warn_printk DO_ONCE_LITE_IF(condition, WARN_ON, 1) #endif =20 +#ifndef WARN_ONCE #define WARN_ONCE(condition, format...) \ DO_ONCE_LITE_IF(condition, WARN, 1, format) +#endif =20 #define WARN_TAINT_ONCE(condition, taint, format...) \ DO_ONCE_LITE_IF(condition, WARN_TAINT, 1, taint, format) From nobody Fri Dec 19 01:37:41 2025 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 D0DD421772A for ; Mon, 10 Nov 2025 11:58:38 +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=1762775921; cv=none; b=ClS47pI0lnugQ1iQGBhCgT0bqcYupXI1wEu4AFHh5jEY+ZWkVR+hPsEZpZzsJDZ/+xxQx+Vexrjz3bt/E+nSimd2CyKwizpT9gZc6VU7mDUEqAVua19QjShQr4VbkEhajpEbWljyS8cPgOObNby2dR2Z9MNhCmY3a9TUZHdw/AA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775921; c=relaxed/simple; bh=8CfEDA79lBcPx7H8WDnvleWLVndNz/te5099TGWHN+E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Oo0I/zMPbU1Dc3r9j5vpPZZQT2GrzJriOopv8tV3xt3KXwrZUzIzwWe6XfnwjmqG7A6ipLQEBrNK6s+pJVbvwsEh6GK2Op+atsvfMe2oJiB4gDHzt/hUJACumGxk61/LfnxQyEJ2FuOYFXb5V0PgxNyWm0QZPKibcYy96nYJ7g0= 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=NYDM4NAv; 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="NYDM4NAv" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=gebqXZYQcid4lUxlN6M8ilOhWjiGcP2qN2BZztNPrlE=; b=NYDM4NAv+d5NFDK287Bxq/SqP5 7oCmpho+K8OJHEP0toBHNsKLMqQVKkFUGlH3Pwg6Ps/+soszw7IYQlGpAlsehfVQdsv2Vzrqz/Bxi rgK5+or3uPjdaUwOZTJUoNONiBJGE6SSS/u9zXnB7W+0HuG7O5BPVnFix5ef6KPQg+zh/mbAqWK1J D2e6POxChOmGaBAQQB9r5+jxy+ZMH442rI/xGuC6pGgQRxrQdJX9AHdcUeLwo+zJai/c2Da8FwUy4 EMYaad5b3DlCpdllw+f211dxlXWndzXWjuRn64cfaCFZEpw9JGdIIE+5jeU1wxhtKxWie8OH/CF67 +xVMw6IA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vIPfv-0000000AZel-3cDm; Mon, 10 Nov 2025 11:03:08 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 6DD26303061; Mon, 10 Nov 2025 12:58:33 +0100 (CET) Message-ID: <20251110115758.456717741@infradead.org> User-Agent: quilt/0.68 Date: Mon, 10 Nov 2025 12:46:45 +0100 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, torvalds@linuxfoundation.org, maciej.wieczor-retman@intel.com Subject: [PATCH v2 12/12] x86_64/bug: Inline the UD1 References: <20251110114633.202485143@infradead.org> 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" (Ab)use the static_call infrastructure to convert all: call __WARN_trap instances into the desired: ud1 (%ecx), %rdi eliminating the CALL/RET, but more importantly, fixing the fact that all WARNs will have: RIP: 0010:__WARN_trap+0 Basically, by making it a static_call trampoline call, objtool will collect the callsites, and then the inline rewrite will hit the special case and replace the code with the magic instruction. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/bug.h | 5 ++++- arch/x86/kernel/static_call.c | 13 +++++++++++-- arch/x86/kernel/traps.c | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -137,9 +137,12 @@ do { \ #ifdef HAVE_ARCH_BUG_FORMAT_ARGS =20 #ifndef __ASSEMBLY__ +#include struct bug_entry; extern void __WARN_trap(struct bug_entry *bug, ...); =20 +DECLARE_STATIC_CALL(WARN_trap, __WARN_trap); + struct pt_regs; struct sysv_va_list { /* from AMD64 System V ABI */ unsigned int gp_offset; @@ -171,7 +174,7 @@ extern void *__warn_args(struct arch_va_ #define __WARN_print_arg(flags, format, arg...) \ do { \ int __flags =3D (flags) | BUGFLAG_WARNING | BUGFLAG_ARGS ; \ - __WARN_trap(__WARN_bug_entry(__flags, format), ## arg); \ + static_call_mod(WARN_trap)(__WARN_bug_entry(__flags, format), ## arg); \ asm (""); /* inhibit tail-call optimization */ \ } while (0) =20 --- a/arch/x86/kernel/static_call.c +++ b/arch/x86/kernel/static_call.c @@ -26,6 +26,11 @@ static const u8 xor5rax[] =3D { 0x2e, 0x2e =20 static const u8 retinsn[] =3D { RET_INSN_OPCODE, 0xcc, 0xcc, 0xcc, 0xcc }; =20 +/* + * ud1 (%ecx),%rdi -- see __WARN_trap() / decode_bug() + */ +static const u8 warninsn[] =3D { 0x67, 0x48, 0x0f, 0xb9, 0x39 }; + static u8 __is_Jcc(u8 *insn) /* Jcc.d32 */ { u8 ret =3D 0; @@ -69,7 +74,10 @@ static void __ref __static_call_transfor emulate =3D code; code =3D &xor5rax; } - + if (func =3D=3D &__WARN_trap) { + emulate =3D code; + code =3D &warninsn; + } break; =20 case NOP: @@ -128,7 +136,8 @@ static void __static_call_validate(u8 *i } else { if (opcode =3D=3D CALL_INSN_OPCODE || !memcmp(insn, x86_nops[5], 5) || - !memcmp(insn, xor5rax, 5)) + !memcmp(insn, xor5rax, 5) || + !memcmp(insn, warninsn, 5)) return; } =20 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -215,6 +216,9 @@ static inline unsigned long pt_regs_val( } =20 #ifdef HAVE_ARCH_BUG_FORMAT_ARGS +DEFINE_STATIC_CALL(WARN_trap, __WARN_trap); +EXPORT_STATIC_CALL_TRAMP(WARN_trap); + /* * Create a va_list from an exception context. */