summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2026-03-13 03:33:01 +0300
committerSean Christopherson <seanjc@google.com>2026-04-03 19:37:25 +0300
commit7ad02ff1e4a4d1a06483ec839cff26ea232db70f (patch)
tree622ab77b1334b24cdb78f54046418e4bbc7079a7
parent6d71f9349d9bf09bf82309bdc46704b4b6f6b314 (diff)
downloadlinux-7ad02ff1e4a4d1a06483ec839cff26ea232db70f.tar.xz
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>
-rw-r--r--arch/x86/kvm/svm/sev.c7
1 files changed, 2 insertions, 5 deletions
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);