]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: guest_memfd: Add macro to iterate over gmem_files for a mapping/inode
authorSean Christopherson <seanjc@google.com>
Thu, 16 Oct 2025 17:28:43 +0000 (10:28 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 20 Oct 2025 13:30:39 +0000 (06:30 -0700)
Add a kvm_gmem_for_each_file() to make it more obvious that KVM is
iterating over guest_memfd _files_, not guest_memfd instances, as could
be assumed given the name "gmem_list".

No functional change intended.

Reviewed-by: Ackerley Tng <ackerleytng@google.com>
Tested-by: Ackerley Tng <ackerleytng@google.com>
Reviewed-by: Shivank Garg <shivankg@amd.com>
Tested-by: Shivank Garg <shivankg@amd.com>
Link: https://lore.kernel.org/r/20251016172853.52451-3-seanjc@google.com
[sean: drop .clang-format change]
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/guest_memfd.c

index 2989c5fe426f855f68e9df7a1bdf1f281b9a02dd..5cce20ff418dae75cf8882b44095dda98181aac2 100644 (file)
@@ -22,6 +22,9 @@ struct gmem_file {
        struct list_head entry;
 };
 
+#define kvm_gmem_for_each_file(f, mapping) \
+       list_for_each_entry(f, &(mapping)->i_private_list, entry)
+
 /**
  * folio_file_pfn - like folio_file_page, but return a pfn.
  * @folio: The folio which contains this index.
@@ -164,13 +167,12 @@ static void __kvm_gmem_invalidate_begin(struct gmem_file *f, pgoff_t start,
 static void kvm_gmem_invalidate_begin(struct inode *inode, pgoff_t start,
                                      pgoff_t end)
 {
-       struct list_head *gmem_list = &inode->i_mapping->i_private_list;
        enum kvm_gfn_range_filter attr_filter;
        struct gmem_file *f;
 
        attr_filter = kvm_gmem_get_invalidate_filter(inode);
 
-       list_for_each_entry(f, gmem_list, entry)
+       kvm_gmem_for_each_file(f, inode->i_mapping)
                __kvm_gmem_invalidate_begin(f, start, end, attr_filter);
 }
 
@@ -189,10 +191,9 @@ static void __kvm_gmem_invalidate_end(struct gmem_file *f, pgoff_t start,
 static void kvm_gmem_invalidate_end(struct inode *inode, pgoff_t start,
                                    pgoff_t end)
 {
-       struct list_head *gmem_list = &inode->i_mapping->i_private_list;
        struct gmem_file *f;
 
-       list_for_each_entry(f, gmem_list, entry)
+       kvm_gmem_for_each_file(f, inode->i_mapping)
                __kvm_gmem_invalidate_end(f, start, end);
 }