Skip to contentSkip to conversation

IOMMU: move page number calculation to generic code

PATCH Applied Joerg Roedel 7 participants 40 messages Jul 25, 2008 – Jul 31, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover IOMMU: move page number calculation to generic code

This small patch series introduces a generic iommu_num_pages function into the IOMMU helper code. This function can be used to calculate the number of pages an IOMMU has to map for a specific mapping request.

The patchset converts the x86 IOMMU implementations for AMD IOMMU and the GART to use this function.

Other IOMMU implementations are not changed because I can't test them.

diffstat:

 arch/x86/kernel/amd_iommu.c   |   13 +++++--------
 arch/x86/kernel/pci-gart_64.c |   11 ++++-------
 include/linux/iommu-helper.h  |    1 +
 lib/iommu-helper.c            |    8 ++++++++
 4 files changed, 18 insertions(+), 15 deletions(-)
#1 lore raw

PATCH 1/1 AMD IOMMU: replace to_pages macro with iommu_num_pages

This patch removes the to_pages macro from AMD IOMMU code and calls the generic iommu_num_pages function instead.

---
 arch/x86/kernel/amd_iommu.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
arch/x86/kernel/amd_iommu.c +5 -8
index 7469740..22d7d05 100644
@@ -29,9 +29,6 @@
 
 #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28))
 
-#define to_pages(addr, size) \
-	 (round_up(((addr) & ~PAGE_MASK) + (size), PAGE_SIZE) >> PAGE_SHIFT)
-
 #define EXIT_LOOP_COUNT 10000000
 
 static DEFINE_RWLOCK(amd_iommu_devtable_lock);
@@ -185,7 +182,7 @@ static int iommu_flush_pages(struct amd_iommu *iommu, u16 domid,
 		u64 address, size_t size)
 {
 	int s = 0;
-	unsigned pages = to_pages(address, size);
+	unsigned pages = iommu_num_pages(address, size);
 
 	address &= PAGE_MASK;
 
@@ -557,8 +554,8 @@ static struct dma_ops_domain *dma_ops_domain_alloc(struct amd_iommu *iommu,
 	if (iommu->exclusion_start &&
 	    iommu->exclusion_start < dma_dom->aperture_size) {
 		unsigned long startpage = iommu->exclusion_start >> PAGE_SHIFT;
-		int pages = to_pages(iommu->exclusion_start,
-				iommu->exclusion_length);
+		int pages = iommu_num_pages(iommu->exclusion_start,
+					    iommu->exclusion_length);
 		dma_ops_reserve_addresses(dma_dom, startpage, pages);
 	}
 
@@ -767,7 +764,7 @@ static dma_addr_t __map_single(struct device *dev,
 	unsigned int pages;
 	int i;
 
-	pages = to_pages(paddr, size);
+	pages = iommu_num_pages(paddr, size);
 	paddr &= PAGE_MASK;
 
 	address = dma_ops_alloc_addresses(dev, dma_dom, pages);
@@ -802,7 +799,7 @@ static void __unmap_single(struct amd_iommu *iommu,
 	if ((dma_addr == 0) || (dma_addr + size > dma_dom->aperture_size))
 		return;
 
-	pages = to_pages(dma_addr, size);
+	pages = iommu_num_pages(dma_addr, size);
 	dma_addr &= PAGE_MASK;
 	start = dma_addr;
 
Signature · 1 line
1.5.3.7
#2 lore raw

PATCH 1/1 add iommu_num_pages helper function

In reply to Joerg Roedel

Calculating the number of pages from given address and length numbers is a task required in multiple IOMMU implementations. So implement this as a generic function into the IOMMU helper code.

Cc FUJITA Tomonori <[email protected]>
---
 include/linux/iommu-helper.h |    1 +
 lib/iommu-helper.c           |    8 ++++++++
 2 files changed, 9 insertions(+), 0 deletions(-)
include/linux/iommu-helper.h +1 -0
index c975caf..f8598f5 100644
@@ -8,3 +8,4 @@ extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 				      unsigned long align_mask);
 extern void iommu_area_free(unsigned long *map, unsigned long start,
 			    unsigned int nr);
+extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
lib/iommu-helper.c +8 -0
index a3b8d4c..889ddce 100644
@@ -80,3 +80,11 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
 	}
 }
 EXPORT_SYMBOL(iommu_area_free);
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
+{
+	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
+
+	return size >> PAGE_SHIFT;
+}
+EXPORT_SYMBOL(iommu_num_pages);
Signature · 1 line
1.5.3.7
#3 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 10 lines · On Fri, 25 Jul 2008 14:57:58 +0200 Joerg Roedel <[email protected]> wrote:

Calculating the number of pages from given address and length numbers is a task required in multiple IOMMU implementations. So implement this as a generic function into the IOMMU helper code.

Cc FUJITA Tomonori <[email protected]>
---
 include/linux/iommu-helper.h |    1 +
 lib/iommu-helper.c           |    8 ++++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

Thanks. I planed to work on this after rc1. You beat me. :)

Quoted 15 lines
include/linux/iommu-helper.h +1 -0
index c975caf..f8598f5 100644
@@ -8,3 +8,4 @@ extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 				      unsigned long align_mask);
 extern void iommu_area_free(unsigned long *map, unsigned long start,
 			    unsigned int nr);
+extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
lib/iommu-helper.c +0 -0
index a3b8d4c..889ddce 100644
@@ -80,3 +80,11 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
 	}

lib/iommu-helper.c void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) · line 90

Quoted 10 lines
lib/iommu-helper.c +8 -0
 }
 EXPORT_SYMBOL(iommu_area_free);
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
+{
+	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
+
+	return size >> PAGE_SHIFT;
+}
+EXPORT_SYMBOL(iommu_num_pages);

This doesn't work since PAGE_SIZE != IOMMU_PAGE_SIZE on the majority of architectures.

