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); @@ -2043,6 +2044,8 @@ new_l3 |= PTE_W; if ((va >> 63) == 0) new_l3 |= PTE_U; + else + new_l3 |= PTE_A | PTE_D; new_l3 |= (pn << PTE_PPN0_S); if ((flags & PMAP_ENTER_WIRED) != 0) @@ -2157,8 +2160,13 @@ * No, might be a protection or wiring change. */ if ((orig_l3 & PTE_SW_MANAGED) != 0) { - if (pmap_is_write(new_l3)) + if (pmap_is_write(new_l3)) { + if (flags & PROT_WRITE) + new_l3 |= PTE_D; vm_page_aflag_set(m, PGA_WRITEABLE); + } + if (flags & PROT_READ) + new_l3 |= PTE_A; } goto validate; } @@ -2414,8 +2422,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); /*