On Wed, Aug 31, 2022, Isaku Yamahata wrote:
Sometimes compiler (my gcc is (Ubuntu 11.1.0-1ubuntu1~20.04) 11.1.0) doesn't like clobering the frame pointer as follows. (I edited the caller site for other test.)
x86_64/tdx_vm_tests.c:343:1: error: bp cannot be used in ‘asm’ here
I ended up the following workaround. I didn't use pushq/popq pair because I didn't want to play with offset in the stack of the caller.
diff --git a/tools/testing/selftests/kvm/lib/x86_64/tdx.h b/tools/testing/selftests/kvm/lib/x86_64/tdx.h index aa6961c6f304..8ddf3b64f003 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/tdx.h +++ b/tools/testing/selftests/kvm/lib/x86_64/tdx.h @@ -122,7 +122,11 @@ void prepare_source_image(struct kvm_vm *vm, void *guest_code, */ static inline void tdcall(struct kvm_regs *regs) {
unsigned long saved_rbp = 0;
asm volatile (
/* gcc complains that frame pointer %rbp can't be clobbered. */
"movq %%rbp, %28;\n\t" "mov %13, %%rax;\n\t" "mov %14, %%rbx;\n\t" "mov %15, %%rcx;\n\t"
@@ -152,6 +156,8 @@ static inline void tdcall(struct kvm_regs *regs) "mov %%r15, %10;\n\t" "mov %%rsi, %11;\n\t" "mov %%rdi, %12;\n\t"
"movq %28, %%rbp\n\t"
"movq $0, %28\n\t" : "=m" (regs->rax), "=m" (regs->rbx), "=m" (regs->rdx), "=m" (regs->r8), "=m" (regs->r9), "=m" (regs->r10), "=m" (regs->r11), "=m" (regs->r12), "=m" (regs->r13),
@@ -161,9 +167,10 @@ static inline void tdcall(struct kvm_regs *regs) "m" (regs->rdx), "m" (regs->r8), "m" (regs->r9), "m" (regs->r10), "m" (regs->r11), "m" (regs->r12), "m" (regs->r13), "m" (regs->r14), "m" (regs->r15),
"m" (regs->rbp), "m" (regs->rsi), "m" (regs->rdi)
"m" (regs->rbp), "m" (regs->rsi), "m" (regs->rdi),
"m" (saved_rbp) : "rax", "rbx", "rcx", "rdx", "r8", "r9", "r10", "r11",
"r12", "r13", "r14", "r15", "rbp", "rsi", "rdi");
"r12", "r13", "r14", "r15", "rsi", "rdi");
}
Inline assembly for TDCALL is going to be a mess. Assuming proper assembly doesn't Just Work for selftests, we should solve that problem and build this on top.