target/arm: Introduce aarch64_set_svcr
v2 cover target/arm: Introduce aarch64_set_svcr
This is a respin of Richard's patch
https://lore.kernel.org/qemu-devel/[email protected]/
but split in multiple trivial changes, as I was having hard time to understand all changes at once while reviewing it.
Richard Henderson (7):
target/arm/sme: Reorg SME access handling in handle_msr_i() target/arm/sme: Rebuild hflags in set_pstate() helpers target/arm/sme: Introduce aarch64_set_svcr() target/arm/sme: Reset SVE state in aarch64_set_svcr() target/arm/sme: Reset ZA state in aarch64_set_svcr() target/arm/sme: Rebuild hflags in aarch64_set_svcr() target/arm/sme: Unify set_pstate() SM/ZA helpers as set_svcr()
linux-user/aarch64/cpu_loop.c | 11 ++-------- linux-user/aarch64/signal.c | 13 ++--------- target/arm/cpu.h | 2 +- target/arm/helper-sme.h | 3 +-- target/arm/helper.c | 41 ++++++++++++++++++++++++++++++++--- target/arm/sme_helper.c | 37 ++----------------------------- target/arm/translate-a64.c | 19 ++++++---------- 7 files changed, 53 insertions(+), 73 deletions(-)
Signature · 1 line
2.38.1
PATCH v2 1/7 target/arm/sme: Reorg SME access handling in handle_msr_i()
From: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
--- target/arm/translate-a64.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
target/arm/translate-a64.c +13 -11
@@ -1841,18 +1841,20 @@ static void handle_msr_i(DisasContext *s, uint32_t insn, goto do_unallocated; }if (sme_access_check (s)) { -bool i = crm &1 ; -bool changed = false; +int old = s->pstate_sm | (s->pstate_za <<1 ); +int new = (crm &1 ) *3 ; +int msk = (crm >>1 ) &3 ; -if ((crm &2 ) && i != s->pstate_sm) { -gen_helper_set_pstate_sm (cpu_env,tcg_constant_i32 (i)); - changed = true; - } -if ((crm &4 ) && i != s->pstate_za) { -gen_helper_set_pstate_za (cpu_env,tcg_constant_i32 (i)); - changed = true; - } -if (changed) { +if ((old ^ new) & msk) { +/* At least one bit changes. */ +bool i = crm &1 ; + +if ((crm &2 ) && i != s->pstate_sm) { +gen_helper_set_pstate_sm (cpu_env,tcg_constant_i32 (i)); + } +if ((crm &4 ) && i != s->pstate_za) { +gen_helper_set_pstate_za (cpu_env,tcg_constant_i32 (i)); + }gen_rebuild_hflags (s); }else { s->base.is_jmp =DISAS_NEXT ;
Signature · 1 line
2.38.1
PATCH v2 2/7 target/arm/sme: Rebuild hflags in set_pstate() helpers
In reply to Philippe Mathieu-DaudéFrom: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
--- target/arm/sme_helper.c | 2 ++ target/arm/translate-a64.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
target/arm/sme_helper.c +2 -0
@@ -45,6 +45,7 @@ void helper_set_pstate_sm(CPUARMState *env, uint32_t i) } env->svcr ^=R_SVCR_SM_MASK ;arm_reset_sve_state (env); +arm_rebuild_hflags (env); }void helper_set_pstate_za (CPUARMState *env,uint32_t i)
@@ -65,6 +66,7 @@ void helper_set_pstate_za(CPUARMState *env, uint32_t i)if (i) {memset (env->zarray,0 ,sizeof (env->zarray)); } +arm_rebuild_hflags (env); }void helper_sme_zero (CPUARMState *env,uint32_t imm,uint32_t svl)
target/arm/translate-a64.c +0 -1
@@ -1855,7 +1855,6 @@ static void handle_msr_i(DisasContext *s, uint32_t insn,if ((crm &4 ) && i != s->pstate_za) {gen_helper_set_pstate_za (cpu_env,tcg_constant_i32 (i)); } -gen_rebuild_hflags (s); }else { s->base.is_jmp =DISAS_NEXT ; }
Signature · 1 line
2.38.1
PATCH v2 3/7 target/arm/sme: Introduce aarch64_set_svcr()
In reply to Philippe Mathieu-DaudéFrom: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
--- linux-user/aarch64/cpu_loop.c | 2 +- linux-user/aarch64/signal.c | 2 +- target/arm/cpu.h | 1 + target/arm/helper.c | 8 ++++++++ target/arm/sme_helper.c | 4 ++-- 5 files changed, 13 insertions(+), 4 deletions(-)
linux-user/aarch64/cpu_loop.c +1 -1
@@ -93,8 +93,8 @@ void cpu_loop(CPUARMState *env)* On syscall, PSTATE.ZA is preserved, along with the ZA matrix. * PSTATE.SM is cleared, per SMSTOP, which does ResetSVEState. */ +aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK );if (FIELD_EX64 (env->svcr,SVCR ,SM )) { - env->svcr =FIELD_DP64 (env->svcr,SVCR ,SM ,0 );arm_rebuild_hflags (env);arm_reset_sve_state (env); }
linux-user/aarch64/signal.c +1 -1
@@ -669,11 +669,11 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,* Invoke the signal handler with both SM and ZA disabled. * When clearing SM, ResetSVEState, per SMSTOP. */ +aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK |R_SVCR_ZA_MASK );if (FIELD_EX64 (env->svcr,SVCR ,SM )) {arm_reset_sve_state (env); }if (env->svcr) { - env->svcr =0 ;arm_rebuild_hflags (env); }
target/arm/cpu.h +1 -0
@@ -1123,6 +1123,7 @@ int aarch64_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);void aarch64_sve_narrow_vq (CPUARMState *env,unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64); +void aarch64_set_svcr (CPUARMState *env,uint64_t new,uint64_t mask);void arm_reset_sve_state (CPUARMState *env);/*
target/arm/helper.c +8 -0
@@ -6722,11 +6722,19 @@ static CPAccessResult access_esm(CPUARMState *env, const ARMCPRegInfo *ri,return CP_ACCESS_OK ; } +void aarch64_set_svcr (CPUARMState *env,uint64_t new,uint64_t mask) +{ +uint64_t change = (env->svcr ^ new) & mask; + + env->svcr ^= change; +} +static void svcr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) {helper_set_pstate_sm (env,FIELD_EX64 (value,SVCR ,SM ));helper_set_pstate_za (env,FIELD_EX64 (value,SVCR ,ZA )); +aarch64_set_svcr (env, value,-1 );arm_rebuild_hflags (env); }
target/arm/sme_helper.c +2 -2
@@ -43,7 +43,7 @@ void helper_set_pstate_sm(CPUARMState *env, uint32_t i)if (i ==FIELD_EX64 (env->svcr,SVCR ,SM )) {return ; } - env->svcr ^=R_SVCR_SM_MASK ; +aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK );arm_reset_sve_state (env);arm_rebuild_hflags (env); }
@@ -53,7 +53,7 @@ void helper_set_pstate_za(CPUARMState *env, uint32_t i)if (i ==FIELD_EX64 (env->svcr,SVCR ,ZA )) {return ; } - env->svcr ^=R_SVCR_ZA_MASK ; +aarch64_set_svcr (env,0 ,R_SVCR_ZA_MASK );/* * ResetSMEState.
Signature · 1 line
2.38.1
PATCH v2 4/7 target/arm/sme: Reset SVE state in aarch64_set_svcr()
In reply to Philippe Mathieu-DaudéFrom: Richard Henderson <[email protected]>
Move arm_reset_sve_state() calls to aarch64_set_svcr().
Message-Id: <[email protected]>
--- linux-user/aarch64/cpu_loop.c | 1 - linux-user/aarch64/signal.c | 8 +------- target/arm/cpu.h | 1 - target/arm/helper.c | 13 +++++++++++++ target/arm/sme_helper.c | 10 ---------- 5 files changed, 14 insertions(+), 19 deletions(-)
linux-user/aarch64/cpu_loop.c +0 -1
@@ -96,7 +96,6 @@ void cpu_loop(CPUARMState *env)aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK );if (FIELD_EX64 (env->svcr,SVCR ,SM )) {arm_rebuild_hflags (env); -arm_reset_sve_state (env); } ret = do_syscall(env, env->xregs[8],
linux-user/aarch64/signal.c +1 -7
@@ -665,14 +665,8 @@ static void target_setup_frame(int usig, struct target_sigaction *ka, env->btype =2 ; } -/* -* Invoke the signal handler with both SM and ZA disabled. -* When clearing SM, ResetSVEState, per SMSTOP. -*/ +/* Invoke the signal handler with both SM and ZA disabled. */ aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK |R_SVCR_ZA_MASK ); -if (FIELD_EX64 (env->svcr,SVCR ,SM )) { -arm_reset_sve_state (env); - }if (env->svcr) {arm_rebuild_hflags (env); }
target/arm/cpu.h +0 -1
@@ -1124,7 +1124,6 @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64);void aarch64_set_svcr (CPUARMState *env,uint64_t new,uint64_t mask); -void arm_reset_sve_state (CPUARMState *env);/* * SVE registers are encoded in KVM's memory in an endianness-invariant format.
target/arm/helper.c +13 -0
@@ -6722,11 +6722,24 @@ static CPAccessResult access_esm(CPUARMState *env, const ARMCPRegInfo *ri,return CP_ACCESS_OK ; } +/* ResetSVEState */ +static void arm_reset_sve_state (CPUARMState *env) +{ +memset (env->vfp.zregs,0 ,sizeof (env->vfp.zregs)); +/* Recall that FFR is stored as pregs[16]. */ +memset (env->vfp.pregs,0 ,sizeof (env->vfp.pregs)); +vfp_set_fpcr (env,0x0800009f ); +} +void aarch64_set_svcr (CPUARMState *env,uint64_t new,uint64_t mask) {uint64_t change = (env->svcr ^ new) & mask; env->svcr ^= change; + +if (change &R_SVCR_SM_MASK ) { +arm_reset_sve_state (env); + } } static void svcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
target/arm/sme_helper.c +0 -10
@@ -29,22 +29,12 @@#include "vec_internal.h" #include "sve_ldst_internal.h" -/* ResetSVEState */ -void arm_reset_sve_state (CPUARMState *env) -{ -memset (env->vfp.zregs,0 ,sizeof (env->vfp.zregs)); -/* Recall that FFR is stored as pregs[16]. */ -memset (env->vfp.pregs,0 ,sizeof (env->vfp.pregs)); -vfp_set_fpcr (env,0x0800009f ); -} -void helper_set_pstate_sm (CPUARMState *env,uint32_t i) {if (i ==FIELD_EX64 (env->svcr,SVCR ,SM )) {return ; }aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK ); -arm_reset_sve_state (env);arm_rebuild_hflags (env); }
Signature · 1 line
2.38.1
PATCH v2 5/7 target/arm/sme: Reset ZA state in aarch64_set_svcr()
In reply to Philippe Mathieu-DaudéFrom: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
--- target/arm/helper.c | 12 ++++++++++++ target/arm/sme_helper.c | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-)
target/arm/helper.c +12 -0
@@ -6740,6 +6740,18 @@ void aarch64_set_svcr(CPUARMState *env, uint64_t new, uint64_t mask)if (change &R_SVCR_SM_MASK ) {arm_reset_sve_state (env); } + +/* +* ResetSMEState. +* +* SetPSTATE_ZA zeros on enable and disable. We can zero this only +* on enable: while disabled, the storage is inaccessible and the +* value does not matter. We're not saving the storage in vmstate +* when disabled either. +*/ +if (change & new &R_SVCR_ZA_MASK ) { +memset (env->zarray,0 ,sizeof (env->zarray)); + } } static void svcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
target/arm/sme_helper.c +0 -12
@@ -44,18 +44,6 @@ void helper_set_pstate_za(CPUARMState *env, uint32_t i)return ; }aarch64_set_svcr (env,0 ,R_SVCR_ZA_MASK ); - -/* -* ResetSMEState. -* -* SetPSTATE_ZA zeros on enable and disable. We can zero this only -* on enable: while disabled, the storage is inaccessible and the -* value does not matter. We're not saving the storage in vmstate -* when disabled either. -*/ -if (i) { -memset (env->zarray,0 ,sizeof (env->zarray)); - }arm_rebuild_hflags (env); }
Signature · 1 line
2.38.1
PATCH v2 6/7 target/arm/sme: Rebuild hflags in aarch64_set_svcr()
In reply to Philippe Mathieu-DaudéFrom: Richard Henderson <[email protected]>
Message-Id: <[email protected]>
--- linux-user/aarch64/cpu_loop.c | 8 +------- linux-user/aarch64/signal.c | 3 --- target/arm/helper.c | 6 +++++- target/arm/sme_helper.c | 8 -------- 4 files changed, 6 insertions(+), 19 deletions(-)
linux-user/aarch64/cpu_loop.c +1 -7
@@ -89,14 +89,8 @@ void cpu_loop(CPUARMState *env)switch (trapnr) {case EXCP_SWI : -/* -* On syscall, PSTATE.ZA is preserved, along with the ZA matrix. -* PSTATE.SM is cleared, per SMSTOP, which does ResetSVEState. -*/ +/* On syscall, PSTATE.ZA is preserved, PSTATE.SM is cleared. */ aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK ); -if (FIELD_EX64 (env->svcr,SVCR ,SM )) { -arm_rebuild_hflags (env); - } ret = do_syscall(env, env->xregs[8], env->xregs[0],
linux-user/aarch64/signal.c +0 -3
@@ -667,9 +667,6 @@ static void target_setup_frame(int usig, struct target_sigaction *ka,/* Invoke the signal handler with both SM and ZA disabled. */ aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK |R_SVCR_ZA_MASK ); -if (env->svcr) { -arm_rebuild_hflags (env); - }if (info) {tswap_siginfo (&frame->info, info);
target/arm/helper.c +5 -1
@@ -6735,6 +6735,9 @@ void aarch64_set_svcr(CPUARMState *env, uint64_t new, uint64_t mask) {uint64_t change = (env->svcr ^ new) & mask; +if (change ==0 ) { +return ; + } env->svcr ^= change;if (change &R_SVCR_SM_MASK ) {
@@ -6752,6 +6755,8 @@ void aarch64_set_svcr(CPUARMState *env, uint64_t new, uint64_t mask)if (change & new &R_SVCR_ZA_MASK ) {memset (env->zarray,0 ,sizeof (env->zarray)); } + +arm_rebuild_hflags (env); } static void svcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
@@ -6760,7 +6765,6 @@ static void svcr_write(CPUARMState *env, const ARMCPRegInfo *ri,helper_set_pstate_sm (env,FIELD_EX64 (value,SVCR ,SM ));helper_set_pstate_za (env,FIELD_EX64 (value,SVCR ,ZA ));aarch64_set_svcr (env, value,-1 ); -arm_rebuild_hflags (env); } static void smcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
target/arm/sme_helper.c +0 -8
@@ -31,20 +31,12 @@void helper_set_pstate_sm (CPUARMState *env,uint32_t i) { -if (i ==FIELD_EX64 (env->svcr,SVCR ,SM )) { -return ; - }aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK ); -arm_rebuild_hflags (env); }void helper_set_pstate_za (CPUARMState *env,uint32_t i) { -if (i ==FIELD_EX64 (env->svcr,SVCR ,ZA )) { -return ; - }aarch64_set_svcr (env,0 ,R_SVCR_ZA_MASK ); -arm_rebuild_hflags (env); }void helper_sme_zero (CPUARMState *env,uint32_t imm,uint32_t svl)
Signature · 1 line
2.38.1
PATCH v2 7/7 target/arm/sme: Unify set_pstate() SM/ZA helpers as set_svcr()
In reply to Philippe Mathieu-DaudéFrom: Richard Henderson <[email protected]>
Unify the two helper_set_pstate_{sm,za} in this function. Do not call helper_* functions from svcr_write.
Message-Id: <[email protected]>
--- target/arm/helper-sme.h | 3 +-- target/arm/helper.c | 2 -- target/arm/sme_helper.c | 9 ++------- target/arm/translate-a64.c | 10 ++-------- 4 files changed, 5 insertions(+), 19 deletions(-)
target/arm/helper-sme.h +1 -2
@@ -17,8 +17,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ -DEF_HELPER_FLAGS_2(set_pstate_sm, TCG_CALL_NO_RWG, void, env, i32) -DEF_HELPER_FLAGS_2(set_pstate_za, TCG_CALL_NO_RWG, void, env, i32) +DEF_HELPER_FLAGS_3(set_svcr, TCG_CALL_NO_RWG, void, env, i32, i32)DEF_HELPER_FLAGS_3 (sme_zero,TCG_CALL_NO_RWG , void, env, i32, i32)
target/arm/helper.c +0 -2
@@ -6762,8 +6762,6 @@ void aarch64_set_svcr(CPUARMState *env, uint64_t new, uint64_t mask)static void svcr_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value) { -helper_set_pstate_sm (env,FIELD_EX64 (value,SVCR ,SM )); -helper_set_pstate_za (env,FIELD_EX64 (value,SVCR ,ZA ));aarch64_set_svcr (env, value,-1 ); }
target/arm/sme_helper.c +2 -7
@@ -29,14 +29,9 @@#include "vec_internal.h" #include "sve_ldst_internal.h" -void helper_set_pstate_sm (CPUARMState *env,uint32_t i) +void helper_set_svcr (CPUARMState *env,uint32_t val,uint32_t mask) { -aarch64_set_svcr (env,0 ,R_SVCR_SM_MASK ); -} - -void helper_set_pstate_za (CPUARMState *env,uint32_t i) -{ -aarch64_set_svcr (env,0 ,R_SVCR_ZA_MASK ); +aarch64_set_svcr (env, val, mask); }void helper_sme_zero (CPUARMState *env,uint32_t imm,uint32_t svl)
target/arm/translate-a64.c +2 -8
@@ -1847,14 +1847,8 @@ static void handle_msr_i(DisasContext *s, uint32_t insn,if ((old ^ new) & msk) {/* At least one bit changes. */ -bool i = crm &1 ; - -if ((crm &2 ) && i != s->pstate_sm) { -gen_helper_set_pstate_sm (cpu_env,tcg_constant_i32 (i)); - } -if ((crm &4 ) && i != s->pstate_za) { -gen_helper_set_pstate_za (cpu_env,tcg_constant_i32 (i)); - } +gen_helper_set_svcr (cpu_env,tcg_constant_i32 (new), +tcg_constant_i32 (msk)); }else { s->base.is_jmp =DISAS_NEXT ; }
Signature · 1 line
2.38.1
Quoted 14 lines · Philippe Mathieu-Daudé
This is a respin of Richard's patch
https://lore.kernel.org/qemu-devel/[email protected]/
but split in multiple trivial changes, as I was having hard time to understand all changes at once while reviewing it.Richard Henderson (7):
target/arm/sme: Reorg SME access handling inhandle_msr_i()target/arm/sme: Rebuild hflags inset_pstate()helpers target/arm/sme: Introduceaarch64_set_svcr()target/arm/sme: Reset SVE state inaarch64_set_svcr()target/arm/sme: Reset ZA state inaarch64_set_svcr()target/arm/sme: Rebuild hflags inaarch64_set_svcr()target/arm/sme: Unifyset_pstate()SM/ZA helpers asset_svcr()
Quoted 8 lines
linux-user/aarch64/cpu_loop.c | 11 ++-------- linux-user/aarch64/signal.c | 13 ++--------- target/arm/cpu.h | 2 +- target/arm/helper-sme.h | 3 +-- target/arm/helper.c | 41 ++++++++++++++++++++++++++++++++--- target/arm/sme_helper.c | 37 ++----------------------------- target/arm/translate-a64.c | 19 ++++++---------- 7 files changed, 53 insertions(+), 73 deletions(-)
Peter Maydell
AppliedQuoted 6 lines · Philippe Mathieu-Daudé
This is a respin of Richard's patch
https://lore.kernel.org/qemu-devel/[email protected]/
but split in multiple trivial changes, as I was having hard time to understand all changes at once while reviewing it.
Applied to target-arm.next, thanks.
-- PMM