#4 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 37 lines · FUJITA Tomonori
Quoted 10 lines · On Fri, 25 Jul 2008 14:57:58 +0200 Joerg Roedel <[email protected]> wrote:

Calculating the number of pages from given address and length numbers is a task required in multiple IOMMU implementations. So implement this as a generic function into the IOMMU helper code.

Cc FUJITA Tomonori <[email protected]>
---
 include/linux/iommu-helper.h |    1 +
 lib/iommu-helper.c           |    8 ++++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

Thanks. I planed to work on this after rc1. You beat me. :)

Quoted 20 lines
include/linux/iommu-helper.h +1 -0
index c975caf..f8598f5 100644
@@ -8,3 +8,4 @@ extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 				      unsigned long align_mask);
 extern void iommu_area_free(unsigned long *map, unsigned long start,
 			    unsigned int nr);
+extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
lib/iommu-helper.c +3 -0
index a3b8d4c..889ddce 100644
@@ -80,3 +80,11 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
 	}
 }
 EXPORT_SYMBOL(iommu_area_free);
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
+{
Quoted 8 lines

lib/iommu-helper.c void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) · line 90

Quoted 5 lines
lib/iommu-helper.c +5 -0
+	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
+
+	return size >> PAGE_SHIFT;
+}
+EXPORT_SYMBOL(iommu_num_pages);

This doesn't work since PAGE_SIZE != IOMMU_PAGE_SIZE on the majority of architectures.

A quick grep in include/ tells me that only powerpc is declaring IOMMU_PAGE_SIZE by now.

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#5 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 47 lines · On Fri, 25 Jul 2008 15:21:21 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 37 lines · FUJITA Tomonori
Quoted 10 lines · On Fri, 25 Jul 2008 14:57:58 +0200 Joerg Roedel <[email protected]> wrote:

Calculating the number of pages from given address and length numbers is a task required in multiple IOMMU implementations. So implement this as a generic function into the IOMMU helper code.

Cc FUJITA Tomonori <[email protected]>
---
 include/linux/iommu-helper.h |    1 +
 lib/iommu-helper.c           |    8 ++++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

Thanks. I planed to work on this after rc1. You beat me. :)

Quoted 20 lines
include/linux/iommu-helper.h +1 -0
index c975caf..f8598f5 100644
@@ -8,3 +8,4 @@ extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 				      unsigned long align_mask);
 extern void iommu_area_free(unsigned long *map, unsigned long start,
 			    unsigned int nr);
+extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
lib/iommu-helper.c +3 -0
index a3b8d4c..889ddce 100644
@@ -80,3 +80,11 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
 	}
 }
 EXPORT_SYMBOL(iommu_area_free);
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
+{
Quoted 8 lines

lib/iommu-helper.c void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) · line 90

Quoted 5 lines
lib/iommu-helper.c +5 -0
+	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
+
+	return size >> PAGE_SHIFT;
+}
+EXPORT_SYMBOL(iommu_num_pages);

This doesn't work since PAGE_SIZE != IOMMU_PAGE_SIZE on the majority of architectures.

Quoted 2 lines

A quick grep in include/ tells me that only powerpc is declaring IOMMU_PAGE_SIZE by now.

Ah, I just meant the I/O size of IOMMUs.

This macro doesn't work for IA64, POWER, and SPARC.

#6 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 50 lines · FUJITA Tomonori
Quoted 47 lines · On Fri, 25 Jul 2008 15:21:21 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 45 lines · FUJITA Tomonori
Quoted 10 lines · On Fri, 25 Jul 2008 14:57:58 +0200 Joerg Roedel <[email protected]> wrote:

Calculating the number of pages from given address and length numbers is a task required in multiple IOMMU implementations. So implement this as a generic function into the IOMMU helper code.

Cc FUJITA Tomonori <[email protected]>
---
 include/linux/iommu-helper.h |    1 +
 lib/iommu-helper.c           |    8 ++++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

Thanks. I planed to work on this after rc1. You beat me. :)

Quoted 15 lines
include/linux/iommu-helper.h +1 -0
index c975caf..f8598f5 100644
@@ -8,3 +8,4 @@ extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 				      unsigned long align_mask);
 extern void iommu_area_free(unsigned long *map, unsigned long start,
 			    unsigned int nr);
+extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
lib/iommu-helper.c +0 -0
index a3b8d4c..889ddce 100644
@@ -80,3 +80,11 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
 	}

lib/iommu-helper.c void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) · line 90

Quoted 10 lines
lib/iommu-helper.c +8 -0
 }
 EXPORT_SYMBOL(iommu_area_free);
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
+{
+	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
+
+	return size >> PAGE_SHIFT;
+}
+EXPORT_SYMBOL(iommu_num_pages);

This doesn't work since PAGE_SIZE != IOMMU_PAGE_SIZE on the majority of architectures.

Quoted 6 lines
Quoted 2 lines

A quick grep in include/ tells me that only powerpc is declaring IOMMU_PAGE_SIZE by now.

Ah, I just meant the I/O size of IOMMUs.

This macro doesn't work for IA64, POWER, and SPARC.

Is there any other architecture independent way to find out the page size the IOMMU is using? If yes I can rework that patchset. If not, I suggest that we (you?) introduce one in a follow-on patch series and fix the iommu_num_pages function then.

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#7 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 54 lines · On Fri, 25 Jul 2008 15:41:59 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 53 lines · FUJITA Tomonori
Quoted 49 lines · On Fri, 25 Jul 2008 15:21:21 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 37 lines · FUJITA Tomonori
Quoted 10 lines · On Fri, 25 Jul 2008 14:57:58 +0200 Joerg Roedel <[email protected]> wrote:

Calculating the number of pages from given address and length numbers is a task required in multiple IOMMU implementations. So implement this as a generic function into the IOMMU helper code.

