Re: [PATCH v2 1/5] KVM: guest_memfd: Remove partial hugepage handling from kvm_gmem_populate()

From: Sean Christopherson

Date: Mon Dec 15 2025 - 19:18:58 EST


On Mon, Dec 15, 2025, Vishal Annapurve wrote:
> On Mon, Dec 15, 2025 at 7:35 AM Michael Roth <michael.roth@xxxxxxx> wrote:
> > 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.

The current code _shouldn't_ hit it.

> This note concerns future efforts to add hugepage support and could be
> omitted altogether from the current implementation.

IMO, this is a good use of WARN_ON_ONCE(). It documents guest_memfd's assumptions
and/or limitations, which is extremely helpful to readers/contributors that aren't
familiar with guest_memfd and/or its history of hugepage support.