Skip to contentSkip to conversation

powerpc/mm: Add _PAGE_SAO to _PAGE_CACHE_CTL mask

PATCH Applied Reza Arbab 5 participants 7 messages Jan 28, 2019 – Feb 8, 2019 PowerPC

lore
Share & tools
lore

Reza Arbab

author
#0 lore raw

PATCH 1/1 powerpc/mm: Add _PAGE_SAO to _PAGE_CACHE_CTL mask

In htab_convert_pte_flags(), _PAGE_CACHE_CTL is used to check for the _PAGE_SAO flag:

  else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
          rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);

But, it isn't defined to include that flag:

  #define _PAGE_CACHE_CTL (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)

This happens to work, but only because of the flag values:

  #define _PAGE_SAO               0x00010 /* Strong access order */
  #define _PAGE_NON_IDEMPOTENT    0x00020 /* non idempotent memory */
  #define _PAGE_TOLERANT          0x00030 /* tolerant memory, cache inhibited */

To prevent any issues if these particulars ever change, add _PAGE_SAO to the mask.

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -1
index 2e6ada2..1d97a28 100644
@@ -811,7 +811,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
 	return hash__set_pte_at(mm, addr, ptep, pte, percpu);
 }
 
-#define _PAGE_CACHE_CTL	(_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
+#define _PAGE_CACHE_CTL	(_PAGE_SAO | _PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
 
 #define pgprot_noncached pgprot_noncached
 static inline pgprot_t pgprot_noncached(pgprot_t prot)
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 10 lines · Reza Arbab

In htab_convert_pte_flags(), _PAGE_CACHE_CTL is used to check for the _PAGE_SAO flag:

  else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
          rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);

But, it isn't defined to include that flag:

  #define _PAGE_CACHE_CTL (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
Quoted 8 lines

This happens to work, but only because of the flag values:

  #define _PAGE_SAO               0x00010 /* Strong access order */
  #define _PAGE_NON_IDEMPOTENT    0x00020 /* non idempotent memory */
  #define _PAGE_TOLERANT          0x00030 /* tolerant memory, cache inhibited */

To prevent any issues if these particulars ever change, add _PAGE_SAO to the mask.

This does not feel right, doing

#define _PAGE_CACHE_CTL 0x30

would make more sense as SAO/NI/TOLERANT is enum so applying "|" to them just seems wrong.

Quoted 21 lines
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -1
index 2e6ada2..1d97a28 100644
@@ -811,7 +811,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
 	return hash__set_pte_at(mm, addr, ptep, pte, percpu);
 }
 
-#define _PAGE_CACHE_CTL	(_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
+#define _PAGE_CACHE_CTL	(_PAGE_SAO | _PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
 
 #define pgprot_noncached pgprot_noncached
 static inline pgprot_t pgprot_noncached(pgprot_t prot)
Signature · 1 line
Alexey
#2 lore raw
In reply to Reza Arbab
Quoted 10 lines · Reza Arbab

In htab_convert_pte_flags(), _PAGE_CACHE_CTL is used to check for the _PAGE_SAO flag:

   else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
           rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);

But, it isn't defined to include that flag:

   #define _PAGE_CACHE_CTL (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
Quoted 9 lines

This happens to work, but only because of the flag values:

   #define _PAGE_SAO               0x00010 /* Strong access order */
   #define _PAGE_NON_IDEMPOTENT    0x00020 /* non idempotent memory */
   #define _PAGE_TOLERANT          0x00030 /* tolerant memory, cache inhibited */

To prevent any issues if these particulars ever change, add _PAGE_SAO to the mask.

Not sure what the fix is about. We set the related hash pte flags via

	if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_TOLERANT)
		rflags |= HPTE_R_I;
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_NON_IDEMPOTENT)
		rflags |= (HPTE_R_I | HPTE_R_G);
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
		rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);
	else
		/*
		 * Add memory coherence if cache inhibited is not set
		 */
		rflags |= HPTE_R_M;
Quoted 20 lines
---
  arch/powerpc/include/asm/book3s/64/pgtable.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +1 -1
index 2e6ada2..1d97a28 100644
@@ -811,7 +811,7 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
  	return hash__set_pte_at(mm, addr, ptep, pte, percpu);
  }
 
