Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFI fixes #1901

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions riscv/csrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ bool mnstatus_csr_t::unlogged_write(const reg_t val) noexcept {
// NMIE can be set but not cleared
const reg_t mask = (~read() & MNSTATUS_NMIE)
| (proc->extension_enabled('H') ? MNSTATUS_MNPV : 0)
| (proc->extension_enabled(EXT_ZICFILP) ? MNSTATUS_MNPELP : 0)
| MNSTATUS_MNPP;

const reg_t requested_mnpp = proc->legalize_privilege(get_field(val, MNSTATUS_MNPP));
Expand Down
1 change: 1 addition & 0 deletions riscv/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#define USTATUS_UPIE 0x00000010

#define MNSTATUS_NMIE 0x00000008
#define MNSTATUS_MNPELP 0x00000200
#define MNSTATUS_MNPP 0x00001800
#define MNSTATUS_MNPV 0x00000080

Expand Down
6 changes: 6 additions & 0 deletions riscv/insns/mnret.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ if (prev_prv != PRV_M) {
STATE.mstatus->write(mstatus);
}
s = set_field(s, MNSTATUS_NMIE, 1);
if (ZICFILP_xLPE(prev_virt, prev_prv)) {
STATE.elp = static_cast<elp_t>(get_field(s, MNSTATUS_MNPELP));
}
if (p->extension_enabled(EXT_ZICFILP)) {
s = set_field(s, MNSTATUS_MNPELP, elp_t::NO_LP_EXPECTED);
}
STATE.mnstatus->write(s);
p->set_privilege(prev_prv, prev_virt);
2 changes: 1 addition & 1 deletion riscv/insns/ssrdp.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "zicfiss.h"

if (xSSE()) {
WRITE_RD(STATE.ssp->read());
WRITE_RD(sext_xlen(STATE.ssp->read()));
} else {
#include "mop_r_N.h"
}
4 changes: 3 additions & 1 deletion riscv/mmu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ void mmu_t::load_slow_path_intrapage(reg_t len, uint8_t* bytes, mem_access_info_
refill_tlb(addr, paddr, host_addr, LOAD);

} else if (!mmio_load(paddr, len, bytes)) {
throw trap_load_access_fault(access_info.effective_virt, transformed_addr, 0, 0);
(access_info.flags.ss_access)?
throw trap_store_access_fault(access_info.effective_virt, transformed_addr, 0, 0) :
throw trap_load_access_fault(access_info.effective_virt, transformed_addr, 0, 0);
}

if (access_info.flags.lr) {
Expand Down
2 changes: 1 addition & 1 deletion riscv/zicfiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
shadow_return_addr = MMU.ss_load<uint32_t>(STATE.ssp->read()); \
else \
shadow_return_addr = MMU.ss_load<uint64_t>(STATE.ssp->read()); \
software_check(value == shadow_return_addr, SHADOW_STACK_FAULT); \
software_check(zext_xlen(value) == shadow_return_addr, SHADOW_STACK_FAULT); \
STATE.ssp->write(STATE.ssp->read() + xlen / 8);

#endif