Skip to content

Commit

Permalink
Merge pull request #1889 from ved-rivos/010925
Browse files Browse the repository at this point in the history
(Guest)Page fault cause by Svnapot occur before A/D update
  • Loading branch information
aswaterman authored Jan 9, 2025
2 parents fa05e4e + 0bbf0d6 commit 49727e8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions riscv/mmu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ reg_t mmu_t::s2xlate(reg_t gva, reg_t gpa, access_type type, access_type trap_ty
} else {
reg_t ad = PTE_A | ((type == STORE) * PTE_D);

int napot_bits = ((pte & PTE_N) ? (ctz(ppn) + 1) : 0);
if (((pte & PTE_N) && (ppn == 0 || i != 0)) || (napot_bits != 0 && napot_bits != 4))
break;

if ((pte & ad) != ad) {
if (hade) {
// set accessed and possibly dirty bits
Expand All @@ -466,10 +470,6 @@ reg_t mmu_t::s2xlate(reg_t gva, reg_t gpa, access_type type, access_type trap_ty
reg_t vpn = gpa >> PGSHIFT;
reg_t page_mask = (reg_t(1) << PGSHIFT) - 1;

int napot_bits = ((pte & PTE_N) ? (ctz(ppn) + 1) : 0);
if (((pte & PTE_N) && (ppn == 0 || i != 0)) || (napot_bits != 0 && napot_bits != 4))
break;

reg_t page_base = ((ppn & ~((reg_t(1) << napot_bits) - 1))
| (vpn & ((reg_t(1) << napot_bits) - 1))
| (vpn & ((reg_t(1) << ptshift) - 1))) << PGSHIFT;
Expand Down Expand Up @@ -571,6 +571,10 @@ reg_t mmu_t::walk(mem_access_info_t access_info)
} else {
reg_t ad = PTE_A | ((type == STORE) * PTE_D);

int napot_bits = ((pte & PTE_N) ? (ctz(ppn) + 1) : 0);
if (((pte & PTE_N) && (ppn == 0 || i != 0)) || (napot_bits != 0 && napot_bits != 4))
break;

if ((pte & ad) != ad) {
if (hade) {
// Check for write permission to the first-stage PT in second-stage
Expand All @@ -587,10 +591,6 @@ reg_t mmu_t::walk(mem_access_info_t access_info)
// for superpage or Svnapot NAPOT mappings, make a fake leaf PTE for the TLB's benefit.
reg_t vpn = addr >> PGSHIFT;

int napot_bits = ((pte & PTE_N) ? (ctz(ppn) + 1) : 0);
if (((pte & PTE_N) && (ppn == 0 || i != 0)) || (napot_bits != 0 && napot_bits != 4))
break;

reg_t page_base = ((ppn & ~((reg_t(1) << napot_bits) - 1))
| (vpn & ((reg_t(1) << napot_bits) - 1))
| (vpn & ((reg_t(1) << ptshift) - 1))) << PGSHIFT;
Expand Down

0 comments on commit 49727e8

Please sign in to comment.