Skip to content

Commit fba88ed

Browse files
sunnanyongpalmer-dabbelt
authored andcommitted
riscv/mm: Adjust PAGE_PROT_NONE to comply with THP semantics
This is a preparation for enabling THP migration. As the commit b65399f("arm64/mm: Change THP helpers to comply with generic MM semantics") mentioned, pmd_present() and pmd_trans_huge() are expected to behave in the following manner: ------------------------------------------------------------------------- | PMD states | pmd_present | pmd_trans_huge | ------------------------------------------------------------------------- | Mapped | Yes | Yes | ------------------------------------------------------------------------- | Splitting | Yes | Yes | ------------------------------------------------------------------------- | Migration/Swap | No | No | ------------------------------------------------------------------------- At present the PROT_NONE bit reuses the READ bit could not comply with above semantics with two problems: 1. When splitting a PMD THP, PMD is first invalidated with pmdp_invalidate()->pmd_mkinvalid(), which clears the PRESENT bit and PROT_NONE bit/READ bit, if the PMD is read-only, then the PAGE_LEAF property is also cleared, which results in pmd_present() return false. 2. When migrating, the swap entry only clear the PRESENT bit and PROT_NONE bit/READ bit, the W/X bit may be set, so _PAGE_LEAF may be true which results in pmd_present() return true. Solution: Adjust PROT_NONE bit from READ to GLOBAL bit can satisfy the above rules: 1. GLOBAL bit has no other meanings, not like the R/W/X bit, which is also relative with _PAGE_LEAF property. 2. GLOBAL bit is at bit 5, making swap entry start from bit 6, bit 0-5 are zero, which means the PRESENT, PROT_NONE, and PAGE_LEAF are all false, then the pmd_present() and pmd_trans_huge() return false when in migration/swap. Signed-off-by: Nanyong Sun <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 8ee3043 commit fba88ed

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* _PAGE_PROT_NONE is set on not-present pages (and ignored by the hardware) to
3232
* distinguish them from swapped out pages
3333
*/
34-
#define _PAGE_PROT_NONE _PAGE_READ
34+
#define _PAGE_PROT_NONE _PAGE_GLOBAL
3535

3636
#define _PAGE_PFN_SHIFT 10
3737

arch/riscv/include/asm/pgtable.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
/* Page protection bits */
120120
#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER)
121121

122-
#define PAGE_NONE __pgprot(_PAGE_PROT_NONE)
122+
#define PAGE_NONE __pgprot(_PAGE_PROT_NONE | _PAGE_READ)
123123
#define PAGE_READ __pgprot(_PAGE_BASE | _PAGE_READ)
124124
#define PAGE_WRITE __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE)
125125
#define PAGE_EXEC __pgprot(_PAGE_BASE | _PAGE_EXEC)
@@ -628,11 +628,12 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma,
628628
*
629629
* Format of swap PTE:
630630
* bit 0: _PAGE_PRESENT (zero)
631-
* bit 1: _PAGE_PROT_NONE (zero)
632-
* bits 2 to 6: swap type
633-
* bits 7 to XLEN-1: swap offset
631+
* bit 1 to 3: _PAGE_LEAF (zero)
632+
* bit 5: _PAGE_PROT_NONE (zero)
633+
* bits 6 to 10: swap type
634+
* bits 10 to XLEN-1: swap offset
634635
*/
635-
#define __SWP_TYPE_SHIFT 2
636+
#define __SWP_TYPE_SHIFT 6
636637
#define __SWP_TYPE_BITS 5
637638
#define __SWP_TYPE_MASK ((1UL << __SWP_TYPE_BITS) - 1)
638639
#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)

0 commit comments

Comments
 (0)