diff mbox

[RFC,2/2] arm: mm: Double logical invert for LPAE pte_write(), pte_dirty()

Message ID 1392396913-13570-3-git-send-email-steve.capper@linaro.org
State New
Headers show

Commit Message

Steve Capper Feb. 14, 2014, 4:55 p.m. UTC
On LPAE, L_PTE_WRITE and L_PTE_DIRTY are in the upper 32-bits.
Unfortunately, results from pte_write() and pte_dirty() are downcast
to 32-bits by core code:
  o gather_stats
  o huge_pte_dirty
  o huge_pte_write
  o make_migration_entry

This patch adds a double logical invert to pte_write() and pte_dirty()
for LPAE to ensure that the lower 32-bits are set if true.

Signed-off-by: Steve Capper <steve.capper@linaro.org>
---
 arch/arm/include/asm/pgtable-2level.h |  2 ++
 arch/arm/include/asm/pgtable-3level.h | 14 ++++++++++++++
 arch/arm/include/asm/pgtable.h        |  2 --
 3 files changed, 16 insertions(+), 2 deletions(-)

Comments

Steve Capper Feb. 21, 2014, 8:39 a.m. UTC | #1
On Thu, Feb 20, 2014 at 05:26:51PM +0000, Will Deacon wrote:
> On Fri, Feb 14, 2014 at 04:55:13PM +0000, Steve Capper wrote:
> > On LPAE, L_PTE_WRITE and L_PTE_DIRTY are in the upper 32-bits.
> > Unfortunately, results from pte_write() and pte_dirty() are downcast
> > to 32-bits by core code:
> >   o gather_stats
> >   o huge_pte_dirty
> >   o huge_pte_write
> >   o make_migration_entry
> > 
> > This patch adds a double logical invert to pte_write() and pte_dirty()
> > for LPAE to ensure that the lower 32-bits are set if true.
> 
> Yikes, this sounds like something we should put in -stable, no? If so,
> better make it patch 1 of this series.

Yeah, it makes sense to have this as the first patch. It probably
should go through stable, I will mark the next version of this patch
for stable.

> 
>   Reviewed-by: Will Deacon <will.deacon@arm.com>

Thanks Will.

Cheers,
--
Steve
Catalin Marinas Feb. 21, 2014, 11:20 a.m. UTC | #2
On Thu, Feb 20, 2014 at 05:26:51PM +0000, Will Deacon wrote:
> On Fri, Feb 14, 2014 at 04:55:13PM +0000, Steve Capper wrote:
> > On LPAE, L_PTE_WRITE and L_PTE_DIRTY are in the upper 32-bits.
> > Unfortunately, results from pte_write() and pte_dirty() are downcast
> > to 32-bits by core code:
> >   o gather_stats
> >   o huge_pte_dirty
> >   o huge_pte_write
> >   o make_migration_entry
> > 
> > This patch adds a double logical invert to pte_write() and pte_dirty()
> > for LPAE to ensure that the lower 32-bits are set if true.
> 
> Yikes, this sounds like something we should put in -stable, no? If so,
> better make it patch 1 of this series.

That's a bug on arm64 as well since functions like gather_stats() take
an int as argument.

However, my preference is for a static inline function instead of "!!"
on arm64.

Steve, would you send a patch for arm64? If not, I can do it (with your
reported-by).

Thanks.
Steve Capper Feb. 21, 2014, 11:51 a.m. UTC | #3
On Fri, Feb 21, 2014 at 11:28:12AM +0000, Russell King - ARM Linux wrote:
> On Fri, Feb 14, 2014 at 04:55:13PM +0000, Steve Capper wrote:
> > On LPAE, L_PTE_WRITE and L_PTE_DIRTY are in the upper 32-bits.
> > Unfortunately, results from pte_write() and pte_dirty() are downcast
> > to 32-bits by core code:
> >   o gather_stats
> >   o huge_pte_dirty
> >   o huge_pte_write
> >   o make_migration_entry
> > 
> > This patch adds a double logical invert to pte_write() and pte_dirty()
> > for LPAE to ensure that the lower 32-bits are set if true.
> 
> We should ensure all those functions return something which is compatible
> with "int" correctly.  It didn't matter for non-LPAE as the PTEs fit in
> 32-bit, but with LPAE, that really needs fixing independently of your
> other patch.

Agreed, I'm getting that written/tested now for arm and arm64.

Cheers,
diff mbox

Patch

diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
index ca43b84..7e8ebe7 100644
--- a/arch/arm/include/asm/pgtable-2level.h
+++ b/arch/arm/include/asm/pgtable-2level.h
@@ -162,6 +162,8 @@  static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
 
 #define pmd_large(pmd)		(pmd_val(pmd) & 2)
 #define pmd_bad(pmd)		(pmd_val(pmd) & 2)
+#define pte_write(pte)		(pte_val(pte) & L_PTE_WRITE)
+#define pte_dirty(pte)		(pte_val(pte) & L_PTE_DIRTY)
 
 #define copy_pmd(pmdpd,pmdps)		\
 	do {				\
diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
index 8a392ef..62efcc5 100644
--- a/arch/arm/include/asm/pgtable-3level.h
+++ b/arch/arm/include/asm/pgtable-3level.h
@@ -135,6 +135,20 @@ 
 
 #ifndef __ASSEMBLY__
 
+/*
+ * On LPAE, L_PTE_WRITE and L_PTE_DIRTY are in the upper 32-bits.
+ * Unfortunately, results from pte_write() and pte_dirty() are downcast
+ * to 32-bits by core code:
+ *  o gather_stats
+ *  o huge_pte_dirty
+ *  o huge_pte_write
+ *  o make_migration_entry
+ *
+ * Double logical invert to make sure lower 32-bits are set if true.
+ */
+#define pte_write(pte)		(!!(pte_val(pte) & L_PTE_WRITE))
+#define pte_dirty(pte)		(!!(pte_val(pte) & L_PTE_DIRTY))
+
 #define pud_none(pud)		(!pud_val(pud))
 #define pud_bad(pud)		(!(pud_val(pud) & 2))
 #define pud_present(pud)	(pud_val(pud))
diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
index 7a17611..e94a616 100644
--- a/arch/arm/include/asm/pgtable.h
+++ b/arch/arm/include/asm/pgtable.h
@@ -216,8 +216,6 @@  static inline pte_t *pmd_page_vaddr(pmd_t pmd)
 
 #define pte_none(pte)		(!pte_val(pte))
 #define pte_present(pte)	(pte_val(pte) & L_PTE_PRESENT)
-#define pte_write(pte)		(pte_val(pte) & L_PTE_WRITE)
-#define pte_dirty(pte)		(pte_val(pte) & L_PTE_DIRTY)
 #define pte_young(pte)		(pte_val(pte) & L_PTE_YOUNG)
 #define pte_exec(pte)		(!(pte_val(pte) & L_PTE_XN))
 #define pte_special(pte)	(0)