Skip to contentSkip to conversation

Fix build failure with v5.8-rc1

PATCH Applied Christophe Leroy 5 participants 16 messages Jun 15, 2020 – Jun 18, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Fix build failure with v5.8-rc1

Commit 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses") leads to following build failure on powerpc 8xx.

To fix it, this small series introduces a new helper named ptep_get() to replace the direct access with READ_ONCE(). This new helper can be overriden by architectures.

CC mm/gup.o
In file included from ./include/linux/kernel.h:11:0,

                 from mm/gup.c:2:
In function 'gup_hugepte.constprop',
    inlined from 'gup_huge_pd.isra.79' at mm/gup.c:2465:8:
./include/linux/compiler.h:392:38: error: call to '__compiletime_assert_222' declared with attribute error: Unsupported access size for {READ,WRITE}_ONCE().
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
./include/linux/compiler.h:373:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^

./include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
./include/linux/compiler.h:405:2: note: in expansion of macro 'compiletime_assert'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
./include/linux/compiler.h:291:2: note: in expansion of macro 'compiletime_assert_rwonce_type'
compiletime_assert_rwonce_type(x); \
^
mm/gup.c:2428:8: note: in expansion of macro 'READ_ONCE'

  pte = READ_ONCE(*ptep);
        ^
In function 'gup_get_pte',
    inlined from 'gup_pte_range' at mm/gup.c:2228:9,
    inlined from 'gup_pmd_range' at mm/gup.c:2613:15,
    inlined from 'gup_pud_range' at mm/gup.c:2641:15,
    inlined from 'gup_p4d_range' at mm/gup.c:2666:15,
    inlined from 'gup_pgd_range' at mm/gup.c:2694:15,
    inlined from 'internal_get_user_pages_fast' at mm/gup.c:2795:3:
./include/linux/compiler.h:392:38: error: call to '__compiletime_assert_219' declared with attribute error: Unsupported access size for {READ,WRITE}_ONCE().
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
./include/linux/compiler.h:373:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^

./include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
./include/linux/compiler.h:405:2: note: in expansion of macro 'compiletime_assert'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
./include/linux/compiler.h:291:2: note: in expansion of macro 'compiletime_assert_rwonce_type'
compiletime_assert_rwonce_type(x); \
^
mm/gup.c:2199:9: note: in expansion of macro 'READ_ONCE'

  return READ_ONCE(*ptep);
         ^

make[2]: *** [mm/gup.o] Error 1

Christophe Leroy (3):
mm/gup: Use huge_ptep_get() in gup_hugepte()
mm: Allow arches to provide ptep_get()
powerpc/8xx: Provide ptep_get() with 16k pages

 arch/powerpc/include/asm/nohash/32/pgtable.h | 10 ++++++++++
 include/asm-generic/hugetlb.h                |  2 +-
 include/linux/pgtable.h                      |  7 +++++++
 mm/gup.c                                     |  4 ++--
 4 files changed, 20 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.0
#1 lore raw

PATCH 1/3 mm/gup: Use huge_ptep_get() in gup_hugepte()

gup_hugepte() reads hugepage table entries, it can't read them directly, huge_ptep_get() must be used.

Fixes 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses")
Cc Will Deacon <[email protected]>
---
 mm/gup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/gup.c +1 -1
index de9e36262ccb..761df4944ef5 100644
@@ -2425,7 +2425,7 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
 	if (pte_end < end)
 		end = pte_end;
 
-	pte = READ_ONCE(*ptep);
+	pte = huge_ptep_get(ptep);
 
 	if (!pte_access_permitted(pte, flags & FOLL_WRITE))
 		return 0;
Signature · 1 line
2.25.0
#3 lore raw

PATCH 2/3 mm: Allow arches to provide ptep_get()

In reply to Christophe Leroy

Since commit 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses"), it is not possible anymore to use READ_ONCE() to access complex page table entries like the one defined for powerpc 8xx with 16k size pages.

Define a ptep_get() helper that architectures can override instead of performing a READ_ONCE() on the page table entry pointer.

Fixes 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses")
Cc Will Deacon <[email protected]>
---
 include/asm-generic/hugetlb.h | 2 +-
 include/linux/pgtable.h       | 7 +++++++
 mm/gup.c                      | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)
