Skip to content

Commit 26973fa

Browse files
chleroympe
authored andcommitted
powerpc/mm: use pte helpers in generic code
Get rid of platform specific _PAGE_XXXX in powerpc common code and use helpers instead. mm/dump_linuxpagetables.c will be handled separately Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 34eb138 commit 26973fa

File tree

7 files changed

+41
-45
lines changed

7 files changed

+41
-45
lines changed

arch/powerpc/include/asm/book3s/32/pgtable.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,14 @@ static inline bool pte_ci(pte_t pte)
331331
#define pte_access_permitted pte_access_permitted
332332
static inline bool pte_access_permitted(pte_t pte, bool write)
333333
{
334-
unsigned long pteval = pte_val(pte);
335334
/*
336335
* A read-only access is controlled by _PAGE_USER bit.
337336
* We have _PAGE_READ set for WRITE and EXECUTE
338337
*/
339-
unsigned long need_pte_bits = _PAGE_PRESENT | _PAGE_USER;
340-
341-
if (write)
342-
need_pte_bits |= _PAGE_WRITE;
338+
if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte))
339+
return false;
343340

344-
if ((pteval & need_pte_bits) != need_pte_bits)
341+
if (write && !pte_write(pte))
345342
return false;
346343

347344
return true;

arch/powerpc/include/asm/nohash/32/pgtable.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
277277
static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
278278
pte_t *ptep)
279279
{
280-
pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), _PAGE_RO);
280+
unsigned long clr = ~pte_val(pte_wrprotect(__pte(~0)));
281+
unsigned long set = pte_val(pte_wrprotect(__pte(0)));
282+
283+
pte_update(ptep, clr, set);
281284
}
282285
static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
283286
unsigned long addr, pte_t *ptep)
@@ -291,9 +294,10 @@ static inline void __ptep_set_access_flags(struct vm_area_struct *vma,
291294
unsigned long address,
292295
int psize)
293296
{
294-
unsigned long set = pte_val(entry) &
295-
(_PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_RW | _PAGE_EXEC);
296-
unsigned long clr = ~pte_val(entry) & (_PAGE_RO | _PAGE_NA);
297+
pte_t pte_set = pte_mkyoung(pte_mkdirty(pte_mkwrite(pte_mkexec(__pte(0)))));
298+
pte_t pte_clr = pte_mkyoung(pte_mkdirty(pte_mkwrite(pte_mkexec(__pte(~0)))));
299+
unsigned long set = pte_val(entry) & pte_val(pte_set);
300+
unsigned long clr = ~pte_val(entry) & ~pte_val(pte_clr);
297301

298302
pte_update(ptep, clr, set);
299303

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ static inline pgprot_t pte_pgprot(pte_t pte) { return __pgprot(pte_val(pte) & PA
3232
*/
3333
static inline int pte_protnone(pte_t pte)
3434
{
35-
return (pte_val(pte) &
36-
(_PAGE_PRESENT | _PAGE_USER)) == _PAGE_PRESENT;
35+
return pte_present(pte) && !pte_user(pte);
3736
}
3837

3938
static inline int pmd_protnone(pmd_t pmd)

arch/powerpc/mm/pgtable.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,13 @@ static inline int is_exec_fault(void)
4444
static inline int pte_looks_normal(pte_t pte)
4545
{
4646

47-
#if defined(CONFIG_PPC_BOOK3S_64)
48-
if ((pte_val(pte) & (_PAGE_PRESENT | _PAGE_SPECIAL)) == _PAGE_PRESENT) {
47+
if (pte_present(pte) && !pte_special(pte)) {
4948
if (pte_ci(pte))
5049
return 0;
5150
if (pte_user(pte))
5251
return 1;
5352
}
5453
return 0;
55-
#else
56-
return (pte_val(pte) &
57-
(_PAGE_PRESENT | _PAGE_SPECIAL | _PAGE_NO_CACHE | _PAGE_USER |
58-
_PAGE_PRIVILEGED)) ==
59-
(_PAGE_PRESENT | _PAGE_USER);
60-
#endif
6154
}
6255

6356
static struct page *maybe_pte_to_page(pte_t pte)
@@ -117,7 +110,7 @@ static pte_t set_pte_filter(pte_t pte)
117110
struct page *pg;
118111

119112
/* No exec permission in the first place, move on */
120-
if (!(pte_val(pte) & _PAGE_EXEC) || !pte_looks_normal(pte))
113+
if (!pte_exec(pte) || !pte_looks_normal(pte))
121114
return pte;
122115

123116
/* If you set _PAGE_EXEC on weird pages you're on your own */
@@ -137,7 +130,7 @@ static pte_t set_pte_filter(pte_t pte)
137130
}
138131

139132
/* Else, we filter out _PAGE_EXEC */
140-
return __pte(pte_val(pte) & ~_PAGE_EXEC);
133+
return pte_exprotect(pte);
141134
}
142135

143136
static pte_t set_access_flags_filter(pte_t pte, struct vm_area_struct *vma,
@@ -150,7 +143,7 @@ static pte_t set_access_flags_filter(pte_t pte, struct vm_area_struct *vma,
150143
* if necessary. Also if _PAGE_EXEC is already set, same deal,
151144
* we just bail out
152145
*/
153-
if (dirty || (pte_val(pte) & _PAGE_EXEC) || !is_exec_fault())
146+
if (dirty || pte_exec(pte) || !is_exec_fault())
154147
return pte;
155148

156149
#ifdef CONFIG_DEBUG_VM
@@ -176,7 +169,7 @@ static pte_t set_access_flags_filter(pte_t pte, struct vm_area_struct *vma,
176169
set_bit(PG_arch_1, &pg->flags);
177170

178171
bail:
179-
return __pte(pte_val(pte) | _PAGE_EXEC);
172+
return pte_mkexec(pte);
180173
}
181174

182175
#endif /* CONFIG_PPC_BOOK3S */
@@ -191,10 +184,10 @@ void set_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
191184
* Make sure hardware valid bit is not set. We don't do
192185
* tlb flush for this update.
193186
*/
194-
VM_WARN_ON(pte_val(*ptep) & _PAGE_PRESENT);
187+
VM_WARN_ON(pte_hw_valid(*ptep));
195188

196189
/* Add the pte bit when trying to set a pte */
197-
pte = __pte(pte_val(pte) | _PAGE_PTE);
190+
pte = pte_mkpte(pte);
198191

199192
/* Note: mm->context.id might not yet have been assigned as
200193
* this context might not have been activated yet when this

arch/powerpc/mm/pgtable_32.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,17 @@ EXPORT_SYMBOL(ioremap_coherent);
112112
void __iomem *
113113
ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long flags)
114114
{
115+
pte_t pte = __pte(flags);
116+
115117
/* writeable implies dirty for kernel addresses */
116-
if ((flags & (_PAGE_RW | _PAGE_RO)) != _PAGE_RO)
117-
flags |= _PAGE_DIRTY | _PAGE_HWWRITE;
118+
if (pte_write(pte))
119+
pte = pte_mkdirty(pte);
118120

119121
/* we don't want to let _PAGE_USER and _PAGE_EXEC leak out */
120-
flags &= ~(_PAGE_USER | _PAGE_EXEC);
121-
flags |= _PAGE_PRIVILEGED;
122+
pte = pte_exprotect(pte);
123+
pte = pte_mkprivileged(pte);
122124

123-
return __ioremap_caller(addr, size, __pgprot(flags), __builtin_return_address(0));
125+
return __ioremap_caller(addr, size, pte_pgprot(pte), __builtin_return_address(0));
124126
}
125127
EXPORT_SYMBOL(ioremap_prot);
126128

@@ -235,8 +237,7 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot)
235237
/* The PTE should never be already set nor present in the
236238
* hash table
237239
*/
238-
BUG_ON((pte_val(*pg) & (_PAGE_PRESENT | _PAGE_HASHPTE)) &&
239-
pgprot_val(prot));
240+
BUG_ON((pte_present(*pg) | pte_hashpte(*pg)) && pgprot_val(prot));
240241
set_pte_at(&init_mm, va, pg, pfn_pte(pa >> PAGE_SHIFT, prot));
241242
}
242243
smp_wmb();

arch/powerpc/mm/pgtable_64.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,23 +230,23 @@ void __iomem *ioremap_coherent(phys_addr_t addr, unsigned long size)
230230
void __iomem * ioremap_prot(phys_addr_t addr, unsigned long size,
231231
unsigned long flags)
232232
{
233+
pte_t pte = __pte(flags);
233234
void *caller = __builtin_return_address(0);
234235

235236
/* writeable implies dirty for kernel addresses */
236-
if (flags & _PAGE_WRITE)
237-
flags |= _PAGE_DIRTY;
237+
if (pte_write(pte))
238+
pte = pte_mkdirty(pte);
238239

239240
/* we don't want to let _PAGE_EXEC leak out */
240-
flags &= ~_PAGE_EXEC;
241+
pte = pte_exprotect(pte);
241242
/*
242243
* Force kernel mapping.
243244
*/
244-
flags &= ~_PAGE_USER;
245-
flags |= _PAGE_PRIVILEGED;
245+
pte = pte_mkprivileged(pte);
246246

247247
if (ppc_md.ioremap)
248-
return ppc_md.ioremap(addr, size, __pgprot(flags), caller);
249-
return __ioremap_caller(addr, size, __pgprot(flags), caller);
248+
return ppc_md.ioremap(addr, size, pte_pgprot(pte), caller);
249+
return __ioremap_caller(addr, size, pte_pgprot(pte), caller);
250250
}
251251

252252

arch/powerpc/xmon/xmon.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,15 +2996,17 @@ static void show_task(struct task_struct *tsk)
29962996
#ifdef CONFIG_PPC_BOOK3S_64
29972997
void format_pte(void *ptep, unsigned long pte)
29982998
{
2999+
pte_t entry = __pte(pte);
3000+
29993001
printf("ptep @ 0x%016lx = 0x%016lx\n", (unsigned long)ptep, pte);
30003002
printf("Maps physical address = 0x%016lx\n", pte & PTE_RPN_MASK);
30013003

30023004
printf("Flags = %s%s%s%s%s\n",
3003-
(pte & _PAGE_ACCESSED) ? "Accessed " : "",
3004-
(pte & _PAGE_DIRTY) ? "Dirty " : "",
3005-
(pte & _PAGE_READ) ? "Read " : "",
3006-
(pte & _PAGE_WRITE) ? "Write " : "",
3007-
(pte & _PAGE_EXEC) ? "Exec " : "");
3005+
pte_young(entry) ? "Accessed " : "",
3006+
pte_dirty(entry) ? "Dirty " : "",
3007+
pte_read(entry) ? "Read " : "",
3008+
pte_write(entry) ? "Write " : "",
3009+
pte_exec(entry) ? "Exec " : "");
30083010
}
30093011

30103012
static void show_pte(unsigned long addr)

0 commit comments

Comments
 (0)