Skip to contentSkip to conversation

KVM: use folio_nr_pages() instead of shift operation

PATCH Applied Pedro Demarchi Gomes 3 participants 4 messages Oct 4, 2025 – Oct 22, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: use folio_nr_pages() instead of shift operation

folio_nr_pages() is a faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
 virt/kvm/guest_memfd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
virt/kvm/guest_memfd.c +2 -2
index 7d85cc33c0bb..5fc5475cf826 100644
@@ -77,9 +77,9 @@ static int kvm_gmem_prepare_folio(struct kvm *kvm, struct kvm_memory_slot *slot,
 	 * The order will be passed when creating the guest_memfd, and
 	 * checked when creating memslots.
 	 */
-	WARN_ON(!IS_ALIGNED(slot->gmem.pgoff, 1 << folio_order(folio)));
+	WARN_ON(!IS_ALIGNED(slot->gmem.pgoff, folio_nr_pages(folio)));
 	index = gfn - slot->base_gfn + slot->gmem.pgoff;
-	index = ALIGN_DOWN(index, 1 << folio_order(folio));
+	index = ALIGN_DOWN(index, folio_nr_pages(folio));
 	r = __kvm_gmem_prepare_folio(kvm, slot, index, folio);
 	if (!r)
 		kvm_gmem_mark_prepared(folio);
Signature · 1 line
2.39.5
#2 lore raw
Quoted 8 lines · Sean Christopherson
Quoted 2 lines · Pedro Demarchi Gomes

folio_nr_pages() is a faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

Applied to kvm-x86 gmem, thanks!

[1/1] KVM: use folio_nr_pages() instead of shift operation

      https://github.com/kvm-x86/linux/commit/fa492ac7fb04

FYI, I rebased this onto 6.18-rc2 to avoid a silly merge. New hash:

[1/1] KVM: guest_memfd: use folio_nr_pages() instead of shift operation

      https://github.com/kvm-x86/linux/commit/765fcd7c0753
Reviewed-by on v1 1/1
#3 lore raw
In reply to Pedro Demarchi Gomes
Quoted 14 lines · Pedro Demarchi Gomes

folio_nr_pages() is a faster helper function to get the number of pages when NR_PAGES_IN_LARGE_FOLIO is enabled.

---
  virt/kvm/guest_memfd.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
virt/kvm/guest_memfd.c +0 -0
index 7d85cc33c0bb..5fc5475cf826 100644
@@ -77,9 +77,9 @@ static int kvm_gmem_prepare_folio(struct kvm *kvm, struct kvm_memory_slot *slot,
  	 * The order will be passed when creating the guest_memfd, and

virt/kvm/guest_memfd.c static int kvm_gmem_prepare_folio(struct kvm *kvm, struct kvm_memory_slot *slot, · line 85

Quoted 10 lines
virt/kvm/guest_memfd.c +2 -2
  	 * checked when creating memslots.
  	 */
-	WARN_ON(!IS_ALIGNED(slot->gmem.pgoff, 1 << folio_order(folio)));
+	WARN_ON(!IS_ALIGNED(slot->gmem.pgoff, folio_nr_pages(folio)));
  	index = gfn - slot->base_gfn + slot->gmem.pgoff;
-	index = ALIGN_DOWN(index, 1 << folio_order(folio));
+	index = ALIGN_DOWN(index, folio_nr_pages(folio));
  	r = __kvm_gmem_prepare_folio(kvm, slot, index, folio);
  	if (!r)
  		kvm_gmem_mark_prepared(folio);

FWIW

Signature · 3 lines
Cheers

David / dhildenb