include/asm-generic/hugetlb.h +1 -1
index 40f85decc2ee..8e1e6244a89d 100644
@@ -122,7 +122,7 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
 #ifndef __HAVE_ARCH_HUGE_PTEP_GET
 static inline pte_t huge_ptep_get(pte_t *ptep)
 {
-	return READ_ONCE(*ptep);
+	return ptep_get(ptep);
 }
 #endif
 
include/linux/pgtable.h +7 -0
index 32b6c52d41b9..56c1e8eb7bb0 100644
@@ -249,6 +249,13 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
 }
 #endif
 
+#ifndef __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	return READ_ONCE(*ptep);
+}
+#endif
+
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #ifndef __HAVE_ARCH_PMDP_HUGE_GET_AND_CLEAR
 static inline pmd_t pmdp_huge_get_and_clear(struct mm_struct *mm,
mm/gup.c +1 -1
index 761df4944ef5..6f47697f8fb0 100644
@@ -2196,7 +2196,7 @@ static inline pte_t gup_get_pte(pte_t *ptep)
  */
 static inline pte_t gup_get_pte(pte_t *ptep)
 {
-	return READ_ONCE(*ptep);
+	return ptep_get(ptep);
 }
 #endif /* CONFIG_GUP_GET_PTE_LOW_HIGH */
 
Signature · 1 line
2.25.0
#4 lore raw

PATCH 3/3 powerpc/8xx: Provide ptep_get() with 16k pages

In reply to Christophe Leroy

READ_ONCE() now enforces atomic read, which leads to:

CC mm/gup.o
In file included from ./include/linux/kernel.h:11:0,

                 from mm/gup.c:2:
In function 'gup_hugepte.constprop',
    inlined from 'gup_huge_pd.isra.79' at mm/gup.c:2465:8:
./include/linux/compiler.h:392:38: error: call to '__compiletime_assert_222' declared with attribute error: Unsupported access size for {READ,WRITE}_ONCE().
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
./include/linux/compiler.h:373:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^

./include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
./include/linux/compiler.h:405:2: note: in expansion of macro 'compiletime_assert'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
./include/linux/compiler.h:291:2: note: in expansion of macro 'compiletime_assert_rwonce_type'
compiletime_assert_rwonce_type(x); \
^
mm/gup.c:2428:8: note: in expansion of macro 'READ_ONCE'

  pte = READ_ONCE(*ptep);
        ^
In function 'gup_get_pte',
    inlined from 'gup_pte_range' at mm/gup.c:2228:9,
    inlined from 'gup_pmd_range' at mm/gup.c:2613:15,
    inlined from 'gup_pud_range' at mm/gup.c:2641:15,
    inlined from 'gup_p4d_range' at mm/gup.c:2666:15,
    inlined from 'gup_pgd_range' at mm/gup.c:2694:15,
    inlined from 'internal_get_user_pages_fast' at mm/gup.c:2795:3:
./include/linux/compiler.h:392:38: error: call to '__compiletime_assert_219' declared with attribute error: Unsupported access size for {READ,WRITE}_ONCE().
  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
                                      ^
./include/linux/compiler.h:373:4: note: in definition of macro '__compiletime_assert'
    prefix ## suffix();    \
    ^

./include/linux/compiler.h:392:2: note: in expansion of macro '_compiletime_assert'
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
^
./include/linux/compiler.h:405:2: note: in expansion of macro 'compiletime_assert'
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
^
./include/linux/compiler.h:291:2: note: in expansion of macro 'compiletime_assert_rwonce_type'
compiletime_assert_rwonce_type(x); \
^
mm/gup.c:2199:9: note: in expansion of macro 'READ_ONCE'

  return READ_ONCE(*ptep);
         ^

make[2]: *** [mm/gup.o] Error 1

Define ptep_get() on 8xx when using 16k pages.

Fixes 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses")
Cc Will Deacon <[email protected]>
---
 arch/powerpc/include/asm/nohash/32/pgtable.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/include/asm/nohash/32/pgtable.h +10 -0
index b56f14160ae5..77addb599ce7 100644
@@ -286,6 +286,16 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 	return __pte(pte_update(mm, addr, ptep, ~0, 0, 0));
 }
 
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif
+
 #define __HAVE_ARCH_PTEP_SET_WRPROTECT
 static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
 				      pte_t *ptep)
