Re: [PATCH v2 1/5] KVM: guest_memfd: Remove partial hugepage handling from kvm_gmem_populate()
From: Vishal Annapurve
Date: Mon Dec 15 2025 - 19:12:15 EST
On Mon, Dec 15, 2025 at 7:35 AM Michael Roth <michael.roth@xxxxxxx> wrote:
>
> kvm_gmem_populate(), and the associated post-populate callbacks, have
> some limited support for dealing with guests backed by hugepages by
> passing the order information along to each post-populate callback and
> iterating through the pages passed to kvm_gmem_populate() in
> hugepage-chunks.
>
> However, guest_memfd doesn't yet support hugepages, and in most cases
> additional changes in the kvm_gmem_populate() path would also be needed
> to actually allow for this functionality.
>
> This makes the existing code unecessarily complex, and makes changes
> difficult to work through upstream due to theoretical impacts on
> hugepage support that can't be considered properly without an actual
> hugepage implementation to reference. So for now, remove what's there
> so changes for things like in-place conversion can be
> implemented/reviewed more efficiently.
>
> Suggested-by: Vishal Annapurve <vannapurve@xxxxxxxxxx>
> Co-developed-by: Vishal Annapurve <vannapurve@xxxxxxxxxx>
> Signed-off-by: Vishal Annapurve <vannapurve@xxxxxxxxxx>
> Signed-off-by: Michael Roth <michael.roth@xxxxxxx>
Tested-By: Vishal Annapurve <vannapurve@xxxxxxxxxx>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index fdaea3422c30..9dafa44838fe 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -151,6 +151,15 @@ static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index)
> mapping_gfp_mask(inode->i_mapping), policy);
> mpol_cond_put(policy);
>
> + /*
> + * External interfaces like kvm_gmem_get_pfn() support dealing
> + * with hugepages to a degree, but internally, guest_memfd currently
> + * assumes that all folios are order-0 and handling would need
> + * to be updated for anything otherwise (e.g. page-clearing
> + * operations).
> + */
> + WARN_ON_ONCE(folio_order(folio));
I am not sure if this WARN_ON adds any value. i.e. The current code
can't hit it. This note concerns future efforts to add hugepage
support and could be omitted altogether from the current
implementation.
> +
> return folio;
> }
>