[PATCH RFC v2 34/50] KVM: guest_memfd: Skip checking outstanding references in PFN mode

From: Ackerley Tng via B4 Relay

Date: Thu Oct 22 2026 - 19:40:24 EST


From: Ackerley Tng <ackerleytng@xxxxxxxxxx>

When converting memory attributes to private, guest_memfd verifies that
there are no outstanding references to folios in the page cache.

For PFN mode, retain the part where memory is unmapped from userspace,
since userspace should not be able to map private memory.

Since memory was not mapped into userspace using pages, there will not be
any other users that had GUP-ed the memory and there is no need to check
for outstanding references (that indicate other users of the memory).

Signed-off-by: Ackerley Tng <ackerleytng@xxxxxxxxxx>
---
virt/kvm/guest_memfd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 50031e191968b..daf4541c3dec6 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -854,7 +854,8 @@ static int __kvm_gmem_set_attributes(struct inode *inode, pgoff_t start,
*/
unmap_mapping_pages(mapping, start, nr_pages, false);

- if (kvm_gmem_has_outstanding_references(inode, start, nr_pages,
+ if (!kvm_gmem_is_pfn_mode(gi) &&
+ kvm_gmem_has_outstanding_references(inode, start, nr_pages,
err_index)) {
mas_destroy(&mas);
r = -EAGAIN;

--
2.56.0.257.gf7497c7d27-goog