Signature · 1 line
2.25.0
Acked-by on v1 3/3
#5 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

Quoted 17 lines · Christophe Leroy

READ_ONCE() now enforces atomic read, which leads to:

Fixes 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses")
Cc Will Deacon <[email protected]>
---
 arch/powerpc/include/asm/nohash/32/pgtable.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/include/asm/nohash/32/pgtable.h +0 -0
index b56f14160ae5..77addb599ce7 100644
@@ -286,6 +286,16 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 	return __pte(pte_update(mm, addr, ptep, ~0, 0, 0));
 }

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 10 lines
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
 
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

Other than that, the series looks good to me, Thanks!

Acked-by on the v1 series
#13 lore raw
In reply to Christophe Leroy

[+Arnd in case he's interested in this series]

Quoted 7 lines · Christophe Leroy

Commit 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses") leads to following build failure on powerpc 8xx.

To fix it, this small series introduces a new helper named ptep_get() to replace the direct access with READ_ONCE(). This new helper can be overriden by architectures.

Thanks for doing this, and sorry for the breakage. For the series:

Hopefully we can introduce accessors for the other page-table levels too, but that can obviously happen incrementally.

Will

Quoted 14 lines

Christophe Leroy (3):
mm/gup: Use huge_ptep_get() in gup_hugepte()
mm: Allow arches to provide ptep_get()
powerpc/8xx: Provide ptep_get() with 16k pages

 arch/powerpc/include/asm/nohash/32/pgtable.h | 10 ++++++++++
 include/asm-generic/hugetlb.h                |  2 +-
 include/linux/pgtable.h                      |  7 +++++++
 mm/gup.c                                     |  4 ++--
 4 files changed, 20 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.0
#14 lore raw
In reply to Christophe Leroy
Quoted 3 lines · Christophe Leroy

Commit 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses") leads to following build failure on powerpc 8xx.

I've put this in my fixes branch.

cheers

#2 lore raw

Re: [PATCH 1/3] mm/gup: Use huge_ptep_get() in gup_hugepte()

In reply to Christophe Leroy
Quoted 4 lines · Christophe Leroy

gup_hugepte() reads hugepage table entries, it can't read them directly, huge_ptep_get() must be used.

Fixes 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses")

I see that commit in older versions of linux-next but not in mainline.

In mainline it seems to be: 9e343b467c70 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses")

I guess it got rebased somewhere along the way.

I fixed it up when applying, and the other two as well.

cheers

Quoted 21 lines
---
 mm/gup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/gup.c +1 -1
index de9e36262ccb..761df4944ef5 100644
@@ -2425,7 +2425,7 @@ static int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
 	if (pte_end < end)
 		end = pte_end;
 
-	pte = READ_ONCE(*ptep);
+	pte = huge_ptep_get(ptep);
 
 	if (!pte_access_permitted(pte, flags & FOLL_WRITE))
 		return 0;
Signature · 1 line
2.25.0
#6 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

In reply to Peter Zijlstra
Quoted 18 lines · Peter Zijlstra
Quoted 17 lines · Christophe Leroy

READ_ONCE() now enforces atomic read, which leads to:

Fixes 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses")
Cc Will Deacon <[email protected]>
---
 arch/powerpc/include/asm/nohash/32/pgtable.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/include/asm/nohash/32/pgtable.h +0 -0
index b56f14160ae5..77addb599ce7 100644
@@ -286,6 +286,16 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 	return __pte(pte_update(mm, addr, ptep, ~0, 0, 0));
 }
 
Quoted 12 lines

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 9 lines
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

I tried writing a helpful comment but it's too late for my brain to form sensible sentences.

Christophe can you send a follow-up with a comment explaining it? In particular the zero entries stand out, it's kind of subtle that those entries are only populated with the right value when we write to the page table.

cheers

#7 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

Quoted 16 lines · Michael Ellerman
Quoted 14 lines · Peter Zijlstra

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 9 lines · Christophe Leroy
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

Quoted 7 lines

I tried writing a helpful comment but it's too late for my brain to form sensible sentences.

Christophe can you send a follow-up with a comment explaining it? In particular the zero entries stand out, it's kind of subtle that those entries are only populated with the right value when we write to the page table.

