Skip to content

Commit

Permalink
Merge pull request #1641 from xinyuwang-starfive/master
Browse files Browse the repository at this point in the history
add hlvx pmp protect to fix issue 1557
  • Loading branch information
jerryz123 committed Apr 29, 2024
2 parents b3bcc12 + 10b9737 commit 0d1c346
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions riscv/csrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool pmpaddr_csr_t::subset_match(reg_t addr, reg_t len) const noexcept {
return !(is_tor ? tor_homogeneous : napot_homogeneous);
}

bool pmpaddr_csr_t::access_ok(access_type type, reg_t mode) const noexcept {
bool pmpaddr_csr_t::access_ok(access_type type, reg_t mode, bool hlvx) const noexcept {
const bool cfgx = cfg & PMP_X;
const bool cfgw = cfg & PMP_W;
const bool cfgr = cfg & PMP_R;
Expand All @@ -191,7 +191,7 @@ bool pmpaddr_csr_t::access_ok(access_type type, reg_t mode) const noexcept {
const bool typer = type == LOAD;
const bool typex = type == FETCH;
const bool typew = type == STORE;
const bool normal_rwx = (typer && cfgr) || (typew && cfgw) || (typex && cfgx);
const bool normal_rwx = (typer && cfgr && (!hlvx || cfgx)) || (typew && cfgw) || (typex && cfgx);
const bool mseccfg_mml = state->mseccfg->get_mml();

if (mseccfg_mml) {
Expand Down
2 changes: 1 addition & 1 deletion riscv/csrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class pmpaddr_csr_t: public csr_t {
bool subset_match(reg_t addr, reg_t len) const noexcept;

// Is the specified access allowed given the pmpcfg privileges?
bool access_ok(access_type type, reg_t mode) const noexcept;
bool access_ok(access_type type, reg_t mode, bool hlvx) const noexcept;

// To check lock bit status from outside like mseccfg
bool is_locked() const noexcept {
Expand Down
6 changes: 3 additions & 3 deletions riscv/mmu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ reg_t mmu_t::translate(mem_access_info_t access_info, reg_t len)
reg_t mode = (reg_t) access_info.effective_priv;

reg_t paddr = walk(access_info) | (addr & (PGSIZE-1));
if (!pmp_ok(paddr, len, access_info.flags.ss_access ? STORE : type, mode))
if (!pmp_ok(paddr, len, access_info.flags.ss_access ? STORE : type, mode, access_info.flags.hlvx))
throw_access_exception(virt, addr, type);
return paddr;
}
Expand Down Expand Up @@ -340,7 +340,7 @@ tlb_entry_t mmu_t::refill_tlb(reg_t vaddr, reg_t paddr, char* host_addr, access_
return entry;
}

bool mmu_t::pmp_ok(reg_t addr, reg_t len, access_type type, reg_t mode)
bool mmu_t::pmp_ok(reg_t addr, reg_t len, access_type type, reg_t mode, bool hlvx)
{
if (!proc || proc->n_pmp == 0)
return true;
Expand All @@ -361,7 +361,7 @@ bool mmu_t::pmp_ok(reg_t addr, reg_t len, access_type type, reg_t mode)
if (!all_match)
return false;

return proc->state.pmpaddr[i]->access_ok(type, mode);
return proc->state.pmpaddr[i]->access_ok(type, mode, hlvx);
}
}

Expand Down
6 changes: 3 additions & 3 deletions riscv/mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class mmu_t
{
const size_t ptesize = sizeof(T);

if (!pmp_ok(pte_paddr, ptesize, LOAD, PRV_S))
if (!pmp_ok(pte_paddr, ptesize, LOAD, PRV_S, false))
throw_access_exception(virt, addr, trap_type);

void* host_pte_addr = sim->addr_to_mem(pte_paddr);
Expand All @@ -466,7 +466,7 @@ class mmu_t
{
const size_t ptesize = sizeof(T);

if (!pmp_ok(pte_paddr, ptesize, STORE, PRV_S))
if (!pmp_ok(pte_paddr, ptesize, STORE, PRV_S, false))
throw_access_exception(virt, addr, trap_type);

void* host_pte_addr = sim->addr_to_mem(pte_paddr);
Expand Down Expand Up @@ -499,7 +499,7 @@ class mmu_t
}

reg_t pmp_homogeneous(reg_t addr, reg_t len);
bool pmp_ok(reg_t addr, reg_t len, access_type type, reg_t mode);
bool pmp_ok(reg_t addr, reg_t len, access_type type, reg_t mode, bool hlvx);

#ifdef RISCV_ENABLE_DUAL_ENDIAN
bool target_big_endian;
Expand Down

0 comments on commit 0d1c346

Please sign in to comment.