[RFC PATCH 2/5] KVM: guest_memfd: Move gmem function declarations to dedicated guest_memfd.h

Sean Christopherson
2026-04-28T17:16:00Z

Extract the gmem function declarations out of kvm_mm.h and into a dedicated
header, guest_memfd.h. This will allow creating a MAINTAINERS entry for
guest_memfd without having to rely on content pattern matching.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
virt/kvm/guest_memfd.c | 1 +
virt/kvm/guest_memfd.h | 34 ++++++++++++++++++++++++++++++++++
virt/kvm/kvm_main.c | 1 +
virt/kvm/kvm_mm.h | 27 ---------------------------
4 files changed, 36 insertions(+), 27 deletions(-)
create mode 100644 virt/kvm/guest_memfd.h

diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 69c9d6d546b2..a93a31568337 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -9,6 +9,7 @@
#include <linux/pagemap.h>

#include "kvm_mm.h"
+#include "guest_memfd.h"

static struct vfsmount *kvm_gmem_mnt;

diff --git a/virt/kvm/guest_memfd.h b/virt/kvm/guest_memfd.h
new file mode 100644
index 000000000000..e8b825da264b
--- /dev/null
+++ b/virt/kvm/guest_memfd.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __KVM_GUEST_MEMFD_H__
+#define __KVM_GUEST_MEMFD_H__
+
+#include <linux/kvm_types.h>
+
+#ifdef CONFIG_KVM_GUEST_MEMFD
+int kvm_gmem_init(struct module *module);
+void kvm_gmem_exit(void);
+int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args);
+int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,
+ unsigned int fd, loff_t offset);
+void kvm_gmem_unbind(struct kvm_memory_slot *slot);
+#else
+static inline int kvm_gmem_init(struct module *module)
+{
+ return 0;
+}
+static inline void kvm_gmem_exit(void) {};
+static inline int kvm_gmem_bind(struct kvm *kvm,
+ struct kvm_memory_slot *slot,
+ unsigned int fd, loff_t offset)
+{
+ WARN_ON_ONCE(1);
+ return -EIO;
+}
+
+static inline void kvm_gmem_unbind(struct kvm_memory_slot *slot)
+{
+ WARN_ON_ONCE(1);
+}
+#endif /* CONFIG_KVM_GUEST_MEMFD */
+
+#endif /* __KVM_GUEST_MEMFD_H__ */
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 89489996fbc1..a4035ffb421f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -56,6 +56,7 @@

#include "coalesced_mmio.h"
#include "async_pf.h"
+#include "guest_memfd.h"
#include "kvm_mm.h"
#include "vfio.h"

diff --git a/virt/kvm/kvm_mm.h b/virt/kvm/kvm_mm.h
index 9fcc5d5b7f8d..4958c0a93d64 100644
--- a/virt/kvm/kvm_mm.h
+++ b/virt/kvm/kvm_mm.h
@@ -67,31 +67,4 @@ static inline void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm,
}
#endif /* HAVE_KVM_PFNCACHE */

-#ifdef CONFIG_KVM_GUEST_MEMFD
-int kvm_gmem_init(struct module *module);
-void kvm_gmem_exit(void);
-int kvm_gmem_create(struct kvm *kvm, struct kvm_create_guest_memfd *args);
-int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,
- unsigned int fd, loff_t offset);
-void kvm_gmem_unbind(struct kvm_memory_slot *slot);
-#else
-static inline int kvm_gmem_init(struct module *module)
-{
- return 0;
-}
-static inline void kvm_gmem_exit(void) {};
-static inline int kvm_gmem_bind(struct kvm *kvm,
- struct kvm_memory_slot *slot,
- unsigned int fd, loff_t offset)
-{
- WARN_ON_ONCE(1);
- return -EIO;
-}
-
-static inline void kvm_gmem_unbind(struct kvm_memory_slot *slot)
-{
- WARN_ON_ONCE(1);
-}
-#endif /* CONFIG_KVM_GUEST_MEMFD */
-
#endif /* __KVM_MM_H__ */
--
2.54.0.545.g6539524ca2-goog