KVM: guest_memfd: Add macro to iterate over gmem_files for a mapping/inode

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>
This commit is contained in:
Sean Christopherson
2025-10-16 10:28:43 -07:00
parent 497b1dfbca
commit 392dd9d948

View 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);
}