Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: guest_memfd: move kvm_gmem_get_index() and use in kvm_gmem_prepare_folio()

Move kvm_gmem_get_index() to the top of the file so that it can be used
in kvm_gmem_prepare_folio() to replace the open-coded calculation.

No functional change intended.

Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Shivank Garg <shivankg@amd.com>
Link: https://lore.kernel.org/r/20251012071607.17646-1-shivankg@amd.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

authored by

Shivank Garg and committed by
Sean Christopherson
049e560d f634f108

+6 -6
+6 -6
virt/kvm/guest_memfd.c
··· 25 25 return folio_pfn(folio) + (index & (folio_nr_pages(folio) - 1)); 26 26 } 27 27 28 + static pgoff_t kvm_gmem_get_index(struct kvm_memory_slot *slot, gfn_t gfn) 29 + { 30 + return gfn - slot->base_gfn + slot->gmem.pgoff; 31 + } 32 + 28 33 static int __kvm_gmem_prepare_folio(struct kvm *kvm, struct kvm_memory_slot *slot, 29 34 pgoff_t index, struct folio *folio) 30 35 { ··· 83 78 * checked when creating memslots. 84 79 */ 85 80 WARN_ON(!IS_ALIGNED(slot->gmem.pgoff, 1 << folio_order(folio))); 86 - index = gfn - slot->base_gfn + slot->gmem.pgoff; 81 + index = kvm_gmem_get_index(slot, gfn); 87 82 index = ALIGN_DOWN(index, 1 << folio_order(folio)); 88 83 r = __kvm_gmem_prepare_folio(kvm, slot, index, folio); 89 84 if (!r) ··· 338 333 * kvm_gmem_release() clears slot->gmem.file. 339 334 */ 340 335 return get_file_active(&slot->gmem.file); 341 - } 342 - 343 - static pgoff_t kvm_gmem_get_index(struct kvm_memory_slot *slot, gfn_t gfn) 344 - { 345 - return gfn - slot->base_gfn + slot->gmem.pgoff; 346 336 } 347 337 348 338 static bool kvm_gmem_supports_mmap(struct inode *inode)