From nobody Thu Dec 18 14:09:46 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 237DA23A563 for ; Mon, 2 Jun 2025 14:50:43 +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=1748875846; cv=none; b=mnDV6jJ/ueTHZ02kniRygpualPlr//Gg0nC41/gP8xVddhJPBPPXnNfWY3TpxQrdg+hkP/37drwkOOWqbyHwop0gXSZ5QrER00TzuMDyIjIWNNzgyLgzmU0sHK8ZRIdH8QYFGsoyjQ+PArn12PwVFa0X2pU28fcmXUXgWCxeOZc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875846; c=relaxed/simple; bh=ZBz5QvEz+12dQjO6oD9ugRiWPAe9RqXA9VqmCk3NIZA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UlvVoHIG2uC3mrVOVheMlcN4uPRd82B+CAbxFKczRC3lKf6ziIPpNOJC/3+il/sgryeNzcgTxm7Is+uCCkrRkIt2lXV6m6r7ECA+nv6VYdlihHdLYJH8S0SMPbOeCjhN02ZpzTakQ++YKGE81dLD49KyF/9ZjEh8G1oqeAGbTeY= 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=swj7ZRcS; 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="swj7ZRcS" 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=swj7ZRcSogAfSES7mGimNVmXGB Itg/w2bwFsgTDdu/7v/PjuCx/Zs52PAeEyDJ3he2DUoe9Jxy2Z4fVmXxVI1r+RWHH2SqPt4D6FAeY JjszsoueoXJK8O7LtY+jw0dM4BkhhUOBETK6w3QOeWo6y2uoXWdsGFPoUCZcO62sFrQXh7r5LKSFl Y9JOfFtfGx+ViiWM1QLGc4TYVgjwYD05cFMQuTf3Rv1Z6Ck+qWJjwcKN7YCc/Aa27q82Q8x829Kz4 XRR8lvWLr6O1xhx+XHWgURxPYw9uHN45/ad76cgMxrw6NYK4NVn3LIX/01IooKu/1hzdp0N5c6DQc s/pzc4zA==; 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 1uM6Ul-000000011N9-3Q4Y; Mon, 02 Jun 2025 14:50:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 0A63E300F1D; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144755.319275437@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:02 +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: [RFC 1/8] x86: Provide assembly __bug_table helpers References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. 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 Thu Dec 18 14:09:46 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 25B6723A578 for ; Mon, 2 Jun 2025 14:50:43 +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=1748875846; cv=none; b=Jfll/rl1/2MbI5dqpeKUT54kdKAehHpZm9ojj0eXV1ojJiqHhOyEwqwgrSXUcIdlX99Kj5mEmO8YnFXEVsJXX7aBpONK+dDxu450HEORqAr4JoaSu8S/NxxIQac/RF44DptaFpNdhCf2r10gUPSoRWmR5TYoAexoQjYHAqj2B3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875846; c=relaxed/simple; bh=iws5S7pat0zz/LR9v/TjCKdALYQwvsfWLSEuW0M8rMk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=HfPw7HOb3U2RKKuSWYHPsVhNE85EBnxCmYd31jxtaR4XAkDQRpvN6eNNkvjpkyS6DYiWdn4gCfD/Oz3YBHuYUyMUaS5ZLqIIlCcXv/6cqvUxszZo6zJw2Lsdxj5KPsibCx1GZYHReSzd54XT+4tfMbjhgXnmH/nvkFAPgdQbhbc= 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=GRyYtFVj; 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="GRyYtFVj" 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=OStL3zggcD6pgJqSYbkKyooYuBuqpBbUVM9TPqFQoVQ=; b=GRyYtFVjzR/0aeMSUTkAItNGSO AqMTbWVHnZb/4G6d1Wly6LRJC1Jb8+j9M2VCRW/TSvZwFU0YgrBrf2+byK0KygcJ5PtdruXqSdC0c 4HvrPO6mibsbX20DZ0+C0BnarUSwFiypSk0M5gBuLMWf9KeP7nO6S5K+boMJJ0zHqlJGyVeXnodSv 4Cduo1trG9oYXED2lmX+lxi1W/atuwbzGs0Usd9/63uQEqJkE3AqW1lJInKRx7Fl8NtbAX45vRCsa yuPWQqUGIvsZYbd2SntADvBRuwTdjSEu7MWoyi8kth0/mljYO9hX8xo1ApQsgcPP99sLZhbSTZU/w ApbqQxoA==; 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 1uM6Ul-000000011NB-3WpN; Mon, 02 Jun 2025 14:50:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 0E7CF301150; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144755.436183368@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:03 +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: [RFC 2/8] bug: Add BUGFLAG_FORMAT infrastructure References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add BUGFLAG_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 | 8 ++++++++ lib/bug.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) --- 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_FORMAT (1 << 4) #define BUGFLAG_TAINT(taint) ((taint) << 8) #define BUG_GET_TAINT(bug) ((bug)->flags >> 8) #endif @@ -36,6 +37,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,6 +163,10 @@ struct bug_entry *find_bug(unsigned long return module_find_bug(bugaddr); } =20 +#ifndef __warn_printf +#define __warn_printf(...) +#endif + static enum bug_trap_type __report_bug(unsigned long bugaddr, struct pt_re= gs *regs) { struct bug_entry *bug; @@ -190,6 +207,9 @@ static enum bug_trap_type __report_bug(u if ((bug->flags & BUGFLAG_NO_CUT_HERE) =3D=3D 0) printk(KERN_DEFAULT CUT_HERE); =20 + if (bug->flags & BUGFLAG_FORMAT) + __warn_printf(bug_get_format(bug), regs); + if (warning) { /* this is a WARN_ON rather than BUG/BUG_ON */ __warn(file, line, (void *)bugaddr, BUG_GET_TAINT(bug), regs, From nobody Thu Dec 18 14:09:46 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 28ACD23A58B for ; Mon, 2 Jun 2025 14:50:43 +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=1748875845; cv=none; b=WQ6/yvujkhlmGzFKM/hwNeeoAJ5vBya5uzWvdFQjhnb/vY3GE6mMHq8y8FdKdLmoi/37aGuojVAU+nUQr4JN/2alsaXDdi5aMU0/y9Lt5cAcZZnVD0I8IdbFLAvZOmlvR1WXvageKVfPAf7dUMqF4/KtH3zUMlSz3Di+/74Ter0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875845; c=relaxed/simple; bh=XHgjdAC2laFSG+IeNK9oonkhCgzlsiBnhP07D4n+jTk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dmB0yCDdmjfl18K5IW3BEZprg4Za9DRx15fmW2SfvjLfMmmuOQUym+gd2essLR2eFQcTER+kTYBsXS4jnfqtv8XFji1Xs04CzDMkJpB0j4xMtEJVw90VkQq4R8l2qD+wo9k8U3aFcUtRYI65ivnraBGRqX4FDNgjWBPsRyQsoEk= 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=snYhyp0w; 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="snYhyp0w" 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=snYhyp0wRMgcdyeu2g/blxn8kP C70VpnaYjagDZ4mlVRDmLRv+g3q6d8nscaFmo7LO82Z2Hkt0SC/ptWaFB6gBhjOcSkkfFp6v5YOfD 3AEibv8IK0KzfwRx6V4mDy3dkmFBpJPjF9EvyinIQOlIfMn0FSLRAJvxgy5EQhZ+abTqUTsFKffIC XsKedK3h19aX8x7rNZ4HSjtblyM1EyuHJoloLxuByD0PM/RYGqt8RaxfnK70iX0cbQpYuVQEjCtKc vb4wiB/yPHpSNKROAM01HyHQSAUjUUNF1fmWgrT+7y3SgJGic+5awHZCFgUJWRdfSN+nDXy4Cj+XR q/Sohjuw==; 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 1uM6Ul-000000011N8-3VMo; Mon, 02 Jun 2025 14:50:35 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 11EC1301BD5; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144755.587938101@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:04 +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: [RFC 3/8] bug: Clean up CONFIG_GENERIC_BUG_RELATIVE_POINTERS References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. 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 Thu Dec 18 14:09:46 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 2738623A57F for ; Mon, 2 Jun 2025 14:50:43 +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=1748875846; cv=none; b=OwbKS/Xgd0WasNqQ6wKjqQxmz8zhY4aL8brldW7g/kmagV19bliAiPbZkIOxy6lGGD8fVWaWmCJwi55ipHrxcnYXhHgIu6+VgVdfN/MOI1q3G786e5i0I9JHtHKKxXaw4XvvFaX1CaQJo4S80BJhgHcAFuwr5I9KvkPIM7HvYqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875846; c=relaxed/simple; bh=AlHC5/BilzjrDcGhznYccIH8XOD7is6M3CUqPr7wpwE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=A9XJbEcioJTsbo/aHHclutcaBjY02Rv057ZYwV7Qs1k58AkSGJzEpSnbO+4ckRIuVo5a6cjy6NsWR170xOOz8H/jQ35PqCqOj7zkEq24t0bF5oHuwbojm/We2/1lc7QE4ytlYDfxcJTDEp6pjB5tW7Hm9sGTZHU79Ajwx6HwIh0= 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=YU2tRRqw; 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="YU2tRRqw" 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=wKrfLqZdE1rdriWF/jTKDOY96xBrQFlV1Ecx9AQ4XD4=; b=YU2tRRqw3bLM2010C4myNyzJgG q3en+Yt0lnxvHtZl9zh7g9GdXlAK/2xkCmwLVfmTKEZc7/8KEn5tyxMUEpylMwjQNHjdwosAGPgke Mw7NV/RxcWJAnHJpwG9crCDKY5ba0p+JsDKNZlBAaoNpo+IHCPgzDFzqj7bYWKryBJAvdS9JG8r8f D+b3YGzcB3HqGVl0gIcz49ePRNZxAewZFeMnbR/BMemsEVVehvkBXDtu922ABHF7DnjE6h6C2+ok0 7tF8hcScujthX4urqF5qs4sjb+8+EDc0lqjtb5X+rGcrKMQIFGAjawcmfw56w+qcxAyBAY6LbfLrS OV/6RCew==; 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 1uM6Um-000000011NC-0Rvn; Mon, 02 Jun 2025 14:50:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 16161302DF7; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144755.697777039@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:05 +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: [RFC 4/8] bug: Allow architectures to provide __WARN_printf() References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. 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 Thu Dec 18 14:09:46 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 2B78B23184E for ; Mon, 2 Jun 2025 14:50:43 +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=1748875846; cv=none; b=A9TRSXWbdNI0yXJUXL9JejXrzyTELnzz9J8Ty599na74Mg9q+7Mcu0pOAPNnASNB0gqNjICC+Tmyh2VisHGcHC81KwPZHywxAxxWG4WDkt+aH5NtrY0HCVtD8feIzew6WbUZNRxGayVpn1P/Wb68JmGc3U1Si2OcXaU8d/ZZLwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875846; c=relaxed/simple; bh=6kJOAUMsc8HMgjMagf9vgDotplayYfY4AFfDZsHcSmY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=H8NJT0Gr+Cjn7dSzCpdXCQJaJzH+vJK47wxzcfgkS8b4doyQ9Zg6OUmKjv+UGHfGaLrgV/tZ2j18u45ARwwCfFoulO0TOXO8j2xl/zpoY2x0r3OzuwS7qcuA3Ena6klj9oQG5MW+wN1zODauoqydHTbiIhp8S0FTjWk5hQqrRs0= 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=bvSCWL3r; 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="bvSCWL3r" 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=DvFqRm8nJWnpEZYnj31LHs5A6jeWMzNqCfexDa7UTTg=; b=bvSCWL3rbcP/5zrmeJK5+LopSU FX/UoL5CFwgr+ssrNks2ylCATPfZYSGOY7xq/FTvwAnr7fYhx7D5wIvGRYw7yAFdepB4ArYY9Nqr0 fYPfTrEQKR8sn0qIdsEVZF11CmO0V977hop8oOO6Q6yEcGtQVhspdVNNtqSQqk0N7mLCmUYZ9xlHG bRW9uqvwi0x1/+6tchmDI3m4eYrH5K7lHyyDThXY3D7KmElFjX7OLw9KFrCeCCy88404QJueVq9qW MYVWtLU/xY0wO1DNDIrxwTpYoP2umZLSKgfyGaEJRdM6jJWOPb9X1NrH4AyOby7zzC8iSES8nAY4d 8MQI8jng==; 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 1uM6Um-000000011NH-1W48; Mon, 02 Jun 2025 14:50:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 19ADA302E73; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144755.811500537@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:06 +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: [RFC 5/8] x86_64/bug: Add BUG_FORMAT basics References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. 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 | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -31,6 +31,7 @@ =20 #ifdef CONFIG_GENERIC_BUG =20 + #ifdef CONFIG_X86_32 #define ASM_BUG_REL(val) .long val #else @@ -47,22 +48,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 Thu Dec 18 14:09:46 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 68E282397A4 for ; Mon, 2 Jun 2025 14:50: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=1748875842; cv=none; b=F20ShgCTxNZByEvSJ9K7fO2mTpTzvFmnNpb6gv6CfFFyPxWXypJZIn81zdgLf3YOAnujgFE2KWpOAHySGuB1e0dQadyqNsoqvvs3/HD9d1hzAgW6VCkPbiC2R+rEXNrNBAj/3wXQ6j48vLEd3MMIjB8+PgOhN7NczGPaQMRwVPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875842; c=relaxed/simple; bh=9ask0x1MH44A13iKlcXRqwo+ulB6fe24UGpHQIqrNdU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=DlN8YLyiIaW0Vd2tLXwkPcov0hwCz3vpEM3oGck0Qj+mr2Xr0zX2Zi0SUOHSUTD4eJAR7fXyaZbsCZCnLpStAG8grMM2T5gn8+Jh89m4VJjFF80BxgM2TttArg/8cF+KgXXlmN8ChMFlSQkiF2uG3A7fHD9jXBEC7dw6CgkcDBQ= 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=bii+HbPL; 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="bii+HbPL" 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=Fe15PAc1KDj7wmr3V9LXMwmTjRdPDzQD54wLiyeYxnM=; b=bii+HbPLqDiKwg5qU1+KLHq/XH hzdZP8Czy92wrE04cF7aVbOstdaPJDmZ7P4+khI9pByGaDr0BJ7aL7aiXV7M9QHiNEmEwFJhJRrOo 4XYvWqg+EXeGx37QpB4/6WR+6kx4nBIHTwB0ijE4Hcjs/Tl8ceXpA1pw9pam6GFgJaZWWMZt7wE5p dDMsJfkGyoNN1H8nWOT01KdvQvhYuhSInJbmFOy1FYeuwTGZ9WoySHV41BacqU4yq11rHXHFD1lgj sgeZt+FeOyykWkCUFRPYDMGJ7Jj7hSz/JCvxoBlE+oxze9y+7WahFuxwA5nVQaAbiK3/0LDLrwkSM d4dgAarg==; 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 1uM6Um-00000000dlI-24ur; Mon, 02 Jun 2025 14:50:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 1DA1E302E7A; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144755.928750774@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:07 +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: [RFC 6/8] x86_64/bug: Implement __WARN_printf() References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Optimize __WARN_printf() for the common number of arguments. By storing the WARN() format string in the bug_entry, it becomes possible to print this from the exception handler, instead of having to emit a __warn_printf() call before tripping the exception. This yields more compact code, while also providing an opportunity to simplify WARN_ONCE() -- in a future patch. The only 'minor' detail is how to get the printf() arguments into the exception handler. Note that the regular calling convention uses 6 registers to pass arguments (before pushing to the stack) and observe that UD1 has a ModRM byte which can encode two registers. This then suggests using UD1 exceptions for small __WARN_printf() argument numbers, encoding the registers holding the arguments in the UD1 instruction. Except that, when creating a histogram of the number of arguments given to WARN (including WARN_ONCE): defconfig: allyesconfig: 899 __COUNT_printf_3 9694 __COUNT_printf_0 795 __COUNT_printf_2 4498 __COUNT_printf_1 360 __COUNT_printf_0 3213 __COUNT_printf_3 212 __COUNT_printf_1 2949 __COUNT_printf_2 86 __COUNT_printf_4 186 __COUNT_printf_4 37 __COUNT_printf_5 84 __COUNT_printf_5 15 __COUNT_printf_6 50 __COUNT_printf_6 14 __COUNT_printf_7 16 __COUNT_printf_7 3 __COUNT_printf_8 3 __COUNT_printf_8 3 __COUNT_printf_12 3 __COUNT_printf_12 2 __COUNT_printf_9 It becomes clear that supporting 3 arguments is rather critical. This requires encoding 3 registers in an instruction, which calls for some creativity :-) Use the form: UD1 disp8(%ecx), %reg And encode two registers (one per nibble) in the displacement value. Use (%ecx) as base, because UBSAN already uses (%eax) to encode its immediates. This then yields the following encodings: nr args: insn: 0 UD2 1 UD1 (%ecx), %reg 2 UD1 %reg2, %reg1 3 UD1 disp8(%ecx), %reg1 Use the normal COUNT_ARGS() trick to split the variadic WARN() macro into per nr_args sub-marcos, except use a custom mapping such that 4 and above map to another variadic that does the current thing as fallback. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/bug.h | 115 +++++++++++++++++++++++++++++++++++++ arch/x86/kernel/traps.c | 137 ++++++++++++++++++++++++++++++++++++----= ----- 2 files changed, 225 insertions(+), 27 deletions(-) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -5,6 +5,7 @@ #include #include #include +#include =20 /* * Despite that some emulators terminate on UD2, we use it for WARN(). @@ -26,6 +27,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 @@ -108,6 +110,119 @@ do { \ instrumentation_end(); \ } while (0) =20 +#ifdef HAVE_ARCH_BUG_FORMAT + +#ifndef __ASSEMBLER__ +struct pt_regs; +extern void __warn_printf(const char *fmt, struct pt_regs *regs); +#define __warn_printf __warn_printf +#endif + +#define __WARN_printf_0(flags, format) \ +do { \ + __auto_type __flags =3D (flags) | BUGFLAG_WARNING | BUGFLAG_FORMAT; \ + instrumentation_begin(); \ + asm_inline volatile("1: ud2\n" \ + ANNOTATE_REACHABLE(1b) \ + __stringify(ASM_BUGTABLE_FLAGS(1b, %c[fmt], %c[file], %c[line], %c[fl= ])) "\n" \ + : : [file] "i" (__FILE__), [line] "i" (__LINE__), \ + [fl] "i" (__flags), [fmt] "i" (format)); \ + instrumentation_end(); \ +} while (0) + +#define __WARN_printf_1(flags, format, arg1) \ +do { \ + __auto_type __flags =3D (flags) | BUGFLAG_WARNING | BUGFLAG_FORMAT; \ + instrumentation_begin(); \ + asm_inline volatile("1: ud1 (%%ecx), %[a1]\n" \ + ANNOTATE_REACHABLE(1b) \ + __stringify(ASM_BUGTABLE_FLAGS(1b, %c[fmt], %c[file], %c[line], %c[fl= ])) "\n" \ + : : [file] "i" (__FILE__), [line] "i" (__LINE__), \ + [fl] "i" (__flags), [fmt] "i" (format), \ + [a1] "r" ((unsigned long)(arg1))); \ + instrumentation_end(); \ +} while (0) + +#define __WARN_printf_2(flags, format, arg1, arg2) \ +do { \ + __auto_type __flags =3D (flags) | BUGFLAG_WARNING | BUGFLAG_FORMAT; \ + instrumentation_begin(); \ + asm_inline volatile("1: ud1 %[a2], %[a1]\n" \ + ANNOTATE_REACHABLE(1b) \ + __stringify(ASM_BUGTABLE_FLAGS(1b, %c[fmt], %c[file], %c[line], %c[fl= ])) "\n" \ + : : [file] "i" (__FILE__), [line] "i" (__LINE__), \ + [fl] "i" (__flags), [fmt] "i" (format), \ + [a1] "r" ((unsigned long)(arg1)), \ + [a2] "r" ((unsigned long)(arg2))); \ + instrumentation_end(); \ +} while (0) + +/* + * warn_add_reg var reg -- adds the machine register index to var + */ +#define DEFINE_WARN_REG \ + ".macro warn_add_reg var:req reg:req\n" \ + ".set .Lfound, 0\n" \ + ".set .Lregnr, 0\n" \ + ".irp rs,rax,rcx,rdx,rbx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15\n"= \ + ".ifc \\reg, %%\\rs\n" \ + ".set .Lfound, .Lfound+1\n" \ + ".set \\var, \\var + .Lregnr\n" \ + ".endif\n" \ + ".set .Lregnr, .Lregnr+1\n" \ + ".endr\n" \ + ".set .Lregnr, 0\n" \ + ".irp rs,eax,ecx,edx,ebx,esp,ebp,esi,edi,r8d,r9d,r10d,r11d,r12d,r13d,r14d= ,r15d\n" \ + ".ifc \\reg, %%\\rs\n" \ + ".set .Lfound, .Lfound+1\n" \ + ".set \\var, \\var + .Lregnr\n" \ + ".endif\n" \ + ".set .Lregnr, .Lregnr+1\n" \ + ".endr\n" \ + ".if (.Lfound !=3D 1)\n" \ + ".error \"warn_add_reg: bad register argument\"\n" \ + ".endif\n" \ + ".endm\n" + +#define UNDEFINE_WARN_REG \ + ".purgem warn_add_reg\n" + +#define __WARN_printf_3(flags, format, arg1, arg2, arg3) \ +do { \ + __auto_type __flags =3D (flags) | BUGFLAG_WARNING | BUGFLAG_FORMAT; \ + instrumentation_begin(); \ + asm_inline volatile( \ + DEFINE_WARN_REG \ + ".set warn_imm, 0\n" \ + "warn_add_reg warn_imm, %[a3]\n" \ + ".set warn_imm, (warn_imm << 4)\n" \ + "warn_add_reg warn_imm, %[a2]\n" \ + UNDEFINE_WARN_REG \ + "1: ud1 warn_imm(%%ecx),%[a1]\n" \ + ANNOTATE_REACHABLE(1b) \ + __stringify(ASM_BUGTABLE_FLAGS(1b, %c[fmt], %c[file], %c[line], %c[fl]))= "\n" \ + : : [file] "i" (__FILE__), [line] "i" (__LINE__), \ + [fl] "i" (__flags), [fmt] "i" (format), \ + [a1] "r" ((unsigned long)(arg1)), \ + [a2] "r" ((unsigned long)(arg2)), \ + [a3] "r" ((unsigned long)(arg3))); \ + instrumentation_end(); \ +} while (0) + +#define __WARN_printf_n(flags, fmt, arg...) do { \ + instrumentation_begin(); \ + __warn_printk(fmt, arg); \ + __WARN_FLAGS(BUGFLAG_NO_CUT_HERE | (flags)); \ + instrumentation_end(); \ + } while (0) + +#define WARN_ARGS(X...) __COUNT_ARGS(, ##X, n, n, n, n, n, n, n, n, n, n, = n, n, 3, 2, 1, 0) + +#define __WARN_printf(taint, fmt, arg...) \ + CONCATENATE(__WARN_printf_, WARN_ARGS(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 @@ -81,18 +81,6 @@ =20 DECLARE_BITMAP(system_vectors, NR_VECTORS); =20 -__always_inline int is_valid_bugaddr(unsigned long addr) -{ - if (addr < TASK_SIZE_MAX) - return 0; - - /* - * We got #UD, if the text isn't readable we'd have gotten - * a different exception. - */ - return *(unsigned short *)addr =3D=3D INSN_UD2; -} - /* * Check for UD1 or UD2, accounting for Address Size Override Prefixes. * If it's a UD1, further decode to determine its use: @@ -103,24 +91,49 @@ __always_inline int is_valid_bugaddr(uns * UBSan{10}: 67 0f b9 40 10 ud1 0x10(%eax),%eax * static_call: 0f b9 cc ud1 %esp,%ecx * - * Notably UBSAN uses EAX, static_call uses ECX. + * WARN_printf_0: ud2 + * WARN_printf_1: ud1 (%ecx),%reg + * WARN_printf_2: ud1 %reg,%reg + * WARN_printf_3: ud1 0xBA(%ecx),%reg + * + * Notably UBSAN uses (%eax), static_call uses %esp. + * + * @regs will return one register per nibble, typically ModRM reg in the l= ow + * nibble and ModRM rm in the next nibble (including REX bits). In case of= the + * WARN_printf_3 case the 8 bit immediate is used to encode two registers = and + * a total of 3 nibbles will be set. + * + * @imm will return the immediate value encoded in the instruction, or 0. + * + * @len will return the length of the instruction decoded. */ -__always_inline int decode_bug(unsigned long addr, s32 *imm, int *len) +__always_inline int decode_bug(unsigned long addr, u32 *regs, s32 *imm, in= t *len) { unsigned long start =3D addr; + u8 v, rex =3D 0, reg, rm; bool lock =3D false; - u8 v; + int type =3D BUG_UD1; =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++); =20 - if (v =3D=3D INSN_LOCK) { - lock =3D true; - v =3D *(u8 *)(addr++); + if (v =3D=3D INSN_ASOP) + continue; + + if (v =3D=3D INSN_LOCK) { + lock =3D true; + continue; + } + + if ((v & 0xf0) =3D=3D 0x40) { + rex =3D v; + continue; + } + + break; } =20 switch (v) { @@ -141,6 +154,9 @@ __always_inline int decode_bug(unsigned return BUG_NONE; } =20 + *regs =3D 0; + *imm =3D 0; + v =3D *(u8 *)(addr++); if (v =3D=3D SECOND_BYTE_OPCODE_UD2) { *len =3D addr - start; @@ -150,19 +166,33 @@ __always_inline int decode_bug(unsigned if (v !=3D SECOND_BYTE_OPCODE_UD1) return BUG_NONE; =20 - *imm =3D 0; v =3D *(u8 *)(addr++); /* ModRM */ - 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); + *regs =3D (rm << 4) | reg; + /* 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 1) /* CX */ + type =3D BUG_UD1_WARN; break; =20 case 1: *imm =3D *(s8 *)addr; + if (rm =3D=3D 1) { /* CX */ + /* + * The 8bit immediate is used to encode two more + * registers, while the rm value is used to encode + * this is a UD1_WARN. Munge the immediate into the + * regs value such that 3 nibbles are set. + */ + *regs =3D ((*(u8 *)addr) << 4) | reg; + type =3D BUG_UD1_WARN; + } addr +=3D 1; break; =20 @@ -170,18 +200,37 @@ __always_inline int decode_bug(unsigned addr +=3D 4; break; =20 - case 3: break; + case 3: if (rm !=3D 4) /* SP */ + type =3D BUG_UD1_WARN; + break; } =20 /* record instruction length */ *len =3D addr - start; =20 - if (X86_MODRM_REG(v) =3D=3D 0) /* EAX */ + if (!rm && X86_MODRM_MOD(v) !=3D 3) /* (%eax) */ return BUG_UD1_UBSAN; =20 - return BUG_UD1; + return type; } =20 +int is_valid_bugaddr(unsigned long addr) +{ + int ud_type, ud_len; + u32 ud_regs; + s32 ud_imm; + + if (addr < TASK_SIZE_MAX) + return 0; + + /* + * We got #UD, if the text isn't readable we'd have gotten + * a different exception. + */ + ud_type =3D decode_bug(addr, &ud_regs, &ud_imm, &ud_len); + + return ud_type =3D=3D BUG_UD2 || ud_type =3D=3D BUG_UD1_WARN; +} =20 static nokprobe_inline int do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str, @@ -305,14 +354,42 @@ static inline void handle_invalid_op(str ILL_ILLOPN, error_get_trap_addr(regs)); } =20 +#ifdef HAVE_ARCH_BUG_FORMAT +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)); +} + +void __warn_printf(const char *fmt, struct pt_regs *regs) +{ + unsigned long a1, a2, a3; + u32 r =3D regs->orig_ax; + + /* + * @r is the ud_regs value from decode_bug() which will have at most 3 + * registers encoded. Notably printk() will ignore any spurious + * arguments. + */ + a1 =3D pt_regs_val(regs, (r >> 0) & 0xf); + a2 =3D pt_regs_val(regs, (r >> 4) & 0xf); + a3 =3D pt_regs_val(regs, (r >> 8) & 0xf); + + printk(fmt, a1, a2, a3); +} +#endif + static noinstr bool handle_bug(struct pt_regs *regs) { unsigned long addr =3D regs->ip; bool handled =3D false; int ud_type, ud_len; + u32 ud_regs; s32 ud_imm; =20 - ud_type =3D decode_bug(addr, &ud_imm, &ud_len); + ud_type =3D decode_bug(addr, &ud_regs, &ud_imm, &ud_len); if (ud_type =3D=3D BUG_NONE) return handled; =20 @@ -334,7 +411,13 @@ static noinstr bool handle_bug(struct pt raw_local_irq_enable(); =20 switch (ud_type) { + case BUG_UD1_WARN: case BUG_UD2: + /* + * #UD does not have an error code, use orig_ax to pass the ud_regs value + * to __warn_printf(). + */ + regs->orig_ax =3D ud_regs; if (report_bug(regs->ip, regs) =3D=3D BUG_TRAP_TYPE_WARN) { handled =3D true; break; From nobody Thu Dec 18 14:09:46 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 2D26323A98D for ; Mon, 2 Jun 2025 14:50: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=1748875847; cv=none; b=t29j4Qi3TGP26q/UtmYZ+StP3R2z72/mYBZEFNyF6oCq1X7KixujmhzAAcmnLQ7nzbt6wwYrRSKRQhz6Rpse5ezaJQzdGhwdeqf/72BJ+GSRvJK+EtwhX2FYCQzoMs6h7KpbhYgEjRSRRVru2B4EURO+wNH6Gh6LOOxK4o/H4R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875847; c=relaxed/simple; bh=M1wLJ1U2IZQ/RGJmUXq4UWuL9Ig+iV4SJMa9/urbS4Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=YGApS6aBbVZRd4vqdZ2eP5yYjxBNPyG61uqM+aa/R9ZBl5DzG3gd74Dc5F3As254oEZ+l1m1T6ArEy/OOs2umjfh9s/EAOJ0RIeSsrUGma8+MFd6Fx79Nymbn/5cOz7NE4jTXHbHjjqxL6ab74iqQT+obJ/HcniFdCw9JslbTJI= 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=i8+o/+Sk; 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="i8+o/+Sk" 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=KP9pjzaD1fczEPNzXY+jMudoniTkbuwzTKsHu5JGUxM=; b=i8+o/+SkQ7eZP5OV3+dbLM4jGd SPuVnoxfbkAHop3/jqAPfTlzNo24bL2t03Mbphu5r8Df1ZBj8zUptSJSkwm160oEOyazMhmls5ruL L+1DS8CP1UfM0rvnL1kYYkDsNeBZoHKSFj0p6YwB9zVtXpzQEzKNrLP847hCtgzDQufMMKYXt2ExH 4lsM+4uCaRfLdbJKyKJXyboOwsKl4vCSMQMKda+IWIFpQU6fEq7yOR4Ia7jmB/HAiX8hA3V3LfdXB V4cafA/C5byk+zTZQnUHv/d7vyceMVZU5Gh4szBen7BmHrHL+ttIkSUwuxUkoer6ZW12nIL5sv9HW A6Yuxyxg==; 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 1uM6Um-000000011NI-1Sg6; Mon, 02 Jun 2025 14:50:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 20EA7306573; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144756.054408110@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:08 +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: [RFC 7/8] x86/bug: Implement WARN_ONCE() References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. 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 | 28 ++++++++++++++++++++++++++++ include/asm-generic/bug.h | 2 ++ 2 files changed, 30 insertions(+) --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -221,6 +221,34 @@ do { \ #define __WARN_printf(taint, fmt, arg...) \ CONCATENATE(__WARN_printf_, WARN_ARGS(arg))(BUGFLAG_TAINT(taint), fmt, ##= arg) =20 +#define __WONCE_printf_0(flags, format) \ + __WARN_printf_0(flags|BUGFLAG_ONCE, format) + +#define __WONCE_printf_1(flags, format, arg1) \ + __WARN_printf_1(flags|BUGFLAG_ONCE, format, arg1) + +#define __WONCE_printf_2(flags, format, arg1, arg2) \ + __WARN_printf_2(flags|BUGFLAG_ONCE, format, arg1, arg2) + +#define __WONCE_printf_3(flags, format, arg1, arg2, arg3) \ + __WARN_printf_3(flags|BUGFLAG_ONCE, format, arg1, arg2, arg3) + +#define __WONCE_printf_n(flags, format, arg...) \ + if (__ONCE_LITE_IF(true)) __WARN_printf_n(flags, format, arg) + +#define _WARN_ONCE(cond, format, arg...) ({ \ + int __ret_warn_on =3D !!(cond); \ + if (unlikely(__ret_warn_on)) { \ + CONCATENATE(__WONCE_printf_, WARN_ARGS(arg))(0, 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 Thu Dec 18 14:09:46 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 B7E8E239099 for ; Mon, 2 Jun 2025 14:50: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=1748875841; cv=none; b=Nc3YpJ0Gl4JrKWHkBuFXHPiKtwLc1auolD8gJGkMQE73YgTSuHdwL+lv9Tt1BCk0I2yNb3+RYJ/nxMtxD8oc+vX5kSv2YasULo9WEPcrvnPhgwWnnKb+YtrIN4OtH0SN9W9/cAOIrqwEeysfxCAK4Fd3IXpp6PSnrPHuXota1/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748875841; c=relaxed/simple; bh=ArGqYqLAPAwYcAf5/soqdMotxidfgLg0HCKUX+WdmsU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=HdsxkPcygPynWK/vGHybiUScpByyySyVI8UalYxvvKZx8sheAD1KbiV23CElVXsYaR5TovX1KrEU0luvh4xe1lX2mx2/RPn3RMUgyObOUo7vE6YrQE1SvnAXO0eJ8K7r+9+tDgbBNXGzrlzoEuLCi3uHFIwP1kZRYo3JsjemBWw= 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=Rr0vZ+y1; 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="Rr0vZ+y1" 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=69eKPMKauwr5SrpkkD7307Ri6VHkmTkjx6DQ3rxMAyA=; b=Rr0vZ+y154c6de0eVfQK5ZZvnq nkZ+Q98GTYjKZRetaekSAnnJHNGUUN38OTgpS7VBKtpsJUr/zrcEPMvBtVstyp/NLKLYIB/5GiDod OXaitPg0Q+UMDsxU6aJjUS24dMToOpyJHTxE3rwEyAmxvYTftRLv/l0zXsuSSPheQlarwrgKKsq4M DlP12tLjv9cqA3MMw7N266EGWhl8WF+aSJg9A62bp+QviefOLuARJ51b53sMwNaZFjABBTn7fdF9I 1ImeSCqVTX7ShCQqPNcy8PyMZx4vzL6PCQ/OFCMk12O/cyqwcULJOQEfLhyf6IzbLn0GtyXB8M9HC kVahMgLg==; 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 1uM6Um-00000000dlJ-26x5; Mon, 02 Jun 2025 14:50:36 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 0) id 247083080C5; Mon, 2 Jun 2025 16:50:35 +0200 (CEST) Message-ID: <20250602144756.163540221@infradead.org> User-Agent: quilt/0.66 Date: Mon, 02 Jun 2025 16:42:09 +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: [RFC 8/8] x86: Clean up default rethunk warning References: <20250602144201.301974933@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Bad-Reply: References but no 'Re:' in Subject. 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 | 24 +++++++++++++++++------- 4 files changed, 17 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 */ @@ -53,8 +51,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,21 @@ 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 \ + 1: ALTERNATIVE "", "ud2", X86_FEATURE_ALWAYS ; \ + ASM_BUGTABLE_FLAGS(1b, .Lwarn, \ + 0, 0, BUGFLAG_WARNING | \ + BUGFLAG_ONCE | BUGFLAG_FORMAT) ; \ + ANNOTATE_REACHABLE + /* * This function name is magical and is used by -mfunction-return=3Dthunk-= extern * for the compiler to generate JMPs to it. @@ -432,15 +448,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)