Re: [RFC PATCH v2 03/17] KVM: selftest: Adding TDX life cycle test.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux