Skip to contentSkip to conversation

powerpc: fix usage of _PAGE_RO in hugepage

PATCH Applied Christophe Leroy 2 participants 3 messages Sep 19, 2016 – Sep 25, 2016 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc: fix usage of _PAGE_RO in hugepage

On some CPUs like the 8xx, _PAGE_RW hence _PAGE_WRITE is defined as 0 and _PAGE_RO has to be set when a page is not writable

_PAGE_RO is defined by default in pte-common.h, however BOOK3S/64 doesn't include that file so _PAGE_RO has to be defined explicitly in book3s/64/pgtable.h

Fixes a7b9f671f2d14 ("powerpc32: adds handling of _PAGE_RO")

---
v1: This patch was initially part of the v1 serie of patchs for providing
hugepage support to the 8xx. As suggested by Aneesh, that serie has been splited to focus only on hugepage implementation for 8xx. This patch is a fix and is independant of 8xx hugepage implementation, allthough it is required to have hugepage support working properly on the 8xx.

v2: Added a comment in the code as suggested by Aneesh.

 arch/powerpc/include/asm/book3s/64/pgtable.h | 2 ++
 arch/powerpc/mm/hugetlbpage.c                | 7 +++++++
 2 files changed, 9 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +2 -0
index 8ec8be9..9fd77f8 100644
@@ -6,6 +6,8 @@
  */
 #define _PAGE_BIT_SWAP_TYPE	0
 
+#define _PAGE_RO		0
+
 #define _PAGE_EXEC		0x00001 /* execute permission */
 #define _PAGE_WRITE		0x00002 /* write access allowed */
 #define _PAGE_READ		0x00004	/* read access allowed */
arch/powerpc/mm/hugetlbpage.c +7 -0
index 7372ee1..a5d3ecd 100644
@@ -1019,8 +1019,15 @@ int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
 
 	pte = READ_ONCE(*ptep);
 	mask = _PAGE_PRESENT | _PAGE_READ;
+
+	/*
+	 * On some CPUs like the 8xx, _PAGE_RW hence _PAGE_WRITE is defined
+	 * as 0 and _PAGE_RO has to be set when a page is not writable
+	 */
 	if (write)
 		mask |= _PAGE_WRITE;
+	else
+		mask |= _PAGE_RO;
 
 	if ((pte_val(pte) & mask) != mask)
 		return 0;
Signature · 1 line
2.1.0
author Reviewed-by Aneesh Kumar K.V on v2 1/1
#1 lore raw
Quoted 9 lines · Christophe Leroy

On some CPUs like the 8xx, _PAGE_RW hence _PAGE_WRITE is defined as 0 and _PAGE_RO has to be set when a page is not writable

_PAGE_RO is defined by default in pte-common.h, however BOOK3S/64 doesn't include that file so _PAGE_RO has to be defined explicitly in book3s/64/pgtable.h

Fixes a7b9f671f2d14 ("powerpc32: adds handling of _PAGE_RO")

Forgot to add from V1:

Christophe

Quoted 48 lines

---
v1: This patch was initially part of the v1 serie of patchs for providing
hugepage support to the 8xx. As suggested by Aneesh, that serie has been splited to focus only on hugepage implementation for 8xx. This patch is a fix and is independant of 8xx hugepage implementation, allthough it is required to have hugepage support working properly on the 8xx.

v2: Added a comment in the code as suggested by Aneesh.

 arch/powerpc/include/asm/book3s/64/pgtable.h | 2 ++
 arch/powerpc/mm/hugetlbpage.c                | 7 +++++++
 2 files changed, 9 insertions(+)
arch/powerpc/include/asm/book3s/64/pgtable.h +2 -0
index 8ec8be9..9fd77f8 100644
@@ -6,6 +6,8 @@
  */
 #define _PAGE_BIT_SWAP_TYPE	0
 
+#define _PAGE_RO		0
+
 #define _PAGE_EXEC		0x00001 /* execute permission */
 #define _PAGE_WRITE		0x00002 /* write access allowed */
 #define _PAGE_READ		0x00004	/* read access allowed */
arch/powerpc/mm/hugetlbpage.c +7 -0
index 7372ee1..a5d3ecd 100644
@@ -1019,8 +1019,15 @@ int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long addr,
 
 	pte = READ_ONCE(*ptep);
 	mask = _PAGE_PRESENT | _PAGE_READ;
+
+	/*
+	 * On some CPUs like the 8xx, _PAGE_RW hence _PAGE_WRITE is defined
+	 * as 0 and _PAGE_RO has to be set when a page is not writable
+	 */
 	if (write)
 		mask |= _PAGE_WRITE;
+	else
+		mask |= _PAGE_RO;
 
 	if ((pte_val(pte) & mask) != mask)
 		return 0;
#2 lore raw
In reply to Christophe Leroy
Quoted 10 lines · Christophe Leroy

On some CPUs like the 8xx, _PAGE_RW hence _PAGE_WRITE is defined as 0 and _PAGE_RO has to be set when a page is not writable

_PAGE_RO is defined by default in pte-common.h, however BOOK3S/64 doesn't include that file so _PAGE_RO has to be defined explicitly in book3s/64/pgtable.h

Fixes a7b9f671f2d14 ("powerpc32: adds handling of _PAGE_RO")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/6b8cb66a6a7cc182b47da6a0a1

cheers