[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251209092419.GD3707837@noisy.programming.kicks-ass.net>
Date: Tue, 9 Dec 2025 10:24:19 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Josh Poimboeuf <jpoimboe@...nel.org>
Cc: x86@...nel.org, linux-kernel@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>,
Ingo Molnar <mingo@...nel.org>, Borislav Petkov <bp@...en8.de>,
Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH 8/8] x86/alternative: Convert alternatives to assembler
macros
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.
Powered by blists - more mailing lists