From nobody Fri Dec 19 07:41:06 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 5979A20A5F2 for ; Sat, 7 Jun 2025 10:03:40 +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=1749290622; cv=none; b=afJaSZDDSawLiJqCGTdg7tQM0zmZ7HEbeoJ1FdXOASqeURVVeMw2/zpwCBaNeR91g5reuUWQs+v+fJEiDdLeBIUgpwFch+wzgfMCxh87sEHL/QzFFB7TeRK8gbXc5WprNcfkSpmf3anX6bRq2oSEm5imiQoU+gFrbak29aNW2rU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290622; c=relaxed/simple; bh=ZBz5QvEz+12dQjO6oD9ugRiWPAe9RqXA9VqmCk3NIZA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Wvs1oP6vTE8EIVSmGR+JJRu8KIuGZp3/j4khxdN/kRbE8a1ENFRBmYZbwGDnlI+gpgPGkZJ67oyhTCMJqhdYRt6ixNpDrpNqGOP2gOBEvbfTawL4QYmxVR+ExRsdSA7KagAC/5iGoMtYnYW2Ja4WbVi+92YNTJEOqjU8hT05Sxs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=IgbMJ8t/; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="IgbMJ8t/" 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=/BnzbZewuJowStjNBBWDV4qAQq+n+zc+/95pnGIzIL0=; b=IgbMJ8t/Knibv7fPlZsAKW0LCY cnSv4xH7O2tTUWoFoRhDmc+ggXjSRSR6U76yXEL5nO4TgeD5eFwNNJ6lUDr045qcCx2+SJPDObkDd yZGCmapkotYl62WkvpoveKtIFOV/yeM9C6Ahm6QSany8+nQUCWaSclgIjFy3ulCACcZbtfEgMUXHo sHGfjrZxSmW1KYP0zOM0xfnK85QfbbmA6Q1B9NOwuVkCNsM8MSR6wXbDkEHX4XaP4O/no2e3N/Pc6 TVBgIJZqMQuEdwDYkOA1SXjKudRExauG/KTEanCvaT0tvzmg0DL7dH/EuqH+T8kGD2s2SiS047q/I hratTBcA==; 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 1uNqOm-00000006HYM-3w6z; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 55A0B301C9B; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.117023224@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:25 +0200 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 Subject: [PATCH 01/11] x86: Provide assembly __bug_table helpers References: <20250607094224.104791182@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 usage from assembly becomes possible. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/bug.h | 54 ++++++++++++++++++++--------------------= ----- 1 file changed, 24 insertions(+), 30 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -32,46 +32,40 @@ #ifdef CONFIG_GENERIC_BUG =20 #ifdef CONFIG_X86_32 -# define __BUG_REL(val) ".long " __stringify(val) +#define ASM_BUG_REL(val) .long val #else -# define __BUG_REL(val) ".long " __stringify(val) " - ." +#define ASM_BUG_REL(val) .long val - . #endif =20 #ifdef CONFIG_DEBUG_BUGVERBOSE +#define ASM_BUGTABLE_VERBOSE(file, line) \ + ASM_BUG_REL(file) ; \ + .word line +#define ASM_BUGTABLE_VERBOSE_SIZE 6 /* sizeof(file) + sizeof(line) */ +#else +#define ASM_BUGTABLE_VERBOSE(file, line) +#define ASM_BUGTABLE_VERBOSE_SIZE 0 +#endif =20 -#define _BUG_FLAGS(ins, flags, extra) \ -do { \ - asm_inline volatile("1:\t" ins "\n" \ - ".pushsection __bug_table,\"aw\"\n" \ - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ - "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ - "\t.word %c1" "\t# bug_entry::line\n" \ - "\t.word %c2" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c3\n" \ - ".popsection\n" \ - extra \ - : : "i" (__FILE__), "i" (__LINE__), \ - "i" (flags), \ - "i" (sizeof(struct bug_entry))); \ -} while (0) +#define ASM_BUGTABLE_BASE_SIZE 6 /* sizeof(bug_addr) + sizeof(flags) */ =20 -#else /* !CONFIG_DEBUG_BUGVERBOSE */ +#define ASM_BUGTABLE_FLAGS(at, file, line, flags) \ + .pushsection __bug_table, "aw" ; \ + 123: ASM_BUG_REL(at) ; \ + ASM_BUGTABLE_VERBOSE(file, line) ; \ + .word flags ; \ + .org 123b + ASM_BUGTABLE_BASE_SIZE + ASM_BUGTABLE_VERBOSE_SIZE ;\ + .popsection =20 -#define _BUG_FLAGS(ins, flags, extra) \ +#define _BUG_FLAGS(insn, flags, extra) \ do { \ - asm_inline volatile("1:\t" ins "\n" \ - ".pushsection __bug_table,\"aw\"\n" \ - "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ - "\t.word %c0" "\t# bug_entry::flags\n" \ - "\t.org 2b+%c1\n" \ - ".popsection\n" \ - extra \ - : : "i" (flags), \ - "i" (sizeof(struct bug_entry))); \ + asm_inline volatile("1:\t" insn "\n" \ + __stringify(ASM_BUGTABLE_FLAGS(1b, %c[file], %c[line], %c[fl])) "\n" \ + extra \ + : : [file] "i" (__FILE__), [line] "i" (__LINE__), \ + [fl] "i" (flags)); \ } while (0) =20 -#endif /* CONFIG_DEBUG_BUGVERBOSE */ - #else =20 #define _BUG_FLAGS(ins, flags, extra) asm volatile(ins) From nobody Fri Dec 19 07:41:06 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 717A9221D92 for ; Sat, 7 Jun 2025 10:03:45 +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=1749290627; cv=none; b=BwF2yeROch5x+FNC+Ux/wcHFyXDQ6uUhvMuBPJ8Ho8bSWEC/oc3m2wz6gpkR3AQ7xKA8VrFf9jJqAxjcDPqhZS3SlfaKRoCZs/cjg5SDgTwLp5qT2/yydCDnQXtcofouQCgW6AjJIQyWCKxHzwohHgSwWeTM+HvxIn56k7Etad4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290627; c=relaxed/simple; bh=v8zMrrx+Vd9rz29sYzyrTFcl+yNwirp1jzZuIPvgIiA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=B1mXz21dNASSL35Fax9YD1PD+tTAMYC4lUUPFsfHRiUDIVBVr3w3EYvJHpTbJK36qm3OuyaFis7Juon7YbZt+xkWVvGjHWybVnNN4aw0NvYye+vT6kBO1ln55xM6sN43aetHnV8Ws1OuBQ9C6N0UevzTzHcjvlE55Qgzr8MT4lE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=TOGJsj3H; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="TOGJsj3H" 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=43gEQOf5Sh+lovVXtaC9R0dz67eHKXNxBmPliUUAKWs=; b=TOGJsj3H7YZ5jRZHTNAbkry/3a lT23fbL24SYbhDlIBqComY6cRuvcDpue0l8AS95tE3jnHkadKWJ6xBXwmUHlyHH6c7jxPAcMgm+8m uAnN91fhSWXd/gClYm2yIYrCi+umci4ACkWoyoq/vjhCYdjB6u/CY4Kbf4VTyRrVy4vGrY/80NybD thar5WJQna3/eVQjRTCcR56c+VfU/uDMG35tC8c3YDhqlqBRzUyi551sO1r2y1tWHEaGKNMW8aELS n2y1bKy+IY2w8lqnhC0TnECThMaILP66J8NmYPRUF/5phBXiOm9jhCXJOCgfUz3GSJBrFnLw45yyX CdWnFPdg==; 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 1uNqOm-00000001N8k-20SA; Sat, 07 Jun 2025 10:03:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 597AB301CEB; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.242161830@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:26 +0200 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 Subject: [PATCH 02/11] bug: Add BUG_FORMAT infrastructure References: <20250607094224.104791182@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 07:41:06 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 5985A20CCED for ; Sat, 7 Jun 2025 10:03:40 +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=1749290622; cv=none; b=tABm4ZoDpoJ9ZIbJoUR0NjJe08ohshyNSA/AePO6sr7OY27aostDmbTOyKMoufbP/q3QcLYnJeBV0Hd5ILZsLORvu2mr+G/uw/rcjhusn+14t99/oLMe0gQq3B4pdoZ7mPycU7Ijd52ulmBddoNWlnw9eZdY65c+rz1TAd0JLdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290622; c=relaxed/simple; bh=XHgjdAC2laFSG+IeNK9oonkhCgzlsiBnhP07D4n+jTk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=tDyIUtdwnfD3uVOWFdJB4Ba2MXJ8ffTMkH1nisGKf0q67DHLqtsuH04jifiQZHJGKUe3wG2mXvdOzo2oF2JXvAvgiKSqi+V0PrrSkqXdPMHHiY6eXfAKzy+JziJtswRBElZI9AfIFddAX2mCgIN7P9o8fJxMlq3DU9df5euaxpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=E4dZswMr; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="E4dZswMr" 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=E4dZswMr8tfltB9DKc6nvYZWbv ypV+ZKQkoxG3uFbW6w4dVhXYk9mUg5nJpxiZmPzFFGrWcxw3OoZZ6sf4T08yzfDwYvg1IhNYAOgCx KRSKS7pGAWSCIrv1UBYQq1tdFPaEUAiiMciSQgHNdZTOBVLwYxbDXeNPi7R9n73ChILhyMuW3sA0k UwUVVLQlR/7XlpphyHLfTRMXMNd0hE+kqEWBuYJmxb3rTBWxsDH/gB5Bz6H0iDMfSZxQBaeZrJeGt nRQprSBijQvQBjAqbgRML3kHOTdYKLUdXbUvARPekq+toHF1hX8OvGxxelE0rWyw6nIPN/qN1eRTv nEOXrYXw==; 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 1uNqOm-00000006HYO-3zI2; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 5D726302E73; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.351055162@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:27 +0200 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 Subject: [PATCH 03/11] bug: Clean up CONFIG_GENERIC_BUG_RELATIVE_POINTERS References: <20250607094224.104791182@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 07:41:06 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 5990D20E03F for ; Sat, 7 Jun 2025 10:03:40 +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=1749290623; cv=none; b=F2nXu5k6Tg+p3goih+fBNIeDdcXUxk+J1BwO9gx7LV8bQyZUkLMeRSr1hPJXVJ98T2YTF6RFxOMKyy9dfASXHmJlQgmitofdLwE3wFWuCKIPY9Ar/uH/brNKR9VAeDWG256sCE5VwPuel37cic7pbOtTJF4f75Z+JTsYOmebhdo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290623; c=relaxed/simple; bh=bvzPl/K+tGdRuxnSs4jCh9Mtfh9hDwOZoQ9j5n6ecec=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=WwQWqMqxW/8UeVG3CnMAMVAH2b0V28QLXlfdLProa61viefDTpcG0z8+xRVMBx1K8Mtpx9fCdRlxdukjOagvtAJprm31Zg888Lh+Hk6qrpOSdmw2YqJB9GbHLX95I8U9Uy2RX9Q1+5kf07ncUS0tmWR+JCb33JplhGDI+ulx3Ik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=BPDpqhJ7; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="BPDpqhJ7" 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=4BupnHa0sKslSms4QWZa2Ba2ZbtsDMMo1DuTgRU2pls=; b=BPDpqhJ7yPrRavEYrPht5fxYtn X/OEXdDE4zbLO0SrkAhaTV4HzZ8RA38AEGdGlPd6xwmWjdGRn8SmlLcWJCurryAUHJ7OtmW81AhlV c/LiFWANaJXnMz44gynNkdMw+wRrqS34+w2ZtFOFFHPYSjtQ4SoU2x6/dT194jY9MhAvBkDE+QIwp JOx/pxbS0y6np40LWz3BW8OWMMnDDDILTlR9fNerMMbGglwwOGaCoc/ZFk3LkINYwIYcElhmBkbFK Y+y3admdJqkNBz053DVq8GXh+rzn+TVi8hxHs4UK3QJFEOetp3oUWDvgFWLVqQBwLpeW8wiohRlbo oa8WK6eg==; 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 1uNqOm-00000006HYN-3xis; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 61898302E7A; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.472060044@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:28 +0200 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 Subject: [PATCH 04/11] bug: Add BUG_FORMAT_ARGS infrastructure References: <20250607094224.104791182@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 07:41:06 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 6DBE222173F for ; Sat, 7 Jun 2025 10:03:45 +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=1749290627; cv=none; b=avJ0kOEu/z5siaHeXmAWtt9UGG37BSBBCWzavknRwBDS4V+jkJXGEZrRdPbCiZVOzZQ4O6XJMNUmT8uV8CrhJ+rL2E7kNJH3WTA+rlY0zubHVQpCl2HPDXcU3um7pU2VC8GR2WlvF4GM36OOk0HiOUz/UrPU0If8s4yn06zRL60= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290627; c=relaxed/simple; bh=hygQNXQ+xhB4b9/63ywu2opaPSkxb9cfn8zgZzY10U0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VqdasYL9rWIgHTeqhsKESAriqVMQy6DlS9FUZmpoiulwYYUClfYcMPl3Jg9nnYBTwWMsQBqAI8extYvWem1CtoW2OohNElQ5XKQzEQ0ELP0JMjvJdhoKoGWYqssKvVN0VyLt/vftOJ8z5HC0N7DUwjkI/ete7Ddw+rrVFiZTAko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=UNE1h+zY; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="UNE1h+zY" 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=o64h18BSiLruIN1YC6ldxQoJNaHV4cyR4p9OeFqd4Ag=; b=UNE1h+zYQay17U+eDLrvRg+Hcq GwSPa3utMsXnHIuYOz4DZmV4IiSVt667Bk9uV/rg8OXbn7turNtTjXTOIW4zi/xz10r5V/7+1TO5F USAnjMgIWMIH0dthR/h+go7u1dH3x4I3Ek10d3OcU2bJHeU8gltoOfK2MgRTR8dPwanmtnHGysSQo lnobTuuQ63leuZRiPAdlKIszsQ3U+6+tSprcrs5tRyGFPxcaz1hB5QWfo4tyn5epZDJGUpJIYtTIE MnkfAkNMvNVxPgybOirU6b4jHKoEJ9tDJWT4omT+MgJG/84X/uS5WZeGJCnlmmhN2GSbc+nDjleAo O5TRzwGw==; 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 1uNqOn-00000001N8o-1PU9; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 6616F306573; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.584065098@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:29 +0200 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 Subject: [PATCH 05/11] bug: Add report_bug_entry() References: <20250607094224.104791182@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 07:41:06 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 7006E221D8B for ; Sat, 7 Jun 2025 10:03:45 +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=1749290627; cv=none; b=U4L8ryZpnT9Ont6OC1nnseRilsbI2GndOJWH/I+pKRSChYr8y7hr/LdgvzI5LUdSdoz7vsKKvWUstQyct50pNt2wdqn41U43otkWwQxJji6GAORm4KQ2cGBPUPMu4KfzEaQWKpQYUOr4Rd7FiANGr+O99uT1YihhJApEMFCVdHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290627; c=relaxed/simple; bh=AlHC5/BilzjrDcGhznYccIH8XOD7is6M3CUqPr7wpwE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=WJfyo1Ky8sIsaaipNWXBhUklgARPkS5QnYW5lWr5ak88PlsKkMgdkGzp9Laok3mf0sHxL/rJU3SBnw5FVSFiOwzAOC/IsYni9/aTgZjAbYSTUIPl4Qs6VlkAxrSS5Sr19GKTcG0Mq50I5Dh66jJ33C17pHCSXUHhsfFsN4fhjpI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=J2l+xeXN; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="J2l+xeXN" 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=wKrfLqZdE1rdriWF/jTKDOY96xBrQFlV1Ecx9AQ4XD4=; b=J2l+xeXNIS+cTAKejepdqk9hN4 RzI/B6NAB19F5ANezCsfp32t3lpVloq42pZg35hq9w9mR9HkrSuuG3UDs9zAZpNnzhmsZFi3vpSIV EabGzGIap6UB6WMsidhFIreWVdyCtn5rP6Ctmhgy3BjY0DLcZ762yfEC9syTy9FSlcSr8aZ0OHxb1 WRgha67YCsFaUCwkeVJhItbiVCL7dEO7Sa8FMEOD3ZlhYnPl1YuK9bLpFNiKtSGogzAXu6yX+6N4E Qv90NFqWLLim6pl0Gov6iwit63ATepy6MFr4U2WrpqR8Cus53NaB8KrR8ZQCQxMOBCc4cLTLTeGUk R8ue32Cw==; 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 1uNqOn-00000001N8p-1Scs; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 6B0F13080C5; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.693171271@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:30 +0200 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 Subject: [PATCH 06/11] bug: Allow architectures to provide __WARN_printf() References: <20250607094224.104791182@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" Instead of providing __WARN_FLAGS(), allow an architecture to provide __WARN_printf(), which allows for optimizing WARN(), rather than WARN_ON(). Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/bug.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -94,14 +94,7 @@ 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 +#if defined(__WARN_FLAGS) && !defined(__WARN_printf) #define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN)) #define __WARN_printf(taint, arg...) do { \ instrumentation_begin(); \ @@ -118,6 +111,18 @@ extern __printf(1, 2) void __warn_printk }) #endif =20 +#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 07:41:06 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 5973A1FF5F9 for ; Sat, 7 Jun 2025 10:03:40 +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=1749290624; cv=none; b=Y3VbqIezws29wmdk4guS6ZXxgwr+R0UH3kXkvpCzP073O0/pNdyXdloYtraCU/+ELFJOER8kWGUsQ1VlrGYBtnNX6z9cPaZtnMR/gsFIvbz0KbWR0PGQfeeTyPctJImZB4Izs/zpsL+wgIYhGdbI7moWkdDr0e+7cioSqiyWnck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290624; c=relaxed/simple; bh=5sy30kFCGlSsC+wcNavLpzVxQNtjwE3zUA9dFLSA7SU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Nxu95yElERI6Pzt0K/p32ibCEtDfCRm0fx9UFt5yUWM0BvM32jdLRP6x+7j3CO/qjZxhEhRa2Tl9D3vSnildo438MU2qixrrMgCCTHpTmTPtIBIVjUNRamHEgHH/V1NyOipxcTGZlouwncanvWYVrqgmtUzfkcwcOcHYKyqjKRI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=W3KRxsim; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="W3KRxsim" 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=/r3tohHa+5hLiNWumHkrIOwUIWZ21d8ljkkGSu3hNUU=; b=W3KRxsim5sdZGqkN5Q2mHKYjyC n9Omj0k17av+YRV16hwxyr9oNkfoPcQTtsk+4AuU0T9PTtupIVZl0pVW3sRFSqu9xD8sttt6YYD17 ezrylgJ8HotfAP8KWFTNoHoICik1bk5JE6+7Jetm5C7/w5roz9gbB/fZPkXWqzqGvHitJTk82xYIb 1jgYOeqdy9XrRywQbghvFkj1pOqvJDTztDzoridQiXYEMdB8jvxFBKfDAFZvbTF5cPE+Qn132Ty0b /naqWfG650cU+WGw58y4zwSh+rA2NyJ0iXywGk657AAc2ln4dsN7TikRane47eTAQjKFoPbsvu908 cKG6Tffg==; 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 1uNqOm-00000006HYP-3ucD; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 6EA0F3085FC; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.822433827@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:31 +0200 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 Subject: [PATCH 07/11] x86_64/bug: Add BUG_FORMAT basics References: <20250607094224.104791182@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 | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -47,22 +47,35 @@ #define ASM_BUGTABLE_VERBOSE_SIZE 0 #endif =20 +#ifdef CONFIG_X86_64 +#define HAVE_ARCH_BUG_FORMAT +#define ASM_BUGTABLE_FORMAT(format) \ + ASM_BUG_REL(format) +#define ASM_BUGTABLE_FORMAT_SIZE 4 /* sizeof(format) */ +#else +#define ASM_BUGTABLE_FORMAT(format) +#define ASM_BUGTABLE_FORMAT_SIZE 0 +#endif + #define ASM_BUGTABLE_BASE_SIZE 6 /* sizeof(bug_addr) + sizeof(flags) */ =20 -#define ASM_BUGTABLE_FLAGS(at, file, line, flags) \ +#define ASM_BUGTABLE_FLAGS(at, format, file, line, flags) \ .pushsection __bug_table, "aw" ; \ 123: ASM_BUG_REL(at) ; \ + ASM_BUGTABLE_FORMAT(format) ; \ ASM_BUGTABLE_VERBOSE(file, line) ; \ .word flags ; \ - .org 123b + ASM_BUGTABLE_BASE_SIZE + ASM_BUGTABLE_VERBOSE_SIZE ;\ + .org 123b + ASM_BUGTABLE_BASE_SIZE + ASM_BUGTABLE_FORMAT_SIZE + ASM_BUGTA= BLE_VERBOSE_SIZE ; \ .popsection =20 #define _BUG_FLAGS(insn, flags, extra) \ do { \ asm_inline volatile("1:\t" insn "\n" \ - __stringify(ASM_BUGTABLE_FLAGS(1b, %c[file], %c[line], %c[fl])) "\n" \ + __stringify(ASM_BUGTABLE_FLAGS(1b, %c[fmt], %c[file], %c[line], %c[fl= ])) "\n" \ extra \ - : : [file] "i" (__FILE__), [line] "i" (__LINE__), \ + : : [fmt] "i" (NULL), \ + [file] "i" (__FILE__), \ + [line] "i" (__LINE__), \ [fl] "i" (flags)); \ } while (0) From nobody Fri Dec 19 07:41:06 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 72ED6221DA3 for ; Sat, 7 Jun 2025 10:03:45 +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=1749290627; cv=none; b=rJbrbI9/xLnBkyN++yrgYF49QnjytGe035XpXnAVxK9ckXckv0DhUt9p38UVFCpHMrxuP26mQCa8Z/5j0qIYDPn8eThNfW78dNnttB6mVFIr+PHf/zU1s3jCZdZF5FLYWOMMWNEn55b+lttatr8VmaO7zK2/qtD6UQhoyse0dCk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290627; c=relaxed/simple; bh=DYaSQSo8XramTwIg+FgRYvsxuh7ZvjIEVzq0O2S2atw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pChq5VC2kEhMMZYbz1OODEWu+nOCtyKjWLeZkg/0U9ZMCo3ZFNoKbHiC11oD1IchA/Bghh+AGRflj9qTkXtKV0V42y8HYgRbx+H0v+wi2eORoNXmza9jhMBEPVaB2qzYkMi0fG1phoVwcyccQ13gvs7W/vRuEPbigMyloMrMxrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=Vn2avIXp; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="Vn2avIXp" 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=bFVPEi6U0KQyYea2Fk8oEF2pdPqEcV65g1xBZZkCpvo=; b=Vn2avIXp/xUeAyetK/dZ6Y2vG3 6UQV8im+ZY+7r1Fw77QyqG14MIrBB5CUVC9Jysgapge2mAxop9EK4MJun/c0YDe8vTYV8UdcKJmg5 s2JSVmQJ/uNxJJrNAMFIVPLd25y1X26bl1Cv5J2vgnHfxMGZ+5HvPezgyysJbW1vYgRnnoXIe4JT5 4OOp9+cEOEXa3Qw//jnUXJjXydHIIiot3+V7fPPuJHUJfTFfhtwuL6oc3E4Qpok0wXj0HVjmaDfwH YPCLKdPMSFKmKR+h5obj5r6bS3d/lHK3EgDCoFnirKA+Xf1XvOIxw8BPYSu4OHNpid32bI85nK9QS axHnOf1A==; 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 1uNqOn-00000001N8q-1dJZ; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 72AC330860A; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095618.934805791@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:32 +0200 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 Subject: [PATCH 08/11] x86_64/bug: Implement __WARN_printf() References: <20250607094224.104791182@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 This will be adressed in a follow up patch. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/entry/entry.S | 8 +++ arch/x86/include/asm/bug.h | 47 +++++++++++++++++++ arch/x86/kernel/traps.c | 107 ++++++++++++++++++++++++++++++++++++++++= ----- 3 files changed, 152 insertions(+), 10 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 @@ -26,6 +26,7 @@ #define BUG_UD2 0xfffe #define BUG_UD1 0xfffd #define BUG_UD1_UBSAN 0xfffc +#define BUG_UD1_WARN 0xfffb #define BUG_EA 0xffea #define BUG_LOCK 0xfff0 =20 @@ -49,6 +50,7 @@ =20 #ifdef CONFIG_X86_64 #define HAVE_ARCH_BUG_FORMAT +#define HAVE_ARCH_BUG_FORMAT_ARGS #define ASM_BUGTABLE_FORMAT(format) \ ASM_BUG_REL(format) #define ASM_BUGTABLE_FORMAT_SIZE 4 /* sizeof(format) */ @@ -107,6 +109,51 @@ do { \ instrumentation_end(); \ } while (0) =20 +#define __WARN() __WARN_FLAGS(BUGFLAG_TAINT(TAINT_WARN)) + +#ifdef HAVE_ARCH_BUG_FORMAT + +#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(__stringify(ASM_BUGTABLE_FLAGS(1f, %c[fmt], %c[file], %c[line], %c[fl= ])) "\n" \ + "\tlea (123b)(%%rip), %[addr] \n1:\t" \ + : [addr] "=3Dr" (bug) \ + : [fmt] "i" (format), \ + [file] "i" (__FILE__), \ + [line] "i" (__LINE__), \ + [fl] "i" (flags)); \ + 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 */ + #include =20 #endif /* _ASM_X86_BUG_H */ --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -108,19 +108,29 @@ __always_inline int is_valid_bugaddr(uns __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,10 +166,21 @@ __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; @@ -176,12 +197,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 +/* + * 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 +416,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 07:41:06 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 597EF20B808 for ; Sat, 7 Jun 2025 10:03:40 +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=1749290622; cv=none; b=PtsnPAF0PoA5zXQZBK11x7O7YzXPy/t3xatKlX+f2M1E/vy2oF/IaSA7STDTkYdJ53joMszq5Goitz2sbF5FN1WtL70KBOb8mYuvYZ7rpY/GgLwMoohKL2aWmRG78aDBkLW/nPbOBEoo5wT6w5P9vY/KCLVTkmmj6GobAunDkdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290622; c=relaxed/simple; bh=T+JvWQ7WmFVrrgrlaW8MxVqV6Y+CruIRIU2dHq7dkiA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=LqFQ9iGc9+lIPuQSflQ/qQGf1FcDoD1xTEF0VoGHuarGB0l4ls6oJ5yTR5slASgq6WU+tYpq5eT2AYw734Wb53NvwFqMZBjK2YdohQ6YZqAeRdbPYa9cHvfcq48dhmjWtNuDkFQQFwO3Lo3luZhGdQv4H2rWj4BweTLoCcNRw54= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=RQIvIcmE; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="RQIvIcmE" 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=edbwZNaA+PdxQdP5/vR9WRKtGIl8nSjLytqfD3kWk4U=; b=RQIvIcmE4j7lMOw4h1jA5bl8EO f0bynYEarV+Th6B/8KP7dLPM4H+uf+V6l3xslklpc2wOxtae0aB8TnArJ9TDAJ4M1zhctLfhMpCm3 pXkGyo0R6GbmuGXPVMsOzunZYmKkcn9iHEXGzArS2xF6DTXQRQm6rlx5KrEOge4z4ZEfTlj/dcaoR I1/MaGWfBNV4I3SVmaWMlMujUrkKGyxjf2IU3oxsaRfKoQuyVsozqPfx3JZguhmFoXdyQFyB+KUBQ 2xwT/6Br2h5pCSKmZBglB6nwtFkCyBtmLq+NKn/HgMYHQQ4JIL18CP1WY9UMsHh/gwVB2APAwHJa/ x/M2m7NQ==; 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 1uNqOn-00000006HYU-2COt; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 771CE308630; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095619.043649140@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:33 +0200 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 Subject: [PATCH 09/11] x86/bug: Implement WARN_ONCE() References: <20250607094224.104791182@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 | 14 ++++++++++++++ include/asm-generic/bug.h | 2 ++ 2 files changed, 16 insertions(+) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -152,6 +152,20 @@ 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; \ +}) + +/* + * Make sure WARN_ONCE() arguments get expanded before trying to count the= m. + */ +#define WARN_ONCE(cond, format...) __WARN_ONCE(cond, format) + #endif /* HAVE_ARCH_BUG_FORMAT */ =20 #include --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -155,8 +155,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 07:41:06 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 598B420D4E3 for ; Sat, 7 Jun 2025 10:03:40 +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=1749290622; cv=none; b=lTdG+mpvM2l0pAqEAJN3N7uTgFf0tLQAqoYgpLs1Dc1YVkJLQpaTqBucKtILZao18ZWQF10mgaBubIBZuFwEjv7YVA+PHUiEs87U94787u3dnz8s1seJEabthUDskmEznN85N+C4r2B9buOxPQZDSIjWE6Ifl5LpCdCM0a6fk6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290622; c=relaxed/simple; bh=i+OfsPwLoK5azu0EdY+IsK9gunqujhn7UxYgkkXzcKc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=QMEiY+OtzLsfaY60wsTmCkdJKlLxKzEgJX/NOBqZui/EwyJ0P54sjiFmGUuT0Abe+di0crPqir4WCSDioGo8KSJ53dAuyOQRkUBaWb4lufvw53LbEkaS9uwA/4DLv1th52Z0lmKu72LfiT8CSkeGDaqL6W2emt9UvJqfI9GdiK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=kg+8tAMh; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="kg+8tAMh" 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=H5XuaI4M2quwYMvzlGKb3RXWYbNYp0xBI+Jvaliu4Hk=; b=kg+8tAMhRDRepDJJe3NguKC4MA SuAVdrmB2OpQduG/bvgOHAqT23Nc5L1mVeLavVpGAyRsVMJwI+sH4cpGOzQzCbfI9jGr0r6WBeve0 z2NBROlec14JJWCLiPq+PE23iivHFZI7SNU8bpp/OKM6jJEPOEF81HILX0nuE+QsoqDlfVh2waLJa aqOaLBrW1wqqLNn+SXNwl0e99YoTHRzMGAYh5Nn4M38VDRwYksHT7kPsdusxs8Ozh5S23TzUR/Wsf rhvWABdo6bpccauhfBD+B2ReCg6sEQGcFTbVQVgA/3LqkP8W7P+t/0WzOLL0kPdMoq2UBkmIy6w+z +a9/rruA==; 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 1uNqOn-00000006HYV-2HhU; Sat, 07 Jun 2025 10:03:37 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id A14EB308637; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095619.149445852@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:34 +0200 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 Subject: [PATCH 10/11] x86: Clean up default rethunk warning References: <20250607094224.104791182@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" Replace the funny __warn_thunk thing with a more regular WARN_ONCE() and simplify the ifdeffery. Notably this avoids RET from having recursive RETs (once from the thunk and once from the C function) -- recurive RET makes my head hurt for no good reason. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/entry/entry.S | 4 ---- arch/x86/include/asm/nospec-branch.h | 2 -- arch/x86/kernel/cpu/bugs.c | 5 ----- arch/x86/lib/retpoline.S | 22 +++++++++++++++------- 4 files changed, 15 insertions(+), 18 deletions(-) --- a/arch/x86/entry/entry.S +++ b/arch/x86/entry/entry.S @@ -13,8 +13,6 @@ #include #include =20 -#include "calling.h" - .pushsection .noinstr.text, "ax" =20 /* Clobbers AX, CX, DX */ @@ -61,8 +59,6 @@ EXPORT_SYMBOL_GPL(mds_verw_sel); =20 .popsection =20 -THUNK warn_thunk_thunk, __warn_thunk - /* * Clang's implementation of TLS stack cookies requires the variable in * question to be a TLS variable. If the variable happens to be defined as= an --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -386,8 +386,6 @@ extern void clear_bhb_loop(void); =20 extern void (*x86_return_thunk)(void); =20 -extern void __warn_thunk(void); - #ifdef CONFIG_MITIGATION_CALL_DEPTH_TRACKING extern void call_depth_return_thunk(void); =20 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -3415,8 +3415,3 @@ ssize_t cpu_show_indirect_target_selecti return cpu_show_common(dev, attr, buf, X86_BUG_ITS); } #endif - -void __warn_thunk(void) -{ - WARN_ONCE(1, "Unpatched return thunk in use. This should not happen!\n"); -} --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -12,6 +12,7 @@ #include #include #include +#include =20 .section .text..__x86.indirect_thunk =20 @@ -416,6 +417,19 @@ EXPORT_SYMBOL(its_return_thunk) =20 #endif /* CONFIG_MITIGATION_ITS */ =20 + .pushsection .rodata.str1.1 +.Lwarn: + .string "Unpatched return thunk in use.\n" + .popsection + +/* + * Helper that will trip WARN_ONCE() after alternatives have ran. + */ +#define ALT_WARN_RETHUNK \ + ANNOTATE_REACHABLE ; \ + 1: ALTERNATIVE "", "ud2", X86_FEATURE_ALWAYS ; \ + ASM_BUGTABLE_FLAGS(1b, .Lwarn, 0, 0, BUGFLAG_WARNING | BUGFLAG_ONCE ) + /* * This function name is magical and is used by -mfunction-return=3Dthunk-= extern * for the compiler to generate JMPs to it. @@ -432,15 +446,9 @@ EXPORT_SYMBOL(its_return_thunk) SYM_CODE_START(__x86_return_thunk) UNWIND_HINT_FUNC ANNOTATE_NOENDBR -#if defined(CONFIG_MITIGATION_UNRET_ENTRY) || \ - defined(CONFIG_MITIGATION_SRSO) || \ - defined(CONFIG_MITIGATION_CALL_DEPTH_TRACKING) - ALTERNATIVE __stringify(ANNOTATE_UNRET_SAFE; ret), \ - "jmp warn_thunk_thunk", X86_FEATURE_ALWAYS -#else + ALT_WARN_RETHUNK ANNOTATE_UNRET_SAFE ret -#endif int3 SYM_CODE_END(__x86_return_thunk) SYM_PIC_ALIAS(__x86_return_thunk) From nobody Fri Dec 19 07:41:06 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 744E3221DAA for ; Sat, 7 Jun 2025 10:03:45 +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=1749290627; cv=none; b=WKZIv4bbiI+PNZwk2bK7lGUE0fxFIfTEHhvPoiPiYpls281lFJXeVfBoGKPoXSM4S9IOEXGTb7zG7sunYAGr/RM/dBYZOgg+btwAs/xQW9j4OhwU2IyRPPKVmMH1nwfhc3He7hkR3tjfL2G6lOnzcO8lDJ5PEjNQ6GT6dIHcgeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749290627; c=relaxed/simple; bh=pzeXDym4rFlxHjUM6lGvSJYOh9Z77wjccIHNhVRkSls=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=El1y/HZfEhbBGnsrdSzrW3igzXaQokcuZxfKCu4S54ZlnQiu3LWBmRMXOGopgaCpb9RBtj/E3z/k2/eC5KvVymnfj/YL5FnqbjvDr3i+C/HQcVL2A4Z6uKSobijfyjYe+hjOjObuPb+/O5mF3RWCW/5TZQs6RGWXXNAbINQxgBY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (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=P4Uz4zpd; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (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="P4Uz4zpd" 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=Ug06c8Cdy3MYSSIJrDSMvpOcTWe0AbJenyAnmifWbVM=; b=P4Uz4zpdUG6I2yEQwojTqCkehf pHWVxSh5VoaRtoCNQTpiBd16erIzVVsciXQ6pgkOCG6WRE5Zs5SNb4848MJLQPbl8uylj1hP5Eoet 76vk8fpiLqBeRANLDluv8Xvo6hvYn0ooQQw/7D/XLdu+GmmKSYpzqPBBw7aoV3ubpVQroeC7tMqTB bu6YDOn6n7SpIHPTJ0tE/JgGBQG61cuUbP/YCewVUuQrd53p20tUcVLW51wQYLCbm6ht1ZmL4eGpV NASynuCtstkeOAx2pYzME0XiUYxabVKwdnt/u3bwmStmSN503P8y9RKvajyyDVwf5u+wSE/mPlxZy l2MUJBKw==; 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 1uNqOo-00000001N8v-0IKw; Sat, 07 Jun 2025 10:03:38 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id A5E1A308661; Sat, 7 Jun 2025 12:03:35 +0200 (CEST) Message-ID: <20250607095619.270604632@infradead.org> User-Agent: quilt/0.66 Date: Sat, 07 Jun 2025 11:42:35 +0200 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 Subject: [PATCH 11/11] x86_64/bug: Inline the UD1 References: <20250607094224.104791182@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 @@ -114,9 +114,12 @@ do { \ #ifdef HAVE_ARCH_BUG_FORMAT =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; @@ -145,7 +148,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 @@ -209,6 +210,9 @@ static inline unsigned long pt_regs_val( } =20 #ifdef HAVE_ARCH_BUG_FORMAT +DEFINE_STATIC_CALL(WARN_trap, __WARN_trap); +EXPORT_STATIC_CALL_TRAMP(WARN_trap); + /* * Create a va_list from an exception context. */