Re: [PATCH v14 21/22] KVM: selftests: Add ucall support for TDX
From: Peter Fang
Date: Thu Aug 27 2026 - 22:06:35 EST
On Mon, Aug 17, 2026 at 04:38:49PM +0800, Xiaoyao Li wrote:
> > +
> > +static u8 vm_type;
> > +static gpa_t ucall_mmio_gpa;
> > +
> > +void ucall_arch_init(struct kvm_vm *vm, gpa_t mmio_gpa)
> > +{
> > + vm_type = vm->type;
vm_type is u8 but vm->type is unsigned long
> > + sync_global_to_guest(vm, vm_type);
>
> It works and it looks simple. But we have the architectural approach to test
> if a guest is TD guest, by checking the CPUID 0x21.
>
> Since checking CPUID 0x21 is not complex, and as a bonus it can help test if
> TDX module behaves correctly for CPUID leaf 0x21, I think we should switch
> to use CPUID 0x21 to check if it is TDX VM in guest code?
Hmm... This makes me wonder if vm->arch.s_bit below could be replaced
with the same architectural approach. GPAW is available through
TDG.VP.INFO or the initial RBX value. This does require a bit more
plumbing though.
>
> > + if (is_tdx_vm(vm)) {
> > + ucall_mmio_gpa = UCALL_MMIO_GPA | vm->arch.s_bit;
>
> So the passed-in @mmio_gpa is not used. Why cannot use the mmio_gpa,
>
> slot0->region.guest_phys_addr + slot0->region.memory_size
>
> chosen by __vm_create()?
Looks like this was discussed previously [1]. Maybe at least a comment
here would help?
[1] https://lore.kernel.org/all/ajGaMb6Lrk3OS8B4@xxxxxxxxxx/
>