Skip to contentSkip to conversation

powerpc/mm: Check for _PAGE_PTE in *_devmap()

PATCH Applied Oliver O'Halloran 5 participants 5 messages Jul 27, 2017 – Jul 28, 2017 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc/mm: Check for _PAGE_PTE in *_devmap()

The ISA radix translation tree contains two different types of entry, directories and leaves. The formats of the two entries are different with the directory entries containing no spare bits for use by software. As a result we need to ensure that the *_devmap() family of functions check fail for everything except leaf (PTE) entries.

---
"i'll just tweak the mbox before i sent it, what's the worst that can happen" *completely breaks KVM*
"..."

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -1
index d1da415..6bc6248 100644
@@ -610,7 +610,9 @@ static inline pte_t pte_mkdevmap(pte_t pte)
 
 static inline int pte_devmap(pte_t pte)
 {
-	return !!(pte_raw(pte) & cpu_to_be64(_PAGE_DEVMAP));
+	uint64_t mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE);
+
+	return (pte_raw(pte) & mask) == mask;
 }
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
Signature · 1 line
2.7.4
Tested-by on v2 1/1
#1 lore raw
Quoted 21 lines · On 27/07/2017 17:35, [email protected] (Oliver O'Halloran) wrote:

The ISA radix translation tree contains two different types of entry, directories and leaves. The formats of the two entries are different with the directory entries containing no spare bits for use by software. As a result we need to ensure that the *_devmap() family of functions check fail for everything except leaf (PTE) entries.

---
"i'll just tweak the mbox before i sent it, what's the worst that can happen" *completely breaks KVM*
"..."

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +0 -0
index d1da415..6bc6248 100644

arch/powerpc/include/asm/book3s/64/pgtable.h static inline pte_t pte_mkdevmap(pte_t pte) · line 618

Quoted 10 lines
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -1
@@ -610,7 +610,9 @@ static inline pte_t pte_mkdevmap(pte_t pte)
 
 static inline int pte_devmap(pte_t pte)
 {
-	return !!(pte_raw(pte) & cpu_to_be64(_PAGE_DEVMAP));
+	uint64_t mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE);
+
+	return (pte_raw(pte) & mask) == mask;
 }
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
Tested-by on v2 1/1
#2 lore raw
In reply to Oliver O'Halloran
Quoted 33 lines · Oliver O'Halloran

The ISA radix translation tree contains two different types of entry, directories and leaves. The formats of the two entries are different with the directory entries containing no spare bits for use by software. As a result we need to ensure that the *_devmap() family of functions check fail for everything except leaf (PTE) entries.

---
"i'll just tweak the mbox before i sent it, what's the worst that can happen" *completely breaks KVM*
"..."

---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +3 -1
index d1da415..6bc6248 100644
@@ -610,7 +610,9 @@ static inline pte_t pte_mkdevmap(pte_t pte)
 
 static inline int pte_devmap(pte_t pte)
 {
-	return !!(pte_raw(pte) & cpu_to_be64(_PAGE_DEVMAP));
+	uint64_t mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE);
+
+	return (pte_raw(pte) & mask) == mask;
 }
 
 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
Signature · 1 line
2.7.4

Michael should thank you because I was about to send another insane suggestion and ask him if that makes sense. :-D

Reviewed-by on v2 1/1
#3 lore raw
In reply to Oliver O'Halloran
Quoted 1 line · Oliver O'Halloran

The ISA radix translation tree contains two different types of entry,

s/entry/entries

Quoted 4 lines
Quoted 1 line

directories and leaves. The formats of the two entries are

different
with the directory entries containing no spare bits for use by software.

Rather than saying the directory entries contain no spare bits, would it be better to say something like: the devmap property only relates to pte (leaf) entries and so we shouldn't perform the check on/should always return false for page directory entries?

Quoted 26 lines

As a result we need to ensure that the *_devmap() family of functions check fail for everything except leaf (PTE) entries.

---
"i'll just tweak the mbox before i sent it, what's the worst that can happen"
*completely breaks KVM*
"..."
---
 arch/powerpc/include/asm/book3s/64/pgtable.h | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/book3s/64/pgtable.h +0 -0
index d1da415..6bc6248 100644
@@ -610,7 +610,9 @@ static inline pte_t pte_mkdevmap(pte_t pte)


 static inline int pte_devmap(pte_t pte)
 {

arch/powerpc/include/asm/book3s/64/pgtable.h +3 -1
-	return !!(pte_raw(pte) & cpu_to_be64(_PAGE_DEVMAP));
+	uint64_t mask = cpu_to_be64(_PAGE_DEVMAP | _PAGE_PTE);
+
+	return (pte_raw(pte) & mask) == mask;
Quoted 3 lines

 }

 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)

#4 lore raw
In reply to Oliver O'Halloran
Quoted 10 lines · Oliver O'Halloran

The ISA radix translation tree contains two different types of entry, directories and leaves. The formats of the two entries are different with the directory entries containing no spare bits for use by software. As a result we need to ensure that the *_devmap() family of functions check fail for everything except leaf (PTE) entries.

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/c9c98bc5cc2ab4e0d5c9ad58286fa7

cheers