iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu: exynos: pointers are nto physical addresses
@ 2016-02-29  8:45 Arnd Bergmann
       [not found] ` <1456735568-3886545-1-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
  2016-02-29 15:45 ` Joerg Roedel
  0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-02-29  8:45 UTC (permalink / raw)
  To: Joerg Roedel, Marek Szyprowski, Joerg Roedel, Kukjin Kim,
	Krzysztof Kozlowski
  Cc: linux-arm-kernel, Arnd Bergmann, iommu, linux-samsung-soc,
	linux-kernel

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.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
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.

Please fix and that that as well.

 drivers/iommu/exynos-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
index b0665042bf29..484b3b37631f 100644
--- a/drivers/iommu/exynos-iommu.c
+++ b/drivers/iommu/exynos-iommu.c
@@ -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);
 
-- 
2.7.0

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

* Re: [PATCH] iommu: exynos: pointers are nto physical addresses
       [not found] ` <1456735568-3886545-1-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
@ 2016-02-29  9:33   ` Marek Szyprowski
  2016-02-29  9:54     ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Szyprowski @ 2016-02-29  9:33 UTC (permalink / raw)
  To: Arnd Bergmann, Joerg Roedel, Joerg Roedel, Kukjin Kim,
	Krzysztof Kozlowski
  Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi Arnd,

On 2016-02-29 09:45, Arnd Bergmann wrote:
> 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.
>
> Signed-off-by: Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>
> Fixes: 740a01eee9ad ("iommu/exynos: Add support for v5 SYSMMU")

Thanks for this fix.

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

>   drivers/iommu/exynos-iommu.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c
> index b0665042bf29..484b3b37631f 100644
> --- a/drivers/iommu/exynos-iommu.c
> +++ b/drivers/iommu/exynos-iommu.c
> @@ -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
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

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

* Re: [PATCH] iommu: exynos: pointers are nto physical addresses
  2016-02-29  9:33   ` Marek Szyprowski
@ 2016-02-29  9:54     ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2016-02-29  9:54 UTC (permalink / raw)
  To: Marek Szyprowski
  Cc: Joerg Roedel, Joerg Roedel, Kukjin Kim, Krzysztof Kozlowski,
	linux-arm-kernel, iommu, linux-samsung-soc, linux-kernel

On Monday 29 February 2016 10:33:59 Marek Szyprowski wrote:
> > ---
> > 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?

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

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

* Re: [PATCH] iommu: exynos: pointers are nto physical addresses
  2016-02-29  8:45 [PATCH] iommu: exynos: pointers are nto physical addresses Arnd Bergmann
       [not found] ` <1456735568-3886545-1-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
@ 2016-02-29 15:45 ` Joerg Roedel
  1 sibling, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2016-02-29 15:45 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Joerg Roedel, Marek Szyprowski, Kukjin Kim, Krzysztof Kozlowski,
	linux-arm-kernel, iommu, linux-samsung-soc, linux-kernel

On Mon, Feb 29, 2016 at 09:45:59AM +0100, Arnd Bergmann wrote:
> 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.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> 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.
> 
> Please fix and that that as well.
> 
>  drivers/iommu/exynos-iommu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks Arnd.

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

end of thread, other threads:[~2016-02-29 15:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-29  8:45 [PATCH] iommu: exynos: pointers are nto physical addresses Arnd Bergmann
     [not found] ` <1456735568-3886545-1-git-send-email-arnd-r2nGTMty4D4@public.gmane.org>
2016-02-29  9:33   ` Marek Szyprowski
2016-02-29  9:54     ` Arnd Bergmann
2016-02-29 15:45 ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).