Re: [PATCH RFC 10/12] KVM: guest_memfd: Clarify comment about gmem.file vs kvm->srcu

From: Sean Christopherson

Date: Thu Jun 25 2026 - 14:20:23 EST


On Wed, May 27, 2026, Ackerley Tng wrote:
> Clarify the existing comment about synchronize_srcu() and
> kvm_gmem_get_pfn() to provide further context. Explain which
> synchronize_srcu() prevents races with how kvm_gmem_get_pfn() is used.
>
> Also point reader to documentation for better understanding.
>
> Signed-off-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
> ---
> virt/kvm/guest_memfd.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
> index 69c9d6d546b28..f2218db0af980 100644
> --- a/virt/kvm/guest_memfd.c
> +++ b/virt/kvm/guest_memfd.c
> @@ -711,8 +711,13 @@ static void __kvm_gmem_unbind(struct kvm_memory_slot *slot, struct gmem_file *f)
> xa_store_range(&f->bindings, start, end - 1, NULL, GFP_KERNEL);
>
> /*
> - * synchronize_srcu(&kvm->srcu) ensured that kvm_gmem_get_pfn()
> - * cannot see this memslot.
> + * This is called when memslots are updated, after the old
> + * memslot container is no longer in
> + * use. synchronize_srcu(&kvm->srcu) was called there, so
> + * kvm_gmem_get_pfn() from KVM's guest fault handling cannot
> + * see this memslot. See Documentation/virt/kvm/locking.rst
> + * for more information about kvm->srcu and the memslots
> + * container.

If we want to add to this comment, I would much rather do so as part of an update
to kvm_gmem_release()'s comment as well.

https://lore.kernel.org/all/20251113232229.1698886-1-seanjc@xxxxxxxxxx