|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 2/6] xen/riscv: set A/D bits in Xen's page-table mappings under Svade
The previous patch set A/D bits in case of the Svade extension for G-stage
mappings. Xen's own S-stage mappings need the same fix as both
setup_initial_mapping() (the boot page tables) and arch_pmap_map() (the
fixmap) build leaf PTEs directly instead of going through
pt_update_entry(), which is what adds A/D bits. So with Svade, both would
fault on first access.
Add PTE_ACCESSED to all PAGE_HYPERVISOR_* and also PTE_DIRTY to
PAGE_HYPERVISOR_RW as it needs to be set during a write to avoid a fault.
This fixes arch_pmap_map() for free, since it already builds its PTE from
PAGE_HYPERVISOR_RW. Switch setup_initial_mapping() to use these macros for
its default, text and rodata permissions, and for the temporary root entry
built by check_pgtbl_mode_support(), instead of the equivalent raw bit
lists. The latter drops PTE_WRITABLE, going from RWX to RX, but this is
harmless, as that entry only has to make the current instruction stream
fetchable between the two CSR_SATP writes used to probe SATP mode support,
and nothing writes through it.
Drop the now-redundant PTE_LEAF_DEFAULT, since converting the last
open-coded site above leaves it with no user outside page.h itself.
A PTE is a table entry iff PTE_VALID is set and R/W/X are all clear, so
update pte_is_table() and pte_is_mapping() accordingly.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
---
Changes since v1:
- change commit title
- mention in patch message that arch_pmap_map() is fixed too, via the
PAGE_HYPERVISOR_RW change, not just setup_initial_mapping().
- convert check_pgtbl_mode_support()'s temporary root entry to
PAGE_HYPERVISOR_RX, as it's harmless.
- drop PTE_LEAF_DEFAULT entirely instead of keeping it, now that no site
open-codes it anymore.
- drop the pte_is_table() comment line that referenced PAGE_HYPERVISOR_RW,
now stale.
---
xen/arch/riscv/include/asm/page.h | 15 +++++++--------
xen/arch/riscv/mm.c | 9 ++++-----
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/xen/arch/riscv/include/asm/page.h
b/xen/arch/riscv/include/asm/page.h
index b465a90325..1977634efc 100644
--- a/xen/arch/riscv/include/asm/page.h
+++ b/xen/arch/riscv/include/asm/page.h
@@ -46,12 +46,11 @@
#define PTE_PBMT_NOCACHE BIT(61, UL)
#define PTE_PBMT_IO BIT(62, UL)
-#define PTE_LEAF_DEFAULT (PTE_VALID | PTE_READABLE | PTE_WRITABLE)
#define PTE_TABLE (PTE_VALID)
-#define PAGE_HYPERVISOR_RO (PTE_VALID | PTE_READABLE)
-#define PAGE_HYPERVISOR_RW (PTE_VALID | PTE_READABLE | PTE_WRITABLE)
-#define PAGE_HYPERVISOR_RX (PTE_VALID | PTE_READABLE | PTE_EXECUTABLE)
+#define PAGE_HYPERVISOR_RO (PTE_VALID | PTE_READABLE | PTE_ACCESSED)
+#define PAGE_HYPERVISOR_RW (PTE_VALID | PTE_READABLE | PTE_WRITABLE |
PTE_ACCESSED | PTE_DIRTY)
+#define PAGE_HYPERVISOR_RX (PTE_VALID | PTE_READABLE | PTE_EXECUTABLE
| PTE_ACCESSED)
#define PAGE_HYPERVISOR PAGE_HYPERVISOR_RW
/*
@@ -174,10 +173,9 @@ static inline bool pte_is_table(pte_t p)
* According to the spec if V=1 and W=1 then R also needs to be 1 as
* R = 0 is reserved for future use ( look at the Table 4.5 ) so check
* in ASSERT that if (V==1 && W==1) then R isn't 0.
- *
- * PAGE_HYPERVISOR_RW contains PTE_VALID too.
*/
- ASSERT(((p.pte & PAGE_HYPERVISOR_RW) != (PTE_VALID | PTE_WRITABLE)));
+ ASSERT((p.pte & (PTE_VALID | PTE_READABLE | PTE_WRITABLE)) !=
+ (PTE_VALID | PTE_WRITABLE));
return ((p.pte & (PTE_VALID | PTE_ACCESS_MASK)) == PTE_VALID);
}
@@ -185,7 +183,8 @@ static inline bool pte_is_table(pte_t p)
static inline bool pte_is_mapping(pte_t p)
{
/* See pte_is_table() */
- ASSERT(((p.pte & PAGE_HYPERVISOR_RW) != (PTE_VALID | PTE_WRITABLE)));
+ ASSERT((p.pte & (PTE_VALID | PTE_READABLE | PTE_WRITABLE)) !=
+ (PTE_VALID | PTE_WRITABLE));
return (p.pte & PTE_VALID) && (p.pte & PTE_ACCESS_MASK);
}
diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c
index 4d3b8c2204..53bebbcabf 100644
--- a/xen/arch/riscv/mm.c
+++ b/xen/arch/riscv/mm.c
@@ -140,7 +140,7 @@ static void __init setup_initial_mapping(struct mmu_desc
*mmu_desc,
case 1: /* Level 0 */
{
unsigned long paddr = (page_addr - map_start) + pa_start;
- unsigned int permissions = PTE_LEAF_DEFAULT;
+ unsigned int permissions = PAGE_HYPERVISOR_RW;
unsigned long addr = is_identity_mapping
? page_addr : virt_to_maddr(page_addr);
pte_t pte_to_be_written;
@@ -149,11 +149,10 @@ static void __init setup_initial_mapping(struct mmu_desc
*mmu_desc,
if ( is_kernel_text(addr) ||
is_kernel_inittext(addr) )
- permissions =
- PTE_EXECUTABLE | PTE_READABLE | PTE_VALID;
+ permissions = PAGE_HYPERVISOR_RX;
if ( is_kernel_rodata(addr) )
- permissions = PTE_READABLE | PTE_VALID;
+ permissions = PAGE_HYPERVISOR_RO;
pte_to_be_written = paddr_to_pte(paddr, permissions);
@@ -198,7 +197,7 @@ static bool __init check_pgtbl_mode_support(struct mmu_desc
*mmu_desc,
index = pt_index(page_table_level, aligned_load_start);
stage1_pgtbl_root[index] = paddr_to_pte(aligned_load_start,
- PTE_LEAF_DEFAULT | PTE_EXECUTABLE);
+ PAGE_HYPERVISOR_RX);
sfence_vma();
csr_write(CSR_SATP,
--
2.55.0
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |