Re: [PATCH v2 0/6] x86: Clean up fast syscall return validation

From: Ingo Molnar
Date: Thu Oct 05 2023 - 16:20:55 EST



* Brian Gerst <brgerst@xxxxxxxxx> wrote:

> Looking at the compiled output, the only suboptimal code appears to be
> the canonical address test, where the C code uses the CL register for
> the shifts instead of immediates.
>
> 180: e9 00 00 00 00 jmp 185 <do_syscall_64+0x85>
> 181: R_X86_64_PC32 .altinstr_aux-0x4
> 185: b9 07 00 00 00 mov $0x7,%ecx
> 18a: eb 05 jmp 191 <do_syscall_64+0x91>
> 18c: b9 10 00 00 00 mov $0x10,%ecx
> 191: 48 89 c2 mov %rax,%rdx
> 194: 48 d3 e2 shl %cl,%rdx
> 197: 48 d3 fa sar %cl,%rdx
> 19a: 48 39 d0 cmp %rdx,%rax
> 19d: 75 39 jne 1d8 <do_syscall_64+0xd8>

Yeah, it didn't look equivalent - so I guess we want a C equivalent for:

- ALTERNATIVE "shl $(64 - 48), %rcx; sar $(64 - 48), %rcx", \
- "shl $(64 - 57), %rcx; sar $(64 - 57), %rcx", X86_FEATURE_LA57

instead of the pgtable_l5_enabled() runtime test that
__is_canonical_address() uses?

Thanks,

Ingo