Re: [PATCH v14 12/22] KVM: selftests: Require guest_memfd for TDX VMs

From: Lisa Wang

Date: Fri Sep 25 2026 - 18:04:40 EST


On Fri, Aug 14, 2026 at 03:42:48PM +0800, Xiaoyao Li wrote:
> > static bool is_guest_memfd_required(struct vm_shape shape)
> > {
> > #ifdef __x86_64__
> > - return shape.type == KVM_X86_SNP_VM;
> > + return (shape.type == KVM_X86_SNP_VM || shape.type == KVM_X86_TDX_VM);
>
> Instead of updating is_guest_memfd_required(), I'm thinking how about just
> replacing is_guest_memfd_required() with vm_arch_has_protected_memory()?

vm_arch_has_protected_memory() returns true for SEV, but an SEV VM is
expected not to use guest_memfd. If we replace is_guest_memfd_required()
with vm_arch_has_protected_memory(), we need an extra test to ensure
SEV VMs work well without guest_memfd.

Thus, I prefer keeping is_guest_memfd_required().

> > @@ -27,6 +27,7 @@ static struct ucall_header *ucall_pool;
> > void ucall_init(struct kvm_vm *vm, gpa_t mmio_gpa)
> > {
> > + struct userspace_mem_region *region;
> > struct ucall_header *hdr;
> > struct ucall *uc;
> > gva_t gva;
> > @@ -37,6 +38,13 @@ void ucall_init(struct kvm_vm *vm, gpa_t mmio_gpa)
> > hdr = (struct ucall_header *)addr_gva2hva(vm, gva);
> > memset(hdr, 0, sizeof(*hdr));
> > + region = vm_get_mem_region(vm, MEM_REGION_DATA);
> > + if (region->region.flags & KVM_MEM_GUEST_MEMFD) {
> > + size_t aligned_sz = align_up(sizeof(*hdr), vm->page_size);
> > +
> > + vm_mem_set_shared(vm, addr_gva2gpa(vm, gva), aligned_sz);
> > + }
>
> this diff about the ucall needs to be a separate patch. What's the reason to
> add it to this patch in this version?

Thanks. Will separate in the next version.

> > for (i = 0; i < KVM_MAX_VCPUS; ++i) {
> > uc = &hdr->ucalls[i];
> > uc->hva = uc;
> >
>