[PATCH 25/41] kvm: Use private inode list instead of i_private_list

Jan Kara
2026-03-20T13:43:10Z

Instead of using mapping->i_private_list use a list in private part of
the inode.

CC: kvm@vger.kernel.org
CC: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
virt/kvm/guest_memfd.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 017d84a7adf3..42b237491c4e 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -30,6 +30,7 @@ struct gmem_file {
struct gmem_inode {
struct shared_policy policy;
struct inode vfs_inode;
+ struct list_head gmem_file_list;

u64 flags;
};
@@ -39,8 +40,8 @@ static __always_inline struct gmem_inode *GMEM_I(struct inode *inode)
return container_of(inode, struct gmem_inode, vfs_inode);
}

-#define kvm_gmem_for_each_file(f, mapping) \
- list_for_each_entry(f, &(mapping)->i_private_list, entry)
+#define kvm_gmem_for_each_file(f, inode) \
+ list_for_each_entry(f, &GMEM_I(inode)->gmem_file_list, entry)

/**
* folio_file_pfn - like folio_file_page, but return a pfn.
@@ -202,7 +203,7 @@ static void kvm_gmem_invalidate_begin(struct inode *inode, pgoff_t start,

attr_filter = kvm_gmem_get_invalidate_filter(inode);

- kvm_gmem_for_each_file(f, inode->i_mapping)
+ kvm_gmem_for_each_file(f, inode)
__kvm_gmem_invalidate_begin(f, start, end, attr_filter);
}

@@ -223,7 +224,7 @@ static void kvm_gmem_invalidate_end(struct inode *inode, pgoff_t start,
{
struct gmem_file *f;

- kvm_gmem_for_each_file(f, inode->i_mapping)
+ kvm_gmem_for_each_file(f, inode)
__kvm_gmem_invalidate_end(f, start, end);
}

@@ -609,7 +610,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags)
kvm_get_kvm(kvm);
f->kvm = kvm;
xa_init(&f->bindings);
- list_add(&f->entry, &inode->i_mapping->i_private_list);
+ list_add(&f->entry, &GMEM_I(inode)->gmem_file_list);

fd_install(fd, file);
return fd;
@@ -945,6 +946,7 @@ static struct inode *kvm_gmem_alloc_inode(struct super_block *sb)
mpol_shared_policy_init(&gi->policy, NULL);

gi->flags = 0;
+ INIT_LIST_HEAD(&gi->gmem_file_list);
return &gi->vfs_inode;
}

--
2.51.0