Cc FUJITA Tomonori <[email protected]>
---
 include/linux/iommu-helper.h |    1 +
 lib/iommu-helper.c           |    8 ++++++++
 2 files changed, 9 insertions(+), 0 deletions(-)

Thanks. I planed to work on this after rc1. You beat me. :)

Quoted 20 lines
include/linux/iommu-helper.h +1 -0
index c975caf..f8598f5 100644
@@ -8,3 +8,4 @@ extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 				      unsigned long align_mask);
 extern void iommu_area_free(unsigned long *map, unsigned long start,
 			    unsigned int nr);
+extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
lib/iommu-helper.c +3 -0
index a3b8d4c..889ddce 100644
@@ -80,3 +80,11 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
 	}
 }
 EXPORT_SYMBOL(iommu_area_free);
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
+{
Quoted 8 lines

lib/iommu-helper.c void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) · line 90

Quoted 5 lines
lib/iommu-helper.c +5 -0
+	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
+
+	return size >> PAGE_SHIFT;
+}
+EXPORT_SYMBOL(iommu_num_pages);

This doesn't work since PAGE_SIZE != IOMMU_PAGE_SIZE on the majority of architectures.

A quick grep in include/ tells me that only powerpc is declaring IOMMU_PAGE_SIZE by now.

Quoted 6 lines
Quoted 3 lines

Ah, I just meant the I/O size of IOMMUs.

This macro doesn't work for IA64, POWER, and SPARC.

Is there any other architecture independent way to find out the page size the IOMMU is using? If yes I can rework that patchset.

There isn't now, I think.

Quoted 2 lines

If not, I suggest that we (you?) introduce one in a follow-on patch series and fix the iommu_num_pages function then.

That's fine by me. Or I could try to find a solution and submit new patchset with your AMD and GART patches.

BTW, I prefer to push this patchset via -mm rather than x86 since after all we need to clean up all the IOMMUs.

#8 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 8 lines · FUJITA Tomonori
Quoted 3 lines · On Fri, 25 Jul 2008 15:41:59 +0200 Joerg Roedel <[email protected]> wrote:

Is there any other architecture independent way to find out the page size the IOMMU is using? If yes I can rework that patchset.

There isn't now, I think.

Ok.

Quoted 6 lines
Quoted 3 lines

If not, I suggest that we (you?) introduce one in a follow-on patch series and fix the iommu_num_pages function then.

That's fine by me. Or I could try to find a solution and submit new patchset with your AMD and GART patches.

Thats also possible. But I prefer to fix that incrementally and merge this first step.

Quoted 2 lines

BTW, I prefer to push this patchset via -mm rather than x86 since after all we need to clean up all the IOMMUs.

Push it through -mm would make sense since it touches generic code in lib/. On the other side in x86 we would avoid merge conflicts with updates in AMD IOMMU and GART code.

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#9 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 9 lines · On Fri, 25 Jul 2008 16:14:25 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines

If not, I suggest that we (you?) introduce one in a follow-on patch series and fix the iommu_num_pages function then.

That's fine by me. Or I could try to find a solution and submit new patchset with your AMD and GART patches.

Thats also possible. But I prefer to fix that incrementally and merge this first step.

Quoted 6 lines
Quoted 2 lines

BTW, I prefer to push this patchset via -mm rather than x86 since after all we need to clean up all the IOMMUs.

Push it through -mm would make sense since it touches generic code in lib/. On the other side in x86 we would avoid merge conflicts with updates in AMD IOMMU and GART code.

Ok, I have no preference. It's not urgent and I can work on this later on. I leave it to you and x86 maintainers.

Thanks,

#10 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 15 lines · FUJITA Tomonori
Quoted 12 lines · On Fri, 25 Jul 2008 16:14:25 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 5 lines
Quoted 2 lines

If not, I suggest that we (you?) introduce one in a follow-on patch series and fix the iommu_num_pages function then.

That's fine by me. Or I could try to find a solution and submit new patchset with your AMD and GART patches.

Thats also possible. But I prefer to fix that incrementally and merge this first step.

Quoted 2 lines

BTW, I prefer to push this patchset via -mm rather than x86 since after all we need to clean up all the IOMMUs.

Quoted 6 lines
Quoted 3 lines

Push it through -mm would make sense since it touches generic code in lib/. On the other side in x86 we would avoid merge conflicts with updates in AMD IOMMU and GART code.

Ok, I have no preference. It's not urgent and I can work on this later on. I leave it to you and x86 maintainers.

ok, i'll apply the 3 patches to tip/x86/iommu. As usual, feel free to send IOMMU cleanups/generalizations/fixes against tip/master:

http://people.redhat.com/mingo/tip.git/README

Ingo

#11 lore raw

Re: [PATCH] add iommu_num_pages helper function

Hi Ingo,

Quoted 5 lines · On Sat, 26 Jul 2008 15:41:56 +0200 Ingo Molnar <[email protected]> wrote:

ok, i'll apply the 3 patches to tip/x86/iommu. As usual, feel free to send IOMMU cleanups/generalizations/fixes against tip/master:

http://people.redhat.com/mingo/tip.git/README

So, I assume a patch created on July 25 is not destined for 2.6.27, right? Especially since it breaks another architecture build and has only made it to linux-next on July 29 ... and needs more work given the comments already on this patch.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#12 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 10 lines · On Tue, 29 Jul 2008 11:07:49 +1000 Stephen Rothwell <[email protected]>…

Hi Ingo,

Quoted 5 lines · On Sat, 26 Jul 2008 15:41:56 +0200 Ingo Molnar <[email protected]> wrote:

ok, i'll apply the 3 patches to tip/x86/iommu. As usual, feel free to send IOMMU cleanups/generalizations/fixes against tip/master:

http://people.redhat.com/mingo/tip.git/README

So, I assume a patch created on July 25 is not destined for 2.6.27,

