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

From: Li, Xin3
Date: Sat Oct 08 2022 - 01:40:59 EST


> > + 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));
> > }
> >
> > #endif /* CONFIG_X86_64 */
> > --
> > 2.34.1
>
> There are not that many call sites, so using something like this (incorporating
> Peter Z's suggestion for the exception handler) would be better from a code
> readability perspective vs. a tiny increase in code size.

The existing approach patches the binary code thus we don't need to check it at runtime.

>
> if (static_cpu_has(X86_FEATURE_LKGS))
> asm volatile("1: " LKGS_DI
> _ASM_EXTABLE_TYPE_REG(1b, 1b, EX_TYPE_ZERO_REG,
> %k[sel])
> : [sel] "+D" (sel) : : "memory");
> else
> asm_load_gs_index(sel);