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 06E041991CB for ; Tue, 9 Dec 2025 09:24:28 +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=1765272272; cv=none; b=jJvKw53sAn3DCoe9ydrXCfi1Uau7+f2MACQFipY7T5o8lyKSyuzLD8PG5A/7NVUBY5FtKUWAO53imIzy+ZbjJZf8cHf0UNTcxUh4b+ltp9L/0CVRc+4YrGlZ5thBY9gN8gn3TV2ipBGIzKYXpVCtcDcZ2p9WcjYpzPp7e13Bypw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765272272; c=relaxed/simple; bh=ph9f8dO29YvnEuAH0V2X+lx6zJUGNU0efMeJHLFFvKQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FxketV8iK4qwEiYQSKgv3BdNth0PXOs/HPJrEjO35m80aBP1RFlZDxzISSiD7vahO6VdWb3onOQX3MszdH1Ybc9v0bc84MHX7nWSl4mSf1PvGy+XmVk3oapHrB1ubK6mlO+9XWnok4t3jvNLuYeQMnNDrj9cFtepPbrF+qMYorY= 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=v2PAH20Z; 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="v2PAH20Z" 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=ss5cCEW/GPcwGcRtkAzRb3BQQCLRmljpPrFEZvJxDrE=; b=v2PAH20ZwgrJnkqbocsniZYHmi 7jUNDFeI6aWVxAr6On/m1Fj+ZlKEFMPlILsNgiTBmIBs7Q1/eHJzC8GIpGydwcmV70wHeZBLqpO8s J6Dlge3cNeIiICdeukOceI53nA5Jbe6ME6P22H5pkDQATjCZHaGVay4NwrWJXY7jzNbcj9Hd2P1FO tlryy+tMTNPgpNXCGtP0R3vqD2Jw/BQCb5ASPRK7g4gn3ALCJKzueIocUoOxUfeDpZzFwUVrQxQQD GLcm3NpYwGMUhVA8NAJNPqpTimsJMy5doyl93ilOEAqRYf8fnhBZ7AbG7s/sEkGHmiW9qiqsZcmoq mvceOuFw==; 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 1vStxE-0000000B0om-3MkE; Tue, 09 Dec 2025 09:24:20 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 651B63006F2; Tue, 09 Dec 2025 10:24:19 +0100 (CET) Date: Tue, 9 Dec 2025 10:24:19 +0100 From: Peter Zijlstra To: Josh Poimboeuf Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Ingo Molnar , Borislav Petkov , Thomas Gleixner Subject: Re: [PATCH 8/8] x86/alternative: Convert alternatives to assembler macros Message-ID: <20251209092419.GD3707837@noisy.programming.kicks-ass.net> References: <051df5c21cbf6d9ac396c22b3ab3c51d73c0def7.1765044697.git.jpoimboe@kernel.org> <20251208095109.GD3707891@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 Mon, Dec 08, 2025 at 02:46:23PM -0800, Josh Poimboeuf wrote: > On Mon, Dec 08, 2025 at 10:51:09AM +0100, Peter Zijlstra wrote: > > On Sat, Dec 06, 2025 at 01:41:15PM -0800, Josh Poimboeuf wrote: > > > Improve code generation readability by converting the alternatives into > > > assembler macros which are created when alternative.h is included. > > > > > > Before: > > > > > > # ./arch/x86/include/asm/smap.h:47: alternative("", "stac", X86_FEATURE_SMAP); > > > # 47 "./arch/x86/include/asm/smap.h" 1 > > > # ALT: oldinstr > > > 771: > > > > > > 772: > > > # ALT: padding > > > .skip -(((775f-774f)-(772b-771b)) > 0) * ((775f-774f)-(772b-771b)),0x90 > > > 773: > > > .pushsection .altinstructions, "aM", @progbits, 14 > > > .long 771b - . > > > .long 774f - . > > > .4byte ( 9*32+20) > > > .byte 773b-771b > > > .byte 775f-774f > > > .popsection > > > .pushsection .altinstr_replacement, "ax" > > > ANNOTATE_DATA_SPECIAL > > > # ALT: replacement > > > 774: > > > stac > > > 775: > > > .popsection > > > > > > After: > > > > > > # ./arch/x86/include/asm/smap.h:47: alternative("", "stac", X86_FEATURE_SMAP); > > > # 47 "./arch/x86/include/asm/smap.h" 1 > > > ALTERNATIVE "", "stac", "( 9*32+20)" > > > > > > > So the problem with the gas macro thing is that it doesn't allow for > > that nesting. I don't think we currently use it other than to define the > > ALTERNATIVE_2 and ALTERNATIVE_3 macros, but IIRC the reason I started > > all that was because it was fairly trivial to use things like > > CALL_NOSPEC in an alternative (where CALL_NOSPEC is already an > > alternative). > > Trying to wrap my head around this nested alternative thing as I don't > see any current code doing that. Does that only work when the inner > alternative points to the same first original instruction as the outer > one? Or, can you patch anywhere inside the original or replacement? They'd have to be at the exact same location.