On Tue, Apr 02, 2019 at 03:31:01PM +1100, Alexey Kardashevskiy wrote: > 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 <a...@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);
I think this is redundant with.. > + for (entry = 0, pinned = 0; entry < entries; entry += chunk) { > + unsigned long n = min(entries - entry, chunk); .. this. But otherwise LGTM. > + > + 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; > } > -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
signature.asc
Description: PGP signature