Hmm, seems that they will go into 2.6.27:

http://marc.info/?l=linux-kernel&m=121729275722287&w=2

Quoted 3 lines

right? Especially since it breaks another architecture build and has only made it to linux-next on July 29 ... and needs more work given the comments already on this patch.

It doesn't break another architecture build since only x86 IOMMUs use the helper function. But as I pointed out, it doesn't work for some architectures.

#13 lore raw

Re: [PATCH] add iommu_num_pages helper function

Hi,

Quoted 8 lines · On Tue, 29 Jul 2008 10:46:31 +0900 FUJITA Tomonori…
Quoted 2 lines

So, I assume a patch created on July 25 is not destined for 2.6.27,

Hmm, seems that they will go into 2.6.27:

http://marc.info/?l=linux-kernel&m=121729275722287&w=2

Quoted 7 lines
Quoted 3 lines

right? Especially since it breaks another architecture build and has only made it to linux-next on July 29 ... and needs more work given the comments already on this patch.

It doesn't break another architecture build since only x86 IOMMUs use the helper function. But as I pointed out, it doesn't work for some architectures.

Um, did you see the linux-next build report I posted (possibly not):

arch/powerpc/kernel/iommu.c:56: error: static declaration of 'iommu_num_pages' follows non-static declaration include/linux/iommu-helper.h:11: error: previous declaration of 'iommu_num_pages' was here

This is now a build of 2.6.27-rc1 for powerpc64 ppc64_defconfig ...

So we have a patch first posted to lkml on July 25 first hits linux-next on July 29 and is no in Linus' tree on July 29. A grep would have found the problem.

More care required ...

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#14 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 19 lines · On Tue, 29 Jul 2008 13:56:52 +1000 Stephen Rothwell <[email protected]>…

Hi,

Quoted 8 lines · On Tue, 29 Jul 2008 10:46:31 +0900 FUJITA Tomonori…
Quoted 2 lines

So, I assume a patch created on July 25 is not destined for 2.6.27,

Hmm, seems that they will go into 2.6.27:

http://marc.info/?l=linux-kernel&m=121729275722287&w=2

Quoted 7 lines
Quoted 3 lines

right? Especially since it breaks another architecture build and has only made it to linux-next on July 29 ... and needs more work given the comments already on this patch.

It doesn't break another architecture build since only x86 IOMMUs use the helper function. But as I pointed out, it doesn't work for some architectures.

Quoted 6 lines

Um, did you see the linux-next build report I posted (possibly not):

arch/powerpc/kernel/iommu.c:56: error: static declaration of 'iommu_num_pages' follows non-static declaration include/linux/iommu-helper.h:11: error: previous declaration of 'iommu_num_pages' was here

This is now a build of 2.6.27-rc1 for powerpc64 ppc64_defconfig ...

Ah, really sorry. Yeah, it breaks POWER and SPARC builds.

Quoted 5 lines

So we have a patch first posted to lkml on July 25 first hits linux-next on July 29 and is no in Linus' tree on July 29. A grep would have found the problem.

More care required ...

Agreed... As I said before, this is not urgent at all so we didn't need to rush.

A fix has already been posted?

==
From: FUJITA Tomonori <[email protected]>
Subject: [PATCH] move iommu_num_pages helper to x86

This IOMMU helper function doesn't work for some architectures:

http://marc.info/?l=linux-kernel&m=121699304403202&w=2

It also breaks POWER and SPARC builds:

http://marc.info/?l=linux-kernel&m=121730388001890&w=2

Currently, only x86 IOMMUs use this so let's move it to x86 for now.

---
 arch/x86/kernel/pci-dma.c    |    8 ++++++++
 include/asm-x86/iommu.h      |    2 ++
 include/linux/iommu-helper.h |    1 -
 lib/iommu-helper.c           |    8 --------
 4 files changed, 10 insertions(+), 9 deletions(-)
arch/x86/kernel/pci-dma.c +8 -0
index 8dbffb8..87d4d69 100644
@@ -123,6 +123,14 @@ void __init pci_iommu_alloc(void)
 
 	pci_swiotlb_init();
 }
