On 5/22/2026 7:16 AM, Lisa Wang wrote:
[...]

> diff --git a/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h 
> b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> index f647e6ca6b34..48d4bd36c35b 100644
> --- a/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> +++ b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> @@ -11,4 +11,34 @@ static inline bool is_tdx_vm(struct kvm_vm *vm)
>       return vm->type == KVM_X86_TDX_VM;
>  }
>  
> +/*
> + * TDX ioctls
> + * Use underscores to avoid collisions with struct member names.
> + */
> +#define __tdx_vm_ioctl(vm, cmd, _flags, arg)                         \
> +({                                                                   \
> +     int r;                                                          \
> +                                                                     \
> +     union {                                                         \
> +             struct kvm_tdx_cmd c;                                   \
> +             unsigned long raw;                                      \
> +     } tdx_cmd = { .c = {                                            \
> +             .id = (cmd),                                            \
> +             .flags = (u32)(_flags),                         \
> +             .data = (u64)(arg),                             \

Nit:
The two lines' backslashes are misaligned.

> +     } };                                                            \
> +                                                                     \
> +     r = __vm_ioctl(vm, KVM_MEMORY_ENCRYPT_OP, &tdx_cmd.raw);        \
> +     r ?: tdx_cmd.c.hw_error;                                        \
> +})
> +
> +#define tdx_vm_ioctl(vm, cmd, flags, arg)                            \
> +({                                                                   \
> +     int ret = __tdx_vm_ioctl(vm, cmd, flags, arg);                  \

tdx_cmd.c.hw_error is u64 and it could be assigned to ret, which is a int,
the upper bits could be truncated if the upper 32-bit is set.

> +                                                                     \
> +     __TEST_ASSERT_VM_VCPU_IOCTL(!ret, #cmd, ret, vm);               \
> +})
> +
> +void tdx_init_vm(struct kvm_vm *vm, u64 attributes);
> +
>  #endif /* SELFTESTS_TDX_TDX_UTIL_H */[...]

Reply via email to