Index: sys/riscv/include/pte.h =================================================================== --- sys/riscv/include/pte.h +++ sys/riscv/include/pte.h @@ -78,6 +78,7 @@ #define PTE_V (1 << 0) /* Valid */ #define PTE_RWX (PTE_R | PTE_W | PTE_X) #define PTE_RX (PTE_R | PTE_X) +#define PTE_KERN (PTE_V | PTE_R | PTE_W | PTE_X | PTE_A | PTE_D) #define PTE_PPN0_S 10 #define PTE_PPN1_S 19 Index: sys/riscv/riscv/locore.S =================================================================== --- sys/riscv/riscv/locore.S +++ sys/riscv/riscv/locore.S @@ -94,7 +94,7 @@ add t3, t4, t2 li t5, 0 2: - li t0, (PTE_V | PTE_RWX | PTE_D) + li t0, (PTE_KERN) slli t2, t4, PTE_PPN1_S /* << PTE_PPN1_S */ or t5, t0, t2 sd t5, (s1) /* Store PTE entry to position */ @@ -126,7 +126,7 @@ mv s2, s11 srli s2, s2, PAGE_SHIFT - li t0, (PTE_V | PTE_RWX | PTE_D) + li t0, (PTE_KERN) slli t2, s2, PTE_PPN0_S /* << PTE_PPN0_S */ or t0, t0, t2 Index: sys/riscv/riscv/pmap.c =================================================================== --- sys/riscv/riscv/pmap.c +++ sys/riscv/riscv/pmap.c @@ -505,7 +505,7 @@ /* superpages */ pn = (pa / PAGE_SIZE); - entry = (PTE_V | PTE_RWX); + entry = (PTE_KERN); entry |= (pn << PTE_PPN0_S); pmap_load_store(&l1[l1_slot], entry); } @@ -933,7 +933,7 @@ KASSERT(l3 != NULL, ("Invalid page table, va: 0x%lx", va)); pn = (pa / PAGE_SIZE); - entry = (PTE_V | PTE_RWX); + entry = (PTE_KERN); entry |= (pn << PTE_PPN0_S); pmap_load_store(l3, entry); @@ -1035,7 +1035,7 @@ pn = (pa / PAGE_SIZE); l3 = pmap_l3(kernel_pmap, va); - entry = (PTE_V | PTE_RWX); + entry = (PTE_KERN); entry |= (pn << PTE_PPN0_S); pmap_load_store(l3, entry); @@ -1450,7 +1450,8 @@ continue; /* try again */ } l2 = pmap_l1_to_l2(l1, kernel_vm_end); - if ((pmap_load(l2) & PTE_A) != 0) { + if ((pmap_load(l2) & PTE_V) != 0 && + (pmap_load(l2) & PTE_RWX) == 0) { kernel_vm_end = (kernel_vm_end + L2_SIZE) & ~L2_OFFSET; if (kernel_vm_end - 1 >= vm_map_max(kernel_map)) { kernel_vm_end = vm_map_max(kernel_map); @@ -2038,7 +2039,7 @@ pa = VM_PAGE_TO_PHYS(m); pn = (pa / PAGE_SIZE); - new_l3 = PTE_V | PTE_R | PTE_X; + new_l3 = PTE_V | PTE_R | PTE_X | PTE_A | PTE_D; if (prot & VM_PROT_WRITE) new_l3 |= PTE_W; if ((va >> 63) == 0) @@ -2414,8 +2415,7 @@ pa = VM_PAGE_TO_PHYS(m); pn = (pa / PAGE_SIZE); - /* RISCVTODO: check permissions */ - entry = (PTE_V | PTE_RWX); + entry = (PTE_V); entry |= (pn << PTE_PPN0_S); /*