target/arm: a few timer fixes while checking FEAT_ECV_POFF
cover target/arm: a few timer fixes while checking FEAT_ECV_POFF
While I was checking what was needed for FEAT_ECV_POFF I discovered a few potential correctness issues. We had actually already done the work for the feature so the final patch is just documentation.
Alex.
Alex Bennée (5):
target/arm: split evaluation of CNTHCTL timer IRQ masks target/arm: trigger timer recalculation when toggling CNTHCTL:ECV target/arm: trigger timer recalc on SCR:ECVEN change target/arm: trigger timer recalc on HCR:(E2H|TGE) changes docs/system: add FEAT_ECV_POFF to the emulation list
docs/system/arm/emulation.rst | 1 + target/arm/helper.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.3
PATCH 1/5 target/arm: split evaluation of CNTHCTL timer IRQ masks
Whether the physical and virtual timer IRQs are masked are independent of each other so the checking of CNTHCTL:CNTPMASK shouldn't depend of not changing CNTVMASK.
While unlikely to be seen in real life we should still make sure we behave correctly.
--- target/arm/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/helper.c +2 -1
@@ -1802,7 +1802,8 @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri,if ((oldval ^ value) &R_CNTHCTL_CNTVMASK_MASK ) {gt_update_irq (cpu,GTIMER_VIRT ); - }else if ((oldval ^ value) &R_CNTHCTL_CNTPMASK_MASK ) { + } +if ((oldval ^ value) &R_CNTHCTL_CNTPMASK_MASK ) {gt_update_irq (cpu,GTIMER_PHYS ); } }
Signature · 1 line
2.47.3
Re: [PATCH 1/5] target/arm: split evaluation of CNTHCTL timer IRQ masks
Quoted 17 lines · Alex Bennée
Whether the physical and virtual timer IRQs are masked are independent of each other so the checking of CNTHCTL:CNTPMASK shouldn't depend of not changing CNTVMASK.
While unlikely to be seen in real life we should still make sure we behave correctly.
Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/arm/helper.c +0
-0
target/arm/helper.c static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 1809
Quoted 9 lines
target/arm/helper.c +2
-1@@ -1802,7 +1802,8 @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri,if ((oldval ^ value) &R_CNTHCTL_CNTVMASK_MASK ) {gt_update_irq (cpu,GTIMER_VIRT ); - }else if ((oldval ^ value) &R_CNTHCTL_CNTPMASK_MASK ) { + } +if ((oldval ^ value) &R_CNTHCTL_CNTPMASK_MASK ) {gt_update_irq (cpu,GTIMER_PHYS ); } }
r~
PATCH 2/5 target/arm: trigger timer recalculation when toggling CNTHCTL:ECV
In reply to Alex BennéeWhen toggling the state of ECV we affect the offset applied to timers. As a result we should trigger a recalculation of the timer value to take into account the new offset.
--- target/arm/helper.c | 3 +++ 1 file changed, 3 insertions(+)
target/arm/helper.c +3 -0
@@ -1806,6 +1806,9 @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri,if ((oldval ^ value) &R_CNTHCTL_CNTPMASK_MASK ) {gt_update_irq (cpu,GTIMER_PHYS ); } +if ((oldval ^ value) &R_CNTHCTL_ECV_MASK ) { +gt_recalc_timer (cpu,GTIMER_PHYS ); + } } static void gt_cntvoff_write(CPUARMState *env, const ARMCPRegInfo *ri,
Signature · 1 line
2.47.3
Re: [PATCH 2/5] target/arm: trigger timer recalculation when toggling CNTHCTL:ECV
Quoted 14 lines · Alex Bennée
When toggling the state of ECV we affect the offset applied to timers. As a result we should trigger a recalculation of the timer value to take into account the new offset.
Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 3 +++ 1 file changed, 3 insertions(+)target/arm/helper.c +0
-0
target/arm/helper.c static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, · line 1814
Quoted 9 lines
target/arm/helper.c +3
-0@@ -1806,6 +1806,9 @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri,if ((oldval ^ value) &R_CNTHCTL_CNTPMASK_MASK ) {gt_update_irq (cpu,GTIMER_PHYS ); } +if ((oldval ^ value) &R_CNTHCTL_ECV_MASK ) { +gt_recalc_timer (cpu,GTIMER_PHYS ); + } } static void gt_cntvoff_write(CPUARMState *env, const ARMCPRegInfo *ri,
r~
PATCH 3/5 target/arm: trigger timer recalc on SCR:ECVEN change
In reply to Alex BennéeToggling the ECVEN state affects the offset calculated in gt_phys_raw_cnt_offset so we should trigger a re-calculation on its change.
--- target/arm/helper.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target/arm/helper.c +9 -0
@@ -37,6 +37,9 @@#include "qemu/plugin.h" static void switch_mode (CPUARMState *env,int mode); +#ifndef CONFIG_USER_ONLY +static void gt_recalc_timer (ARMCPU *cpu,int timeridx); +#endif int compare_u64 (const void *a,const void *b) {
@@ -821,6 +824,12 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) changed = env->cp15.scr_el3 ^ value; env->cp15.scr_el3 = value; +#ifndef CONFIG_USER_ONLY +if (changed &SCR_ECVEN ) { +gt_recalc_timer (cpu,GTIMER_PHYS ); + } +#endif +/* * If SCR_EL3.{NS,NSE} changes, i.e. change of security state, * we must invalidate all TLBs below EL3.
Signature · 1 line
2.47.3
Re: [PATCH 3/5] target/arm: trigger timer recalc on SCR:ECVEN change
Quoted 26 lines · Alex Bennée
Toggling the ECVEN state affects the offset calculated in
gt_phys_raw_cnt_offsetso we should trigger a re-calculation on its change.Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 9 +++++++++ 1 file changed, 9 insertions(+)target/arm/helper.c +3
-0@@ -37,6 +37,9 @@#include "qemu/plugin.h" static void switch_mode (CPUARMState *env,int mode); +#ifndef CONFIG_USER_ONLY +static void gt_recalc_timer (ARMCPU *cpu,int timeridx); +#endif int compare_u64 (const void *a,const void *b) {@@ -821,6 +824,12 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) changed = env->cp15.scr_el3 ^ value; env->cp15.scr_el3 = value;
target/arm/helper.c static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) · line 835
Quoted 10 lines
target/arm/helper.c +6
-0+#ifndef CONFIG_USER_ONLY +if (changed &SCR_ECVEN ) { +gt_recalc_timer (cpu,GTIMER_PHYS ); + } +#endif +/* * If SCR_EL3.{NS,NSE} changes, i.e. change of security state, * we must invalidate all TLBs below EL3.
As an aside, gt_phys_raw_cnt_offset is missing a check on EL3 existing, before the check for ECVEn set.
r~
Re: [PATCH 3/5] target/arm: trigger timer recalc on SCR:ECVEN change
Quoted 35 lines · Richard Henderson
Quoted 21 lines · Alex Bennée
Toggling the ECVEN state affects the offset calculated in
gt_phys_raw_cnt_offsetso we should trigger a re-calculation on its change.Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 9 +++++++++ 1 file changed, 9 insertions(+)target/arm/helper.c +3
-0@@ -37,6 +37,9 @@#include "qemu/plugin.h" static void switch_mode (CPUARMState *env,int mode); +#ifndef CONFIG_USER_ONLY +static void gt_recalc_timer (ARMCPU *cpu,int timeridx); +#endif int compare_u64 (const void *a,const void *b) {@@ -821,6 +824,12 @@ static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) changed = env->cp15.scr_el3 ^ value;target/arm/helper.c static void scr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) · line 834
Quoted 10 lines
target/arm/helper.c +5
-0env->cp15.scr_el3 = value; +#ifndef CONFIG_USER_ONLY +if (changed &SCR_ECVEN ) { +gt_recalc_timer (cpu,GTIMER_PHYS ); + } +#endif +/* * If SCR_EL3.{NS,NSE} changes, i.e. change of security state, * we must invalidate all TLBs below EL3. Reviewed-by Richard Henderson <[email protected]>
Quoted 2 lines
As an aside,
gt_phys_raw_cnt_offsetis missing a check on EL3 existing, before the check for ECVEn set.
Not many of the references to cp15.scr_el3 seem to have those checks (although I guess that may be inferred from higher up the call chain).
I can add a arm_feature(env, ARM_FEATURE_EL3) in front or maybe we want something similar to arm_is_el2_enabled?
Quoted 3 lines
r~
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 3/5] target/arm: trigger timer recalc on SCR:ECVEN change
Quoted 2 lines · Alex Bennée
Not many of the references to cp15.scr_el3 seem to have those checks (although I guess that may be inferred from higher up the call chain).
It depends on the sense of the test. Some of the bits are 1 to disable, others are 1 to enable. The disable sense bits don't need the feature test.
Quoted 1 line
I can add a
arm_feature(env, ARM_FEATURE_EL3)in front...
Yes please.
r~
PATCH 4/5 target/arm: trigger timer recalc on HCR:(E2H|TGE) changes
In reply to Alex BennéeToggling the HCR state affects the offset calculated in gt_phys_raw_cnt_offset so we should trigger a re-calculation on its change.
--- target/arm/helper.c | 5 +++++ 1 file changed, 5 insertions(+)
target/arm/helper.c +5 -0
@@ -3799,6 +3799,11 @@ static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask) (HCR_VM | HCR_PTW | HCR_DC | HCR_DCT | HCR_FWB | HCR_NV | HCR_NV1)) {tlb_flush (CPU (cpu)); } +#ifndef CONFIG_USER_ONLY +if ((env->cp15.hcr_el2 ^ value) & (HCR_E2H |HCR_TGE )) { +gt_recalc_timer (cpu,GTIMER_PHYS ); + } +#endif env->cp15.hcr_el2 = value;/*
Signature · 1 line
2.47.3
Re: [PATCH 4/5] target/arm: trigger timer recalc on HCR:(E2H|TGE) changes
Quoted 15 lines · Alex Bennée
Toggling the HCR state affects the offset calculated in
gt_phys_raw_cnt_offsetso we should trigger a re-calculation on its change.Signed-off-by Alex Bennée <[email protected]>--- target/arm/helper.c | 5 +++++ 1 file changed, 5 insertions(+)target/arm/helper.c +0
-0@@ -3799,6 +3799,11 @@ static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask) (HCR_VM | HCR_PTW | HCR_DC | HCR_DCT | HCR_FWB | HCR_NV | HCR_NV1)) {
target/arm/helper.c static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask) · line 3809
Quoted 10 lines
target/arm/helper.c +5
-0tlb_flush (CPU (cpu)); } +#ifndef CONFIG_USER_ONLY +if ((env->cp15.hcr_el2 ^ value) & (HCR_E2H |HCR_TGE )) { +gt_recalc_timer (cpu,GTIMER_PHYS ); + } +#endif env->cp15.hcr_el2 = value;/*
The recalc must be after assigning to hcr_el2.
Otherwise,
r~
PATCH 5/5 docs/system: add FEAT_ECV_POFF to the emulation list
In reply to Alex BennéeWe already had this implemented since 2808d3b38a5 (target/arm:
Implement FEAT_ECV CNTPOFF_EL2 handling) but it has its own feature name now. Add it to the list.
--- docs/system/arm/emulation.rst | 1 + 1 file changed, 1 insertion(+)
docs/system/arm/emulation.rst +1 -0
@@ -60,6 +60,7 @@ the following architecture extensions: - FEAT_E2H0 (Programming of HCR_EL2.E2H) - FEAT_EBF16 (AArch64 Extended BFloat16 instructions) - FEAT_ECV (Enhanced Counter Virtualization) +- FEAT_ECV_POFF (Enhanced Counter Virtualization Physical Offset) - FEAT_EL0 (Support for execution at EL0) - FEAT_EL1 (Support for execution at EL1) - FEAT_EL2 (Support for execution at EL2)
Signature · 1 line
2.47.3
Re: [PATCH 5/5] docs/system: add FEAT_ECV_POFF to the emulation list
Quoted 14 lines · Alex Bennée
We already had this implemented since
2808d3b38a5(target/arm:
ImplementFEAT_ECVCNTPOFF_EL2handling) but it has its own feature name now. Add it to the list.Signed-off-by Alex Bennée <[email protected]>--- docs/system/arm/emulation.rst | 1 + 1 file changed, 1 insertion(+)docs/system/arm/emulation.rst +0
-0
docs/system/arm/emulation.rst the following architecture extensions: · line 66
Quoted 7 lines
docs/system/arm/emulation.rst +1
-0@@ -60,6 +60,7 @@ the following architecture extensions: - FEAT_E2H0 (Programming of HCR_EL2.E2H) - FEAT_EBF16 (AArch64 Extended BFloat16 instructions) - FEAT_ECV (Enhanced Counter Virtualization) +- FEAT_ECV_POFF (Enhanced Counter Virtualization Physical Offset) - FEAT_EL0 (Support for execution at EL0) - FEAT_EL1 (Support for execution at EL1) - FEAT_EL2 (Support for execution at EL2)
r~