linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: linuxppc-dev@lists.ozlabs.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH kernel] powerpc/mm_iommu: Allow pinning large regions
Date: Tue,  2 Apr 2019 15:31:01 +1100	[thread overview]
Message-ID: <20190402043101.51229-1-aik@ozlabs.ru> (raw)

When called with vmas_arg==NULL, get_user_pages_longterm() allocates
an array of nr_pages*8 which can easily get greater that the max order,
for example, registering memory for a 256GB guest does this and fails
in __alloc_pages_nodemask().

This adds a loop over chunks of entries to fit the max order limit.

Fixes: 678e174c4c16 ("powerpc/mm/iommu: allow migration of cma allocated pages during mm_iommu_do_alloc", 2019-03-05)
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 arch/powerpc/mm/mmu_context_iommu.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/mm/mmu_context_iommu.c b/arch/powerpc/mm/mmu_context_iommu.c
index 36a826e23d45..e058064b013c 100644
--- a/arch/powerpc/mm/mmu_context_iommu.c
+++ b/arch/powerpc/mm/mmu_context_iommu.c
@@ -131,6 +131,7 @@ long mm_iommu_new(struct mm_struct *mm, unsigned long ua, unsigned long entries,
 	unsigned int pageshift, mem_pageshift;
 	struct page **hpages;
 	phys_addr_t *hpas;
+	unsigned long entry, chunk, pinned;
 
 	mutex_lock(&mem_list_mutex);
 	if (mm_iommu_find(mm, ua, entries)) {
@@ -152,13 +153,29 @@ long mm_iommu_new(struct mm_struct *mm, unsigned long ua, unsigned long entries,
 	}
 
 	down_read(&mm->mmap_sem);
-	ret = get_user_pages_longterm(ua, entries, FOLL_WRITE, hpages, NULL);
+	chunk = (1UL << (PAGE_SHIFT + MAX_ORDER - 1)) /
+		sizeof(struct vm_area_struct *);
+	chunk = min(chunk, entries);
+	for (entry = 0, pinned = 0; entry < entries; entry += chunk) {
+		unsigned long n = min(entries - entry, chunk);
+
+		ret = get_user_pages_longterm(ua + (entry << PAGE_SHIFT), n,
+				FOLL_WRITE, hpages + entry, NULL);
+		if (ret == n) {
+			pinned += n;
+			continue;
+		}
+		if (ret >= 0)
+			pinned += ret;
+		break;
+	}
 	up_read(&mm->mmap_sem);
-	if (ret != entries) {
+	if (pinned != entries) {
 		/* free the reference taken */
-		for (i = 0; i < ret; i++)
+		for (i = 0; i < pinned; i++)
 			put_page(hpages[i]);
-		ret = -EFAULT;
+		if (!ret)
+			ret = -EFAULT;
 		goto cleanup_exit;
 	}
 
-- 
2.17.1


             reply	other threads:[~2019-04-02  4:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02  4:31 Alexey Kardashevskiy [this message]
2019-04-08  3:58 ` [PATCH kernel] powerpc/mm_iommu: Allow pinning large regions David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190402043101.51229-1-aik@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=linuxppc-dev@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).