Skip to content

Commit 31314f6

Browse files
Xin JiangAvenger-285714
authored andcommitted
KVM: SEV: Pin SEV guest memory out of CMA area
hygon inclusion category: bugfix CVE: NA --------------------------- When pin_user_pages_fast pin SEV guest memory without FOLL_LONGTERM flag, the pinning pages may be in CMA area, which resulting in other applications may can't use the CMA area because the pinning pages can't be migrated. Add FOLL_LONGTERM flag to pin_user_pages_fast, which makes sure that we don't keep non_movable pages (due to page reference count) in CMA area. So CMA area can be allocated by other applications. Signed-off-by: Xin Jiang <[email protected]> Signed-off-by: hanliyang <[email protected]>
1 parent 71df945 commit 31314f6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/x86/kvm/svm/sev.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
516516
unsigned long locked, lock_limit;
517517
struct page **pages;
518518
unsigned long first, last;
519+
unsigned int flags = 0;
519520
int ret;
520521

521522
lockdep_assert_held(&kvm->lock);
@@ -548,8 +549,10 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
548549
if (!pages)
549550
return ERR_PTR(-ENOMEM);
550551

552+
flags = write ? FOLL_WRITE : 0;
553+
551554
/* Pin the user virtual address. */
552-
npinned = pin_user_pages_fast(uaddr, npages, write ? FOLL_WRITE : 0, pages);
555+
npinned = pin_user_pages_fast(uaddr, npages, flags | FOLL_LONGTERM, pages);
553556
if (npinned != npages) {
554557
pr_err("SEV: Failure locking %lu pages.\n", npages);
555558
ret = -ENOMEM;

0 commit comments

Comments
 (0)