All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
To: Yong Wu <yong.wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
Cc: "laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org"
	<laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org>,
	"arnd-r2nGTMty4D4@public.gmane.org"
	<arnd-r2nGTMty4D4@public.gmane.org>,
	Catalin Marinas <Catalin.Marinas-5wv7dgnIgG8@public.gmane.org>,
	Will Deacon <Will.Deacon-5wv7dgnIgG8@public.gmane.org>,
	"tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
	<tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org"
	<iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	"djkurtz-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org"
	<djkurtz-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	"thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org"
	<thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>,
	"yt.shen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org"
	<yt.shen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
	"yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org"
	<yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
	"treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org"
	<treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	"linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org"
	<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Subject: Re: [PATCH v2 2/4] iommu: Implement common IOMMU ops for DMA mapping
Date: Thu, 18 Jun 2015 17:54:29 +0100	[thread overview]
Message-ID: <5582F7C5.8060901@arm.com> (raw)
In-Reply-To: <1434639625.26953.12.camel@mhfsdcap03>

On 18/06/15 16:00, Yong Wu wrote:
> Hi Robin,
>      while our drm test, we meet a problem while dma-mmap.
>
>   On Thu, 2015-06-11 at 16:54 +0100, Robin Murphy wrote:
>> Taking inspiration from the existing arch/arm code, break out some
>> generic functions to interface the DMA-API to the IOMMU-API. This will
>> do the bulk of the heavy lifting for IOMMU-backed dma-mapping.
>>
>> Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
>> ---
>>   drivers/iommu/Kconfig     |   7 +
>>   drivers/iommu/Makefile    |   1 +
>>   drivers/iommu/dma-iommu.c | 560 ++++++++++++++++++++++++++++++++++++++++++++++
>>   include/linux/dma-iommu.h |  94 ++++++++
>>   4 files changed, 662 insertions(+)
>>   create mode 100644 drivers/iommu/dma-iommu.c
>>   create mode 100644 include/linux/dma-iommu.h
>>
> [snip]
>> +/**
>> + * iommu_dma_mmap - Map a buffer into provided user VMA
>> + * @pages: Array representing buffer from iommu_dma_alloc()
>> + * @size: Size of buffer in bytes
>> + * @vma: VMA describing requested userspace mapping
>> + *
>> + * Maps the pages of the buffer in @pages into @vma. The caller is responsible
>> + * for verifying the correct size and protection of @vma beforehand.
>> + */
>> +
>> +int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma)
>> +{
>> +	unsigned long uaddr = vma->vm_start;
>> +	unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT;
>> +	int ret = -ENXIO;
>> +
>> +	for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) {
> Is it :  for (i = 0; i < count && uaddr < vma->vm_end; i++)

According to the patches at [1], respecting vma->pgoff is necessary for 
users who only want to mmap part of the buffer. Does your DRM driver by 
any chance need the same fix as the Rockchip one?

>> +		ret = vm_insert_page(vma, uaddr, pages[i]);
>> +		if (ret)
>> +			break;
>> +		uaddr += PAGE_SIZE;
>> +	}
>> +	return ret;
>> +}
>> +

And to save another email:

 >> +	if (WARN_ON(!area || area->pages))
 > Is it:    if (WARN_ON(!area || !area->pages))
 >> +		return -ENXIO;

You're absolutely right, thanks. I've got a couple more bugfixes in 
progress too, so I'll try to get an updated branch pushed out soon; I'll 
hold off posting a v3 to the list until after the upcoming merge window, 
though.

Robin.

[1]:http://thread.gmane.org/gmane.linux.kernel/1932343

WARNING: multiple messages have this Message-ID (diff)
From: robin.murphy@arm.com (Robin Murphy)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 2/4] iommu: Implement common IOMMU ops for DMA mapping
Date: Thu, 18 Jun 2015 17:54:29 +0100	[thread overview]
Message-ID: <5582F7C5.8060901@arm.com> (raw)
In-Reply-To: <1434639625.26953.12.camel@mhfsdcap03>