static inline pte_t ptep_get(pte_t *ptep)

{
	unsigned long val = READ_ONCE(ptep->pte);
	/* 16K pages have 4 identical value 4K entries */
	pte_t pte = {val, val, val, val);
	return pte;
}

Maybe something like that?

#8 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

Le 17/06/2020 à 16:38, Peter Zijlstra a écrit :

Quoted 26 lines · Michael Ellerman
Quoted 16 lines
Quoted 14 lines · Peter Zijlstra

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 9 lines · Christophe Leroy
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

Quoted 7 lines

I tried writing a helpful comment but it's too late for my brain to form sensible sentences.

Christophe can you send a follow-up with a comment explaining it? In particular the zero entries stand out, it's kind of subtle that those entries are only populated with the right value when we write to the page table.

static inline pte_t ptep_get(pte_t *ptep)

Quoted 9 lines
{
	unsigned long val = READ_ONCE(ptep->pte);
	/* 16K pages have 4 identical value 4K entries */
	pte_t pte = {val, val, val, val);
	return pte;
}

Maybe something like that?

This should work as well. Indeed nobody cares about what's in the other three. They are only there to ensure that ptep++ increases the ptep pointer by 16 bytes. Only the HW require 4 identical values, that's taken care of in set_pte_at() and pte_update(). So we should use the most efficient. Thinking once more, maybe what you propose is the most efficient as there is no need to load another register with value 0 in order to write it in the stack.

Christophe

#11 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

In reply to Peter Zijlstra
Quoted 26 lines · Peter Zijlstra
Quoted 16 lines · Michael Ellerman
Quoted 14 lines · Peter Zijlstra

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 9 lines · Christophe Leroy
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

Quoted 7 lines

I tried writing a helpful comment but it's too late for my brain to form sensible sentences.

Christophe can you send a follow-up with a comment explaining it? In particular the zero entries stand out, it's kind of subtle that those entries are only populated with the right value when we write to the page table.

static inline pte_t ptep_get(pte_t *ptep)

Quoted 8 lines
{
	unsigned long val = READ_ONCE(ptep->pte);
	/* 16K pages have 4 identical value 4K entries */
	pte_t pte = {val, val, val, val);
	return pte;
}

Maybe something like that?

I think val wants to be pte_basic_t, but otherwise yeah I like that much better.

cheers

#9 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

In reply to Christophe Leroy
Quoted 34 lines · Christophe Leroy

Le 17/06/2020 à 16:38, Peter Zijlstra a écrit :

Quoted 33 lines · Michael Ellerman
Quoted 16 lines
Quoted 14 lines · Peter Zijlstra

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 9 lines · Christophe Leroy
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

Quoted 7 lines

I tried writing a helpful comment but it's too late for my brain to form sensible sentences.

Christophe can you send a follow-up with a comment explaining it? In particular the zero entries stand out, it's kind of subtle that those entries are only populated with the right value when we write to the page table.

static inline pte_t ptep_get(pte_t *ptep)

{
	unsigned long val = READ_ONCE(ptep->pte);
	/* 16K pages have 4 identical value 4K entries */
	pte_t pte = {val, val, val, val);
	return pte;
}
Quoted 6 lines
Quoted 1 line

Maybe something like that?

This should work as well. Indeed nobody cares about what's in the other three. They are only there to ensure that ptep++ increases the ptep pointer by 16 bytes. Only the HW require 4 identical values, that's taken care of in set_pte_at() and pte_update().

