target/microblaze: Improve bus fault handling
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
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.
--- target/microblaze/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/microblaze/op_helper.c +2 -2
@@ -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
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")Signed-off-by Edgar E. Iglesias <[email protected]>
Quoted 24 lines
--- target/microblaze/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/microblaze/op_helper.c +2
-2@@ -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 ); }
Re: [PATCH v1 1/2] target/microblaze: Use CPU properties to conditionalize bus exceptions
In reply to Edgar E. IglesiasQuoted 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")Signed-off-by Edgar E. Iglesias <[email protected]>
Alistair
Quoted 27 lines
--- target/microblaze/op_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/microblaze/op_helper.c +2
-3@@ -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
PATCH 2/2 target/microblaze: Improve transaction failure handling
In reply to Edgar E. IglesiasFrom: "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
@@ -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
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.
Signed-off-by Edgar E. Iglesias <[email protected]>
Quoted 39 lines
--- target/microblaze/op_helper.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)target/microblaze/op_helper.c +7
-12@@ -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
Re: [PATCH v1 2/2] target/microblaze: Improve transaction failure handling
In reply to Edgar E. IglesiasQuoted 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.
Signed-off-by Edgar E. Iglesias <[email protected]>
Alistair
Quoted 42 lines
--- target/microblaze/op_helper.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)target/microblaze/op_helper.c +7
-13@@ -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
Re: [PATCH v1 2/2] target/microblaze: Improve transaction failure handling
In reply to Edgar E. Iglesiastarget/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~
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 forcs->exception_indexfromhelper_raise_exception.
OK, let's use the patch you posted:
https://lists.gnu.org/archive/html/qemu-devel/2020-08/msg07630.html
Thanks,
Edgar