On 18/06/15 16:00, Yong Wu wrote:
> Hi Robin,
>      while our drm test, we meet a problem while dma-mmap.
>
>   On Thu, 2015-06-11 at 16:54 +0100, Robin Murphy wrote:
>> Taking inspiration from the existing arch/arm code, break out some
>> generic functions to interface the DMA-API to the IOMMU-API. This will
>> do the bulk of the heavy lifting for IOMMU-backed dma-mapping.
>>
>> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
>> ---
>>   drivers/iommu/Kconfig     |   7 +
>>   drivers/iommu/Makefile    |   1 +
>>   drivers/iommu/dma-iommu.c | 560 ++++++++++++++++++++++++++++++++++++++++++++++
>>   include/linux/dma-iommu.h |  94 ++++++++
>>   4 files changed, 662 insertions(+)
>>   create mode 100644 drivers/iommu/dma-iommu.c
>>   create mode 100644 include/linux/dma-iommu.h
>>
> [snip]
>> +/**
>> + * iommu_dma_mmap - Map a buffer into provided user VMA
>> + * @pages: Array representing buffer from iommu_dma_alloc()
>> + * @size: Size of buffer in bytes
>> + * @vma: VMA describing requested userspace mapping
>> + *
>> + * Maps the pages of the buffer in @pages into @vma. The caller is responsible
>> + * for verifying the correct size and protection of @vma beforehand.
>> + */
>> +
>> +int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma)
>> +{
>> +	unsigned long uaddr = vma->vm_start;
>> +	unsigned int i, count = PAGE_ALIGN(size) >> PAGE_SHIFT;
>> +	int ret = -ENXIO;
>> +
>> +	for (i = vma->vm_pgoff; i < count && uaddr < vma->vm_end; i++) {
> Is it :  for (i = 0; i < count && uaddr < vma->vm_end; i++)

According to the patches at [1], respecting vma->pgoff is necessary for 
users who only want to mmap part of the buffer. Does your DRM driver by 
any chance need the same fix as the Rockchip one?

>> +		ret = vm_insert_page(vma, uaddr, pages[i]);
>> +		if (ret)
>> +			break;
>> +		uaddr += PAGE_SIZE;
>> +	}
>> +	return ret;
>> +}
>> +

And to save another email:

 >> +	if (WARN_ON(!area || area->pages))
 > Is it:    if (WARN_ON(!area || !area->pages))
 >> +		return -ENXIO;

You're absolutely right, thanks. I've got a couple more bugfixes in 
progress too, so I'll try to get an updated branch pushed out soon; I'll 
hold off posting a v3 to the list until after the upcoming merge window, 
though.

Robin.

[1]:http://thread.gmane.org/gmane.linux.kernel/1932343

  reply	other threads:[~2015-06-18 16:54 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11 15:54 [PATCH v2 0/4] arm64: IOMMU-backed DMA mapping Robin Murphy
2015-06-11 15:54 ` Robin Murphy
     [not found] ` <cover.1434036796.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-06-11 15:54   ` [PATCH v2 1/4] iommu/iova: Avoid over-allocating when size-aligned Robin Murphy
2015-06-11 15:54     ` Robin Murphy
2015-06-11 15:54   ` [PATCH v2 2/4] iommu: Implement common IOMMU ops for DMA mapping Robin Murphy
2015-06-11 15:54     ` Robin Murphy
     [not found]     ` <bf63d80c36533aa4dcc401b5a4b312ba00237e1c.1434036796.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-06-18 15:00       ` Yong Wu
2015-06-18 15:00         ` Yong Wu
2015-06-18 16:54         ` Robin Murphy [this message]
2015-06-18 16:54           ` Robin Murphy
     [not found]           ` <5582F7C5.8060901-5wv7dgnIgG8@public.gmane.org>
2015-06-19  1:06             ` Yong Wu
2015-06-19  1:06               ` Yong Wu
2015-07-03  9:27       ` Yong Wu
2015-07-03  9:27         ` Yong Wu
2015-07-03 16:44         ` Robin Murphy
2015-07-03 16:44           ` Robin Murphy
     [not found]           ` <5596BBD3.1040708-5wv7dgnIgG8@public.gmane.org>
2015-07-07  7:37             ` Yong Wu
2015-07-07  7:37               ` Yong Wu
2015-06-11 15:54   ` [PATCH v2 3/4] arm64: Add IOMMU dma_ops Robin Murphy
2015-06-11 15:54     ` Robin Murphy
     [not found]     ` <4e298538ccedbe6f593d8edc40eb3a08ad9e4df5.1434036796.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2015-06-18 15:00       ` Yong Wu
2015-06-18 15:00         ` Yong Wu
2015-06-11 15:54   ` [PATCH v2 4/4] arm64: Hook up " Robin Murphy
2015-06-11 15:54     ` Robin Murphy

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=5582F7C5.8060901@arm.com \
    --to=robin.murphy-5wv7dgnigg8@public.gmane.org \
    --cc=Catalin.Marinas-5wv7dgnIgG8@public.gmane.org \
    --cc=Will.Deacon-5wv7dgnIgG8@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=djkurtz-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=laurent.pinchart+renesas-ryLnwIuWjnjg/C1BVhZhaw@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=thunder.leizhen-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=tomasz.figa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=yingjoe.chen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=yong.wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
    --cc=yt.shen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.