Skip to content

Commit f5397c3

Browse files
sunnanyongpalmer-dabbelt
authored andcommitted
riscv: mm: add _PAGE_LEAF macro
In riscv, a page table entry is leaf when any bit of read, write, or execute bit is set. So add a macro:_PAGE_LEAF instead of (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC), which is frequently used to determine if it is a leaf page. This make code easier to read, without any functional change. Signed-off-by: Nanyong Sun <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 6efb943 commit f5397c3

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

arch/riscv/include/asm/pgtable-64.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ static inline int pud_bad(pud_t pud)
4646
#define pud_leaf pud_leaf
4747
static inline int pud_leaf(pud_t pud)
4848
{
49-
return pud_present(pud) &&
50-
(pud_val(pud) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
49+
return pud_present(pud) && (pud_val(pud) & _PAGE_LEAF);
5150
}
5251

5352
static inline void set_pud(pud_t *pudp, pud_t pud)

arch/riscv/include/asm/pgtable-bits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
#define _PAGE_CHG_MASK (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ | \
4040
_PAGE_WRITE | _PAGE_EXEC | \
4141
_PAGE_USER | _PAGE_GLOBAL))
42+
/*
43+
* when all of R/W/X are zero, the PTE is a pointer to the next level
44+
* of the page table; otherwise, it is a leaf PTE.
45+
*/
46+
#define _PAGE_LEAF (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)
4247

4348
#endif /* _ASM_RISCV_PGTABLE_BITS_H */

arch/riscv/include/asm/pgtable.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ static inline int pmd_bad(pmd_t pmd)
190190
#define pmd_leaf pmd_leaf
191191
static inline int pmd_leaf(pmd_t pmd)
192192
{
193-
return pmd_present(pmd) &&
194-
(pmd_val(pmd) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
193+
return pmd_present(pmd) && (pmd_val(pmd) & _PAGE_LEAF);
195194
}
196195

197196
static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
@@ -267,8 +266,7 @@ static inline int pte_exec(pte_t pte)
267266

268267
static inline int pte_huge(pte_t pte)
269268
{
270-
return pte_present(pte)
271-
&& (pte_val(pte) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
269+
return pte_present(pte) && (pte_val(pte) & _PAGE_LEAF);
272270
}
273271

274272
static inline int pte_dirty(pte_t pte)

0 commit comments

Comments
 (0)