Commit 8c564aff authored by Xin Jiang's avatar Xin Jiang Committed by hanliyang
Browse files

KVM: SEV: Pin SEV guest memory out of CMA area

hygon inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAD13S


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: default avatarXin Jiang <jiangxin@hygon.cn>
Signed-off-by: default avatarhanliyang <hanliyang@hygon.cn>
parent 9d5b8fe1
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -516,6 +516,7 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
	unsigned long locked, lock_limit;
	struct page **pages;
	unsigned long first, last;
	unsigned int flags = 0;
	int ret;

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

	flags = write ? FOLL_WRITE : 0;

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