Right, but it seems less error-prone to have the in-memory representation match what we have in the page table (well that's in-memory too but you know what I mean).

Quoted 3 lines

So we should use the most efficient. Thinking once more, maybe what you propose is the most efficient as there is no need to load another register with value 0 in order to write it in the stack.

On 64-bit I'd say it makes zero difference, the only thing that's going to matter is the load from ptep->pte. I don't know whether that's true on the 8xx cores though.

cheers

#15 lore raw
In reply to Christophe Leroy
Quoted 9 lines · Christophe Leroy

Commit 2ab3a0a02905 ("READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses") leads to following build failure on powerpc 8xx.

To fix it, this small series introduces a new helper named ptep_get() to replace the direct access with READ_ONCE(). This new helper can be overriden by architectures.

[...]

Applied to powerpc/fixes.

[1/3] mm/gup: Use huge_ptep_get() in gup_hugepte()

      https://git.kernel.org/powerpc/c/01a80ec6495f9e43f61b3231f3b283ca050a800e
[2/3] mm: Allow arches to provide ptep_get()
      https://git.kernel.org/powerpc/c/f7583fd6bdcc4d0b43f68fb81ebfae9669ee9338
[3/3] powerpc/8xx: Provide ptep_get() with 16k pages
      https://git.kernel.org/powerpc/c/b55129f97aeefd265314e12d98935330e011a14a

cheers

#10 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

In reply to Michael Ellerman

Le 18/06/2020 à 03:00, Michael Ellerman a écrit :

Quoted 46 lines
Quoted 34 lines · Christophe Leroy

Le 17/06/2020 à 16:38, Peter Zijlstra a écrit :

Quoted 33 lines · Michael Ellerman
Quoted 16 lines
Quoted 14 lines · Peter Zijlstra

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 9 lines · Christophe Leroy
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

Quoted 7 lines

I tried writing a helpful comment but it's too late for my brain to form sensible sentences.

Christophe can you send a follow-up with a comment explaining it? In particular the zero entries stand out, it's kind of subtle that those entries are only populated with the right value when we write to the page table.

static inline pte_t ptep_get(pte_t *ptep)

{
	unsigned long val = READ_ONCE(ptep->pte);
	/* 16K pages have 4 identical value 4K entries */
	pte_t pte = {val, val, val, val);
	return pte;
}
Quoted 6 lines
Quoted 1 line

Maybe something like that?

This should work as well. Indeed nobody cares about what's in the other three. They are only there to ensure that ptep++ increases the ptep pointer by 16 bytes. Only the HW require 4 identical values, that's taken care of in set_pte_at() and pte_update().

Right, but it seems less error-prone to have the in-memory representation match what we have in the page table (well that's in-memory too but you know what I mean).

Quoted 7 lines
Quoted 3 lines

So we should use the most efficient. Thinking once more, maybe what you propose is the most efficient as there is no need to load another register with value 0 in order to write it in the stack.

On 64-bit I'd say it makes zero difference, the only thing that's going to matter is the load from ptep->pte. I don't know whether that's true on the 8xx cores though.

On 8xx core, loading a register with value 0 will take one cycle unless there is some bubble left by another instruction (like a load from memory or a taken branch). But that's in the noise.

Christophe

#12 lore raw

Re: [PATCH 3/3] powerpc/8xx: Provide ptep_get() with 16k pages

In reply to Michael Ellerman

Le 18/06/2020 à 02:58, Michael Ellerman a écrit :

Quoted 34 lines
Quoted 33 lines · Peter Zijlstra
Quoted 16 lines · Michael Ellerman
Quoted 14 lines · Peter Zijlstra

arch/powerpc/include/asm/nohash/32/pgtable.h static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, · line 297

Quoted 9 lines · Christophe Leroy
arch/powerpc/include/asm/nohash/32/pgtable.h +9 -0
+#if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
+#define __HAVE_ARCH_PTEP_GET
+static inline pte_t ptep_get(pte_t *ptep)
+{
+	pte_t pte = {READ_ONCE(ptep->pte), 0, 0, 0};
+
+	return pte;
+}
+#endif

Would it make sense to have a comment with this magic? The casual reader might wonder WTH just happened when he stumbles on this :-)

Quoted 7 lines

I tried writing a helpful comment but it's too late for my brain to form sensible sentences.

Christophe can you send a follow-up with a comment explaining it? In particular the zero entries stand out, it's kind of subtle that those entries are only populated with the right value when we write to the page table.

static inline pte_t ptep_get(pte_t *ptep)

{
	unsigned long val = READ_ONCE(ptep->pte);
	/* 16K pages have 4 identical value 4K entries */
	pte_t pte = {val, val, val, val);
	return pte;
}
Quoted 5 lines
Quoted 1 line

Maybe something like that?

I think val wants to be pte_basic_t, but otherwise yeah I like that much better.

I sent a patch for that.

I'll also send one to fix mm/debug_vm_pgtable.c which also uses READ_ONCE() to access page table entries.

Christophe