Skip to contentSkip to conversation

omap: iovmm: Fix IOVMM check for fixed 'da'

PATCH Superseded David Cohen 4 participants 18 messages Mar 8, 2011

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover omap: iovmm: Fix IOVMM check for fixed 'da'

IOVMM driver checks input 'da == 0' when mapping address to determine whether user wants fixed 'da' or not. At the same time, it doesn't disallow address 0x0 to be used, what creates an ambiguous situation. This patch set moves fixed 'da' check to the input flags.
It also fixes da_start value for ISP IOMMU instance.

David Cohen (2):
omap3: change ISP's IOMMU da_start address
omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON
flags

Michael Jones (1):
omap: iovmm: disallow mapping NULL address

 arch/arm/mach-omap2/omap-iommu.c |    2 +-
 arch/arm/plat-omap/iovmm.c       |   28 ++++++++++++++++++----------
 2 files changed, 19 insertions(+), 11 deletions(-)
#1 lore raw

PATCH 1/3 omap: iovmm: disallow mapping NULL address

From: Michael Jones <[email protected]>

commit c7f4ab26e3bcdaeb3e19ec658e3ad9092f1a6ceb allowed mapping the NULL address if da_start==0, which would then not get unmapped. Disallow this again. And spell variable 'alignment' correctly.

---
 arch/arm/plat-omap/iovmm.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
