[PATCH v2] KVM: Ignore MMU notifiers for guest_memfd-only memslots

Lorenzo Stoakes (ARM) ljs at kernel.org
Wed Nov 4 10:06:12 PST 2026


[updated David's email address to @kernel.org]

On Wed, Aug 12, 2026 at 10:42:50AM +0100, Alexandru Elisei wrote:
[ ... ]
> On Fri, Jul 24, 2026 at 12:52:20PM -0700, Sean Christopherson wrote:
> > It'll probably take me a few weeks to circle back to this, as I finally crawled
> > out from underneath a pile of urgent and am just now getting back into review
> > mode, but this is fairly high on my todo list, so with luck we might still squeeze
> > this into 7.3.

Hey Sean,

I wondered whether you'd had a chance to look at this?

After discussing this with Marc and Alex it is clear that this is really a
blocker for Alex's SPE series, as we need a sensible means of ensuring
that stage-2 mappings stay in place.

So ideally would prefer to get something like this in in the next cycle,
if you don't have any objections to it? :)

If it'd be easier, I think a smaller version of the same patch would also
give us what we need? I.e. your snippet from June with the page ageing part
dropped, as below.

Thanks!

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index e7fc94e2910a..a6f37bdb0902 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -264,6 +264,7 @@ union kvm_mmu_notifier_arg {
 enum kvm_gfn_range_filter {
 	KVM_FILTER_SHARED		= BIT(0),
 	KVM_FILTER_PRIVATE		= BIT(1),
+	KVM_FILTER_USERSPACE_MAPPINGS	= BIT(2),
 };

 struct kvm_gfn_range {
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cf4cb586f140..6fc3b443c305 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -616,8 +616,13 @@ static __always_inline kvm_mn_ret_t kvm_handle_hva_range(struct kvm *kvm,
 			/*
 			 * HVA-based notifications aren't relevant to private
 			 * mappings as they don't have a userspace mapping.
+			 *
+			 * Memslots where guest_memfd is the only memory
+			 * provider can also safely ignore changes to the
+			 * userspace mapping.
 			 */
-			gfn_range.attr_filter = KVM_FILTER_SHARED;
+			gfn_range.attr_filter = KVM_FILTER_SHARED |
+						KVM_FILTER_USERSPACE_MAPPINGS;

 			/*
 			 * {gfn(page) | page intersects with [hva_start, hva_end)} =
@@ -724,6 +729,17 @@ void kvm_mmu_invalidate_range_add(struct kvm *kvm, gfn_t start, gfn_t end)
 bool kvm_mmu_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range)
 {
 	kvm_mmu_invalidate_range_add(kvm, range->start, range->end);
+
+	/*
+	 * When reacting to changes in userspace mappings, don't unmap memslots
+	 * that are guest_memfd-only, in which case KVM's MMU mappings are
+	 * pulled directly from guest_memfd, i.e. don't depend on the userspace
+	 * mappings.
+	 */
+	if (range->attr_filter & KVM_FILTER_USERSPACE_MAPPINGS &&
+	    kvm_memslot_is_gmem_only(range->slot))
+		return false;
+
 	return kvm_unmap_gfn_range(kvm, range);
 }

--
Cheers, Lorenzo



More information about the linux-arm-kernel mailing list