[RFC PATCH 1/3] KVM: guest_memfd: Use memslot id to keep track of associated memslots
Sean Christopherson
seanjc at google.com
Mon Jul 6 14:46:03 PDT 2026
On Mon, Jul 06, 2026, Alexandru Elisei wrote:
> On Mon, Jul 06, 2026 at 09:14:59AM +0200, David Hildenbrand wrote:
> > > diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> > > index db57c5766ab6..43ef8e908aaf 100644
> > > --- a/virt/kvm/guest_memfd.c
> > > +++ b/virt/kvm/guest_memfd.c
> > > @@ -25,6 +25,7 @@ struct gmem_file {
> > > struct kvm *kvm;
> > > struct xarray bindings;
> > > struct list_head entry;
> > > + bool found_memslot; /* Used for balancing invalidations when punching a hole */
> >
> > Probabably best to document what it means, not only what it is used for (and
> > maybe document above the member if you end up with more text).
>
> Sure, this is how I changed it:
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index 210bdd76f0aa..3cee64047bce 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -25,7 +25,13 @@ struct gmem_file {
> struct kvm *kvm;
> struct xarray bindings;
> struct list_head entry;
> - bool found_memslot; /* Used for balancing invalidations when punching a hole */
> + /*
> + * Keeps track of whether memory has been unmapped during secondary MMU
> + * invalidation, to keep the invalidate start and end calls balanced.
> + *
> + * Accessed while holding the inode->i_mapping lock in exclusive mode.
> + */
> + bool memslot_invalidated;
> };
>
> Hopefully the new name is better.
Why add a boolean? It's not _needed_ to balance updates, or rather it shouldn't
be needed. filemap_invalidate_lock() prevents modifying bindings while an
invalidation is in-progress. It might be a performation optimization, but if so,
it's a premature one and belongs in a separate patch.
More information about the linux-arm-kernel
mailing list