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: SEV: Use PFN_DOWN() to simplify "number of pages" math when pinning memory

Use PFN_DOWN() instead of open coded equivalents in sev_pin_memory() to
simplify the code and make it easier to read.

No functional change intended (verified before and after versions of the
generated code are identical).

Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
Tested-by: Liam Merwick <liam.merwick@oracle.com>
Link: https://patch.msgid.link/20260313003302.3136111-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

+2 -5
+2 -5
arch/x86/kvm/svm/sev.c
··· 682 682 int npinned; 683 683 unsigned long total_npages, lock_limit; 684 684 struct page **pages; 685 - unsigned long first, last; 686 685 int ret; 687 686 688 687 lockdep_assert_held(&kvm->lock); ··· 691 692 692 693 /* 693 694 * Calculate the number of pages that need to be pinned to cover the 694 - * entire range. Note! This isn't simply ulen >> PAGE_SHIFT, as KVM 695 + * entire range. Note! This isn't simply PFN_DOWN(ulen), as KVM 695 696 * doesn't require the incoming address+size to be page aligned! 696 697 */ 697 - first = (uaddr & PAGE_MASK) >> PAGE_SHIFT; 698 - last = ((uaddr + ulen - 1) & PAGE_MASK) >> PAGE_SHIFT; 699 - npages = (last - first + 1); 698 + npages = PFN_DOWN(uaddr + ulen - 1) - PFN_DOWN(uaddr) + 1; 700 699 if (npages > INT_MAX) 701 700 return ERR_PTR(-EINVAL); 702 701