2019-05-29 07:18:00 -07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2017-07-10 18:06:09 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Regents of the University of California
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASM_RISCV_PGTABLE_BITS_H
|
|
|
|
#define _ASM_RISCV_PGTABLE_BITS_H
|
|
|
|
|
|
|
|
#define _PAGE_ACCESSED_OFFSET 6
|
|
|
|
|
|
|
|
#define _PAGE_PRESENT (1 << 0)
|
|
|
|
#define _PAGE_READ (1 << 1) /* Readable */
|
|
|
|
#define _PAGE_WRITE (1 << 2) /* Writable */
|
|
|
|
#define _PAGE_EXEC (1 << 3) /* Executable */
|
|
|
|
#define _PAGE_USER (1 << 4) /* User */
|
|
|
|
#define _PAGE_GLOBAL (1 << 5) /* Global */
|
|
|
|
#define _PAGE_ACCESSED (1 << 6) /* Set by hardware on any access */
|
|
|
|
#define _PAGE_DIRTY (1 << 7) /* Set by hardware on any write */
|
2023-09-21 10:50:20 +08:00
|
|
|
#define _PAGE_SOFT (3 << 8) /* Reserved for software */
|
2017-07-10 18:06:09 -07:00
|
|
|
|
2023-09-21 10:50:20 +08:00
|
|
|
#define _PAGE_SPECIAL (1 << 8) /* RSW: 0x1 */
|
2017-07-10 18:06:09 -07:00
|
|
|
#define _PAGE_TABLE _PAGE_PRESENT
|
|
|
|
|
2018-12-16 13:03:36 -05:00
|
|
|
/*
|
|
|
|
* _PAGE_PROT_NONE is set on not-present pages (and ignored by the hardware) to
|
|
|
|
* distinguish them from swapped out pages
|
|
|
|
*/
|
riscv/mm: Adjust PAGE_PROT_NONE to comply with THP semantics
This is a preparation for enabling THP migration.
As the commit b65399f6111b("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 <sunnanyong@huawei.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2021-11-23 22:06:37 +08:00
|
|
|
#define _PAGE_PROT_NONE _PAGE_GLOBAL
|
2018-12-16 13:03:36 -05:00
|
|
|
|
2023-01-13 18:10:19 +01:00
|
|
|
/* Used for swap PTEs only. */
|
|
|
|
#define _PAGE_SWP_EXCLUSIVE _PAGE_ACCESSED
|
|
|
|
|
2017-07-10 18:06:09 -07:00
|
|
|
#define _PAGE_PFN_SHIFT 10
|
|
|
|
|
2021-04-30 16:28:47 +08:00
|
|
|
/*
|
|
|
|
* when all of R/W/X are zero, the PTE is a pointer to the next level
|
|
|
|
* of the page table; otherwise, it is a leaf PTE.
|
|
|
|
*/
|
|
|
|
#define _PAGE_LEAF (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC)
|
2017-07-10 18:06:09 -07:00
|
|
|
|
|
|
|
#endif /* _ASM_RISCV_PGTABLE_BITS_H */
|