gem5-dev@gem5.org

The gem5 Developer List

View all threads

[S] Change in gem5/gem5[develop]: arch-riscv: Add pmp index checking

RC
Roger Chang (Gerrit)
Wed, Mar 22, 2023 1:31 AM

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 bbruce@ucdavis.edu
Maintainer: Bobby Bruce bbruce@ucdavis.edu
Tested-by: kokoro noreply+kokoro@google.com
Reviewed-by: Ayaz Akram yazakram@ucdavis.edu
Reviewed-by: Yu-hsin Wang yuhsingw@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 rogerycchang@google.com
Gerrit-Reviewer: Ayaz Akram yazakram@ucdavis.edu
Gerrit-Reviewer: Bobby Bruce bbruce@ucdavis.edu
Gerrit-Reviewer: Jui-min Lee fcrh@google.com
Gerrit-Reviewer: Roger Chang rogerycchang@google.com
Gerrit-Reviewer: Yu-hsin Wang yuhsingw@google.com
Gerrit-Reviewer: kokoro noreply+kokoro@google.com
Gerrit-CC: Hoa Nguyen hoanguyen@ucdavis.edu
Gerrit-MessageType: merged

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 <bbruce@ucdavis.edu> Maintainer: Bobby Bruce <bbruce@ucdavis.edu> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Ayaz Akram <yazakram@ucdavis.edu> Reviewed-by: Yu-hsin Wang <yuhsingw@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 <rogerycchang@google.com> Gerrit-Reviewer: Ayaz Akram <yazakram@ucdavis.edu> Gerrit-Reviewer: Bobby Bruce <bbruce@ucdavis.edu> Gerrit-Reviewer: Jui-min Lee <fcrh@google.com> Gerrit-Reviewer: Roger Chang <rogerycchang@google.com> Gerrit-Reviewer: Yu-hsin Wang <yuhsingw@google.com> Gerrit-Reviewer: kokoro <noreply+kokoro@google.com> Gerrit-CC: Hoa Nguyen <hoanguyen@ucdavis.edu> Gerrit-MessageType: merged