Alex Richardson has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/55404 )
Change subject: arch-riscv: Consistently check privilege mode for CSR
accesses
......................................................................
arch-riscv: Consistently check privilege mode for CSR accesses
According to the RISC-V privileged spec (section 2.1), bits 8 and 9 of
the CSR number encode the lowest privilege mode that is permitted to
access the CSR. Commit 55e7d3e5b6f062659bad5f6fdc8469ce80f102dd added
this check for for CSR_MSTATUS but none of the other CSRs.
Change-Id: Iecf2e387fa9ee810e8b8471341bfa371693b97c5
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/55404
Reviewed-by: Nils Asmussen <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/arch/riscv/isa/formats/standard.isa
1 file changed, 27 insertions(+), 13 deletions(-)
Approvals:
Nils Asmussen: Looks good to me, approved
Jason Lowe-Power: Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/arch/riscv/isa/formats/standard.isa
b/src/arch/riscv/isa/formats/standard.isa
index 9345c1f..e4bd4d8 100644
--- a/src/arch/riscv/isa/formats/standard.isa
+++ b/src/arch/riscv/isa/formats/standard.isa
@@ -290,23 +290,19 @@
%(op_rd)s;
RegVal data, olddata;
-
+ auto lowestAllowedMode = (PrivilegeMode)bits(csr, 9, 8);
+ auto pm = (PrivilegeMode)xc->readMiscReg(MISCREG_PRV);
+ if (pm < lowestAllowedMode) {
+ return std::make_shared<IllegalInstFault>(
+ csprintf("%s is not accessible in %s\n", csrName, pm),
+ machInst);
+ }
switch (csr) {
case CSR_SATP: {
- auto pm = (PrivilegeMode)xc->readMiscReg(MISCREG_PRV);
STATUS status = xc->readMiscReg(MISCREG_STATUS);
- if (pm == PRV_U || (pm == PRV_S && status.tvm == 1)) {
+ if (pm == PRV_S && status.tvm == 1) {
return std::make_shared<IllegalInstFault>(
- "SATP access in user mode or with TVM enabled\n",
- machInst);
- }
- break;
- }
- case CSR_MSTATUS: {
- auto pm = (PrivilegeMode)xc->readMiscReg(MISCREG_PRV);
- if (pm != PrivilegeMode::PRV_M) {
- return std::make_shared<IllegalInstFault>(
- "MSTATUS is only accessibly in machine mode\n",
+ "SATP access with TVM enabled\n",
machInst);
}
break;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/55404
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Iecf2e387fa9ee810e8b8471341bfa371693b97c5
Gerrit-Change-Number: 55404
Gerrit-PatchSet: 3
Gerrit-Owner: Alex Richardson <[email protected]>
Gerrit-Reviewer: Alex Richardson <[email protected]>
Gerrit-Reviewer: Ayaz Akram <[email protected]>
Gerrit-Reviewer: Bobby Bruce <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Nils Asmussen <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s