From: Alexandru Elisei <alexandru.elisei@arm.com>
To: Sean Christopherson <seanjc@google.com>
Cc: David Hildenbrand <david.hildenbrand@arm.com>,
pbonzini@redhat.com, kvm@vger.kernel.org, maz@kernel.org,
oupton@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com,
suzuki.poulose@arm.com, yuzenghui@huawei.com,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
fuad.tabba@linux.dev, mark.rutland@arm.com
Subject: Re: [RFC PATCH 1/3] KVM: guest_memfd: Use memslot id to keep track of associated memslots
Date: Tue, 7 Jul 2026 18:05:57 +0100 [thread overview]
Message-ID: <ak0x9VAWz823HnUk@raptor> (raw)
In-Reply-To: <akwiG_tDu5Eyyc0-@google.com>
Hi Sean,
On Mon, Jul 06, 2026 at 02:46:03PM -0700, Sean Christopherson wrote:
> 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.
It's not about bindings being modified. This is the race I am trying to avoid:
CPU0: CPU1:
KVM_SET_USER_MEMORY_REGION(slot, memory_size=0)
kvm_replace_memslot(kvm, slot, invalid_slot)
kvm_swap_active_memslots(kvm)
kvm_replace_memslot(kvm, invalid_slot, NULL)
kvm_swap_active_memslots(kvm)
fallocate(guest_memfd, FALLOC_FL_PUNCH_HOLE)
__kvm_gmem_invalidate_start()
slot = id_to_memslot(__kvm_memslots(kvm, as_id), id);
if (slot == NULL) {
// Early exit, does not call kvm_mmu_invalidate_start(kvm)
return;
}
__kvm_gmem_invalidate_end()
// No corresponding kvm_mmu_invalidate_start(kvm) call
kvm_mmu_invalidate_end(kvm)
kvm_replace_memslot(kvm, invalid_slot, NULL);
kvm_free_memslot(kvm, slot)
kvm_gmem_unbind(slot)
Does that make sense?
Thanks,
Alex
next prev parent reply other threads:[~2026-07-07 17:06 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 14:29 [RFC PATCH 0/3] KVM: Dirty page logging for guest_memfd-only memslots Alexandru Elisei
2026-07-02 14:29 ` [RFC PATCH 1/3] KVM: guest_memfd: Use memslot id to keep track of associated memslots Alexandru Elisei
2026-07-06 7:14 ` David Hildenbrand
2026-07-06 13:45 ` Alexandru Elisei
2026-07-06 21:46 ` Sean Christopherson
2026-07-07 17:05 ` Alexandru Elisei [this message]
2026-07-06 21:43 ` Sean Christopherson
2026-07-07 17:05 ` Alexandru Elisei
2026-07-02 14:29 ` [RFC PATCH 2/3] KVM: Implement dirty page logging for guest_memfd-only memslots Alexandru Elisei
2026-07-07 1:29 ` Sean Christopherson
2026-07-07 17:12 ` Alexandru Elisei
2026-07-02 14:29 ` [RFC PATCH 3/3] KVM: arm64: Allow " Alexandru Elisei
2026-07-07 0:56 ` [RFC PATCH 0/3] KVM: Dirty " Sean Christopherson
2026-07-07 16:58 ` Alexandru Elisei
2026-07-07 17:12 ` Sean Christopherson
2026-07-09 11:21 ` Mark Rutland
2026-07-09 19:01 ` Sean Christopherson
2026-07-10 10:26 ` Mark Rutland
2026-07-09 20:33 ` Oliver Upton
2026-07-10 10:44 ` Alexandru Elisei
2026-07-10 18:18 ` Oliver Upton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ak0x9VAWz823HnUk@raptor \
--to=alexandru.elisei@arm.com \
--cc=david.hildenbrand@arm.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox