Skip to content

Commit 8d1cf34

Browse files
committed
powerpc/mm: Tweak PTE bit combination definitions
This patch tweaks the way some PTE bit combinations are defined, in such a way that the 32 and 64-bit variant become almost identical and that will make it easier to bring in a new common pte-* file for the new variant of the Book3-E support. The combination of bits defining access to kernel pages are now clearly separated from the combination used by userspace and the core VM. The resulting generated code should remain identical unless I made a mistake. Note: While at it, I removed a non-sensical statement related to CONFIG_KGDB in ppc_mmu_32.c which could cause kernel mappings to be user accessible when that option is enabled. Probably something that bitrot. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 2a7d55f commit 8d1cf34

12 files changed

Lines changed: 89 additions & 76 deletions

File tree

‎arch/powerpc/include/asm/fixmap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern void __set_fixmap (enum fixed_addresses idx,
6161
* Some hardware wants to get fixmapped without caching.
6262
*/
6363
#define set_fixmap_nocache(idx, phys) \
64-
__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)
64+
__set_fixmap(idx, phys, PAGE_KERNEL_NCG)
6565

6666
#define clear_fixmap(idx) \
6767
__set_fixmap(idx, 0, __pgprot(0))

‎arch/powerpc/include/asm/pgtable-ppc32.h‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ extern int icache_44x_need_flush;
144144
#define PMD_PAGE_SIZE(pmd) bad_call_to_PMD_PAGE_SIZE()
145145
#endif
146146

147+
#ifndef _PAGE_KERNEL_RO
148+
#define _PAGE_KERNEL_RO 0
149+
#endif
150+
#ifndef _PAGE_KERNEL_RW
151+
#define _PAGE_KERNEL_RW (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE)
152+
#endif
153+
147154
#define _PAGE_HPTEFLAGS _PAGE_HASHPTE
148155

149156
/* Location of the PFN in the PTE. Most platforms use the same as _PAGE_SHIFT
@@ -186,30 +193,25 @@ extern int icache_44x_need_flush;
186193
#else
187194
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED)
188195
#endif
189-
#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_NO_CACHE)
190-
191-
#define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE)
192-
#define _PAGE_KERNEL (_PAGE_BASE | _PAGE_SHARED | _PAGE_WRENABLE)
193-
#define _PAGE_KERNEL_NC (_PAGE_BASE_NC | _PAGE_SHARED | _PAGE_WRENABLE)
194-
195-
#ifdef CONFIG_PPC_STD_MMU
196-
/* On standard PPC MMU, no user access implies kernel read/write access,
197-
* so to write-protect kernel memory we must turn on user access */
198-
#define _PAGE_KERNEL_RO (_PAGE_BASE | _PAGE_SHARED | _PAGE_USER)
199-
#else
200-
#define _PAGE_KERNEL_RO (_PAGE_BASE | _PAGE_SHARED)
201-
#endif
202-
203-
#define _PAGE_IO (_PAGE_KERNEL_NC | _PAGE_GUARDED)
204-
#define _PAGE_RAM (_PAGE_KERNEL | _PAGE_HWEXEC)
196+
#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED)
197+
198+
/* Permission masks used for kernel mappings */
199+
#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
200+
#define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
201+
_PAGE_NO_CACHE)
202+
#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
203+
_PAGE_NO_CACHE | _PAGE_GUARDED)
204+
#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW | _PAGE_EXEC)
205+
#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
206+
#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO | _PAGE_EXEC)
205207

206208
#if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\
207209
defined(CONFIG_KPROBES)
208210
/* We want the debuggers to be able to set breakpoints anywhere, so
209211
* don't write protect the kernel text */
210-
#define _PAGE_RAM_TEXT _PAGE_RAM
212+
#define PAGE_KERNEL_TEXT PAGE_KERNEL_X
211213
#else
212-
#define _PAGE_RAM_TEXT (_PAGE_KERNEL_RO | _PAGE_HWEXEC)
214+
#define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX
213215
#endif
214216

