2019-01-11 20:48:53

by Souptick Joarder

[permalink] [raw]
Subject: [PATCH 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

Convert to use vm_insert_range() to map range of kernel
memory to user vma.

Signed-off-by: Souptick Joarder <[email protected]>
---
arch/arm/mm/dma-mapping.c | 22 ++++++----------------
1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 78de138..5334391 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1582,31 +1582,21 @@ 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;
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 (vma->vm_pgoff >= nr_pages)
return -ENXIO;

- pages += off;
-
- 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);
+ err = vm_insert_range(vma, pages, nr_pages);
+ if (err)
+ pr_err("Remapping memory failed: %d\n", err);

- return 0;
+ return err;
}
static int arm_iommu_mmap_attrs(struct device *dev,
struct vm_area_struct *vma, void *cpu_addr,
--
1.9.1



2019-01-25 06:26:51

by Souptick Joarder

[permalink] [raw]
Subject: Re: [PATCH 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

On Fri, Jan 11, 2019 at 8:33 PM Souptick Joarder <[email protected]> wrote:
>
> Convert to use vm_insert_range() to map range of kernel
> memory to user vma.
>
> Signed-off-by: Souptick Joarder <[email protected]>

Any comment on this patch ?

> ---
> arch/arm/mm/dma-mapping.c | 22 ++++++----------------
> 1 file changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 78de138..5334391 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -1582,31 +1582,21 @@ 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;
> 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 (vma->vm_pgoff >= nr_pages)
> return -ENXIO;
>
> - pages += off;
> -
> - 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);
> + err = vm_insert_range(vma, pages, nr_pages);
> + if (err)
> + pr_err("Remapping memory failed: %d\n", err);
>
> - return 0;
> + return err;
> }
> static int arm_iommu_mmap_attrs(struct device *dev,
> struct vm_area_struct *vma, void *cpu_addr,
> --
> 1.9.1
>

2019-01-30 10:01:16

by Souptick Joarder

[permalink] [raw]
Subject: Re: [PATCH 2/9] arch/arm/mm/dma-mapping.c: Convert to use vm_insert_range

On Fri, Jan 25, 2019 at 11:54 AM Souptick Joarder <[email protected]> wrote:
>
> On Fri, Jan 11, 2019 at 8:33 PM Souptick Joarder <[email protected]> wrote:
> >
> > Convert to use vm_insert_range() to map range of kernel
> > memory to user vma.
> >
> > Signed-off-by: Souptick Joarder <[email protected]>
>
> Any comment on this patch ?

Any comment on this patch ?

>
> > ---
> > arch/arm/mm/dma-mapping.c | 22 ++++++----------------
> > 1 file changed, 6 insertions(+), 16 deletions(-)
> >
> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> > index 78de138..5334391 100644
> > --- a/arch/arm/mm/dma-mapping.c
> > +++ b/arch/arm/mm/dma-mapping.c
> > @@ -1582,31 +1582,21 @@ 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;
> > 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 (vma->vm_pgoff >= nr_pages)
> > return -ENXIO;
> >
> > - pages += off;
> > -
> > - 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);
> > + err = vm_insert_range(vma, pages, nr_pages);
> > + if (err)
> > + pr_err("Remapping memory failed: %d\n", err);
> >
> > - return 0;
> > + return err;
> > }
> > static int arm_iommu_mmap_attrs(struct device *dev,
> > struct vm_area_struct *vma, void *cpu_addr,
> > --
> > 1.9.1
> >