]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: guest_memfd: Invalidate SHARED GPAs if gmem supports INIT_SHARED
authorSean Christopherson <seanjc@google.com>
Fri, 3 Oct 2025 23:25:56 +0000 (16:25 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 10 Oct 2025 21:25:24 +0000 (14:25 -0700)
commit5d3341d684be80892d8f6f9812f90f9274b81177
tree13500eb245f354956319245bd86340bca4f401cd
parentfe2bf6234e947bf5544db6d386af1df2a8db80f3
KVM: guest_memfd: Invalidate SHARED GPAs if gmem supports INIT_SHARED

When invalidating gmem ranges, e.g. in response to PUNCH_HOLE, process all
possible range types (PRIVATE vs. SHARED) for the gmem instance.  Since
since guest_memfd doesn't yet support in-place conversions, simply pivot
on INIT_SHARED as a gmem instance can currently only have private or shared
memory, not both.

Failure to mark shared GPAs for invalidation is benign in the current code
base, as only x86's TDX consumes KVM_FILTER_{PRIVATE,SHARED}, and TDX
doesn't yet support INIT_SHARED with guest_memfd.  However, invalidating
only private GPAs is conceptually wrong and a lurking bug, e.g. could
result in missed invalidations if ARM starts filtering invalidations based
on attributes.

Fixes: 3d3a04fad25a ("KVM: Allow and advertise support for host mmap() on guest_memfd files")
Reviewed-by: Ackerley Tng <ackerleytng@google.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Link: https://lore.kernel.org/r/20251003232606.4070510-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/guest_memfd.c