Skip to content

Commit ac94ac7

Browse files
kvaneeshmpe
authored andcommitted
powerpc/mm: Add radix callbacks to pte accessors
For those pte accessors, that operate on a different set of pte bits between hash/radix, we add a generic variant that does a conditional to hash linux or radix variant. Signed-off-by: Aneesh Kumar K.V <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 566ca99 commit ac94ac7

File tree

2 files changed

+84
-21
lines changed

2 files changed

+84
-21
lines changed

arch/powerpc/include/asm/book3s/64/hash.h

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,26 @@
8585
#define _PTEIDX_SECONDARY 0x8
8686
#define _PTEIDX_GROUP_IX 0x7
8787

88-
#define PMD_BAD_BITS (PTE_TABLE_SIZE-1)
89-
#define PUD_BAD_BITS (PMD_TABLE_SIZE-1)
88+
#define H_PMD_BAD_BITS (PTE_TABLE_SIZE-1)
89+
#define H_PUD_BAD_BITS (PMD_TABLE_SIZE-1)
9090

9191
#ifndef __ASSEMBLY__
92-
#define pmd_bad(pmd) (pmd_val(pmd) & PMD_BAD_BITS)
93-
94-
#define pud_bad(pud) (pud_val(pud) & PUD_BAD_BITS)
92+
#define hash__pmd_bad(pmd) (pmd_val(pmd) & H_PMD_BAD_BITS)
93+
#define hash__pud_bad(pud) (pud_val(pud) & H_PUD_BAD_BITS)
94+
static inline int hash__pgd_bad(pgd_t pgd)
95+
{
96+
return (pgd_val(pgd) == 0);
97+
}
9598

9699
extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
97100
pte_t *ptep, unsigned long pte, int huge);
98101
extern unsigned long htab_convert_pte_flags(unsigned long pteflags);
99102
/* Atomic PTE updates */
100-
static inline unsigned long pte_update(struct mm_struct *mm,
101-
unsigned long addr,
102-
pte_t *ptep, unsigned long clr,
103-
unsigned long set,
104-
int huge)
103+
static inline unsigned long hash__pte_update(struct mm_struct *mm,
104+
unsigned long addr,
105+
pte_t *ptep, unsigned long clr,
106+
unsigned long set,
107+
int huge)
105108
{
106109
__be64 old_be, tmp_be;
107110
unsigned long old;
@@ -132,7 +135,7 @@ static inline unsigned long pte_update(struct mm_struct *mm,
132135
/* Set the dirty and/or accessed bits atomically in a linux PTE, this
133136
* function doesn't need to flush the hash entry
134137
*/
135-
static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
138+
static inline void hash__ptep_set_access_flags(pte_t *ptep, pte_t entry)
136139
{
137140
__be64 old, tmp, val, mask;
138141

@@ -153,27 +156,23 @@ static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
153156
:"cc");
154157
}
155158

156-
static inline int pgd_bad(pgd_t pgd)
159+
static inline int hash__pte_same(pte_t pte_a, pte_t pte_b)
157160
{
158-
return (pgd_val(pgd) == 0);
161+
return (((pte_raw(pte_a) ^ pte_raw(pte_b)) & ~cpu_to_be64(_PAGE_HPTEFLAGS)) == 0);
159162
}
160163

161-
#define __HAVE_ARCH_PTE_SAME
162-
static inline int pte_same(pte_t pte_a, pte_t pte_b)
164+
static inline int hash__pte_none(pte_t pte)
163165
{
164-
return (((pte_raw(pte_a) ^ pte_raw(pte_b)) & ~cpu_to_be64(_PAGE_HPTEFLAGS)) == 0);
166+
return (pte_val(pte) & ~H_PTE_NONE_MASK) == 0;
165167
}
166168

167-
/* Generic accessors to PTE bits */
168-
static inline int pte_none(pte_t pte) { return (pte_val(pte) & ~H_PTE_NONE_MASK) == 0; }
169-
170169
/* This low level function performs the actual PTE insertion
171170
* Setting the PTE depends on the MMU type and other factors. It's
172171
* an horrible mess that I'm not going to try to clean up now but
173172
* I'm keeping it in one place rather than spread around
174173
*/
175-
static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
176-
pte_t *ptep, pte_t pte, int percpu)
174+
static inline void hash__set_pte_at(struct mm_struct *mm, unsigned long addr,
175+
pte_t *ptep, pte_t pte, int percpu)
177176
{
178177
/*
179178
* Anything else just stores the PTE normally. That covers all 64-bit

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ extern unsigned long __pgd_table_size;
262262

263263
#endif /* __real_pte */
264264

265+
static inline unsigned long pte_update(struct mm_struct *mm, unsigned long addr,
266+
pte_t *ptep, unsigned long clr,
267+
unsigned long set, int huge)
268+
{
269+
if (radix_enabled())
270+
return radix__pte_update(mm, addr, ptep, clr, set, huge);
271+
return hash__pte_update(mm, addr, ptep, clr, set, huge);
272+
}
265273
/*
266274
* For hash even if we have _PAGE_ACCESSED = 0, we do a pte_update.
267275
* We currently remove entries from the hashtable regardless of whether
@@ -501,6 +509,39 @@ static inline bool check_pte_access(unsigned long access, unsigned long ptev)
501509

502510
return true;
503511
}
512+
/*
513+
* Generic functions with hash/radix callbacks
514+
*/
515+
516+
static inline void __ptep_set_access_flags(pte_t *ptep, pte_t entry)
517+
{
518+
if (radix_enabled())
519+
return radix__ptep_set_access_flags(ptep, entry);
520+
return hash__ptep_set_access_flags(ptep, entry);
521+
}
522+
523+
#define __HAVE_ARCH_PTE_SAME
524+
static inline int pte_same(pte_t pte_a, pte_t pte_b)
525+
{
526+
if (radix_enabled())
527+
return radix__pte_same(pte_a, pte_b);
528+
return hash__pte_same(pte_a, pte_b);
529+
}
530+
531+
static inline int pte_none(pte_t pte)
532+
{
533+
if (radix_enabled())
534+
return radix__pte_none(pte);
535+
return hash__pte_none(pte);
536+
}
537+
538+
static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr,
539+
pte_t *ptep, pte_t pte, int percpu)
540+
{
541+
if (radix_enabled())
542+
return radix__set_pte_at(mm, addr, ptep, pte, percpu);
543+
return hash__set_pte_at(mm, addr, ptep, pte, percpu);
544+
}
504545

