target/arm: fix missing exception class
v2 cover target/arm: fix missing exception class
Thanks Peter for the suggestions, I also added a patch to switch a couple of cpu_restore_state+raise_exception pairs in stack limit exception handling for both v7m and v8m.
v2:
- fix raise_exception_ra to restore state before raising exception
- remove redundant do_raise_exception
- remove now redundant open coded raise_exception_ra from MTE and stack limit exception handling
Jamie Iles (4):
target/arm: fix missing exception class target/arm: fold do_raise_exception into raise_exception target/arm: use raise_exception_ra for MTE check failure target/arm: use raise_exception_ra for stack limit exception
target/arm/m_helper.c | 5 +---- target/arm/mte_helper.c | 11 ++--------- target/arm/op_helper.c | 28 +++++++--------------------- 3 files changed, 10 insertions(+), 34 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/4 target/arm: fix missing exception class
The DAIF and PAC checks used raise_exception_ra to raise an exception and unwind CPU state but raise_exception_ra is currently designed for handling data aborts as the syndrome is partially precomputed and encoded in the TB and then merged in merge_syn_data_abort when handling the data abort. Using raise_exception_ra for DAIF and PAC checks results in an empty syndrome being retrieved from data[2] in restore_state_to_opc and setting ESR to 0. This manifested as:
kvm [571]: Unknown exception class: esr: 0x000000 – Unknown/Uncategorized
when launching a KVM guest when the host qemu used a CPU supporting EL2+pointer authentication and enabling pointer authentication in the guest.
Rework raise_exception_ra such that the state is restored before raising the exception so that the exception is not clobbered by restore_state_to_opc.
--- target/arm/op_helper.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
target/arm/op_helper.c +4 -2
@@ -63,8 +63,10 @@ void raise_exception(CPUARMState *env, uint32_t excp,void raise_exception_ra (CPUARMState *env,uint32_t excp,uint32_t syndrome,uint32_t target_el,uintptr_t ra) { -CPUState *cs =do_raise_exception (env, excp, syndrome, target_el); -cpu_loop_exit_restore (cs, ra); +CPUState *cs =env_cpu (env); + +cpu_restore_state (cs, ra, true); +raise_exception (env, excp, syndrome, target_el); } uint64_t HELPER(neon_tbl)(CPUARMState *env, uint32_t desc,
Signature · 1 line
2.30.2
PATCH v2 2/4 target/arm: fold do_raise_exception into raise_exception
In reply to Jamie IlesNow that there are no other users of do_raise_exception, fold it into raise_exception.
--- target/arm/op_helper.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
target/arm/op_helper.c +2 -10
@@ -27,8 +27,8 @@#define SIGNBIT (uint32_t)0x80000000#define SIGNBIT64 ((uint64_t)1 << 63) -static CPUState *do_raise_exception (CPUARMState *env,uint32_t excp, -uint32_t syndrome,uint32_t target_el) +void raise_exception (CPUARMState *env,uint32_t excp, +uint32_t syndrome,uint32_t target_el) {CPUState *cs =env_cpu (env);
@@ -49,14 +49,6 @@ static CPUState *do_raise_exception(CPUARMState *env, uint32_t excp, cs->exception_index = excp; env->exception.syndrome = syndrome; env->exception.target_el = target_el; - -return cs; -} - -void raise_exception (CPUARMState *env,uint32_t excp, -uint32_t syndrome,uint32_t target_el) -{ -CPUState *cs =do_raise_exception (env, excp, syndrome, target_el);cpu_loop_exit (cs); }
Signature · 1 line
2.30.2
PATCH v2 3/4 target/arm: use raise_exception_ra for MTE check failure
In reply to Jamie IlesNow that raise_exception_ra restores the state before raising the exception we can use restore_exception_ra to perform the state restore + exception raising without clobbering the syndrome.
--- target/arm/mte_helper.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
target/arm/mte_helper.c +2 -9
@@ -563,20 +563,13 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,switch (tcf) {case 1 : -/* -* Tag check fail causes a synchronous exception. -* -* In restore_state_to_opc, we set the exception syndrome -* for the load or store operation. Unwind first so we -* may overwrite that with the syndrome for the tag check. -*/ -cpu_restore_state (env_cpu (env), ra, true); env->exception.vaddress = dirty_ptr; is_write =FIELD_EX32 (desc,MTEDESC ,WRITE ); syn =syn_data_abort_no_iss (arm_current_el (env) !=0 ,0 ,0 ,0 ,0 , is_write,0x11 ); -raise_exception (env,EXCP_DATA_ABORT , syn,exception_target_el (env)); +raise_exception_ra (env,EXCP_DATA_ABORT , syn, +exception_target_el (env), ra);/* noreturn, but fall through to the assert anyway */ case 0 :
Signature · 1 line
2.30.2
PATCH v2 4/4 target/arm: use raise_exception_ra for stack limit exception
In reply to Jamie IlesNow that raise_exception_ra restores the state before raising the exception we can use restore_exception_ra to perform the state restore + exception raising without clobbering the PC/condbits.
--- target/arm/m_helper.c | 5 +---- target/arm/op_helper.c | 10 +--------- 2 files changed, 2 insertions(+), 13 deletions(-)
target/arm/m_helper.c +1 -4
@@ -2600,10 +2600,7 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val) limit = is_psp ? env->v7m.psplim[false] : env->v7m.msplim[false];if (val < limit) { -CPUState *cs =env_cpu (env); - -cpu_restore_state (cs,GETPC (), true); -raise_exception (env,EXCP_STKOF ,0 ,1 ); +raise_exception_ra (env,EXCP_STKOF ,0 ,1 ,GETPC ()); }if (is_psp) {
target/arm/op_helper.c +1 -9
@@ -90,15 +90,7 @@ void HELPER(v8m_stackcheck)(CPUARMState *env, uint32_t newvalue)* raising an exception if the limit is breached. */ if (newvalue <v7m_sp_limit (env)) { -CPUState *cs =env_cpu (env); - -/* -* Stack limit exceptions are a rare case, so rather than syncing -* PC/condbits before the call, we use cpu_restore_state() to -* get them right before raising the exception. -*/ -cpu_restore_state (cs,GETPC (), true); -raise_exception (env,EXCP_STKOF ,0 ,1 ); +raise_exception_ra (env,EXCP_STKOF ,0 ,1 ,GETPC ()); } }
Signature · 1 line
2.30.2
Peter Maydell
AppliedQuoted 10 lines · Jamie Iles
Thanks Peter for the suggestions, I also added a patch to switch a couple of cpu_restore_state+raise_exception pairs in stack limit exception handling for both v7m and v8m.
v2:
- fixraise_exception_rato restore state before raising exception
- remove redundantdo_raise_exception
- remove now redundant open codedraise_exception_rafrom MTE and stack limit exception handling
Applied to target-arm.next, thanks. (I tweaked a couple of comments and commit messages.)
-- PMM