[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <217b80f9-e02c-d02c-3c82-425c550e4ed7@arm.com>
Date: Mon, 10 Dec 2018 16:32:06 +0000
From: Robin Murphy <robin.murphy@....com>
To: Souptick Joarder <jrdr.linux@...il.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Matthew Wilcox <willy@...radead.org>,
Michal Hocko <mhocko@...e.com>,
Russell King - ARM Linux <linux@...linux.org.uk>,
iamjoonsoo.kim@....com, treding@...dia.com,
Kees Cook <keescook@...omium.org>,
Marek Szyprowski <m.szyprowski@...sung.com>
Cc: linux-kernel@...r.kernel.org, Linux-MM <linux-mm@...ck.org>,
linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH v3 2/9] arch/arm/mm/dma-mapping.c: Convert to use
vm_insert_range
On 08/12/2018 20:01, Souptick Joarder wrote:
> Hi Robin,
>
> On Fri, Dec 7, 2018 at 12:07 AM Souptick Joarder <jrdr.linux@...il.com> wrote:
>>
>> Convert to use vm_insert_range() to map range of kernel
>> memory to user vma.
>>
>> Signed-off-by: Souptick Joarder <jrdr.linux@...il.com>
>> ---
>> arch/arm/mm/dma-mapping.c | 21 +++++++--------------
>> 1 file changed, 7 insertions(+), 14 deletions(-)
>>
>> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
>> index 661fe48..4eec323 100644
>> --- a/arch/arm/mm/dma-mapping.c
>> +++ b/arch/arm/mm/dma-mapping.c
>> @@ -1582,31 +1582,24 @@ static int __arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma
>> void *cpu_addr, dma_addr_t dma_addr, size_t size,
>> unsigned long attrs)
>> {
>> - unsigned long uaddr = vma->vm_start;
>> - unsigned long usize = vma->vm_end - vma->vm_start;
>> + unsigned long page_count = vma_pages(vma);
>> struct page **pages = __iommu_get_pages(cpu_addr, attrs);
>> unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
>> unsigned long off = vma->vm_pgoff;
>> + int err;
>>
>> if (!pages)
>> return -ENXIO;
>>
>> - if (off >= nr_pages || (usize >> PAGE_SHIFT) > nr_pages - off)
>> + if (off >= nr_pages || page_count > nr_pages - off)
>> return -ENXIO;
>>
>> pages += off;
>> + err = vm_insert_range(vma, vma->vm_start, pages, page_count);
>
> Just to clarify, do we need to adjust page_count with vma->vm_pgoff as
> original code
> have not consider it and run the loop for entire range irrespective of
> vma->vm_pgoff value ?
In this instance, page_count is the size of the VMA, not the size of the
pages array itself, so as I understand things this patch is true to the
original code as-is.
Robin.
>
>> + if (err)
>> + pr_err("Remapping memory failed: %d\n", err);
>>
>> - do {
>> - int ret = vm_insert_page(vma, uaddr, *pages++);
>> - if (ret) {
>> - pr_err("Remapping memory failed: %d\n", ret);
>> - return ret;
>> - }
>> - uaddr += PAGE_SIZE;
>> - usize -= PAGE_SIZE;
>> - } while (usize > 0);
>> -
>> - return 0;
>> + return err;
>> }
>> static int arm_iommu_mmap_attrs(struct device *dev,
>> struct vm_area_struct *vma, void *cpu_addr,
>> --
>> 1.9.1
>>
Powered by blists - more mailing lists