Re: [PATCH v16 12/20] KVM: selftests: Call KVM_TDX_INIT_VCPU when creating a new TDX vcpu

From: Sean Christopherson

Date: Wed Nov 11 2026 - 11:12:27 EST


On Wed, Nov 11, 2026, Xiaoyao Li wrote:
> On 11/6/2026 7:46 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 4330290d29e9..9d951f67b3b5 100644
> > --- a/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> > +++ b/tools/testing/selftests/kvm/include/x86/tdx/tdx_util.h
> > @@ -46,9 +46,31 @@ static inline bool is_tdx_vm(struct kvm_vm *vm)
> > #cmd, ret, errno, strerror(errno), hw_error); \
> > })
> >
> > +#define __tdx_vcpu_ioctl(vcpu, cmd, _flags, arg) \
> > +({ \
> > + union { \
> > + struct kvm_tdx_cmd c; \
> > + unsigned long raw; \
> > + } tdx_cmd = { .c = { \
> > + .id = (cmd), \
> > + .flags = (u32)(_flags), \
> > + .data = (u64)(arg), \
> > + } }; \
> > + \
> > + __vcpu_ioctl(vcpu, KVM_MEMORY_ENCRYPT_OP, &tdx_cmd.raw); \
> > +})
> > +
> > +#define tdx_vcpu_ioctl(vcpu, cmd, flags, arg) \
> > +({ \
> > + int ret = __tdx_vcpu_ioctl(vcpu, cmd, flags, arg); \
> > + \
> > + TEST_ASSERT(!ret, "%s failed, rc: %i errno: %i (%s)", \
>
> Nit: tdx_vm_ioctl() uses %d for ret, while it uses %i for ret. It's better to
> make them consitent.

Ugh, KVM is anything but consistent. I didn't even realize half the macros use
%i instead of %d.

I chose to "fix" tdx_vm_ioctl() purely because it has the completely unnecessary
PRIx64:

TEST_ASSERT(!ret, \
"%s failed, rc: %i errno: %i (%s) hw_error: 0x%lx", \
#cmd, ret, errno, strerror(errno), hw_error); \