From: Sean Christopherson Date: Fri, 13 Mar 2026 00:33:01 +0000 (-0700) Subject: KVM: SEV: Use PFN_DOWN() to simplify "number of pages" math when pinning memory X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ad02ff1e4a4d1a06483ec839cff26ea232db70f;p=thirdparty%2Fkernel%2Flinux.git 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 Tested-by: Liam Merwick Link: https://patch.msgid.link/20260313003302.3136111-5-seanjc@google.com Signed-off-by: Sean Christopherson --- diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index f37e23496b64..15ac2b907260 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -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);