target/arm: MTE fixes
cover target/arm: MTE fixes
One code cleanup and two bug fixes for MTE.
Vincenzo, thanks for the clear report. Can you please run this through your test case?
r~
Richard Henderson (3):
target/arm: Remove redundant mmu_idx lookup target/arm: Fix reported EL for mte_check_fail target/arm: Ignore HCR_EL2.ATA when {E2H,TGE} != 11
target/arm/internals.h | 9 +++++---- target/arm/helper.c | 9 +++++---- target/arm/mte_helper.c | 13 ++++--------- 3 files changed, 14 insertions(+), 17 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 target/arm: Remove redundant mmu_idx lookup
We already have the full ARMMMUIdx as computed from the function parameter.
For the purpose of regime_has_2_ranges, we can ignore any difference between AccType_Normal and AccType_Unpriv, which would be the only difference between the passed mmu_idx and arm_mmu_idx_el.
--- target/arm/mte_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/arm/mte_helper.c +1 -2
@@ -563,8 +563,7 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,case 2 :/* Tag check fail causes asynchronous flag set. */ - mmu_idx =arm_mmu_idx_el (env, el); -if (regime_has_2_ranges (mmu_idx)) { +if (regime_has_2_ranges (arm_mmu_idx)) { select =extract64 (dirty_ptr,55 ,1 ); }else { select =0 ;
Signature · 1 line
2.25.1
Re: [PATCH 1/3] target/arm: Remove redundant mmu_idx lookup
Quoted 19 lines · Richard Henderson
We already have the full ARMMMUIdx as computed from the function parameter.
For the purpose of
regime_has_2_ranges, we can ignore any difference betweenAccType_NormalandAccType_Unpriv, which would be the only difference between the passedmmu_idxandarm_mmu_idx_el.Signed-off-by Richard Henderson <[email protected]>--- target/arm/mte_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)target/arm/mte_helper.c +0
-0
target/arm/mte_helper.c static void mte_check_fail(CPUARMState *env, uint32_t desc, · line 569
Quoted 9 lines
target/arm/mte_helper.c +1
-2@@ -563,8 +563,7 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,case 2 :/* Tag check fail causes asynchronous flag set. */ - mmu_idx =arm_mmu_idx_el (env, el); -if (regime_has_2_ranges (mmu_idx)) { +if (regime_has_2_ranges (arm_mmu_idx)) { select =extract64 (dirty_ptr,55 ,1 ); }else { select =0 ;
Re: [PATCH 1/3] target/arm: Remove redundant mmu_idx lookup
In reply to Richard HendersonQuoted 9 lines · Richard Henderson
We already have the full ARMMMUIdx as computed from the function parameter.
For the purpose of
regime_has_2_ranges, we can ignore any difference betweenAccType_NormalandAccType_Unpriv, which would be the only difference between the passedmmu_idxandarm_mmu_idx_el.Signed-off-by Richard Henderson <[email protected]>
Quoted 19 lines
--- target/arm/mte_helper.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)target/arm/mte_helper.c +1
-2@@ -563,8 +563,7 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc,case 2 :/* Tag check fail causes asynchronous flag set. */ - mmu_idx =arm_mmu_idx_el (env, el); -if (regime_has_2_ranges (mmu_idx)) { +if (regime_has_2_ranges (arm_mmu_idx)) { select =extract64 (dirty_ptr,55 ,1 ); }else { select =0 ;
Signature · 2 lines
Regards, Vincenzo
PATCH 2/3 target/arm: Fix reported EL for mte_check_fail
In reply to Richard HendersonThe reporting in AArch64.TagCheckFail only depends on PSTATE.EL, and not the AccType of the operation. There are two guest visible problems that affect LDTR and STTR because of this:
(1) Selecting TCF0 vs TCF1 to decide on reporting,
(2) Report "data abort same el" not "data abort lower el".
--- target/arm/mte_helper.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
target/arm/mte_helper.c +3 -7
@@ -525,14 +525,10 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc, reg_el =regime_el (env, arm_mmu_idx); sctlr = env->cp15.sctlr_el[reg_el]; -switch (arm_mmu_idx) { -case ARMMMUIdx_E10_0: -case ARMMMUIdx_E20_0: - el =0 ; + el =arm_current_el (env); +if (el ==0 ) { tcf =extract64 (sctlr,38 ,2 ); -break ; -default : - el = reg_el; + }else { tcf =extract64 (sctlr,40 ,2 ); }
Signature · 1 line
2.25.1
Re: [PATCH 2/3] target/arm: Fix reported EL for mte_check_fail
Quoted 9 lines · Richard Henderson
The reporting in AArch64.TagCheckFail only depends on PSTATE.EL, and not the AccType of the operation. There are two guest visible problems that affect LDTR and STTR because of this:
(1) Selecting TCF0 vs TCF1 to decide on reporting,
(2) Report "data abort same el" not "data abort lower el".Reported-by Vincenzo Frascino <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Quoted 27 lines
--- target/arm/mte_helper.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)target/arm/mte_helper.c +3
-7@@ -525,14 +525,10 @@ static void mte_check_fail(CPUARMState *env, uint32_t desc, reg_el =regime_el (env, arm_mmu_idx); sctlr = env->cp15.sctlr_el[reg_el]; -switch (arm_mmu_idx) { -case ARMMMUIdx_E10_0: -case ARMMMUIdx_E20_0: - el =0 ; + el =arm_current_el (env); +if (el ==0 ) { tcf =extract64 (sctlr,38 ,2 ); -break ; -default : - el = reg_el; + }else { tcf =extract64 (sctlr,40 ,2 ); }
Signature · 2 lines
Regards, Vincenzo
PATCH 3/3 target/arm: Ignore HCR_EL2.ATA when {E2H,TGE} != 11
In reply to Richard HendersonUnlike many other bits in HCR_EL2, the description for this bit does not contain the phrase "if ... this field behaves as 0 for all purposes other than", so do not squash the bit in arm_hcr_el2_eff.
Instead, replicate the E2H+TGE test in the two places that require it.
--- target/arm/internals.h | 9 +++++---- target/arm/helper.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-)
target/arm/internals.h +5 -4
@@ -1252,10 +1252,11 @@ static inline bool allocation_tag_access_enabled(CPUARMState *env, int el, && !(env->cp15.scr_el3 & SCR_ATA)) {return false; } -if (el <2 - &&arm_feature (env,ARM_FEATURE_EL2 ) - && !(arm_hcr_el2_eff (env) &HCR_ATA )) { -return false; +if (el <2 &&arm_feature (env,ARM_FEATURE_EL2 )) { +uint64_t hcr =arm_hcr_el2_eff (env); +if (!(hcr &HCR_ATA ) && (!(hcr &HCR_E2H ) || !(hcr &HCR_TGE ))) { +return false; + } } sctlr &= (el ==0 ?SCTLR_ATA0 :SCTLR_ATA );return sctlr !=0 ;
target/arm/helper.c +5 -4
@@ -6874,10 +6874,11 @@ static CPAccessResult access_mte(CPUARMState *env, const ARMCPRegInfo *ri, {int el =arm_current_el (env); -if (el <2 && -arm_feature (env,ARM_FEATURE_EL2 ) && - !(arm_hcr_el2_eff (env) &HCR_ATA )) { -return CP_ACCESS_TRAP_EL2 ; +if (el <2 &&arm_feature (env,ARM_FEATURE_EL2 )) { +uint64_t hcr =arm_hcr_el2_eff (env); +if (!(hcr &HCR_ATA ) && (!(hcr &HCR_E2H ) || !(hcr &HCR_TGE ))) { +return CP_ACCESS_TRAP_EL2 ; + } } if (el < 3 && arm_feature(env, ARM_FEATURE_EL3) &&
Signature · 1 line
2.25.1
Re: [PATCH 3/3] target/arm: Ignore HCR_EL2.ATA when {E2H,TGE} != 11
Quoted 10 lines · Richard Henderson
Unlike many other bits in
HCR_EL2, the description for this bit does not contain the phrase "if ... this field behaves as 0 for all purposes other than", so do not squash the bit inarm_hcr_el2_eff.Instead, replicate the E2H+TGE test in the two places that require it.
Reported-by Vincenzo Frascino <[email protected]>Signed-off-by Richard Henderson <[email protected]>
Quoted 46 lines
--- target/arm/internals.h | 9 +++++---- target/arm/helper.c | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-)target/arm/internals.h +5
-4@@ -1252,10 +1252,11 @@ static inline bool allocation_tag_access_enabled(CPUARMState *env, int el, && !(env->cp15.scr_el3 & SCR_ATA)) {return false; } -if (el <2 - &&arm_feature (env,ARM_FEATURE_EL2 ) - && !(arm_hcr_el2_eff (env) &HCR_ATA )) { -return false; +if (el <2 &&arm_feature (env,ARM_FEATURE_EL2 )) { +uint64_t hcr =arm_hcr_el2_eff (env); +if (!(hcr &HCR_ATA ) && (!(hcr &HCR_E2H ) || !(hcr &HCR_TGE ))) { +return false; + } } sctlr &= (el ==0 ?SCTLR_ATA0 :SCTLR_ATA );return sctlr !=0 ;target/arm/helper.c +5
-4@@ -6874,10 +6874,11 @@ static CPAccessResult access_mte(CPUARMState *env, const ARMCPRegInfo *ri, {int el =arm_current_el (env); -if (el <2 && -arm_feature (env,ARM_FEATURE_EL2 ) && - !(arm_hcr_el2_eff (env) &HCR_ATA )) { -return CP_ACCESS_TRAP_EL2 ; +if (el <2 &&arm_feature (env,ARM_FEATURE_EL2 )) { +uint64_t hcr =arm_hcr_el2_eff (env); +if (!(hcr &HCR_ATA ) && (!(hcr &HCR_E2H ) || !(hcr &HCR_TGE ))) { +return CP_ACCESS_TRAP_EL2 ; + } } if (el < 3 && arm_feature(env, ARM_FEATURE_EL3) &&
Signature · 2 lines
Regards, Vincenzo
Hi Richard,
Quoted 6 lines · Richard Henderson
One code cleanup and two bug fixes for MTE.
Vincenzo, thanks for the clear report. Can you please run this through your test case?
No problem, thank you for addressing the issues quickly. I did run my tests and added my tags to the relevant patches.
Quoted 13 lines
r~
Richard Henderson (3):
target/arm: Remove redundantmmu_idxlookup target/arm: Fix reported EL formte_check_failtarget/arm: Ignore HCR_EL2.ATA when {E2H,TGE} != 11target/arm/internals.h | 9 +++++---- target/arm/helper.c | 9 +++++---- target/arm/mte_helper.c | 13 ++++--------- 3 files changed, 14 insertions(+), 17 deletions(-)
Signature · 2 lines
Regards, Vincenzo
Peter Maydell
AppliedQuoted 7 lines · Richard Henderson
One code cleanup and two bug fixes for MTE.
Vincenzo, thanks for the clear report. Can you please run this through your test case?
Quoted 7 lines
r~
Richard Henderson (3):
target/arm: Remove redundantmmu_idxlookup target/arm: Fix reported EL formte_check_failtarget/arm: Ignore HCR_EL2.ATA when {E2H,TGE} != 11
Applied to target-arm.next, thanks.
-- PMM