Re: [PATCH] KVM: Fix stale gfn_to_pfn() reference in kvm_invalidate_memslot() comment

From: Sean Christopherson

Date: Fri May 15 2026 - 09:18:41 EST


On Fri, May 08, 2026, Jun Miao wrote:
> Commit 06cdaff80e50 ("KVM: Drop gfn_to_pfn() APIs now that all users are
> gone") removed gfn_to_pfn(), but kvm_invalidate_memslot() still references
> gfn_to_pfn() when describing how sp->gfn is validated for guest memory
> accesses.
>
> Update the comment to reference __kvm_faultin_pfn(), which is the actual path
> involved here.
>
> No functional change intended.
>
> Fixes: 06cdaff80e50 ("KVM: Drop gfn_to_pfn() APIs now that all users are gone")
> Signed-off-by: Jun Miao <jun.miao@xxxxxxxxx>
> ---
> virt/kvm/kvm_main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 89489996fbc1..f4b3ea970a78 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1818,7 +1818,7 @@ static void kvm_invalidate_memslot(struct kvm *kvm,
> /*
> * From this point no new shadow pages pointing to a deleted, or moved,
> * memslot will be created. Validation of sp->gfn happens in:
> - * - gfn_to_hva (kvm_read_guest, gfn_to_pfn)
> + * - gfn_to_hva (kvm_read_guest, __kvm_faultin_pfn)

This isn't really accurate either. On x86, INVALID memslots don't even reach
__kvm_faultin_pfn(), because they're filtered out early on by
kvm_mmu_faultin_pfn().

Rather than simply fix the stale function reference, I think we should rewrite
the comment to describe the mechanics of memslots in excruiating detail. The
existing comment is painfully x86-centric, and IMO is unlikely to help anyone
actually understand how all of this works; or at least, is supposed to work :-)

> * - kvm_is_visible_gfn (mmu_check_root)
> */
> kvm_arch_flush_shadow_memslot(kvm, old);
> --
> 2.43.0
>