-#define _PAGE_CACHE_CTL	(_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
+#define _PAGE_CACHE_CTL	(_PAGE_SAO | _PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
 
  #define pgprot_noncached pgprot_noncached
  static inline pgprot_t pgprot_noncached(pgprot_t prot)
author
#3 lore raw
Quoted 8 lines · Aneesh Kumar K.V

Not sure what the fix is about. We set the related hash pte flags via

	if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_TOLERANT)
		rflags |= HPTE_R_I;
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_NON_IDEMPOTENT)
		rflags |= (HPTE_R_I | HPTE_R_G);
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
		rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);

Again, nothing broken here, just a code readability thing. As Alexey (and Charlie) noted, given the above it is a little confusing to define _PAGE_CACHE_CTL this way:

#define _PAGE_CACHE_CTL (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)

I like Alexey's idea, maybe just use a literal?

#define _PAGE_CACHE_CTL 0x30

Signature · 1 line
Reza Arbab
#4 lore raw
Quoted 10 lines · Reza Arbab
Quoted 8 lines · Aneesh Kumar K.V

Not sure what the fix is about. We set the related hash pte flags via

	if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_TOLERANT)
		rflags |= HPTE_R_I;
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_NON_IDEMPOTENT)
		rflags |= (HPTE_R_I | HPTE_R_G);
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
		rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);
Quoted 5 lines

Again, nothing broken here, just a code readability thing. As Alexey (and Charlie) noted, given the above it is a little confusing to define _PAGE_CACHE_CTL this way:

  #define _PAGE_CACHE_CTL      (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)

Yeah that's confusing I agree.

It's not really a maintainability thing, because those bits are in the architecture, so they can't change.

Quoted 3 lines

I like Alexey's idea, maybe just use a literal?

  #define _PAGE_CACHE_CTL 0x30

I prefer your original patch. It serves as documentation on what values we expect to see in that field.

cheers

#5 lore raw
Quoted 23 lines · Michael Ellerman
Quoted 10 lines · Reza Arbab
Quoted 8 lines · Aneesh Kumar K.V

Not sure what the fix is about. We set the related hash pte flags via

	if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_TOLERANT)
		rflags |= HPTE_R_I;
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_NON_IDEMPOTENT)
		rflags |= (HPTE_R_I | HPTE_R_G);
	else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
		rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);
Quoted 5 lines

Again, nothing broken here, just a code readability thing. As Alexey (and Charlie) noted, given the above it is a little confusing to define _PAGE_CACHE_CTL this way:

  #define _PAGE_CACHE_CTL      (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)

Yeah that's confusing I agree.

It's not really a maintainability thing, because those bits are in the architecture, so they can't change.

Quoted 6 lines
Quoted 3 lines

I like Alexey's idea, maybe just use a literal?

  #define _PAGE_CACHE_CTL 0x30

I prefer your original patch. It serves as documentation on what values we expect to see in that field.

As documentation, it gives an idea that there can be both _PAGE_NON_IDEMPOTENT and _PAGE_TOLERANT set which is not true. Putting possible values in the comment next to "#define _PAGE_CACHE_CTL" will document it properly imho.

Signature · 1 line
Alexey
#6 lore raw
In reply to Reza Arbab
Quoted 16 lines · Reza Arbab

In htab_convert_pte_flags(), _PAGE_CACHE_CTL is used to check for the _PAGE_SAO flag:

  else if ((pteflags & _PAGE_CACHE_CTL) == _PAGE_SAO)
          rflags |= (HPTE_R_W | HPTE_R_I | HPTE_R_M);

But, it isn't defined to include that flag:

  #define _PAGE_CACHE_CTL (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)

This happens to work, but only because of the flag values:

  #define _PAGE_SAO               0x00010 /* Strong access order */
  #define _PAGE_NON_IDEMPOTENT    0x00020 /* non idempotent memory */
  #define _PAGE_TOLERANT          0x00030 /* tolerant memory, cache inhibited */
Quoted 5 lines

To prevent any issues if these particulars ever change, add _PAGE_SAO to the mask.

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/865a9432d16fe2f40a1a52005fd30778

cheers