public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/io-pgtable-arm: fix self-test WARNs on i386
@ 2015-02-16 18:38 Will Deacon
  2015-02-25 12:38 ` Joerg Roedel
  0 siblings, 1 reply; 2+ messages in thread
From: Will Deacon @ 2015-02-16 18:38 UTC (permalink / raw)
  To: joro; +Cc: linux-kernel, iommu, Will Deacon

Various build/boot bots have reported WARNs being triggered by the ARM
iopgtable LPAE self-tests on i386 machines.

This boils down to two instances of right-shifting a 32-bit unsigned
long (i.e. an iova) by more than the size of the type. On 32-bit ARM,
this happens to give us zero, hence my testing didn't catch this
earlier.

This patch fixes the issue by using DIV_ROUND_UP and explicit case to
to avoid the erroneous shifts.

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Reported-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---

Joerg -- please can you apply this as a fix for 3.20?

 drivers/iommu/io-pgtable-arm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c
index 5a500edf00cc..b610a8dee238 100644
--- a/drivers/iommu/io-pgtable-arm.c
+++ b/drivers/iommu/io-pgtable-arm.c
@@ -56,7 +56,8 @@
 	((((d)->levels - ((l) - ARM_LPAE_START_LVL(d) + 1))		\
 	  * (d)->bits_per_level) + (d)->pg_shift)
 
-#define ARM_LPAE_PAGES_PER_PGD(d)	((d)->pgd_size >> (d)->pg_shift)
+#define ARM_LPAE_PAGES_PER_PGD(d)					\
+	DIV_ROUND_UP((d)->pgd_size, 1UL << (d)->pg_shift)
 
 /*
  * Calculate the index at level l used to map virtual address a using the
@@ -66,7 +67,7 @@
 	((l) == ARM_LPAE_START_LVL(d) ? ilog2(ARM_LPAE_PAGES_PER_PGD(d)) : 0)
 
 #define ARM_LPAE_LVL_IDX(a,l,d)						\
-	(((a) >> ARM_LPAE_LVL_SHIFT(l,d)) &				\
+	(((u64)(a) >> ARM_LPAE_LVL_SHIFT(l,d)) &			\
 	 ((1 << ((d)->bits_per_level + ARM_LPAE_PGD_IDX(l,d))) - 1))
 
 /* Calculate the block/page mapping size at level l for pagetable in d. */
-- 
2.1.4


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

* Re: [PATCH] iommu/io-pgtable-arm: fix self-test WARNs on i386
  2015-02-16 18:38 [PATCH] iommu/io-pgtable-arm: fix self-test WARNs on i386 Will Deacon
@ 2015-02-25 12:38 ` Joerg Roedel
  0 siblings, 0 replies; 2+ messages in thread
From: Joerg Roedel @ 2015-02-25 12:38 UTC (permalink / raw)
  To: Will Deacon; +Cc: linux-kernel, iommu

On Mon, Feb 16, 2015 at 06:38:20PM +0000, Will Deacon wrote:
> Various build/boot bots have reported WARNs being triggered by the ARM
> iopgtable LPAE self-tests on i386 machines.
> 
> This boils down to two instances of right-shifting a 32-bit unsigned
> long (i.e. an iova) by more than the size of the type. On 32-bit ARM,
> this happens to give us zero, hence my testing didn't catch this
> earlier.
> 
> This patch fixes the issue by using DIV_ROUND_UP and explicit case to
> to avoid the erroneous shifts.
> 
> Reported-by: Fengguang Wu <fengguang.wu@intel.com>
> Reported-by: Huang Ying <ying.huang@intel.com>
> Signed-off-by: Will Deacon <will.deacon@arm.com>
> ---
> 
> Joerg -- please can you apply this as a fix for 3.20?

Applied to my fixes branch, thanks Will.


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

end of thread, other threads:[~2015-02-25 12:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-16 18:38 [PATCH] iommu/io-pgtable-arm: fix self-test WARNs on i386 Will Deacon
2015-02-25 12:38 ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox