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>
This commit is contained in:
Sean Christopherson 2026-03-12 17:33:01 -07:00
parent 6d71f9349d
commit 7ad02ff1e4

View File

@ -682,7 +682,6 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
int npinned;
unsigned long total_npages, lock_limit;
struct page **pages;
unsigned long first, last;
int ret;
lockdep_assert_held(&kvm->lock);
@ -692,12 +691,10 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
/*
* Calculate the number of pages that need to be pinned to cover the
* entire range. Note! This isn't simply ulen >> PAGE_SHIFT, as KVM
* entire range. Note! This isn't simply PFN_DOWN(ulen), as KVM
* doesn't require the incoming address+size to be page aligned!
*/
first = (uaddr & PAGE_MASK) >> PAGE_SHIFT;
last = ((uaddr + ulen - 1) & PAGE_MASK) >> PAGE_SHIFT;
npages = (last - first + 1);
npages = PFN_DOWN(uaddr + ulen - 1) - PFN_DOWN(uaddr) + 1;
if (npages > INT_MAX)
return ERR_PTR(-EINVAL);