On 11.02.25 13:11, Fuad Tabba wrote:
Before transitioning a guest_memfd folio to unshared, thereby
disallowing access by the host and allowing the hypervisor to
transition its view of the guest page as private, we need to be
sure that the host doesn't have any references to the folio.
This patch introduces a new type for guest_memfd folios, which
isn't activated in this series but is here as a placeholder and
to facilitate the code in the next patch. This will be used in
the future to register a callback that informs the guest_memfd
subsystem when the last reference is dropped, therefore knowing
that the host doesn't have any remaining references.
Signed-off-by: Fuad Tabba <tabba@xxxxxxxxxx>
---
include/linux/kvm_host.h | 9 +++++++++
include/linux/page-flags.h | 17 +++++++++++++++++
mm/debug.c | 1 +
mm/swap.c | 9 +++++++++
virt/kvm/guest_memfd.c | 7 +++++++
5 files changed, 43 insertions(+)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index f34f4cfaa513..8b5f28f6efff 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2571,4 +2571,13 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
struct kvm_pre_fault_memory *range);
#endif
+#ifdef CONFIG_KVM_GMEM_SHARED_MEM
+void kvm_gmem_handle_folio_put(struct folio *folio);
+#else
+static inline void kvm_gmem_handle_folio_put(struct folio *folio)
+{
+ WARN_ON_ONCE(1);
+}
+#endif
+
#endif
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 6dc2494bd002..734afda268ab 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -933,6 +933,17 @@ enum pagetype {
PGTY_slab = 0xf5,
PGTY_zsmalloc = 0xf6,
PGTY_unaccepted = 0xf7,
+ /*
+ * guestmem folios are used to back VM memory as managed by guest_memfd.
+ * Once the last reference is put, instead of freeing these folios back
+ * to the page allocator, they are returned to guest_memfd.
+ *
+ * For now, guestmem will only be set on these folios as long as they
+ * cannot be mapped to user space ("private state"), with the plan of
+ * always setting that type once typed folios can be mapped to user
+ * space cleanly.
+ */
I would move that comment above the CONFIG_KVM_GMEM_SHARED_MEM below.
Similar to how we do it for (some of) the others.
Acked-by: David Hildenbrand <david@xxxxxxxxxx>
--
Cheers,
David / dhildenb