From mboxrd@z Thu Jan 1 00:00:00 1970 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 6B8FD26ED29 for ; Wed, 26 Nov 2025 09:54:27 +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=1764150871; cv=none; b=KG6IxTvJFaIQ0MtvsIb2feZpV9/5p2teCs1gE0qunFJtSY2H6KbOQwdohpz/D4Cktg5uflItrhjbZUqYYasY0O6wZPkoHsHfYrs4rP0HiHuIHQxt+omqV3FTaVdWZC1zdr2gY+ybF+M1G3KJC9OH+ZmrM2ntCIXRSZapr7gcAy4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764150871; c=relaxed/simple; bh=ULS5K45n2lCto83LlbhwI5K0unU13vZg5l7nSBMQmIw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HrbvbYyGJVLjMjg4W7dSbFkTdkxp5uAZL5bxYhOkkl9txcowj6DnUPhJAP0c9dWy19ACKiVH4+m3+wLPuuz9HISpUAZESvrcfKke52XHH8b/sr6LyvjvY9fnGC729qE2lkE+cQH2Q0ayk2S5MdMlp7Bg9ytw5wlhDxRSufXgfTA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=niHOOLyw; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="niHOOLyw" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=QovzeBejNXTQULxqtGyb3WR5/XJaujLM+J/I6s7YJgA=; b=niHOOLywchXuHGMR6Kn7zlXxiC w0pTk+8/3PLP2Jmlr21+W34f546A76B/osG3jbxhP1CwD50uaQbBvnHZ/e9AYsQ1XzHfDeAyXu8Ek WUEsEy/RmGRdo8uv48qPYnoaNRRF9EgMVvrK/c/PREN76r0OpAerzmtGNgirahAqTx46iQFhWRAAO d77oMs7tjlMuZV6mI38OWdUFjxWFqi/1l0r7F0bObKpMhdbg3xKrspEAZd6oykeAcgIiNFfu4mlhu 8OiEJy01fGb/SnXyHRw5WYo/Fr13WF1CJxyivwq59KnkONR3MvSby43qvY8O6XldGiijKtK5HUMtH CcVJT9gQ==; 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 1vOCE7-00000009uE6-2cny; Wed, 26 Nov 2025 09:54:20 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 32AE330036B; Wed, 26 Nov 2025 10:54:18 +0100 (CET) Date: Wed, 26 Nov 2025 10:54:18 +0100 From: Peter Zijlstra To: Linus Torvalds Cc: x86@kernel.org, ardb@kernel.org, linux-kernel@vger.kernel.org, kees@kernel.org, acarmina@redhat.com, jpoimboe@kernel.org, mark.rutland@arm.com, maciej.wieczor-retman@intel.com Subject: Re: [PATCH v2 08/12] x86/bug: Add BUG_FORMAT basics Message-ID: <20251126095418.GW3245006@noisy.programming.kicks-ass.net> References: <20251110114633.202485143@infradead.org> <20251110115757.980264454@infradead.org> <20251125111750.GS4067720@noisy.programming.kicks-ass.net> <20251125123301.GO4068168@noisy.programming.kicks-ass.net> <20251125151739.GP4068168@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Nov 25, 2025 at 08:27:50AM -0800, Linus Torvalds wrote: > On Tue, 25 Nov 2025 at 07:17, Peter Zijlstra wrote: > > > > Ard came up with this glorious hack :-) > > "glorious". > > Hmm. I _really_ don't love how it now uses that odd label across > macros, it's not screaming "obvious" to me. True. > How bad would it be to just not use a NULL pointer at all, and instead > make the "no format" be "empty format"? Certainly, how does this look? I verified it works on normal C code and that it compiles and the object data looks right for Rust code. --- diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index d0a96ff5c02c..4b5ab56903bb 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -86,7 +86,7 @@ extern void __WARN_trap(struct bug_entry *bug, ...); #ifdef CONFIG_DEBUG_BUGVERBOSE_DETAILED #define WARN_CONDITION_STR(cond_str) cond_str #else -#define WARN_CONDITION_STR(cond_str) NULL +#define WARN_CONDITION_STR(cond_str) "" #endif #define _BUG_FLAGS(cond_str, ins, flags, extra) \ @@ -103,8 +103,12 @@ do { \ } while (0) #define ARCH_WARN_ASM(file, line, flags, size) \ + ".pushsection .rodata.str1.1, \"aMS\", @progbits, 1\n" \ + "99:\n" \ + "\t.string \"\"\n" \ + ".popsection\n" \ "1:\t " ASM_UD2 "\n" \ - _BUG_FLAGS_ASM("0", file, line, flags, size, "") + _BUG_FLAGS_ASM("99b", file, line, flags, size, "") #else diff --git a/lib/bug.c b/lib/bug.c index 581a66b88c5c..edd9041f89f3 100644 --- a/lib/bug.c +++ b/lib/bug.c @@ -144,7 +144,17 @@ static const char *bug_get_format(struct bug_entry *bug) const char *format = NULL; #ifdef HAVE_ARCH_BUG_FORMAT #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS - format = (const char *)&bug->format_disp + bug->format_disp; + /* + * Allow an architecture to: + * - relative encode NULL (difficult vs KASLR); + * - use a literal 0 (there are no valid objects inside + * the __bug_table itself to refer to after all); + * - use an empty string. + */ + if (bug->format_disp) + format = (const char *)&bug->format_disp + bug->format_disp; + if (format && format[0] == '\0') + format = NULL; #else format = bug->format; #endif