505546
#define _PAGE_CACHE_CTL (_PAGE_NON_IDEMPOTENT | _PAGE_TOLERANT)
506547

@@ -555,6 +596,13 @@ static inline void pmd_clear(pmd_t *pmdp)
555596
#define pmd_none(pmd) (!pmd_val(pmd))
556597
#define pmd_present(pmd) (!pmd_none(pmd))
557598

599+
static inline int pmd_bad(pmd_t pmd)
600+
{
601+
if (radix_enabled())
602+
return radix__pmd_bad(pmd);
603+
return hash__pmd_bad(pmd);
604+
}
605+
558606
static inline void pud_set(pud_t *pudp, unsigned long val)
559607
{
560608
*pudp = __pud(val);
@@ -580,6 +628,15 @@ static inline pud_t pte_pud(pte_t pte)
580628
return __pud(pte_val(pte));
581629
}
582630
#define pud_write(pud) pte_write(pud_pte(pud))
631+
632+
static inline int pud_bad(pud_t pud)
633+
{
634+
if (radix_enabled())
635+
return radix__pud_bad(pud);
636+
return hash__pud_bad(pud);
637+
}
638+
639+
583640
#define pgd_write(pgd) pte_write(pgd_pte(pgd))
584641
static inline void pgd_set(pgd_t *pgdp, unsigned long val)
585642
{
@@ -604,6 +661,13 @@ static inline pgd_t pte_pgd(pte_t pte)
604661
return __pgd(pte_val(pte));
605662
}
606663

664+
static inline int pgd_bad(pgd_t pgd)
665+
{
666+
if (radix_enabled())
667+
return radix__pgd_bad(pgd);
668+
return hash__pgd_bad(pgd);
669+
}
670+
607671
extern struct page *pgd_page(pgd_t pgd);
608672

609673
/* Pointers in the page table tree are physical addresses */

0 commit comments

Comments
 (0)