On 18.02.25 18:24, 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 subsequent patch series. 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.
This patch also introduces the configuration option,
KVM_GMEM_SHARED_MEM, which toggles support for mapping
guest_memfd shared memory at the host.
Signed-off-by: Fuad Tabba <tabba@xxxxxxxxxx>
Acked-by: Vlastimil Babka <vbabka@xxxxxxx>
---
include/linux/kvm_host.h | 4 ++++
include/linux/page-flags.h | 17 +++++++++++++++++
mm/debug.c | 1 +
mm/swap.c | 9 +++++++++
virt/kvm/Kconfig | 5 +++++
virt/kvm/guest_memfd.c | 7 +++++++
6 files changed, 43 insertions(+)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index f34f4cfaa513..3ad0719bfc4f 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2571,4 +2571,8 @@ 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);
+#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.
+ */
Same comment as to v3 regarding moving the comment.
kvm_gmem_handle_folio_put() might be fixed with having it as an inline
function for the time being as discussed.
Acked-by: David Hildenbrand <david@xxxxxxxxxx>
--
Cheers,
David / dhildenb