Re: [PATCH v2] KVM: guest_memfd: take the invalidate lock when unbinding a dying file
From: Sean Christopherson
Date: Thu Sep 24 2026 - 17:54:35 EST
On Tue, 01 Sep 2026 07:20:38 +0000, Shivank Garg wrote:
> kvm_gmem_unbind() takes mapping->invalidate_lock only if the
> get_file_active() succeeds. When the guest_memfd file is dying, its
> reference count is already zero so get_file_active fails and the binding
> is removed without holding the invalidate lock.
>
> kvm_gmem_invalidate_{start,end}() checks f->bindings independently to
> decide whether to begin or end KVM MMU invalidation. So, the bindings
> must therefore remain stable between the two calls. Otherwise, unbind
> can remove a binding after start increments mmu_invalidate_in_progress,
> but before end finds the binding and decrements it.
> Example, unbind race with memory failure:
>
> [...]
Applied to kvm-x86 coco, thanks!
[1/1] KVM: guest_memfd: take the invalidate lock when unbinding a dying file
https://github.com/kvm-x86/linux/commit/0ee2c883b62d
--
https://github.com/kvm-x86/linux/tree/next