linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/iommu: use iommu_num_pages() to calculate the number of iommu page
@ 2015-09-19 13:04 Wei Yang
  2015-09-30 23:50 ` Wei Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Wei Yang @ 2015-09-19 13:04 UTC (permalink / raw)
  To: benh, paulus, mpe; +Cc: linuxppc-dev, Wei Yang

On PowerPC, currently we support different value of PAGE_SIZE and different
value of IOMMU Page Size.

In case the PAGE_SIZE is 4K and the IOMMU Page Size is 16M, and driver
asked for some DMA less than 16M, the current calculation would return 0
and the following allocation in iommu_alloc() would fail.

This patch uses iommu_num_pages() to calculate it.

Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index a8e3490..9885397 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -842,7 +842,7 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
 	memset(ret, 0, size);
 
 	/* Set up tces to cover the allocated range */
-	nio_pages = size >> tbl->it_page_shift;
+	nio_pages = iommu_num_pages(0, size, IOMMU_PAGE_SIZE(tbl));
 	io_order = get_iommu_order(size, tbl);
 	mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
 			      mask >> tbl->it_page_shift, io_order, NULL);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] powerpc/iommu: use iommu_num_pages() to calculate the number of iommu page
  2015-09-19 13:04 [PATCH] powerpc/iommu: use iommu_num_pages() to calculate the number of iommu page Wei Yang
@ 2015-09-30 23:50 ` Wei Yang
  2015-10-01  4:15   ` Michael Ellerman
  0 siblings, 1 reply; 5+ messages in thread
From: Wei Yang @ 2015-09-30 23:50 UTC (permalink / raw)
  To: Wei Yang; +Cc: benh, paulus, mpe, linuxppc-dev

Hmm... some comments on this one? like it or not?

On Sat, Sep 19, 2015 at 09:04:27PM +0800, Wei Yang wrote:
>On PowerPC, currently we support different value of PAGE_SIZE and different
>value of IOMMU Page Size.
>
>In case the PAGE_SIZE is 4K and the IOMMU Page Size is 16M, and driver
>asked for some DMA less than 16M, the current calculation would return 0
>and the following allocation in iommu_alloc() would fail.
>
>This patch uses iommu_num_pages() to calculate it.
>
>Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
>---
> arch/powerpc/kernel/iommu.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
>index a8e3490..9885397 100644
>--- a/arch/powerpc/kernel/iommu.c
>+++ b/arch/powerpc/kernel/iommu.c
>@@ -842,7 +842,7 @@ void *iommu_alloc_coherent(struct device *dev, struct iommu_table *tbl,
> 	memset(ret, 0, size);
>
> 	/* Set up tces to cover the allocated range */
>-	nio_pages = size >> tbl->it_page_shift;
>+	nio_pages = iommu_num_pages(0, size, IOMMU_PAGE_SIZE(tbl));
> 	io_order = get_iommu_order(size, tbl);
> 	mapping = iommu_alloc(dev, tbl, ret, nio_pages, DMA_BIDIRECTIONAL,
> 			      mask >> tbl->it_page_shift, io_order, NULL);
>-- 
>2.5.0

-- 
Richard Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] powerpc/iommu: use iommu_num_pages() to calculate the number of iommu page
  2015-09-30 23:50 ` Wei Yang
@ 2015-10-01  4:15   ` Michael Ellerman
  2015-10-01 22:51     ` Wei Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2015-10-01  4:15 UTC (permalink / raw)
  To: Wei Yang; +Cc: benh, paulus, linuxppc-dev

On Thu, 2015-10-01 at 07:50 +0800, Wei Yang wrote:
> Hmm... some comments on this one? like it or not?

It sounds like it's fixing a bug, but you don't really say. Have you seen this
fail in the wild?

Which commit introduced the breakage?

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] powerpc/iommu: use iommu_num_pages() to calculate the number of iommu page
  2015-10-01  4:15   ` Michael Ellerman
@ 2015-10-01 22:51     ` Wei Yang
  2015-11-12  2:32       ` Wei Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Wei Yang @ 2015-10-01 22:51 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: Wei Yang, benh, paulus, linuxppc-dev

On Thu, Oct 01, 2015 at 02:15:45PM +1000, Michael Ellerman wrote:
>On Thu, 2015-10-01 at 07:50 +0800, Wei Yang wrote:
>> Hmm... some comments on this one? like it or not?
>
>It sounds like it's fixing a bug, but you don't really say. Have you seen this
>fail in the wild?

Hmm... as described in the commit log, this would be a bug when 
PAGE_SIZE is much smaller than IOMMU Page Size. This configuration doesn't
happen on current platform. So I didn't see this failure yet.

>
>Which commit introduced the breakage?

Hmm...  maybe we could say it is 'commit d084775738b7
<powerpc/iommu: Update the generic code to use dynamic iommu page sizes>'.
>From this commit, powerpc iommu supports dynamic iommu page size. 

Before this commit, the size is aligned with PAGE_SIZE, so the value after
shift would be non-zero. After this commit, when PAGE_SIZE is smaller than
the IOMMU Page Size, shift right will make the size 0.

>
>cheers
>

-- 
Richard Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] powerpc/iommu: use iommu_num_pages() to calculate the number of iommu page
  2015-10-01 22:51     ` Wei Yang
@ 2015-11-12  2:32       ` Wei Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Wei Yang @ 2015-11-12  2:32 UTC (permalink / raw)
  To: Wei Yang; +Cc: Michael Ellerman, benh, paulus, linuxppc-dev

Someone willing to take a look?

On Fri, Oct 02, 2015 at 06:51:59AM +0800, Wei Yang wrote:
>On Thu, Oct 01, 2015 at 02:15:45PM +1000, Michael Ellerman wrote:
>>On Thu, 2015-10-01 at 07:50 +0800, Wei Yang wrote:
>>> Hmm... some comments on this one? like it or not?
>>
>>It sounds like it's fixing a bug, but you don't really say. Have you seen this
>>fail in the wild?
>
>Hmm... as described in the commit log, this would be a bug when 
>PAGE_SIZE is much smaller than IOMMU Page Size. This configuration doesn't
>happen on current platform. So I didn't see this failure yet.
>
>>
>>Which commit introduced the breakage?
>
>Hmm...  maybe we could say it is 'commit d084775738b7
><powerpc/iommu: Update the generic code to use dynamic iommu page sizes>'.
>>From this commit, powerpc iommu supports dynamic iommu page size. 
>
>Before this commit, the size is aligned with PAGE_SIZE, so the value after
>shift would be non-zero. After this commit, when PAGE_SIZE is smaller than
>the IOMMU Page Size, shift right will make the size 0.
>
>>
>>cheers
>>
>
>-- 
>Richard Yang
>Help you, Help me

-- 
Richard Yang
Help you, Help me

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-12  2:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-19 13:04 [PATCH] powerpc/iommu: use iommu_num_pages() to calculate the number of iommu page Wei Yang
2015-09-30 23:50 ` Wei Yang
2015-10-01  4:15   ` Michael Ellerman
2015-10-01 22:51     ` Wei Yang
2015-11-12  2:32       ` Wei Yang

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).