iommu: exynos: pointers are nto physical addresses
Subsystems (3)
PATCH 1/1 iommu: exynos: pointers are nto physical addresses
The exynos iommu driver changed an incorrect cast from pointer to 'unsigned int' to an equally incorrect cast to a 'phys_addr_t', which results in an obvious compile-time error when phys_addr_t is wider than pointers are:
drivers/iommu/exynos-iommu.c: In function 'alloc_lv2entry':drivers/iommu/exynos-iommu.c:918:32: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
The code does not actually want the physical address (which would involve using virt_to_phys()), but just checks the alignment, so we can change it to use a cast to uintptr_t instead.
---
I also see that some incorrect __raw_writel() calls have crept in around the same time, which breaks running big-endian kernels when this driver is loaded.
Please fix and that that as well.
drivers/iommu/exynos-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/exynos-iommu.c +1 -1
@@ -915,7 +915,7 @@ static sysmmu_pte_t *alloc_lv2entry(struct exynos_iommu_domain *domain,bool need_flush_flpd_cache =lv1ent_zero (sent); pent =kmem_cache_zalloc (lv2table_kmem_cache,GFP_ATOMIC ); -BUG_ON ((phys_addr_t )pent & (LV2TABLE_SIZE -1 )); +BUG_ON ((uintptr_t )pent & (LV2TABLE_SIZE -1 ));if (!pent)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.7.0
Marek Szyprowski
maintainerHi Arnd,
Quoted 8 lines · Arnd Bergmann
The exynos iommu driver changed an incorrect cast from pointer to 'unsigned int' to an equally incorrect cast to a '
phys_addr_t', which results in an obvious compile-time error whenphys_addr_tis wider than pointers are:
drivers/iommu/exynos-iommu.c: In function 'alloc_lv2entry':drivers/iommu/exynos-iommu.c:918:32: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
Quoted 6 lines
The code does not actually want the physical address (which would involve using
virt_to_phys()), but just checks the alignment, so we can change it to use a cast touintptr_tinstead.Signed-off-by Arnd Bergmann <[email protected]>Fixes 740a01eee9ad ("iommu/exynos: Add support for v5 SYSMMU")
Thanks for this fix.
Quoted 6 lines
---
I also see that some incorrect__raw_writel()calls have crept in around the same time, which breaks running big-endian kernels when this driver is loaded.Please fix and that that as well.
Okay, so in the driver code all __raw_writel should be replaced by writel(), right?
Those __raw_writel() calls were there from the beginning and I didn't know that they should not be used in the driver code.
Quoted 8 lines
drivers/iommu/exynos-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/exynos-iommu.c +0
-0
drivers/iommu/exynos-iommu.c static sysmmu_pte_t *alloc_lv2entry(struct exynos_iommu_domain *domain, · line 921
Quoted 8 lines
drivers/iommu/exynos-iommu.c +1
-1@@ -915,7 +915,7 @@ static sysmmu_pte_t *alloc_lv2entry(struct exynos_iommu_domain *domain,bool need_flush_flpd_cache =lv1ent_zero (sent); pent =kmem_cache_zalloc (lv2table_kmem_cache,GFP_ATOMIC ); -BUG_ON ((phys_addr_t )pent & (LV2TABLE_SIZE -1 )); +BUG_ON ((uintptr_t )pent & (LV2TABLE_SIZE -1 ));if (!pent)return ERR_PTR (-ENOMEM );
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Quoted 9 lines · On Monday 29 February 2016 10:33:59 Marek Szyprowski wrote:
Quoted 6 lines
---
I also see that some incorrect__raw_writel()calls have crept in around the same time, which breaks running big-endian kernels when this driver is loaded.Please fix and that that as well.
Okay, so in the driver code all
__raw_writelshould be replaced bywritel(), right?
Yes, writel() is always the safe choice if you don't know what to use. __raw_writel() should be considered an implementation detail and not used in drivers at all. There is also writel_relaxed(), which is faster than writel() because it leaves out all the barriers (as __raw_writel does too), and you can sometimes use that in the fast path if you can prove that no barriers are needed.
Arnd
Quoted 19 lines · Arnd Bergmann
The exynos iommu driver changed an incorrect cast from pointer to 'unsigned int' to an equally incorrect cast to a '
phys_addr_t', which results in an obvious compile-time error whenphys_addr_tis wider than pointers are:
drivers/iommu/exynos-iommu.c: In function 'alloc_lv2entry':drivers/iommu/exynos-iommu.c:918:32: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]The code does not actually want the physical address (which would involve using
virt_to_phys()), but just checks the alignment, so we can change it to use a cast touintptr_tinstead.Signed-off-by Arnd Bergmann <[email protected]>Fixes 740a01eee9ad ("iommu/exynos: Add support for v5 SYSMMU")---
I also see that some incorrect__raw_writel()calls have crept in around the same time, which breaks running big-endian kernels when this driver is loaded.
Quoted 4 lines
Please fix and that that as well.
drivers/iommu/exynos-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks Arnd.