Re: [PATCH 22/23] x86/nospec: Refactor UNTRAIN_RET[_*]

From: Josh Poimboeuf
Date: Sat Aug 26 2023 - 11:42:43 EST


On Fri, Aug 25, 2023 at 09:22:10PM +0300, Nikolay Borisov wrote:
>
>
> On 25.08.23 г. 10:01 ч., Josh Poimboeuf wrote:
> > Factor out the UNTRAIN_RET[_*] common bits into a helper macro.
> >
> > Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> > ---
> > arch/x86/include/asm/nospec-branch.h | 31 +++++++++-------------------
> > 1 file changed, 10 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
> > index 51e3f1a287d2..dcc78477a38d 100644
> > --- a/arch/x86/include/asm/nospec-branch.h
> > +++ b/arch/x86/include/asm/nospec-branch.h
> > @@ -288,35 +288,24 @@
> > * As such, this must be placed after every *SWITCH_TO_KERNEL_CR3 at a point
> > * where we have a stack but before any RET instruction.
> > */
> > -.macro UNTRAIN_RET
> > +.macro __UNTRAIN_RET ibpb_feature, call_depth_insns
> > #if defined(CONFIG_RETHUNK) || defined(CONFIG_CPU_IBPB_ENTRY)
> > VALIDATE_UNRET_END
> > ALTERNATIVE_3 "", \
> > CALL_UNTRAIN_RET, X86_FEATURE_UNRET, \
> > - "call entry_ibpb", X86_FEATURE_ENTRY_IBPB, \
> > - __stringify(RESET_CALL_DEPTH), X86_FEATURE_CALL_DEPTH
> > + "call entry_ibpb", \ibpb_feature, \
> > + __stringify(\call_depth_insns), X86_FEATURE_CALL_DEPTH
>
> so this becomes __stringify(__stringify(RESET_CALL_DEPTH)) etc.

Apparently the gas macro un-stringifies the argument when using it, so
it needs to be re-stringified again. ¯\_(ツ)_/¯

--
Josh