+
+unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
+{
+	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
+
+	return size >> PAGE_SHIFT;
+}
+EXPORT_SYMBOL(iommu_num_pages);
 #endif
 
 /*
include/asm-x86/iommu.h +2 -0
index ecc8061..5f888cc 100644
@@ -7,6 +7,8 @@ extern struct dma_mapping_ops nommu_dma_ops;
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
+extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
+
 #ifdef CONFIG_GART_IOMMU
 extern int gart_iommu_aperture;
 extern int gart_iommu_aperture_allowed;
include/linux/iommu-helper.h +0 -1
index f8598f5..c975caf 100644
@@ -8,4 +8,3 @@ extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
 				      unsigned long align_mask);
 extern void iommu_area_free(unsigned long *map, unsigned long start,
 			    unsigned int nr);
-extern unsigned long iommu_num_pages(unsigned long addr, unsigned long len);
lib/iommu-helper.c +0 -8
index 889ddce..a3b8d4c 100644
@@ -80,11 +80,3 @@ void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr)
 	}
 }
 EXPORT_SYMBOL(iommu_area_free);
-
-unsigned long iommu_num_pages(unsigned long addr, unsigned long len)
-{
-	unsigned long size = roundup((addr & ~PAGE_MASK) + len, PAGE_SIZE);
-
-	return size >> PAGE_SHIFT;
-}
-EXPORT_SYMBOL(iommu_num_pages);
Signature · 1 line
1.5.5.GIT
#15 lore raw

Re: [PATCH] add iommu_num_pages helper function

From: FUJITA Tomonori <[email protected]>
Date: Tue, 29 Jul 2008 13:38:53 +0900

Quoted 2 lines

Agreed... As I said before, this is not urgent at all so we didn't need to rush.

Please, if you are going to add such interface, add "const unsigned long io_page_size" argument so that powerpc and sparc can use it too.

#16 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 9 lines · On Mon, 28 Jul 2008 22:26:18 -0700 (PDT) David Miller <[email protected]>…

From: FUJITA Tomonori <[email protected]>
Date: Tue, 29 Jul 2008 13:38:53 +0900

Quoted 2 lines

Agreed... As I said before, this is not urgent at all so we didn't need to rush.

Please, if you are going to add such interface, add "const unsigned long io_page_size" argument so that powerpc and sparc can use it too.

I didn't add this function:

http://marc.info/?l=linux-kernel&m=121699080831750&w=2

I pointed out that it doesn't work for some architectures:

http://marc.info/?l=linux-kernel&m=121699304403202&w=2

But sorry about not noticing that it breaks SPARC and POWER.

#17 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to Stephen Rothwell

From: Stephen Rothwell <[email protected]>
Date: Tue, 29 Jul 2008 13:56:52 +1000

Quoted 6 lines

Um, did you see the linux-next build report I posted (possibly not):

arch/powerpc/kernel/iommu.c:56: error: static declaration of 'iommu_num_pages' follows non-static declaration include/linux/iommu-helper.h:11: error: previous declaration of 'iommu_num_pages' was here

This is now a build of 2.6.27-rc1 for powerpc64 ppc64_defconfig ...

It breaks sparc64 the same exact way. :-/

sparc64: Fix build after addition of iommu_num_pages() helper.

It would have been much more pleasant if that new interface:

1) Took an "io_page_size" argument so powerpc and sparc64 could make use of it.

2) Was build tested on something other than x86.

arch/sparc64/kernel/iommu.c +3 -3
index 2a37a6c..600f712 100644
@@ -575,7 +575,7 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
 		}
 		/* Allocate iommu entries for that segment */
 		paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s);
-		npages = iommu_num_pages(paddr, slen);
+		npages = sparc64_iommu_num_pages(paddr, slen);
 		entry = iommu_range_alloc(dev, iommu, npages, &handle);
 
 		/* Handle failure */
@@ -647,7 +647,7 @@ iommu_map_failed:
 			iopte_t *base;
 
 			vaddr = s->dma_address & IO_PAGE_MASK;
-			npages = iommu_num_pages(s->dma_address, s->dma_length);
+			npages = sparc64_iommu_num_pages(s->dma_address, s->dma_length);
 			iommu_range_free(iommu, vaddr, npages);
 
 			entry = (vaddr - iommu->page_table_map_base)
@@ -715,7 +715,7 @@ static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist,
 
 		if (!len)
 			break;
-		npages = iommu_num_pages(dma_handle, len);
+		npages = sparc64_iommu_num_pages(dma_handle, len);
 		iommu_range_free(iommu, dma_handle, npages);
 
 		entry = ((dma_handle - iommu->page_table_map_base)
arch/sparc64/kernel/iommu_common.h +3 -3
index 53b19c8..e64152b 100644
@@ -35,8 +35,8 @@
 
 #define SG_ENT_PHYS_ADDRESS(SG)	(__pa(sg_virt((SG))))
 
-static inline unsigned long iommu_num_pages(unsigned long vaddr,
-					    unsigned long slen)
+static inline unsigned long sparc64_iommu_num_pages(unsigned long vaddr,
+						    unsigned long slen)
 {
 	unsigned long npages;
 
@@ -53,7 +53,7 @@ static inline int is_span_boundary(unsigned long entry,
 				   struct scatterlist *sg)
 {
 	unsigned long paddr = SG_ENT_PHYS_ADDRESS(outs);
-	int nr = iommu_num_pages(paddr, outs->dma_length + sg->length);
+	int nr = sparc64_iommu_num_pages(paddr, outs->dma_length + sg->length);
 
 	return iommu_is_span_boundary(entry, nr, shift, boundary_size);
 }
arch/sparc64/kernel/pci_sun4v.c +3 -3
index a104c80..08dcdbd 100644
@@ -382,7 +382,7 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
 		}
 		/* Allocate iommu entries for that segment */
 		paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s);
-		npages = iommu_num_pages(paddr, slen);
+		npages = sparc64_iommu_num_pages(paddr, slen);
 		entry = iommu_range_alloc(dev, iommu, npages, &handle);
 
 		/* Handle failure */
@@ -459,7 +459,7 @@ iommu_map_failed:
 			unsigned long vaddr, npages;
 
 			vaddr = s->dma_address & IO_PAGE_MASK;
-			npages = iommu_num_pages(s->dma_address, s->dma_length);
+			npages = sparc64_iommu_num_pages(s->dma_address, s->dma_length);
 			iommu_range_free(iommu, vaddr, npages);
 			/* XXX demap? XXX */
 			s->dma_address = DMA_ERROR_CODE;
@@ -498,7 +498,7 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
 
 		if (!len)
 			break;
