Re: [PATCH v9 00/22] Enable FRED with KVM VMX
From: David Woodhouse
Date: Thu May 07 2026 - 19:00:41 EST
On Thu, 2026-05-07 at 15:53 +0200, Maciej Wieczor-Retman wrote:
>
> My theory is that after 'int3' call the FRED event is handled elsewhere and %rdi
> is not preserved. So the original version of the assembly looks okay but I was
> thinking that int3 has side effects.
Please could you try the version at
https://git.infradead.org/?p=users/dwmw2/linux.git;a=commitdiff;h=fred
or this incremental patch:
diff --git a/tools/testing/selftests/kvm/x86/int1_fred_test.c b/tools/testing/selftests/kvm/x86/int1_fred_test.c
index 7ffb54b56047..b91600abda62 100644
--- a/tools/testing/selftests/kvm/x86/int1_fred_test.c
+++ b/tools/testing/selftests/kvm/x86/int1_fred_test.c
@@ -74,7 +74,7 @@ static volatile uint64_t fred_ss_value;
static volatile uint64_t fred_saved_rip;
static volatile bool fred_handler_called;
-static void __used fred_handler(struct fred_stack_frame *frame)
+static __attribute__((used)) void fred_handler(struct fred_stack_frame *frame)
{
fred_ss_value = frame->ss;
fred_saved_rip = frame->rip;
@@ -99,8 +99,41 @@ asm(
/* Pad to +256 for ring 0 entry */
".org fred_entrypoint + 256, 0xcc\n"
"fred_entrypoint_kernel:\n"
- "movq %rsp, %rdi\n"
+ /* Save all GPRs — exception must be transparent to interrupted code */
+ "pushq %rax\n"
+ "pushq %rcx\n"
+ "pushq %rdx\n"
+ "pushq %rbx\n"
+ "pushq %rbp\n"
+ "pushq %rsi\n"
+ "pushq %rdi\n"
+ "pushq %r8\n"
+ "pushq %r9\n"
+ "pushq %r10\n"
+ "pushq %r11\n"
+ "pushq %r12\n"
+ "pushq %r13\n"
+ "pushq %r14\n"
+ "pushq %r15\n"
+ /* Pass pointer to FRED stack frame (above our saved regs) */
+ "leaq 120(%rsp), %rdi\n"
"call fred_handler\n"
+ /* Restore all GPRs */
+ "popq %r15\n"
+ "popq %r14\n"
+ "popq %r13\n"
+ "popq %r12\n"
+ "popq %r11\n"
+ "popq %r10\n"
+ "popq %r9\n"
+ "popq %r8\n"
+ "popq %rdi\n"
+ "popq %rsi\n"
+ "popq %rbp\n"
+ "popq %rbx\n"
+ "popq %rdx\n"
+ "popq %rcx\n"
+ "popq %rax\n"
".byte 0xf2, 0x0f, 0x01, 0xca\n" /* ERETS */
".popsection\n"
);
Attachment:
smime.p7s
Description: S/MIME cryptographic signature