Re: [PATCH 6/6] x86/gsseg: use the LKGS instruction if available for load_gs_index()

From: Peter Zijlstra
Date: Fri Oct 07 2022 - 10:47:49 EST


On Thu, Oct 06, 2022 at 08:40:41AM -0700, Xin Li wrote:

> static inline void native_load_gs_index(unsigned int selector)
> {
> + u16 sel = selector;
> +
> + /*
> + * Note: the fixup is used for the LKGS instruction, but
> + * it needs to be attached to the primary instruction sequence
> + * as it isn't something that gets patched.
> + *
> + * %rax is provided to the assembly routine as a scratch
> + * register.
> + */
> + alternative_io("1: call asm_load_gs_index\n"
> + ".pushsection \".fixup\",\"ax\"\n"
> + "2: xorl %k[sel], %k[sel]\n"
> + " jmp 1b\n"
> + ".popsection\n"
> + _ASM_EXTABLE(1b, 2b),
> + _ASM_BYTES(0x3e) LKGS_DI,
> + X86_FEATURE_LKGS,
> + ASM_OUTPUT2([sel] "+D" (sel), ASM_CALL_CONSTRAINT),
> + ASM_NO_INPUT_CLOBBER(_ASM_AX));
> }

I'm very sure none of this was tested... the .fixup section hasn't
existed for almost a year now.

e5eefda5aa51 ("x86: Remove .fixup section")