diff mbox series

[v2,2/5] target/riscv: Give a more generic size for tlb

Message ID 20211122110230.38783-3-zhiwei_liu@c-sky.com
State New
Headers show
Series Check PMP rules num before propagation | expand

Commit Message

LIU Zhiwei Nov. 22, 2021, 11:02 a.m. UTC
As the caller has given a tlb size parameter, we should use it
to keep pace with it.

Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
---
 target/riscv/cpu_helper.c | 5 +----
 target/riscv/pmp.c        | 7 ++++---
 2 files changed, 5 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index 9eeed38c7e..3f53744897 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -362,7 +362,6 @@  static int get_physical_address_pmp(CPURISCVState *env, int *prot,
                                     int mode)
 {
     pmp_priv_t pmp_priv;
-    target_ulong tlb_size_pmp = 0;
 
     if (!riscv_feature(env, RISCV_FEATURE_PMP)) {
         *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
@@ -377,9 +376,7 @@  static int get_physical_address_pmp(CPURISCVState *env, int *prot,
 
     *prot = pmp_priv_to_page_prot(pmp_priv);
     if (tlb_size != NULL) {
-        if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) {
-            *tlb_size = tlb_size_pmp;
-        }
+        pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), tlb_size);
     }
 
     return TRANSLATE_SUCCESS;
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
index 190ff59fab..ca38087574 100644
--- a/target/riscv/pmp.c
+++ b/target/riscv/pmp.c
@@ -625,7 +625,8 @@  bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
 {
     int i;
     target_ulong val;
-    target_ulong tlb_ea = (tlb_sa + TARGET_PAGE_SIZE - 1);
+    target_ulong tlb_ea = (tlb_sa + *tlb_size - 1);
+    target_ulong old_size = *tlb_size;
 
     if (pmp_get_num_rules(env) == 0) {
         return false;
@@ -634,13 +635,13 @@  bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa,
     for (i = 0; i < MAX_RISCV_PMPS; i++) {
         val = pmp_get_tlb_size(env, i, tlb_sa, tlb_ea);
         if (val) {
-            if (*tlb_size == 0 || *tlb_size > val) {
+            if (*tlb_size > val) {
                 *tlb_size = val;
             }
         }
     }
 
-    if (*tlb_size != 0) {
+    if (*tlb_size != old_size) {
         return true;
     }