Roger Chang has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/69117?usp=email )
Change subject: arch-riscv: Add pmp index checking
......................................................................
arch-riscv: Add pmp index checking
Check the index is within the bounds of PMP table before updating the
address and config
Change-Id: Ie938b3c2a61eca9527192c0452d1db9522f07af9
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/69117
Reviewed-by: Bobby Bruce <bbr...@ucdavis.edu>
Maintainer: Bobby Bruce <bbr...@ucdavis.edu>
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Ayaz Akram <yazak...@ucdavis.edu>
Reviewed-by: Yu-hsin Wang <yuhsi...@google.com>
---
M src/arch/riscv/pmp.cc
1 file changed, 16 insertions(+), 2 deletions(-)
Approvals:
Ayaz Akram: Looks good to me, approved
Yu-hsin Wang: Looks good to me, approved
kokoro: Regressions pass
Bobby Bruce: Looks good to me, approved; Looks good to me, approved
diff --git a/src/arch/riscv/pmp.cc b/src/arch/riscv/pmp.cc
index 940af47..49dc7ba 100644
--- a/src/arch/riscv/pmp.cc
+++ b/src/arch/riscv/pmp.cc
@@ -152,6 +152,13 @@
bool
PMP::pmpUpdateCfg(uint32_t pmp_index, uint8_t this_cfg)
{
+ if (pmp_index >= pmpEntries) {
+ DPRINTF(PMP, "Can't update pmp entry config %u"
+ " because the index exceed the size of pmp entries %u",
+ pmp_index, pmpEntries);
+ return false;
+ }
+
DPRINTF(PMP, "Update pmp config with %u for pmp entry: %u \n",
(unsigned)this_cfg, pmp_index);
if (pmpTable[pmp_index].pmpCfg & PMP_LOCK) {
@@ -231,6 +238,13 @@
bool
PMP::pmpUpdateAddr(uint32_t pmp_index, Addr this_addr)
{
+ if (pmp_index >= pmpEntries) {
+ DPRINTF(PMP, "Can't update pmp entry address %u"
+ " because the index exceed the size of pmp entries %u",
+ pmp_index, pmpEntries);
+ return false;
+ }
+
DPRINTF(PMP, "Update pmp addr %#x for pmp entry %u \n",
this_addr, pmp_index);
@@ -241,8 +255,8 @@
} else if (pmp_index < pmpTable.size() - 1 &&
((pmpTable[pmp_index+1].pmpCfg & PMP_LOCK) != 0) &&
pmpGetAField(pmpTable[pmp_index+1].pmpCfg) == PMP_TOR) {
- DPRINTF(PMP, "Update pmp entry %u failed because the entry %u lock
bit set"
- "and A field is TOR\n",
+ DPRINTF(PMP, "Update pmp entry %u failed because the entry %u lock
bit"
+ " set and A field is TOR\n",
pmp_index, pmp_index+1);
return false;
}
--
To view, visit
https://gem5-review.googlesource.com/c/public/gem5/+/69117?usp=email
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: Ie938b3c2a61eca9527192c0452d1db9522f07af9
Gerrit-Change-Number: 69117
Gerrit-PatchSet: 2
Gerrit-Owner: Roger Chang <rogerycch...@google.com>
Gerrit-Reviewer: Ayaz Akram <yazak...@ucdavis.edu>
Gerrit-Reviewer: Bobby Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Jui-min Lee <f...@google.com>
Gerrit-Reviewer: Roger Chang <rogerycch...@google.com>
Gerrit-Reviewer: Yu-hsin Wang <yuhsi...@google.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-CC: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org