215217
#define PAGE_NONE __pgprot(_PAGE_BASE)
@@ -220,9 +222,6 @@ extern int icache_44x_need_flush;
220222
#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
221223
#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
222224

223-
#define PAGE_KERNEL __pgprot(_PAGE_RAM)
224-
#define PAGE_KERNEL_NOCACHE __pgprot(_PAGE_IO)
225-
226225
/*
227226
* The PowerPC can only do execute protection on a segment (256MB) basis,
228227
* not on a page basis. So we consider execute permission the same as read.

‎arch/powerpc/include/asm/pgtable-ppc64.h‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@
8181
*/
8282
#include <asm/pte-hash64.h>
8383

84-
/* To make some generic powerpc code happy */
85-
#ifndef _PAGE_HWEXEC
86-
#define _PAGE_HWEXEC 0
87-
#endif
88-
8984
/* Some other useful definitions */
9085
#define PTE_RPN_MAX (1UL << (64 - PTE_RPN_SHIFT))
9186
#define PTE_RPN_MASK (~((1UL<<PTE_RPN_SHIFT)-1))
@@ -96,28 +91,44 @@
9691
#define _PAGE_CHG_MASK (PTE_RPN_MASK | _PAGE_HPTEFLAGS | _PAGE_DIRTY | \
9792
_PAGE_ACCESSED | _PAGE_SPECIAL)
9893

94+
#define _PAGE_BASE_NC (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
95+
#define _PAGE_BASE (_PAGE_BASE_NC | _PAGE_COHERENT)
9996

10097

101-
/* __pgprot defined in arch/powerpc/include/asm/page.h */
102-
#define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
103-
104-
#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER)
105-
#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_RW | _PAGE_USER | _PAGE_EXEC)
98+
/* Permission masks used to generate the __P and __S table,
99+
*
100+
* Note:__pgprot is defined in arch/powerpc/include/asm/page.h
101+
*/
102+
#define PAGE_NONE __pgprot(_PAGE_BASE)
103+
#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
104+
#define PAGE_SHARED_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
106105
#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER)
107106
#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
108107
#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER)
109108
#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
110-
#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_WRENABLE)
111-
#define PAGE_KERNEL_CI __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \
112-
_PAGE_WRENABLE | _PAGE_NO_CACHE | _PAGE_GUARDED)
113-
#define PAGE_KERNEL_EXEC __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_EXEC)
114109

115-
#define PAGE_AGP __pgprot(_PAGE_BASE | _PAGE_WRENABLE | _PAGE_NO_CACHE)
116-
#define HAVE_PAGE_AGP
110+
/* Permission masks used for kernel mappings */
111+
#define PAGE_KERNEL __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW)
112+
#define PAGE_KERNEL_NC __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
113+
_PAGE_NO_CACHE)
114+
#define PAGE_KERNEL_NCG __pgprot(_PAGE_BASE_NC | _PAGE_KERNEL_RW | \
115+
_PAGE_NO_CACHE | _PAGE_GUARDED)
116+
#define PAGE_KERNEL_X __pgprot(_PAGE_BASE | _PAGE_KERNEL_RW | _PAGE_EXEC)
117+
#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO)
118+
#define PAGE_KERNEL_ROX __pgprot(_PAGE_BASE | _PAGE_KERNEL_RO | _PAGE_EXEC)
119+
120+
/* Protection bits for use by pte_pgprot() */
121+
#define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | \
122+
_PAGE_NO_CACHE | _PAGE_WRITETHRU | \
123+
_PAGE_4K_PFN | _PAGE_USER | _PAGE_RW | \
124+
_PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_EXEC)
125+
117126

118127
/* We always have _PAGE_SPECIAL on 64 bit */
119128
#define __HAVE_ARCH_PTE_SPECIAL
120129

130+
/* Make modules code happy. We don't set RO yet */
131+
#define PAGE_KERNEL_EXEC PAGE_KERNEL_X
121132

