Skip to contentSkip to conversation

target/microblaze: Improve bus fault handling

PATCH In review Edgar E. Iglesias 5 participants 9 messages Aug 28, 2020 – Aug 31, 2020

lore
Share & tools
lore
#0 lore raw

cover target/microblaze: Improve bus fault handling

From: "Edgar E. Iglesias" <[email protected]>

Richards recent MicroBlaze patches exposed a bug in the MB ports bus fault handling. If the core is not setup for exceptions, we clobber the CPU state when preparing to raise one. This fixes the bug.

Best regards,
Edgar

Edgar E. Iglesias (2):
target/microblaze: Use CPU properties to conditionalize bus exceptions target/microblaze: Improve transaction failure handling

 target/microblaze/op_helper.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 target/microblaze: Use CPU properties to conditionalize bus exceptions

From: "Edgar E. Iglesias" <[email protected]>

Use CPU properties, instead of PVR fields, to conditionalize bus exceptions.

Fixes 2867a96ffb ("target/microblaze: Add props enabling exceptions on failed bus accesses")
---
 target/microblaze/op_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/microblaze/op_helper.c +2 -2
index f3b17a95b3..13ac476199 100644
@@ -490,12 +490,12 @@ void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
 
     env->sregs[SR_EAR] = addr;
     if (access_type == MMU_INST_FETCH) {
-        if ((env->pvr.regs[2] & PVR2_IOPB_BUS_EXC_MASK)) {
+        if (cpu->cfg.iopb_bus_exception) {
             env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
             helper_raise_exception(env, EXCP_HW_EXCP);
         }
     } else {
-        if ((env->pvr.regs[2] & PVR2_DOPB_BUS_EXC_MASK)) {
+        if (cpu->cfg.dopb_bus_exception) {
             env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
             helper_raise_exception(env, EXCP_HW_EXCP);
         }
Signature · 1 line
2.25.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH v1 1/2] target/microblaze: Use CPU properties to conditionalize bus exceptions

Quoted 7 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Use CPU properties, instead of PVR fields, to conditionalize bus exceptions.

Fixes 2867a96ffb ("target/microblaze: Add props enabling exceptions on failed bus accesses")
Quoted 24 lines
---
  target/microblaze/op_helper.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/microblaze/op_helper.c +2 -2
index f3b17a95b3..13ac476199 100644
@@ -490,12 +490,12 @@ void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
 
      env->sregs[SR_EAR] = addr;
      if (access_type == MMU_INST_FETCH) {
-        if ((env->pvr.regs[2] & PVR2_IOPB_BUS_EXC_MASK)) {
+        if (cpu->cfg.iopb_bus_exception) {
              env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
              helper_raise_exception(env, EXCP_HW_EXCP);
          }
      } else {
-        if ((env->pvr.regs[2] & PVR2_DOPB_BUS_EXC_MASK)) {
+        if (cpu->cfg.dopb_bus_exception) {
              env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
              helper_raise_exception(env, EXCP_HW_EXCP);
          }
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH v1 1/2] target/microblaze: Use CPU properties to conditionalize bus exceptions

In reply to Edgar E. Iglesias
Quoted 8 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

Use CPU properties, instead of PVR fields, to conditionalize bus exceptions.

Fixes 2867a96ffb ("target/microblaze: Add props enabling exceptions on failed bus accesses")

Alistair

Quoted 27 lines
---
 target/microblaze/op_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/microblaze/op_helper.c +2 -3
index f3b17a95b3..13ac476199 100644
@@ -490,12 +490,12 @@ void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
 
     env->sregs[SR_EAR] = addr;
     if (access_type == MMU_INST_FETCH) {
-        if ((env->pvr.regs[2] & PVR2_IOPB_BUS_EXC_MASK)) {
+        if (cpu->cfg.iopb_bus_exception) {
             env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
             helper_raise_exception(env, EXCP_HW_EXCP);
         }
     } else {
-        if ((env->pvr.regs[2] & PVR2_DOPB_BUS_EXC_MASK)) {
+        if (cpu->cfg.dopb_bus_exception) {
             env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
             helper_raise_exception(env, EXCP_HW_EXCP);
         }
--

2.25.1

#4 lore raw

PATCH 2/2 target/microblaze: Improve transaction failure handling

In reply to Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

When the CPU has exceptions disabled, avoid unwinding CPU state and clobbering registers if we're not going to raise any exception.

---
 target/microblaze/op_helper.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
target/microblaze/op_helper.c +7 -12
index 13ac476199..190cd96c6a 100644
@@ -483,22 +483,17 @@ void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
     cpu = MICROBLAZE_CPU(cs);
     env = &cpu->env;
 
-    cpu_restore_state(cs, retaddr, true);
     if (!(env->sregs[SR_MSR] & MSR_EE)) {
         return;
     }
 
-    env->sregs[SR_EAR] = addr;
-    if (access_type == MMU_INST_FETCH) {
-        if (cpu->cfg.iopb_bus_exception) {
-            env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
-            helper_raise_exception(env, EXCP_HW_EXCP);
-        }
-    } else {
-        if (cpu->cfg.dopb_bus_exception) {
-            env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
-            helper_raise_exception(env, EXCP_HW_EXCP);
-        }
+    if ((access_type == MMU_INST_FETCH && cpu->cfg.iopb_bus_exception) ||
+        (access_type != MMU_INST_FETCH && cpu->cfg.dopb_bus_exception)) {
+        cpu_restore_state(cs, retaddr, true);
+        env->sregs[SR_ESR] = access_type == MMU_INST_FETCH ?
+                             ESR_EC_INSN_BUS : ESR_EC_DATA_BUS;
+        env->sregs[SR_EAR] = addr;
+        helper_raise_exception(env, EXCP_HW_EXCP);
     }
 }
 #endif
Signature · 1 line
2.25.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH v1 2/2] target/microblaze: Improve transaction failure handling

Quoted 7 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

When the CPU has exceptions disabled, avoid unwinding CPU state and clobbering registers if we're not going to raise any exception.

Quoted 39 lines
---
  target/microblaze/op_helper.c | 19 +++++++------------
  1 file changed, 7 insertions(+), 12 deletions(-)
target/microblaze/op_helper.c +7 -12
index 13ac476199..190cd96c6a 100644
@@ -483,22 +483,17 @@ void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
      cpu = MICROBLAZE_CPU(cs);
      env = &cpu->env;
 
-    cpu_restore_state(cs, retaddr, true);
      if (!(env->sregs[SR_MSR] & MSR_EE)) {
          return;
      }
 
-    env->sregs[SR_EAR] = addr;
-    if (access_type == MMU_INST_FETCH) {
-        if (cpu->cfg.iopb_bus_exception) {
-            env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
-            helper_raise_exception(env, EXCP_HW_EXCP);
-        }
-    } else {
-        if (cpu->cfg.dopb_bus_exception) {
-            env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
-            helper_raise_exception(env, EXCP_HW_EXCP);
-        }
+    if ((access_type == MMU_INST_FETCH && cpu->cfg.iopb_bus_exception) ||
+        (access_type != MMU_INST_FETCH && cpu->cfg.dopb_bus_exception)) {
+        cpu_restore_state(cs, retaddr, true);
+        env->sregs[SR_ESR] = access_type == MMU_INST_FETCH ?
+                             ESR_EC_INSN_BUS : ESR_EC_DATA_BUS;
+        env->sregs[SR_EAR] = addr;
+        helper_raise_exception(env, EXCP_HW_EXCP);
      }
  }
  #endif
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH v1 2/2] target/microblaze: Improve transaction failure handling

In reply to Edgar E. Iglesias
Quoted 8 lines · Edgar E. Iglesias

From: "Edgar E. Iglesias" <[email protected]>

When the CPU has exceptions disabled, avoid unwinding CPU state and clobbering registers if we're not going to raise any exception.

Alistair

Quoted 42 lines
---
 target/microblaze/op_helper.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
target/microblaze/op_helper.c +7 -13
index 13ac476199..190cd96c6a 100644
@@ -483,22 +483,17 @@ void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr,
     cpu = MICROBLAZE_CPU(cs);
     env = &cpu->env;
 
-    cpu_restore_state(cs, retaddr, true);
     if (!(env->sregs[SR_MSR] & MSR_EE)) {
         return;
     }
 
-    env->sregs[SR_EAR] = addr;
-    if (access_type == MMU_INST_FETCH) {
-        if (cpu->cfg.iopb_bus_exception) {
-            env->sregs[SR_ESR] = ESR_EC_INSN_BUS;
-            helper_raise_exception(env, EXCP_HW_EXCP);
-        }
-    } else {
-        if (cpu->cfg.dopb_bus_exception) {
-            env->sregs[SR_ESR] = ESR_EC_DATA_BUS;
-            helper_raise_exception(env, EXCP_HW_EXCP);
-        }
+    if ((access_type == MMU_INST_FETCH && cpu->cfg.iopb_bus_exception) ||
+        (access_type != MMU_INST_FETCH && cpu->cfg.dopb_bus_exception)) {
+        cpu_restore_state(cs, retaddr, true);
+        env->sregs[SR_ESR] = access_type == MMU_INST_FETCH ?
+                             ESR_EC_INSN_BUS : ESR_EC_DATA_BUS;
+        env->sregs[SR_EAR] = addr;
+        helper_raise_exception(env, EXCP_HW_EXCP);
     }
 }
 #endif
--

2.25.1

#7 lore raw

Re: [PATCH v1 2/2] target/microblaze: Improve transaction failure handling

In reply to Edgar E. Iglesias

target/microblaze/op_helper.c void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr, · line 496

Quoted 7 lines · Edgar E. Iglesias
target/microblaze/op_helper.c +7 -0
+    if ((access_type == MMU_INST_FETCH && cpu->cfg.iopb_bus_exception) ||
+        (access_type != MMU_INST_FETCH && cpu->cfg.dopb_bus_exception)) {
+        cpu_restore_state(cs, retaddr, true);
+        env->sregs[SR_ESR] = access_type == MMU_INST_FETCH ?
+                             ESR_EC_INSN_BUS : ESR_EC_DATA_BUS;
+        env->sregs[SR_EAR] = addr;
+        helper_raise_exception(env, EXCP_HW_EXCP);

I think it's better to use cpu_loop_exit_restore, adding the one line for cs->exception_index from helper_raise_exception.

r~

#8 lore raw

Re: [PATCH v1 2/2] target/microblaze: Improve transaction failure handling

Quoted 9 lines · Richard Henderson

target/microblaze/op_helper.c void mb_cpu_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr, · line 496

Quoted 7 lines · Edgar E. Iglesias
target/microblaze/op_helper.c +7 -0
+    if ((access_type == MMU_INST_FETCH && cpu->cfg.iopb_bus_exception) ||
+        (access_type != MMU_INST_FETCH && cpu->cfg.dopb_bus_exception)) {
+        cpu_restore_state(cs, retaddr, true);
+        env->sregs[SR_ESR] = access_type == MMU_INST_FETCH ?
+                             ESR_EC_INSN_BUS : ESR_EC_DATA_BUS;
+        env->sregs[SR_EAR] = addr;
+        helper_raise_exception(env, EXCP_HW_EXCP);
Quoted 3 lines

I think it's better to use cpu_loop_exit_restore, adding the one line for cs->exception_index from helper_raise_exception.

OK, let's use the patch you posted:

https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg07630.html

Thanks,
Edgar