Re: [PATCH v4 13/18] KVM: guest_memfd: Pass GPA, not GFN, to prepare() hook

From: Sean Christopherson

Date: Fri Jul 10 2026 - 18:12:32 EST


On Thu, Jul 09, 2026, Ackerley Tng wrote:
> Sean Christopherson <seanjc@xxxxxxxxxx> writes:
>
> > Pass a GPA instead of a GFN to kvm_arch_gmem_prepare() so that the GFN/GPA
> > can be made optional in the future, i.e. so that guest_memfd can pass
> > INVALID_GPA. This will allow reworking the hook into a general .convert()
>
> How about defining a INVALID_GFN instead of using gpa just so
> INVALID_GPA can be passed? The SNP side takes a gfn, so it seems like
> the 2 PAGE_SHIFTs are extra work.

They are, but I am very hesitant to define INVALID_GFN as I'm worried about the
potential for subtle bugs if both INVALID_GPA and INVALID_GFN exist. E.g. I
almost made a goof in this exact series where I was going to do:

gfn_t gfn = gpa_to_gfn(svm->sev_es.snp_guest_vmsa_gpa);

...

if (gfn == INVALID_GFN)
return;

Where snp_guest_vmsa_gpa is set to INVALID_GPA.

I suppose we could define INVALID_GFN to gpa_to_gfn(INVALID_GPA), but that feels
weird, and I feel more comfortable having magic invalid values in only one domain.