122133
/*
123134
* POWER4 and newer have per page execute protection, older chips can only
@@ -395,7 +406,8 @@ static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
395406
static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
396407
{
397408
unsigned long bits = pte_val(entry) &
398-
(_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
409+
(_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW |
410+
_PAGE_EXEC | _PAGE_HWEXEC);
399411
unsigned long old, tmp;
400412

401413
__asm__ __volatile__(

‎arch/powerpc/include/asm/pgtable.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ static inline void assert_pte_locked(struct mm_struct *mm, unsigned long addr)
2525
# include <asm/pgtable-ppc32.h>
2626
#endif
2727

28+
/* Special mapping for AGP */
29+
#define PAGE_AGP (PAGE_KERNEL_NC)
30+
#define HAVE_PAGE_AGP
31+
2832
#ifndef __ASSEMBLY__
2933

3034
/* Insert a PTE, top-level function is out of line. It uses an inline

‎arch/powerpc/include/asm/pte-8xx.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
/* Until my rework is finished, 8xx still needs atomic PTE updates */
6060
#define PTE_ATOMIC_UPDATES 1
6161

62+
/* We need to add _PAGE_SHARED to kernel pages */
63+
#define _PAGE_KERNEL_RO (_PAGE_SHARED)
64+
#define _PAGE_KERNEL_RW (_PAGE_DIRTY | _PAGE_RW | _PAGE_HWWRITE)
6265

6366
#endif /* __KERNEL__ */
6467
#endif /* _ASM_POWERPC_PTE_8xx_H */

‎arch/powerpc/include/asm/pte-hash32.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@
4444
/* Hash table based platforms need atomic updates of the linux PTE */
4545
#define PTE_ATOMIC_UPDATES 1
4646

47-
4847
#endif /* __KERNEL__ */
4948
#endif /* _ASM_POWERPC_PTE_HASH32_H */

‎arch/powerpc/include/asm/pte-hash64-4k.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
#define _PAGE_F_GIX _PAGE_GROUP_IX
99
#define _PAGE_SPECIAL 0x10000 /* software: special page */
1010

11-
/* There is no 4K PFN hack on 4K pages */
12-
#define _PAGE_4K_PFN 0
13-
1411
/* PTE flags to conserve for HPTE identification */
1512
#define _PAGE_HPTEFLAGS (_PAGE_BUSY | _PAGE_HASHPTE | \
1613
_PAGE_SECONDARY | _PAGE_GROUP_IX)

‎arch/powerpc/include/asm/pte-hash64.h‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,41 @@
66
* Common bits between 4K and 64K pages in a linux-style PTE.
77
* These match the bits in the (hardware-defined) PowerPC PTE as closely
88
* as possible. Additional bits may be defined in pgtable-hash64-*.h
9+
*
10+
* Note: We only support user read/write permissions. Supervisor always
11+
* have full read/write to pages above PAGE_OFFSET (pages below that
12+
* always use the user access permissions).
13+
*
14+
* We could create separate kernel read-only if we used the 3 PP bits
15+
* combinations that newer processors provide but we currently don't.
916
*/
10-
#define _PAGE_PRESENT 0x0001 /* software: pte contains a translation */
11-
#define _PAGE_USER 0x0002 /* matches one of the PP bits */
12-
#define _PAGE_FILE 0x0002 /* (!present only) software: pte holds file offset */
13-
#define _PAGE_EXEC 0x0004 /* No execute on POWER4 and newer (we invert) */
14-
#define _PAGE_GUARDED 0x0008
15-
#define _PAGE_COHERENT 0x0010 /* M: enforce memory coherence (SMP systems) */
16-
#define _PAGE_NO_CACHE 0x0020 /* I: cache inhibit */
17-
#define _PAGE_WRITETHRU 0x0040 /* W: cache write-through */
18-
#define _PAGE_DIRTY 0x0080 /* C: page changed */
19-
#define _PAGE_ACCESSED 0x0100 /* R: page referenced */
20-
#define _PAGE_RW 0x0200 /* software: user write access allowed */
21-
#define _PAGE_BUSY 0x0800 /* software: PTE & hash are busy */
17+
#define _PAGE_PRESENT 0x0001 /* software: pte contains a translation */
18+
#define _PAGE_USER 0x0002 /* matches one of the PP bits */
19+
#define _PAGE_FILE 0x0002 /* (!present only) software: pte holds file offset */
20+
#define _PAGE_EXEC 0x0004 /* No execute on POWER4 and newer (we invert) */
21+
#define _PAGE_GUARDED 0x0008
22+
#define _PAGE_COHERENT 0x0010 /* M: enforce memory coherence (SMP systems) */
23+
#define _PAGE_NO_CACHE 0x0020 /* I: cache inhibit */
24+
#define _PAGE_WRITETHRU 0x0040 /* W: cache write-through */
25+
#define _PAGE_DIRTY 0x0080 /* C: page changed */
26+
#define _PAGE_ACCESSED 0x0100 /* R: page referenced */
27+
#define _PAGE_RW 0x0200 /* software: user write access allowed */
28+
#define _PAGE_BUSY 0x0800 /* software: PTE & hash are busy */
29+
30+
/* No separate kernel read-only */
31+
#define _PAGE_KERNEL_RW (_PAGE_RW | _PAGE_DIRTY) /* user access blocked by key */
32+
#define _PAGE_KERNEL_RO _PAGE_KERNEL_RW
2233