-		npages = iommu_num_pages(dma_handle, len);
+		npages = sparc64_iommu_num_pages(dma_handle, len);
 		iommu_range_free(iommu, dma_handle, npages);
 
 		entry = ((dma_handle - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
#18 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 11 lines · On Mon, 28 Jul 2008 22:24:39 -0700 (PDT) David Miller <[email protected]>…

From: Stephen Rothwell <[email protected]>
Date: Tue, 29 Jul 2008 13:56:52 +1000

Quoted 6 lines

Um, did you see the linux-next build report I posted (possibly not):

arch/powerpc/kernel/iommu.c:56: error: static declaration of 'iommu_num_pages' follows non-static declaration include/linux/iommu-helper.h:11: error: previous declaration of 'iommu_num_pages' was here

This is now a build of 2.6.27-rc1 for powerpc64 ppc64_defconfig ...

It breaks sparc64 the same exact way. :-/

Yeah, it breaks both. It's not a proper helper function that all the architectures can use so how about making it x86 stuff?

http://marc.info/?l=linux-kernel&m=121730644704448&w=2

#19 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to David Miller

Hi Dave,

Quoted 2 lines · On Mon, 28 Jul 2008 22:24:39 -0700 (PDT) David Miller <[email protected]>…

sparc64: Fix build after addition of iommu_num_pages() helper.

I added this to the end of linux-next for today. Hopefully we will have a fix in Linus' tree tomorrow.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#20 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 8 lines · Stephen Rothwell

Hi Dave,

Quoted 2 lines · On Mon, 28 Jul 2008 22:24:39 -0700 (PDT) David Miller <[email protected]>…

sparc64: Fix build after addition of iommu_num_pages() helper.

I added this to the end of linux-next for today. Hopefully we will have a fix in Linus' tree tomorrow.

Yes, my fault, sorry for that breakage :-/
I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

FUJITA,

do you want to work on that or should I try to do this and send it to you for review?

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#21 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 7 lines · On Tue, 29 Jul 2008 11:50:27 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 6 lines · Stephen Rothwell

Hi Dave,

Quoted 2 lines · On Mon, 28 Jul 2008 22:24:39 -0700 (PDT) David Miller <[email protected]>…

sparc64: Fix build after addition of iommu_num_pages() helper.

Quoted 7 lines
Quoted 2 lines

I added this to the end of linux-next for today. Hopefully we will have a fix in Linus' tree tomorrow.

Yes, my fault, sorry for that breakage :-/
I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

Agreed, it fixes both SPARC and POWER breakages.

Quoted 4 lines

FUJITA,

do you want to work on that or should I try to do this and send it to you for review?

I've already sent a patch that fixes the breakages in such way:

http://marc.info/?l=linux-kernel&m=121730644704448&w=2

#22 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 8 lines · FUJITA Tomonori
Quoted 2 lines · On Tue, 29 Jul 2008 11:50:27 +0200 Joerg Roedel <[email protected]> wrote:

do you want to work on that or should I try to do this and send it to you for review?

I've already sent a patch that fixes the breakages in such way:

http://marc.info/?l=linux-kernel&m=121730644704448&w=2

Yes I have seen this patch. I meant the patches that introduce something like IOMMU_PAGE_SIZE for all architectures so that we can make this function generic and move it back to lib/.

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#23 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 6 lines · Joerg Roedel
Quoted 5 lines · FUJITA Tomonori
Quoted 2 lines · On Tue, 29 Jul 2008 11:50:27 +0200 Joerg Roedel <[email protected]> wrote:

do you want to work on that or should I try to do this and send it to you for review?

Quoted 7 lines
Quoted 3 lines

I've already sent a patch that fixes the breakages in such way:

http://marc.info/?l=linux-kernel&m=121730644704448&w=2

Yes I have seen this patch. I meant the patches that introduce something like IOMMU_PAGE_SIZE for all architectures so that we can make this function generic and move it back to lib/.

That will not work in the light of some new stuff coming on powerpc in the future. The iommu page size may/will be dynamic per instance of iommu. IE, it will be mostly decided at runtime, I don't expect machines to have multiple iommus of different page sizes off hand but it -can- happen.

Ben.

#24 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 15 lines · On Thu, 31 Jul 2008 08:44:14 +1000 Benjamin Herrenschmidt…
Quoted 6 lines · Joerg Roedel
Quoted 5 lines · FUJITA Tomonori
Quoted 2 lines · On Tue, 29 Jul 2008 11:50:27 +0200 Joerg Roedel <[email protected]> wrote:

do you want to work on that or should I try to do this and send it to you for review?

Quoted 7 lines
Quoted 3 lines

I've already sent a patch that fixes the breakages in such way:

http://marc.info/?l=linux-kernel&m=121730644704448&w=2

Yes I have seen this patch. I meant the patches that introduce something like IOMMU_PAGE_SIZE for all architectures so that we can make this function generic and move it back to lib/.

Quoted 5 lines

That will not work in the light of some new stuff coming on powerpc in the future. The iommu page size may/will be dynamic per instance of iommu. IE, it will be mostly decided at runtime, I don't expect machines to have multiple iommus of different page sizes off hand but it -can- happen.

You could do something like this:

#define IOMMU_PAGE_SIZE power_iommu_page_size

But I prefer the current proposal to have the size as an argument.

#25 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>
Date: Tue, 29 Jul 2008 11:50:27 +0200

Quoted 3 lines

I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

My suggestion (again) is to pass it in as a "const unsigned long io_page_size" argument and update the callers.

#26 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 9 lines · David Miller

From: Joerg Roedel <[email protected]>
Date: Tue, 29 Jul 2008 11:50:27 +0200

Quoted 3 lines

I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

My suggestion (again) is to pass it in as a "const unsigned long io_page_size" argument and update the callers.

Ok, this has the advantage that it supports more than one IOMMU page size per architecture and its also less intrusive.

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#27 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to David Miller
Quoted 9 lines · On Tue, 29 Jul 2008 03:10:05 -0700 (PDT) David Miller <[email protected]>…

From: Joerg Roedel <[email protected]>
Date: Tue, 29 Jul 2008 11:50:27 +0200

Quoted 3 lines

I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

My suggestion (again) is to pass it in as a "const unsigned long io_page_size" argument and update the callers.

Either is fine by me.

Joerg, if you like, please finish this (for all the architectures, please). As I said before, I planed to work on this cleanup after rc1 (and this should have been 2.6.28 stuff). But I'd appreciate if you would do.

Thanks,

#28 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 13 lines · FUJITA Tomonori
Quoted 9 lines · On Tue, 29 Jul 2008 03:10:05 -0700 (PDT) David Miller <[email protected]>…

From: Joerg Roedel <[email protected]>
Date: Tue, 29 Jul 2008 11:50:27 +0200

Quoted 3 lines

I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

My suggestion (again) is to pass it in as a "const unsigned long io_page_size" argument and update the callers.

Quoted 6 lines

Either is fine by me.

Joerg, if you like, please finish this (for all the architectures, please). As I said before, I planed to work on this cleanup after rc1 (and this should have been 2.6.28 stuff). But I'd appreciate if you would do.

i've queued up your quick fix in tip/x86/urgent to resolve the immediate -git build breakage. The wider patch can then be done on top of that, without being rushed. Any objections to this approach?

Ingo

#29 lore raw

Re: [PATCH] add iommu_num_pages helper function

From: Ingo Molnar <[email protected]>
Date: Tue, 29 Jul 2008 12:31:46 +0200

Quoted 3 lines

i've queued up your quick fix in tip/x86/urgent to resolve the immediate -git build breakage. The wider patch can then be done on top of that, without being rushed. Any objections to this approach?

I do not object :-)

#30 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 9 lines · On Tue, 29 Jul 2008 03:33:42 -0700 (PDT) David Miller <[email protected]>…

From: Ingo Molnar <[email protected]>
Date: Tue, 29 Jul 2008 12:31:46 +0200

Quoted 3 lines

i've queued up your quick fix in tip/x86/urgent to resolve the immediate -git build breakage. The wider patch can then be done on top of that, without being rushed. Any objections to this approach?

I do not object :-)

