Re: [RFC PATCH v2 1/2] selftests/x86: sysret_rip: Handle syscall in a FRED system

From: H. Peter Anvin
Date: Tue Jan 24 2023 - 00:49:10 EST




On 1/23/23 18:27, Ammar Faizi wrote:
From: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>

The current selftest asserts %r11 == %rflags after the 'syscall'
returns to user. Such an assertion doesn't apply to a FRED system
because in a FRED system the 'syscall' instruction does not set
%r11=%rflags and %rcx=%rip.

Handle the FRED case. Now, test that:

- "syscall" in a FRED system doesn't clobber %rcx and %r11.
- "syscall" in a non-FRED system sets %rcx=%rip and %r11=%rflags.

The 'raise()' function from libc can't be used to control those
registers. Therefore, create a syscall wrapper in inline Assembly to
fully control them.

Fixes: 660602140103 ("selftests/x86: Add a selftest for SYSRET to noncanonical addresses")
Link: https://lore.kernel.org/lkml/25b96960-a07e-a952-5c23-786b55054126@xxxxxxxxx
Reported-by: Xin Li <xin3.li@xxxxxxxxx>
Co-developed-by: "H. Peter Anvin" <hpa@xxxxxxxxx>
Signed-off-by: Ammar Faizi <ammarfaizi2@xxxxxxxxxxx>
---

Need hpa's sign off.


For both patches:

Acked-by: H. Peter Anvin (Intel) <hpa@xxxxxxxxx>