2334
/* Strong Access Ordering */
24-
#define _PAGE_SAO (_PAGE_WRITETHRU | _PAGE_NO_CACHE | _PAGE_COHERENT)
35+
#define _PAGE_SAO (_PAGE_WRITETHRU | _PAGE_NO_CACHE | _PAGE_COHERENT)
2536

26-
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_COHERENT)
27-
28-
#define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY)
37+
/* No page size encoding in the linux PTE */
38+
#define _PAGE_PSIZE 0
2939

3040
/* PTEIDX nibble */
3141
#define _PTEIDX_SECONDARY 0x8
3242
#define _PTEIDX_GROUP_IX 0x7
3343

34-
#define PAGE_PROT_BITS (_PAGE_GUARDED | _PAGE_COHERENT | \
35-
_PAGE_NO_CACHE | _PAGE_WRITETHRU | \
36-
_PAGE_4K_PFN | _PAGE_RW | _PAGE_USER | \
37-
_PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_EXEC)
38-
3944

4045
#ifdef CONFIG_PPC_64K_PAGES
4146
#include <asm/pte-hash64-64k.h>

‎arch/powerpc/mm/fsl_booke_mmu.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ unsigned long __init mmu_mapin_ram(void)
162162
phys_addr_t phys = memstart_addr;
163163

164164
while (cam[tlbcam_index] && tlbcam_index < ARRAY_SIZE(cam)) {
165-
settlbcam(tlbcam_index, virt, phys, cam[tlbcam_index], _PAGE_KERNEL, 0);
165+
settlbcam(tlbcam_index, virt, phys, cam[tlbcam_index], PAGE_KERNEL_X, 0);
166166
virt += cam[tlbcam_index];
167167
phys += cam[tlbcam_index];
168168
tlbcam_index++;

‎arch/powerpc/mm/pgtable_32.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ __ioremap_caller(phys_addr_t addr, unsigned long size, unsigned long flags,
164164

165165
/* Make sure we have the base flags */
166166
if ((flags & _PAGE_PRESENT) == 0)
167-
flags |= _PAGE_KERNEL;
167+
flags |= PAGE_KERNEL;
168168

169169
/* Non-cacheable page cannot be coherent */
170170
if (flags & _PAGE_NO_CACHE)
@@ -296,7 +296,7 @@ void __init mapin_ram(void)
296296
p = memstart_addr + s;
297297
for (; s < total_lowmem; s += PAGE_SIZE) {
298298
ktext = ((char *) v >= _stext && (char *) v < etext);
299-
f = ktext ?_PAGE_RAM_TEXT : _PAGE_RAM;
299+
f = ktext ? PAGE_KERNEL_TEXT : PAGE_KERNEL;
300300
map_page(v, p, f);
301301
#ifdef CONFIG_PPC_STD_MMU_32
302302
if (ktext)

0 commit comments

Comments
 (0)