Neither do I. :-)

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#31 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to David Miller
Quoted 9 lines · David Miller

From: Joerg Roedel <[email protected]>
Date: Tue, 29 Jul 2008 11:50:27 +0200

Quoted 3 lines

I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

My suggestion (again) is to pass it in as a "const unsigned long io_page_size" argument and update the callers.

Ok, after setting up cross compile environments for sparc64 and powerpc64 I wrote a patch which adds the io_page_size argument to the iommu_num pages function and moves the function back to lib/iommu-helper.c. The patch touches all 3 architectures and can not be split in a bisectable way.

Who is the best person to send this patch to?

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#32 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 8 lines · On Wed, 30 Jul 2008 14:18:05 +0200 Joerg Roedel <[email protected]> wrote:
Quoted 7 lines · David Miller

From: Joerg Roedel <[email protected]>
Date: Tue, 29 Jul 2008 11:50:27 +0200

Quoted 3 lines

I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

Quoted 7 lines
Quoted 2 lines

My suggestion (again) is to pass it in as a "const unsigned long io_page_size" argument and update the callers.

Ok, after setting up cross compile environments for sparc64 and powerpc64 I wrote a patch which adds the io_page_size argument to the iommu_num pages function and moves the function back to lib/iommu-helper.c.

You need ia64, parisc, and alpha too. :)

I have cross compile environments for them so I can take care of them if you like.

Quoted 2 lines

The patch touches all 3 architectures and can not be split in a bisectable way.

How about naming a new helper function iommu_nr_pages (or something)?

Then you can do the conversion independently. If we like, we use iommu_num_pages name after the conversion.

Quoted 1 line

Who is the best person to send this patch to?

The -mm is an appropriate tree, I think.

#33 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 8 lines · FUJITA Tomonori
Quoted 4 lines · On Wed, 30 Jul 2008 14:18:05 +0200 Joerg Roedel <[email protected]> wrote:

Ok, after setting up cross compile environments for sparc64 and powerpc64 I wrote a patch which adds the io_page_size argument to the iommu_num pages function and moves the function back to lib/iommu-helper.c.

Quoted 4 lines

You need ia64, parisc, and alpha too. :)

I have cross compile environments for them so I can take care of them if you like.

Ok, so you suggest to create a patchset to convert the other IOMMU implementations too. Thats fine for me, I will try to do it :) Do you have hardware to do runtime tests of the code? I have hardware only for x86, sparc64 and alpha.

Quoted 8 lines
Quoted 3 lines

The patch touches all 3 architectures and can not be split in a bisectable way.

How about naming a new helper function iommu_nr_pages (or something)?

Then you can do the conversion independently. If we like, we use iommu_num_pages name after the conversion.

Ok, this would mean only 3 renaming patches to keep the patch series bisectable. This should be acceptable.

Quoted 4 lines
Quoted 2 lines

Who is the best person to send this patch to?

The -mm is an appropriate tree, I think.

Ok, then I submit it to Andrew once its tested.

Thanks,

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#34 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to FUJITA Tomonori
Quoted 9 lines · FUJITA Tomonori
Quoted 5 lines · On Wed, 30 Jul 2008 14:18:05 +0200 Joerg Roedel <[email protected]> wrote:

Ok, after setting up cross compile environments for sparc64 and powerpc64 I wrote a patch which adds the io_page_size argument to the iommu_num pages function and moves the function back to lib/iommu-helper.c.

You need ia64, parisc, and alpha too. :)

Ok, I looked into the different IOMMU drivers for pa-risc and ia64. The changes needed there are non-trival and I can't test them on real hardware (I only have an pa-risc 1.1). So I think I skip these 2 architectures for now. They can be changed by somebody who has the hardware :)
(Alpha instead was trival. I changed this driver)

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#35 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to David Miller
Quoted 9 lines · David Miller

From: Joerg Roedel <[email protected]>
Date: Tue, 29 Jul 2008 11:50:27 +0200

Quoted 3 lines

I think moving that function to x86-only code is the best solution for now. Before moving it back to generic code we need an architecture independent way to find out the IOMMU page size.

My suggestion (again) is to pass it in as a "const unsigned long io_page_size" argument and update the callers.

Yeah. That's better

Ben.

#36 lore raw

Re: [PATCH] add iommu_num_pages helper function

In reply to Stephen Rothwell
Quoted 7 lines · Stephen Rothwell

Hi Ingo,