arch/arm/plat-omap/iovmm.c +10 -6
index 6dc1296..11c9b76 100644
@@ -271,20 +271,24 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
 					   size_t bytes, u32 flags)
 {
 	struct iovm_struct *new, *tmp;
-	u32 start, prev_end, alignement;
+	u32 start, prev_end, alignment;
 
 	if (!obj || !bytes)
 		return ERR_PTR(-EINVAL);
 
 	start = da;
-	alignement = PAGE_SIZE;
+	alignment = PAGE_SIZE;
 
 	if (flags & IOVMF_DA_ANON) {
-		start = obj->da_start;
+		/* Don't map address 0 */
+		if (obj->da_start)
+			start = obj->da_start;
+		else
+			start = obj->da_start + alignment;
 
 		if (flags & IOVMF_LINEAR)
-			alignement = iopgsz_max(bytes);
-		start = roundup(start, alignement);
+			alignment = iopgsz_max(bytes);
+		start = roundup(start, alignment);
 	} else if (start < obj->da_start || start > obj->da_end ||
 					obj->da_end - start < bytes) {
 		return ERR_PTR(-EINVAL);
@@ -304,7 +308,7 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
 			goto found;
 
 		if (tmp->da_end >= start && flags & IOVMF_DA_ANON)
-			start = roundup(tmp->da_end + 1, alignement);
+			start = roundup(tmp->da_end + 1, alignment);
 
 		prev_end = tmp->da_end;
 	}
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [PATCH 1/3] omap: iovmm: disallow mapping NULL address

Quoted 26 lines · David Cohen

From: Michael Jones <[email protected]>

commit c7f4ab26e3bcdaeb3e19ec658e3ad9092f1a6ceb allowed mapping the NULL address if da_start==0, which would then not get unmapped. Disallow this again.  And spell variable 'alignment' correctly.

---
 arch/arm/plat-omap/iovmm.c |   16 ++++++++++------

 1 files changed, 10 insertions(+), 6 deletions(-)
arch/arm/plat-omap/iovmm.c +1 -1
index 6dc1296..11c9b76 100644
@@ -271,20 +271,24 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                                           size_t bytes, u32 flags)
  {
        struct iovm_struct *new, *tmp;
-       u32 start, prev_end, alignement;
+       u32 start, prev_end, alignment;
 
        if (!obj || !bytes)
                return ERR_PTR(-EINVAL);
 
        start = da;

arch/arm/plat-omap/iovmm.c static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da, · line 287

Quoted 10 lines
arch/arm/plat-omap/iovmm.c +6 -2
-       alignement = PAGE_SIZE;
+       alignment = PAGE_SIZE;
 
        if (flags & IOVMF_DA_ANON) {
-               start = obj->da_start;
+               /* Don't map address 0 */
+               if (obj->da_start)
+                       start = obj->da_start;
+               else
+                       start = obj->da_start + alignment;

else part obj->da_star is always 0, so why not?
start = alignment;

so, why I understand, it now it is possible mapp address 0x0 only if IOVMF_DA_ANON is not set, right? maybe that would be mention in the patch.

Regards,
Fernando.

Quoted 22 lines
arch/arm/plat-omap/iovmm.c +3 -4
                if (flags & IOVMF_LINEAR)
-                       alignement = iopgsz_max(bytes);
-               start = roundup(start, alignement);
+                       alignment = iopgsz_max(bytes);
+               start = roundup(start, alignment);
        } else if (start < obj->da_start || start > obj->da_end ||
                                        obj->da_end - start < bytes) {
                return ERR_PTR(-EINVAL);
@@ -304,7 +308,7 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                        goto found;
 
                if (tmp->da_end >= start && flags & IOVMF_DA_ANON)
-                       start = roundup(tmp->da_end + 1, alignement);
+                       start = roundup(tmp->da_end + 1, alignment);
 
                prev_end = tmp->da_end;
        }
--

1.7.0.4

#3 lore raw

Re: [PATCH 1/3] omap: iovmm: disallow mapping NULL address

Quoted 30 lines · Fernando
Quoted 29 lines · David Cohen

From: Michael Jones <[email protected]>

commit c7f4ab26e3bcdaeb3e19ec658e3ad9092f1a6ceb allowed mapping the NULL address if da_start==0, which would then not get unmapped. Disallow this again.  And spell variable 'alignment' correctly.

---
 arch/arm/plat-omap/iovmm.c |   16 ++++++++++------

 1 files changed, 10 insertions(+), 6 deletions(-)
arch/arm/plat-omap/iovmm.c +2 -2
index 6dc1296..11c9b76 100644
@@ -271,20 +271,24 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                                           size_t bytes, u32 flags)
  {
        struct iovm_struct *new, *tmp;
-       u32 start, prev_end, alignement;
+       u32 start, prev_end, alignment;
 
        if (!obj || !bytes)
                return ERR_PTR(-EINVAL);
 
        start = da;
-       alignement = PAGE_SIZE;
+       alignment = PAGE_SIZE;
 
Quoted 10 lines

arch/arm/plat-omap/iovmm.c static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da, · line 287

Quoted 7 lines
arch/arm/plat-omap/iovmm.c +5 -1
        if (flags & IOVMF_DA_ANON) {
-               start = obj->da_start;
+               /* Don't map address 0 */
+               if (obj->da_start)
+                       start = obj->da_start;
+               else
+                       start = obj->da_start + alignment;

else part obj->da_star is always 0, so why not?
start = alignment;

The patch is not from me, but I can fix it if Michael agrees.

Quoted 4 lines

so, why I understand, it now it is possible mapp address 0x0 only if IOVMF_DA_ANON is not set, right? maybe that would be mention in the patch.

Indeed address 0x0 was never meant to be mapped. The mentioned commit on the patch's description did that without noticing. But the new change is documented in the code by the comment "Don't map address 0" and it's also mentioned on the patch description. Is it OK for you?

Regards,

David Cohen

Quoted 27 lines

Regards,
Fernando.

Quoted 22 lines
arch/arm/plat-omap/iovmm.c +3 -4
                if (flags & IOVMF_LINEAR)
-                       alignement = iopgsz_max(bytes);
-               start = roundup(start, alignement);
+                       alignment = iopgsz_max(bytes);
+               start = roundup(start, alignment);
        } else if (start < obj->da_start || start > obj->da_end ||
                                        obj->da_end - start < bytes) {
                return ERR_PTR(-EINVAL);
@@ -304,7 +308,7 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                        goto found;
 
                if (tmp->da_end >= start && flags & IOVMF_DA_ANON)
-                       start = roundup(tmp->da_end + 1, alignement);
+                       start = roundup(tmp->da_end + 1, alignment);
 
                prev_end = tmp->da_end;
        }
--

1.7.0.4

#4 lore raw

Re: [PATCH 1/3] omap: iovmm: disallow mapping NULL address

Quoted 46 lines · David Cohen
Quoted 30 lines · Fernando
Quoted 29 lines · David Cohen

From: Michael Jones <[email protected]>

commit c7f4ab26e3bcdaeb3e19ec658e3ad9092f1a6ceb allowed mapping the NULL address if da_start==0, which would then not get unmapped. Disallow this again.  And spell variable 'alignment' correctly.

---
 arch/arm/plat-omap/iovmm.c |   16 ++++++++++------

 1 files changed, 10 insertions(+), 6 deletions(-)
arch/arm/plat-omap/iovmm.c +2 -2
index 6dc1296..11c9b76 100644
@@ -271,20 +271,24 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                                           size_t bytes, u32 flags)
  {
        struct iovm_struct *new, *tmp;
-       u32 start, prev_end, alignement;
+       u32 start, prev_end, alignment;
 
        if (!obj || !bytes)
                return ERR_PTR(-EINVAL);
 
        start = da;
-       alignement = PAGE_SIZE;
+       alignment = PAGE_SIZE;
 
Quoted 10 lines

arch/arm/plat-omap/iovmm.c static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da, · line 287

Quoted 7 lines
arch/arm/plat-omap/iovmm.c +5 -1
        if (flags & IOVMF_DA_ANON) {
-               start = obj->da_start;
+               /* Don't map address 0 */
+               if (obj->da_start)
+                       start = obj->da_start;
+               else
+                       start = obj->da_start + alignment;

else part obj->da_star is always 0, so why not?
start = alignment;

The patch is not from me, but I can fix it if Michael agrees.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

so, why I understand, it now it is possible mapp address 0x0 only if IOVMF_DA_ANON is not set, right? maybe that would be mention in the patch.

Indeed address 0x0 was never meant to be mapped. The mentioned commit on the patch's description did that without noticing. But the new change is documented in the code by the comment "Don't map address 0"

yeah, but it only applies when "flags & IOVMF_DA_ANON", So if I use IOVMF_DA_FIXED and da_start == 0, I will be able to map some area which starts from address 0x0, right? if so, that looks good to me and the description should mention that if is disallowing mapping address 0x0 when IOVMF_DA_ANON is used.

Regards,
Fernando.

Quoted 34 lines

and it's also mentioned on the patch description. Is it OK for you?

Regards,

David Cohen

Quoted 27 lines

Regards,
Fernando.

Quoted 22 lines
arch/arm/plat-omap/iovmm.c +3 -4
                if (flags & IOVMF_LINEAR)
-                       alignement = iopgsz_max(bytes);
-               start = roundup(start, alignement);
+                       alignment = iopgsz_max(bytes);
+               start = roundup(start, alignment);
        } else if (start < obj->da_start || start > obj->da_end ||
                                        obj->da_end - start < bytes) {
                return ERR_PTR(-EINVAL);
@@ -304,7 +308,7 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                        goto found;
 
                if (tmp->da_end >= start && flags & IOVMF_DA_ANON)
-                       start = roundup(tmp->da_end + 1, alignement);
+                       start = roundup(tmp->da_end + 1, alignment);
 
                prev_end = tmp->da_end;
        }
--

1.7.0.4

#5 lore raw

Re: [PATCH 1/3] omap: iovmm: disallow mapping NULL address

Quoted 55 lines · Fernando
Quoted 46 lines · David Cohen
Quoted 30 lines · Fernando
Quoted 29 lines · David Cohen

From: Michael Jones <[email protected]>

commit c7f4ab26e3bcdaeb3e19ec658e3ad9092f1a6ceb allowed mapping the NULL address if da_start==0, which would then not get unmapped. Disallow this again.  And spell variable 'alignment' correctly.

---
 arch/arm/plat-omap/iovmm.c |   16 ++++++++++------

 1 files changed, 10 insertions(+), 6 deletions(-)
arch/arm/plat-omap/iovmm.c +2 -2
index 6dc1296..11c9b76 100644
@@ -271,20 +271,24 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                                           size_t bytes, u32 flags)
  {
        struct iovm_struct *new, *tmp;
-       u32 start, prev_end, alignement;
+       u32 start, prev_end, alignment;
 
        if (!obj || !bytes)
                return ERR_PTR(-EINVAL);
 
        start = da;
-       alignement = PAGE_SIZE;
+       alignment = PAGE_SIZE;
 
Quoted 10 lines

arch/arm/plat-omap/iovmm.c static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da, · line 287

Quoted 7 lines
arch/arm/plat-omap/iovmm.c +5 -1
        if (flags & IOVMF_DA_ANON) {
-               start = obj->da_start;
+               /* Don't map address 0 */
+               if (obj->da_start)
+                       start = obj->da_start;
+               else
+                       start = obj->da_start + alignment;

else part obj->da_star is always 0, so why not?
start = alignment;

The patch is not from me, but I can fix it if Michael agrees.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

so, why I understand, it now it is possible mapp address 0x0 only if IOVMF_DA_ANON is not set, right? maybe that would be mention in the patch.

Indeed address 0x0 was never meant to be mapped. The mentioned commit on the patch's description did that without noticing. But the new change is documented in the code by the comment "Don't map address 0"

Quoted 5 lines

yeah, but it only applies when "flags & IOVMF_DA_ANON", So if I use IOVMF_DA_FIXED and da_start == 0, I will be able to map some area which starts from address 0x0, right?  if so, that looks good to me and the description should mention that if is disallowing mapping address 0x0 when IOVMF_DA_ANON is used.

Yes, that's the case. I will update the comment. I hope Michael does not complain about the changes. :)

Br,

David

Quoted 39 lines

Regards,
Fernando.

Quoted 34 lines

and it's also mentioned on the patch description. Is it OK for you?

Regards,

David Cohen

Quoted 27 lines

Regards,
Fernando.

Quoted 22 lines
arch/arm/plat-omap/iovmm.c +3 -4
                if (flags & IOVMF_LINEAR)
-                       alignement = iopgsz_max(bytes);
-               start = roundup(start, alignement);
+                       alignment = iopgsz_max(bytes);
+               start = roundup(start, alignment);
        } else if (start < obj->da_start || start > obj->da_end ||
                                        obj->da_end - start < bytes) {
                return ERR_PTR(-EINVAL);
@@ -304,7 +308,7 @@ static struct iovm_struct *alloc_iovm_area(struct iommu *obj, u32 da,
                        goto found;
 
                if (tmp->da_end >= start && flags & IOVMF_DA_ANON)
-                       start = roundup(tmp->da_end + 1, alignement);
+                       start = roundup(tmp->da_end + 1, alignment);
 
                prev_end = tmp->da_end;
        }
--

1.7.0.4

#6 lore raw

PATCH 2/3 omap3: change ISP's IOMMU da_start address

In reply to David Cohen

ISP doesn't consider 0x0 as a valid address, so it should explicitly exclude first page from allowed 'da' range.

---
 arch/arm/mach-omap2/omap-iommu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/omap-iommu.c +1 -1
index 3fc5dc7..3bea489 100644
@@ -33,7 +33,7 @@ static struct iommu_device omap3_devices[] = {
 			.name = "isp",
 			.nr_tlb_entries = 8,
 			.clk_name = "cam_ick",
-			.da_start = 0x0,
+			.da_start = 0x1000,
 			.da_end = 0xFFFFF000,
 		},
 	},
Signature · 1 line
1.7.0.4
#7 lore raw

Re: [PATCH 2/3] omap3: change ISP's IOMMU da_start address

Quoted 13 lines · David Cohen

ISP doesn't consider 0x0 as a valid address, so it should explicitly exclude first page from allowed 'da' range.

---
 arch/arm/mach-omap2/omap-iommu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/omap-iommu.c +0 -0
index 3fc5dc7..3bea489 100644

arch/arm/mach-omap2/omap-iommu.c static struct iommu_device omap3_devices[] = { · line 36

Quoted 5 lines
arch/arm/mach-omap2/omap-iommu.c +1 -1
@@ -33,7 +33,7 @@ static struct iommu_device omap3_devices[] = {
 			.name = "isp",
 			.nr_tlb_entries = 8,
 			.clk_name = "cam_ick",
-			.da_start = 0x0,
+			.da_start = 0x1000,

The NULL address is still valid for the MMU. Can the IOVMF_DA_ANON mapping be specified by the API to be always non-NULL?

This way it would be possible to combine IOVMF_DA_FIXED and IOVMF_DA_ANON mappings in the same IOMMU while still being able to rely that IOVMF_DA_ANON mappings would always be non-NULL.

Regards,

Signature · 2 lines
Sakari Ailus
[email protected]
#8 lore raw

Re: [PATCH 2/3] omap3: change ISP's IOMMU da_start address

Hi Sakari,

Quoted 9 lines · Sakari Ailus
Quoted 8 lines · David Cohen

ISP doesn't consider 0x0 as a valid address, so it should explicitly exclude first page from allowed 'da' range.

---
 arch/arm/mach-omap2/omap-iommu.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 13 lines

arch/arm/mach-omap2/omap-iommu.c static struct iommu_device omap3_devices[] = { · line 36

Quoted 10 lines
arch/arm/mach-omap2/omap-iommu.c +1 -1
index 3fc5dc7..3bea489 100644
@@ -33,7 +33,7 @@ static struct iommu_device omap3_devices[] = {
                       .name = "isp",
                       .nr_tlb_entries = 8,
                       .clk_name = "cam_ick",
-                     .da_start = 0x0,
+                     .da_start = 0x1000,

The NULL address is still valid for the MMU. Can the IOVMF_DA_ANON mapping be specified by the API to be always non-NULL?

The patch 1/3 does that :)

Quoted 4 lines

This way it would be possible to combine IOVMF_DA_FIXED and IOVMF_DA_ANON mappings in the same IOMMU while still being able to rely that IOVMF_DA_ANON mappings would always be non-NULL.

Indeed the IOMMU driver supports it. The flag is set by iovm area and each IOMMU instance supports a mix of mappings with fixed da or not. By changing the OMAP3 "isp" IOMMU pdata's da_start to 0x1000, we're explicitly saying that iovm areas with fixed 'da' or not will never map first page to OMAP3 ISP driver, what is the behavior it expects. Without this patch, thanks to patch 1/3 the IOMMU driver will not map address 0x0 to OMAP3 ISP anyway. But then ISP will be passing wrong information that it would be fine to map first page. :)

Kind regards,

David Cohen

Quoted 7 lines

Regards,

--
Sakari Ailus
[email protected]

#9 lore raw

PATCH 3/3 omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

In reply to David Cohen

Currently IOVMM driver sets IOVMF_DA_FIXED/IOVMF_DA_ANON flags according to input 'da' address when mapping memory:
da == 0: IOVMF_DA_ANON
da != 0: IOVMF_DA_FIXED

It prevents IOMMU to map first page with fixed 'da'. To avoid such issue, IOVMM will not automatically set IOVMF_DA_FIXED. It should now come from the user. IOVMF_DA_ANON will be automatically set if IOVMF_DA_FIXED isn't set.

---
 arch/arm/plat-omap/iovmm.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
arch/arm/plat-omap/iovmm.c +8 -4
index 11c9b76..dde9cb0 100644
@@ -654,7 +654,8 @@ u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
 	flags &= IOVMF_HW_MASK;
 	flags |= IOVMF_DISCONT;
 	flags |= IOVMF_MMIO;
-	flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+	if (~flags & IOVMF_DA_FIXED)
+		flags |= IOVMF_DA_ANON;
 
 	da = __iommu_vmap(obj, da, sgt, va, bytes, flags);
 	if (IS_ERR_VALUE(da))
@@ -713,7 +714,8 @@ u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
 	flags &= IOVMF_HW_MASK;
 	flags |= IOVMF_DISCONT;
 	flags |= IOVMF_ALLOC;
-	flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+	if (~flags & IOVMF_DA_FIXED)
+		flags |= IOVMF_DA_ANON;
 
 	sgt = sgtable_alloc(bytes, flags, da, 0);
 	if (IS_ERR(sgt)) {
@@ -803,7 +805,8 @@ u32 iommu_kmap(struct iommu *obj, u32 da, u32 pa, size_t bytes,
 	flags &= IOVMF_HW_MASK;
 	flags |= IOVMF_LINEAR;
 	flags |= IOVMF_MMIO;
-	flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+	if (~flags & IOVMF_DA_FIXED)
+		flags |= IOVMF_DA_ANON;
 
 	da = __iommu_kmap(obj, da, pa, va, bytes, flags);
 	if (IS_ERR_VALUE(da))
@@ -862,7 +865,8 @@ u32 iommu_kmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
 	flags &= IOVMF_HW_MASK;
 	flags |= IOVMF_LINEAR;
 	flags |= IOVMF_ALLOC;
-	flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+	if (~flags & IOVMF_DA_FIXED)
+		flags |= IOVMF_DA_ANON;
 
 	da = __iommu_kmap(obj, da, pa, va, bytes, flags);
 	if (IS_ERR_VALUE(da))
Signature · 1 line
1.7.0.4
#10 lore raw

Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

Quoted 20 lines · David Cohen

Currently IOVMM driver sets IOVMF_DA_FIXED/IOVMF_DA_ANON flags according to input 'da' address when mapping memory:
da == 0: IOVMF_DA_ANON
da != 0: IOVMF_DA_FIXED

It prevents IOMMU to map first page with fixed 'da'. To avoid such issue, IOVMM will not automatically set IOVMF_DA_FIXED. It should now come from the user. IOVMF_DA_ANON will be automatically set if IOVMF_DA_FIXED isn't set.

---
 arch/arm/plat-omap/iovmm.c |   12 ++++++++----

 1 files changed, 8 insertions(+), 4 deletions(-)
arch/arm/plat-omap/iovmm.c +0 -0
index 11c9b76..dde9cb0 100644

arch/arm/plat-omap/iovmm.c u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt, · line 658

Quoted 6 lines
arch/arm/plat-omap/iovmm.c +2 -1
@@ -654,7 +654,8 @@ u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_DISCONT;
        flags |= IOVMF_MMIO;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;

could we use only one? both are mutual exclusive, what happen if flag is IOVMF_DA_FIXED | IOVMF_DA_ANON? so, I suggest to get rid of IOVMF_DA_ANON.

Regards,
Fernando.

Quoted 37 lines
arch/arm/plat-omap/iovmm.c +6 -4
        da = __iommu_vmap(obj, da, sgt, va, bytes, flags);
        if (IS_ERR_VALUE(da))
@@ -713,7 +714,8 @@ u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_DISCONT;
        flags |= IOVMF_ALLOC;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;
 
        sgt = sgtable_alloc(bytes, flags, da, 0);
        if (IS_ERR(sgt)) {
@@ -803,7 +805,8 @@ u32 iommu_kmap(struct iommu *obj, u32 da, u32 pa, size_t bytes,
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_LINEAR;
        flags |= IOVMF_MMIO;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;
 
        da = __iommu_kmap(obj, da, pa, va, bytes, flags);
        if (IS_ERR_VALUE(da))
@@ -862,7 +865,8 @@ u32 iommu_kmalloc(struct iommu *obj, u32 da, size_t bytes, u32 flags)
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_LINEAR;
        flags |= IOVMF_ALLOC;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;
 
        da = __iommu_kmap(obj, da, pa, va, bytes, flags);
        if (IS_ERR_VALUE(da))
--

1.7.0.4

#11 lore raw

Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags
Date: Tue, 8 Mar 2011 11:59:43 -0600

Quoted 16 lines · David Cohen
Quoted 15 lines

Currently IOVMM driver sets IOVMF_DA_FIXED/IOVMF_DA_ANON flags according to input 'da' address when mapping memory:
da == 0: IOVMF_DA_ANON
da != 0: IOVMF_DA_FIXED

It prevents IOMMU to map first page with fixed 'da'. To avoid such issue, IOVMM will not automatically set IOVMF_DA_FIXED. It should now come from the user. IOVMF_DA_ANON will be automatically set if IOVMF_DA_FIXED isn't set.

---
 arch/arm/plat-omap/iovmm.c |   12 ++++++++----

 1 files changed, 8 insertions(+), 4 deletions(-)
Quoted 15 lines

arch/arm/plat-omap/iovmm.c u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt, · line 658

Quoted 11 lines
arch/arm/plat-omap/iovmm.c +2 -1
index 11c9b76..dde9cb0 100644
@@ -654,7 +654,8 @@ u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_DISCONT;
        flags |= IOVMF_MMIO;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;

could we use only one? both are mutual exclusive, what happen if flag is IOVMF_DA_FIXED | IOVMF_DA_ANON? so, I suggest to get rid of IOVMF_DA_ANON.

Then, what about introducing some MACRO? Better names?

#define set_iovmf_da_anon(flags)
#define set_iovmf_da_fix(flags)
#define set_iovmf_mmio(flags)
......

#12 lore raw

Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

Quoted 36 lines · Hiroshi DOYU

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags
Date: Tue, 8 Mar 2011 11:59:43 -0600

Quoted 16 lines · David Cohen
Quoted 15 lines

Currently IOVMM driver sets IOVMF_DA_FIXED/IOVMF_DA_ANON flags according to input 'da' address when mapping memory:
da == 0: IOVMF_DA_ANON
da != 0: IOVMF_DA_FIXED

It prevents IOMMU to map first page with fixed 'da'. To avoid such issue, IOVMM will not automatically set IOVMF_DA_FIXED. It should now come from the user. IOVMF_DA_ANON will be automatically set if IOVMF_DA_FIXED isn't set.

---
 arch/arm/plat-omap/iovmm.c |   12 ++++++++----

 1 files changed, 8 insertions(+), 4 deletions(-)
Quoted 15 lines

arch/arm/plat-omap/iovmm.c u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt, · line 658

Quoted 11 lines
arch/arm/plat-omap/iovmm.c +2 -1
index 11c9b76..dde9cb0 100644
@@ -654,7 +654,8 @@ u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_DISCONT;
        flags |= IOVMF_MMIO;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;

could we use only one? both are mutual exclusive, what happen if flag is IOVMF_DA_FIXED | IOVMF_DA_ANON? so, I suggest to get rid of IOVMF_DA_ANON.

Quoted 5 lines

Then, what about introducing some MACRO? Better names?

#define set_iovmf_da_anon(flags)
#define set_iovmf_da_fix(flags)
#define set_iovmf_mmio(flags)

will they be used by the users?

I think people are more used to use

iommu_vmap(obj, da, sgt, IOVMF_MMIO | IOVMF_DA_ANON);

than

set_iovmf_da_anon(flags)
set_iovmf_mmio(flags)
iommu_vmap(obj, da, sgt, flags);

I don't have problem with the change, but I think how it is now is ok, just that we don't we two bits to handle anon/fixed da, it can be managed it only 1 bit (one flag), or is there a issue?

Regards,
Fernando.

Quoted 2 lines

......

#13 lore raw

Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

Hi Hiroshi, Fernando,

Quoted 43 lines · Fernando
Quoted 36 lines · Hiroshi DOYU

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags
Date: Tue, 8 Mar 2011 11:59:43 -0600

Quoted 16 lines · David Cohen
Quoted 15 lines

Currently IOVMM driver sets IOVMF_DA_FIXED/IOVMF_DA_ANON flags according to input 'da' address when mapping memory:
da == 0: IOVMF_DA_ANON
da != 0: IOVMF_DA_FIXED

It prevents IOMMU to map first page with fixed 'da'. To avoid such issue, IOVMM will not automatically set IOVMF_DA_FIXED. It should now come from the user. IOVMF_DA_ANON will be automatically set if IOVMF_DA_FIXED isn't set.

---
 arch/arm/plat-omap/iovmm.c |   12 ++++++++----

 1 files changed, 8 insertions(+), 4 deletions(-)
Quoted 15 lines

arch/arm/plat-omap/iovmm.c u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt, · line 658

Quoted 11 lines
arch/arm/plat-omap/iovmm.c +2 -1
index 11c9b76..dde9cb0 100644
@@ -654,7 +654,8 @@ u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_DISCONT;
        flags |= IOVMF_MMIO;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;

could we use only one? both are mutual exclusive, what happen if flag is IOVMF_DA_FIXED | IOVMF_DA_ANON? so, I suggest to get rid of IOVMF_DA_ANON.

Quoted 5 lines

Then, what about introducing some MACRO? Better names?

#define set_iovmf_da_anon(flags)
#define set_iovmf_da_fix(flags)
#define set_iovmf_mmio(flags)

Quoted 5 lines

will they be used by the users?

I think people are more used to use

iommu_vmap(obj, da, sgt, IOVMF_MMIO | IOVMF_DA_ANON);

I'd be happier with this approach, instead of the macros. :) It's intuitive and very common on kernel.

Quoted 10 lines

than

set_iovmf_da_anon(flags)
set_iovmf_mmio(flags)
iommu_vmap(obj, da, sgt, flags);

I don't have problem with the change, but I think how it is now is ok, just that we don't we two bits to handle anon/fixed da, it can be managed it only 1 bit (one flag), or is there a issue?

We can exclude IOVMF_DA_ANON and stick with IOVMF_DA_FIXED only. I can resend my patch if we agree it's OK.

Regards,

David

Quoted 6 lines

Regards,
Fernando.

Quoted 2 lines

......

#14 lore raw

Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

Quoted 63 lines · David Cohen

Hi Hiroshi, Fernando,

Quoted 43 lines · Fernando
Quoted 36 lines · Hiroshi DOYU

From: "ext Guzman Lugo, Fernando" <[email protected]>
Subject: Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags
Date: Tue, 8 Mar 2011 11:59:43 -0600

Quoted 16 lines · David Cohen
Quoted 15 lines

Currently IOVMM driver sets IOVMF_DA_FIXED/IOVMF_DA_ANON flags according to input 'da' address when mapping memory:
da == 0: IOVMF_DA_ANON
da != 0: IOVMF_DA_FIXED

It prevents IOMMU to map first page with fixed 'da'. To avoid such issue, IOVMM will not automatically set IOVMF_DA_FIXED. It should now come from the user. IOVMF_DA_ANON will be automatically set if IOVMF_DA_FIXED isn't set.

---
 arch/arm/plat-omap/iovmm.c |   12 ++++++++----

 1 files changed, 8 insertions(+), 4 deletions(-)
Quoted 15 lines

arch/arm/plat-omap/iovmm.c u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt, · line 658

Quoted 11 lines
arch/arm/plat-omap/iovmm.c +2 -1
index 11c9b76..dde9cb0 100644
@@ -654,7 +654,8 @@ u32 iommu_vmap(struct iommu *obj, u32 da, const struct sg_table *sgt,
        flags &= IOVMF_HW_MASK;
        flags |= IOVMF_DISCONT;
        flags |= IOVMF_MMIO;
-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;

could we use only one? both are mutual exclusive, what happen if flag is IOVMF_DA_FIXED | IOVMF_DA_ANON? so, I suggest to get rid of IOVMF_DA_ANON.

Quoted 5 lines

Then, what about introducing some MACRO? Better names?

#define set_iovmf_da_anon(flags)
#define set_iovmf_da_fix(flags)
#define set_iovmf_mmio(flags)

Quoted 5 lines

will they be used by the users?

I think people are more used to use

iommu_vmap(obj, da, sgt, IOVMF_MMIO | IOVMF_DA_ANON);

I'd be happier with this approach, instead of the macros. :) It's intuitive and very common on kernel.

Quoted 7 lines

than

set_iovmf_da_anon(flags)
set_iovmf_mmio(flags)
iommu_vmap(obj, da, sgt, flags);

Quoted 6 lines
Quoted 3 lines

I don't have problem with the change, but I think how it is now is ok, just that we don't we two bits to handle anon/fixed da, it can be managed it only 1 bit (one flag), or is there a issue?

We can exclude IOVMF_DA_ANON and stick with IOVMF_DA_FIXED only. I can resend my patch if we agree it's OK.

sounds perfect to me.

Regards,
Fernando.

Quoted 12 lines

Regards,

David

Quoted 6 lines

Regards,
Fernando.

Quoted 2 lines

......

#15 lore raw

Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

[snip]

Quoted 30 lines
Quoted 30 lines
Quoted 14 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;

could we use only one? both are mutual exclusive, what happen if flag is IOVMF_DA_FIXED | IOVMF_DA_ANON? so, I suggest to get rid of IOVMF_DA_ANON.

Quoted 5 lines

Then, what about introducing some MACRO? Better names?

#define set_iovmf_da_anon(flags)
#define set_iovmf_da_fix(flags)
#define set_iovmf_mmio(flags)

Quoted 5 lines

will they be used by the users?

I think people are more used to use

iommu_vmap(obj, da, sgt, IOVMF_MMIO | IOVMF_DA_ANON);

I'd be happier with this approach, instead of the macros. :) It's intuitive and very common on kernel.

Quoted 7 lines

than

set_iovmf_da_anon(flags)
set_iovmf_mmio(flags)
iommu_vmap(obj, da, sgt, flags);

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I don't have problem with the change, but I think how it is now is ok, just that we don't we two bits to handle anon/fixed da, it can be managed it only 1 bit (one flag), or is there a issue?

We can exclude IOVMF_DA_ANON and stick with IOVMF_DA_FIXED only. I can resend my patch if we agree it's OK.

sounds perfect to me.

Not sure indeed if this change fits to this same patch. Looks like a 4th patch sounds better.

Br,

David Cohen

#16 lore raw

Re: [PATCH 3/3] omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON flags

Quoted 36 lines · David Cohen

[snip]

Quoted 34 lines
Quoted 34 lines
Quoted 14 lines
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

-       flags |= (da ? IOVMF_DA_FIXED : IOVMF_DA_ANON);
+       if (~flags & IOVMF_DA_FIXED)
+               flags |= IOVMF_DA_ANON;

could we use only one? both are mutual exclusive, what happen if flag is IOVMF_DA_FIXED | IOVMF_DA_ANON? so, I suggest to get rid of IOVMF_DA_ANON.

Quoted 5 lines

Then, what about introducing some MACRO? Better names?

#define set_iovmf_da_anon(flags)
#define set_iovmf_da_fix(flags)
#define set_iovmf_mmio(flags)

Quoted 5 lines

will they be used by the users?

I think people are more used to use

iommu_vmap(obj, da, sgt, IOVMF_MMIO | IOVMF_DA_ANON);

I'd be happier with this approach, instead of the macros. :) It's intuitive and very common on kernel.

Quoted 10 lines

than

set_iovmf_da_anon(flags)
set_iovmf_mmio(flags)
iommu_vmap(obj, da, sgt, flags);

I don't have problem with the change, but I think how it is now is ok, just that we don't we two bits to handle anon/fixed da, it can be managed it only 1 bit (one flag), or is there a issue?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

We can exclude IOVMF_DA_ANON and stick with IOVMF_DA_FIXED only. I can resend my patch if we agree it's OK.

sounds perfect to me.

Not sure indeed if this change fits to this same patch. Looks like a 4th patch sounds better.

Indeed not. :)
A new set is coming soon.

Br,

David

Quoted 5 lines

Br,

David Cohen

#17 lore raw
In reply to David Cohen

From: ext David Cohen <[email protected]>
Subject: [PATCH 0/3] omap: iovmm: Fix IOVMM check for fixed 'da'
Date: Tue, 8 Mar 2011 14:46:02 +0200

Quoted 11 lines

IOVMM driver checks input 'da == 0' when mapping address to determine whether user wants fixed 'da' or not. At the same time, it doesn't disallow address 0x0 to be used, what creates an ambiguous situation. This patch set moves fixed 'da' check to the input flags.
It also fixes da_start value for ISP IOMMU instance.

David Cohen (2):
omap3: change ISP's IOMMU da_start address
omap: iovmm: don't check 'da' to set IOVMF_DA_FIXED/IOVMF_DA_ANON
flags

Quoted 6 lines

Michael Jones (1):
omap: iovmm: disallow mapping NULL address

 arch/arm/mach-omap2/omap-iommu.c |    2 +-
 arch/arm/plat-omap/iovmm.c       |   28 ++++++++++++++++++----------
 2 files changed, 19 insertions(+), 11 deletions(-)

Based on the previous discussion, those look ok for me.