Quoted 4 lines · On Sat, 26 Jul 2008 15:41:56 +0200 Ingo Molnar <[email protected]> wrote:

ok, i'll apply the 3 patches to tip/x86/iommu. As usual, feel free to send IOMMU cleanups/generalizations/fixes against tip/master:

Quoted 6 lines
Quoted 1 line

http://people.redhat.com/mingo/tip.git/README

So, I assume a patch created on July 25 is not destined for 2.6.27, right? Especially since it breaks another architecture build and has only made it to linux-next on July 29 ... and needs more work given the comments already on this patch.

Correct, they were not intended for immediate upstream merging, they werent even in auto-x86-next so there was no meaningful linux-next exposure.

I was surprised they went upstream via the PCI tree yesterday, just hours after i sent them over to Jesse and about an hour before -rc1 was released. [ Nor did intend the core/generic-dma-coherent bits to go upstream right before -rc1 - although those seem to be problem-free so far. ]

I stopped sending non-urgent patches to Linus days ago, to let things calm down for a smooth -rc1 release.

Ingo

#37 lore raw

Re: [PATCH] add iommu_num_pages helper function

Quoted 18 lines · Ingo Molnar
Quoted 6 lines · Stephen Rothwell

Hi Ingo,

Quoted 3 lines · On Sat, 26 Jul 2008 15:41:56 +0200 Ingo Molnar <[email protected]> wrote:

ok, i'll apply the 3 patches to tip/x86/iommu. As usual, feel free to send IOMMU cleanups/generalizations/fixes against tip/master:

Quoted 6 lines
Quoted 1 line

http://people.redhat.com/mingo/tip.git/README

So, I assume a patch created on July 25 is not destined for 2.6.27, right? Especially since it breaks another architecture build and has only made it to linux-next on July 29 ... and needs more work given the comments already on this patch.

Correct, they were not intended for immediate upstream merging, they werent even in auto-x86-next so there was no meaningful linux-next exposure.

Quoted 8 lines

I was surprised they went upstream via the PCI tree yesterday, just hours after i sent them over to Jesse and about an hour before -rc1 was released. [ Nor did intend the core/generic-dma-coherent bits to go upstream right before -rc1 - although those seem to be problem-free so far. ]

I stopped sending non-urgent patches to Linus days ago, to let things calm down for a smooth -rc1 release.

Yeah I had a few things that I wanted to get upstream before -rc1, so I was probably a bit hasty with these bits (I thought they had had more soak time). Sounds like things are all worked out now though...

Thanks,
Jesse

#38 lore raw

PATCH 1/1 x86 gart: replace to_pages macro with iommu_num_pages

In reply to Joerg Roedel

This patch removes the to_pages macro from x86 GART code and calls the generic iommu_num_pages function instead.

---
 arch/x86/kernel/pci-gart_64.c |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)
arch/x86/kernel/pci-gart_64.c +4 -7
index 1062dc1..31bc068 100644
@@ -67,9 +67,6 @@ static u32 gart_unmapped_entry;
 	(((x) & 0xfffff000) | (((x) >> 32) << 4) | GPTE_VALID | GPTE_COHERENT)
 #define GPTE_DECODE(x) (((x) & 0xfffff000) | (((u64)(x) & 0xff0) << 28))
 
-#define to_pages(addr, size) \
-	(round_up(((addr) & ~PAGE_MASK) + (size), PAGE_SIZE) >> PAGE_SHIFT)
-
 #define EMERGENCY_PAGES 32 /* = 128KB */
 
 #ifdef CONFIG_AGP
@@ -241,7 +238,7 @@ nonforced_iommu(struct device *dev, unsigned long addr, size_t size)
 static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
 				size_t size, int dir)
 {
-	unsigned long npages = to_pages(phys_mem, size);
+	unsigned long npages = iommu_num_pages(phys_mem, size);
 	unsigned long iommu_page = alloc_iommu(dev, npages);
 	int i;
 
@@ -304,7 +301,7 @@ static void gart_unmap_single(struct device *dev, dma_addr_t dma_addr,
 		return;
 
 	iommu_page = (dma_addr - iommu_bus_base)>>PAGE_SHIFT;
-	npages = to_pages(dma_addr, size);
+	npages = iommu_num_pages(dma_addr, size);
 	for (i = 0; i < npages; i++) {
 		iommu_gatt_base[iommu_page + i] = gart_unmapped_entry;
 		CLEAR_LEAK(iommu_page + i);
@@ -387,7 +384,7 @@ static int __dma_map_cont(struct device *dev, struct scatterlist *start,
 		}
 
 		addr = phys_addr;
-		pages = to_pages(s->offset, s->length);
+		pages = iommu_num_pages(s->offset, s->length);
 		while (pages--) {
 			iommu_gatt_base[iommu_page] = GPTE_ENCODE(addr);
 			SET_LEAK(iommu_page);
@@ -470,7 +467,7 @@ gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
 
 		seg_size += s->length;
 		need = nextneed;
-		pages += to_pages(s->offset, s->length);
+		pages += iommu_num_pages(s->offset, s->length);
 		ps = s;
 	}
 	if (dma_map_cont(dev, start_sg, i - start, sgmap, pages, need) < 0)
Signature · 1 line
1.5.3.7
Applied
#39 lore raw
In reply to Joerg Roedel
Quoted 6 lines · Joerg Roedel

This small patch series introduces a generic iommu_num_pages function into the IOMMU helper code. This function can be used to calculate the number of pages an IOMMU has to map for a specific mapping request.

The patchset converts the x86 IOMMU implementations for AMD IOMMU and the GART to use this function.

applied to tip/x86/iommu - thanks Joerg.

Quoted 1 line

Other IOMMU implementations are not changed because I can't test them.

if it's straightforward and expected to work with a high likelyhood then please do it nevertheless. As long as it's finegrained patches we ought to be able to filter out broken changes.

Ingo