target/arm: Implement FEAT_ECV (Enhanced Counter Virtualization)
cover target/arm: Implement FEAT_ECV (Enhanced Counter Virtualization)
This patchset implements the Arm FEAT_ECV architectural feature, which provides:
* some new trap bits for hypervisors to trap accesses to various counter and timer registers
* support for scaling of the event stream for the guest (which we don't need to implement because our events are always nops)
* new registers CNTPCTSS_EL0 and NCTVCTSS_EL0 which are "self-sychronizing" views of the CNTPCT_EL0 and CNTVCT_EL0, meaning that no barriers are needed around their accesses. For us these are just the same as the normal views, because all our sysregs are inherently self-sychronizing.
* a new register CNTPOFF_EL2, which allows the hypervisor to set an adjustable offset for what the guest sees in the physical timer and counter (similar to the existing CNTVOFF_EL2 for the virtual timer and counter)
These patchsets implement support for this and enable them in the 'max' CPU. At the start of the series there's one patch doing some "move things to a better header file" and one bugfix for a "no sensible guest should ever do this" corner case.
I'm hoping we can get these reviewed in time to get them in before softfreeze.
thanks
-- PMM
Peter Maydell (8):
target/arm: Move some register related defines to internals.h target/arm: Timer _EL02 registers UNDEF for E2H == 0 target/arm: use FIELD macro for CNTHCTL bit definitions target/arm: Don't allow RES0 CNTHCTL_EL2 bits to be written target/arm: Implement new FEAT_ECV trap bits target/arm: Define CNTPCTSS_EL0 and CNTVCTSS_EL0 target/arm: Implement FEAT_ECV CNTPOFF_EL2 handling target/arm: Enable FEAT_ECV for 'max' CPU
docs/system/arm/emulation.rst | 1 + target/arm/cpu-features.h | 10 ++ target/arm/cpu.h | 129 +---------------------- target/arm/internals.h | 143 +++++++++++++++++++++++++ target/arm/helper.c | 189 +++++++++++++++++++++++++++++++--- target/arm/tcg/cpu64.c | 1 + target/arm/trace-events | 1 + 7 files changed, 334 insertions(+), 140 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/8 target/arm: Move some register related defines to internals.h
cpu.h has a lot of #defines relating to CPU register fields. Most of these aren't actually used outside target/arm code, so there's no point in cluttering up the cpu.h file with them. Move some easy ones to internals.h.
---
I want to add some more CNTHCTL_* values, and don't really want to put more into cpu.h. There's obviously more that could be moved here, but I don't want to get into doing too much all at once. I pondered having a different file for these, but probably we'd end up pulling it in everywhere we do internals.h.
--- target/arm/cpu.h | 128 ----------------------------------------- target/arm/internals.h | 128 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 128 deletions(-)
target/arm/cpu.h +0 -128
@@ -141,11 +141,6 @@ typedef struct ARMGenericTimer {uint64_t ctl;/* Timer Control register */ } ARMGenericTimer; -#define VTCR_NSW (1u << 29) -#define VTCR_NSA (1u << 30) -#define VSTCR_SW VTCR_NSW -#define VSTCR_SA VTCR_NSA -/* Define a maximum sized vector register. * For 32-bit, this is a 128-bit NEON/AdvSIMD register. * For 64-bit, this is a 2048-bit SVE register.
@@ -1382,73 +1377,6 @@ void pmu_init(ARMCPU *cpu);#define SCTLR_SPINTMASK (1ULL << 62)/* FEAT_NMI */ #define SCTLR_TIDCP (1ULL << 63)/* FEAT_TIDCP1 */ -/* Bit definitions for CPACR (AArch32 only) */ -FIELD(CPACR, CP10, 20, 2) -FIELD(CPACR, CP11, 22, 2) -FIELD(CPACR, TRCDIS, 28, 1) /* matches CPACR_EL1.TTA */ -FIELD(CPACR, D32DIS, 30, 1) /* up to v7; RAZ in v8 */ -FIELD (CPACR ,ASEDIS ,31 ,1 ) - -/* Bit definitions for CPACR_EL1 (AArch64 only) */ -FIELD(CPACR_EL1, ZEN, 16, 2) -FIELD(CPACR_EL1, FPEN, 20, 2) -FIELD(CPACR_EL1, SMEN, 24, 2) -FIELD (CPACR_EL1 ,TTA ,28 ,1 )/* matches CPACR.TRCDIS */ - -/* Bit definitions for HCPTR (AArch32 only) */ -FIELD(HCPTR, TCP10, 10, 1) -FIELD(HCPTR, TCP11, 11, 1) -FIELD(HCPTR, TASE, 15, 1) -FIELD(HCPTR, TTA, 20, 1) -FIELD(HCPTR, TAM, 30, 1) /* matches CPTR_EL2.TAM */ -FIELD (HCPTR ,TCPAC ,31 ,1 )/* matches CPTR_EL2.TCPAC */ - -/* Bit definitions for CPTR_EL2 (AArch64 only) */ -FIELD(CPTR_EL2, TZ, 8, 1) /* !E2H */ -FIELD(CPTR_EL2, TFP, 10, 1) /* !E2H, matches HCPTR.TCP10 */ -FIELD(CPTR_EL2, TSM, 12, 1) /* !E2H */ -FIELD(CPTR_EL2, ZEN, 16, 2) /* E2H */ -FIELD(CPTR_EL2, FPEN, 20, 2) /* E2H */ -FIELD(CPTR_EL2, SMEN, 24, 2) /* E2H */ -FIELD(CPTR_EL2, TTA, 28, 1) -FIELD(CPTR_EL2, TAM, 30, 1) /* matches HCPTR.TAM */ -FIELD (CPTR_EL2 ,TCPAC ,31 ,1 )/* matches HCPTR.TCPAC */ - -/* Bit definitions for CPTR_EL3 (AArch64 only) */ -FIELD(CPTR_EL3, EZ, 8, 1) -FIELD(CPTR_EL3, TFP, 10, 1) -FIELD(CPTR_EL3, ESM, 12, 1) -FIELD(CPTR_EL3, TTA, 20, 1) -FIELD(CPTR_EL3, TAM, 30, 1) -FIELD(CPTR_EL3, TCPAC, 31, 1) - -#define MDCR_MTPME (1U << 28) -#define MDCR_TDCC (1U << 27) -#define MDCR_HLP (1U << 26)/* MDCR_EL2 */ -#define MDCR_SCCD (1U << 23)/* MDCR_EL3 */ -#define MDCR_HCCD (1U << 23)/* MDCR_EL2 */ -#define MDCR_EPMAD (1U << 21) -#define MDCR_EDAD (1U << 20) -#define MDCR_TTRF (1U << 19) -#define MDCR_STE (1U << 18)/* MDCR_EL3 */ -#define MDCR_SPME (1U << 17)/* MDCR_EL3 */ -#define MDCR_HPMD (1U << 17)/* MDCR_EL2 */ -#define MDCR_SDD (1U << 16) -#define MDCR_SPD (3U << 14) -#define MDCR_TDRA (1U << 11) -#define MDCR_TDOSA (1U << 10) -#define MDCR_TDA (1U << 9) -#define MDCR_TDE (1U << 8) -#define MDCR_HPME (1U << 7) -#define MDCR_TPM (1U << 6) -#define MDCR_TPMCR (1U << 5) -#define MDCR_HPMN (0x1fU) - -/* Not all of the MDCR_EL3 bits are present in the 32-bit SDCR */ -#define SDCR_VALID_MASK (MDCR_MTPME | MDCR_TDCC | MDCR_SCCD | \ - MDCR_EPMAD | MDCR_EDAD | MDCR_TTRF | \ - MDCR_STE | MDCR_SPME | MDCR_SPD) -#define CPSR_M (0x1fU)#define CPSR_T (1U << 5)#define CPSR_F (1U << 6)
@@ -1495,41 +1423,6 @@ FIELD(CPTR_EL3, TCPAC, 31, 1)#define XPSR_NZCV CPSR_NZCV#define XPSR_IT CPSR_IT -#define TTBCR_N (7U << 0)/* TTBCR.EAE==0 */ -#define TTBCR_T0SZ (7U << 0)/* TTBCR.EAE==1 */ -#define TTBCR_PD0 (1U << 4) -#define TTBCR_PD1 (1U << 5) -#define TTBCR_EPD0 (1U << 7) -#define TTBCR_IRGN0 (3U << 8) -#define TTBCR_ORGN0 (3U << 10) -#define TTBCR_SH0 (3U << 12) -#define TTBCR_T1SZ (3U << 16) -#define TTBCR_A1 (1U << 22) -#define TTBCR_EPD1 (1U << 23) -#define TTBCR_IRGN1 (3U << 24) -#define TTBCR_ORGN1 (3U << 26) -#define TTBCR_SH1 (1U << 28) -#define TTBCR_EAE (1U << 31) - -FIELD(VTCR, T0SZ, 0, 6) -FIELD(VTCR, SL0, 6, 2) -FIELD(VTCR, IRGN0, 8, 2) -FIELD(VTCR, ORGN0, 10, 2) -FIELD(VTCR, SH0, 12, 2) -FIELD(VTCR, TG0, 14, 2) -FIELD(VTCR, PS, 16, 3) -FIELD(VTCR, VS, 19, 1) -FIELD(VTCR, HA, 21, 1) -FIELD(VTCR, HD, 22, 1) -FIELD(VTCR, HWU59, 25, 1) -FIELD(VTCR, HWU60, 26, 1) -FIELD(VTCR, HWU61, 27, 1) -FIELD(VTCR, HWU62, 28, 1) -FIELD(VTCR, NSW, 29, 1) -FIELD(VTCR, NSA, 30, 1) -FIELD(VTCR, DS, 32, 1) -FIELD (VTCR ,SL2 ,33 ,1 ) -/* Bit definitions for ARMv8 SPSR (PSTATE) format. * Only these are valid when in AArch64 mode; in * AArch32 mode SPSRs are basically CPSR-format.
@@ -1737,21 +1630,6 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)#define HCR_TWEDEN (1ULL << 59)#define HCR_TWEDEL MAKE_64BIT_MASK(60, 4) -#define HCRX_ENAS0 (1ULL << 0) -#define HCRX_ENALS (1ULL << 1) -#define HCRX_ENASR (1ULL << 2) -#define HCRX_FNXS (1ULL << 3) -#define HCRX_FGTNXS (1ULL << 4) -#define HCRX_SMPME (1ULL << 5) -#define HCRX_TALLINT (1ULL << 6) -#define HCRX_VINMI (1ULL << 7) -#define HCRX_VFNMI (1ULL << 8) -#define HCRX_CMOW (1ULL << 9) -#define HCRX_MCE2 (1ULL << 10) -#define HCRX_MSCEN (1ULL << 11) - -#define HPFAR_NS (1ULL << 63) -#define SCR_NS (1ULL << 0)#define SCR_IRQ (1ULL << 1)#define SCR_FIQ (1ULL << 2)
@@ -1790,12 +1668,6 @@ static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)#define SCR_GPF (1ULL << 48)#define SCR_NSE (1ULL << 62) -#define HSTR_TTEE (1 << 16) -#define HSTR_TJDBX (1 << 17) - -#define CNTHCTL_CNTVMASK (1 << 18) -#define CNTHCTL_CNTPMASK (1 << 19) -/* Return the current FPSCR value. */ uint32_t vfp_get_fpscr (CPUARMState *env);void vfp_set_fpscr (CPUARMState *env,uint32_t val);
target/arm/internals.h +128 -0
134 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 1/8] target/arm: Move some register related defines to internals.h
Quoted 5 lines · Peter Maydell
cpu.hhas a lot of #defines relating to CPU register fields. Most of these aren't actually used outside target/arm code, so there's no point in cluttering up thecpu.hfile with them. Move some easy ones tointernals.h.
Quoted 8 lines
Signed-off-by Peter Maydell <[email protected]>---
I want to add some more CNTHCTL_* values, and don't really want to put more intocpu.h. There's obviously more that could be moved here, but I don't want to get into doing too much all at once. I pondered having a different file for these, but probably we'd end up pulling it in everywhere we dointernals.h.
Yeah, have been there before :/
Quoted 4 lines
--- target/arm/cpu.h | 128 ----------------------------------------- target/arm/internals.h | 128 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 128 deletions(-)
Re: [PATCH 1/8] target/arm: Move some register related defines to internals.h
In reply to Peter MaydellQuoted 13 lines · Peter Maydell
cpu.hhas a lot of #defines relating to CPU register fields. Most of these aren't actually used outside target/arm code, so there's no point in cluttering up thecpu.hfile with them. Move some easy ones tointernals.h.Signed-off-by Peter Maydell<[email protected]>---
I want to add some more CNTHCTL_* values, and don't really want to put more intocpu.h. There's obviously more that could be moved here, but I don't want to get into doing too much all at once. I pondered having a different file for these, but probably we'd end up pulling it in everywhere we dointernals.h.
Quoted 4 lines
--- target/arm/cpu.h | 128 ----------------------------------------- target/arm/internals.h | 128 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 128 deletions(-)
r~
PATCH 2/8 target/arm: Timer _EL02 registers UNDEF for E2H == 0
In reply to Peter MaydellThe timer _EL02 registers should UNDEF for invalid accesses from EL2 or EL3 when HCR_EL2.E2H == 0, not take a cp access trap. We were delivering the exception to EL2 with the wrong syndrome.
--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/helper.c +1 -1
@@ -6551,7 +6551,7 @@ static CPAccessResult e2h_access(CPUARMState *env, const ARMCPRegInfo *ri,return CP_ACCESS_OK ; }if (!(arm_hcr_el2_eff (env) &HCR_E2H )) { -return CP_ACCESS_TRAP ; +return CP_ACCESS_TRAP_UNCATEGORIZED ; }return CP_ACCESS_OK ; }
Signature · 1 line
2.34.1
Re: [PATCH 2/8] target/arm: Timer _EL02 registers UNDEF for E2H == 0
Quoted 8 lines · Peter Maydell
The timer
_EL02registers should UNDEF for invalid accesses from EL2 or EL3 when HCR_EL2.E2H == 0, not take a cp access trap. We were delivering the exception to EL2 with the wrong syndrome.Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
r~
PATCH 3/8 target/arm: use FIELD macro for CNTHCTL bit definitions
In reply to Peter MaydellWe prefer the FIELD macro over ad-hoc #defines for register bits; switch CNTHCTL to that style before we add any more bits.
--- target/arm/internals.h | 19 +++++++++++++++++-- target/arm/helper.c | 9 ++++----- 2 files changed, 21 insertions(+), 7 deletions(-)
target/arm/internals.h +17 -2
@@ -224,8 +224,23 @@ FIELD(VTCR, SL2, 33, 1)#define HSTR_TTEE (1 << 16)#define HSTR_TJDBX (1 << 17) -#define CNTHCTL_CNTVMASK (1 << 18) -#define CNTHCTL_CNTPMASK (1 << 19) +FIELD(CNTHCTL, EL0PCTEN, 0, 1) +FIELD(CNTHCTL, EL0VCTEN, 1, 1) +FIELD(CNTHCTL, EVNTEN, 2, 1) +FIELD(CNTHCTL, EVNTDIR, 3, 1) +FIELD(CNTHCTL, EVNTI, 4, 4) +FIELD(CNTHCTL, EL0VTEN, 8, 1) +FIELD(CNTHCTL, EL0PTEN, 9, 1) +FIELD(CNTHCTL, EL1PCTEN, 10, 1) +FIELD(CNTHCTL, EL1PTEN, 11, 1) +FIELD(CNTHCTL, ECV, 12, 1) +FIELD(CNTHCTL, EL1TVT, 13, 1) +FIELD(CNTHCTL, EL1TVCT, 14, 1) +FIELD(CNTHCTL, EL1NVPCT, 15, 1) +FIELD(CNTHCTL, EL1NVVCT, 16, 1) +FIELD(CNTHCTL, EVNTIS, 17, 1) +FIELD(CNTHCTL, CNTVMASK, 18, 1) +FIELD (CNTHCTL ,CNTPMASK ,19 ,1 )/* We use a few fake FSR values for internal purposes in M profile. * M profile cores don't have A/R format FSRs, but currently our
target/arm/helper.c +4 -5
@@ -2652,8 +2652,8 @@ static void gt_update_irq(ARMCPU *cpu, int timeridx)* It is RES0 in Secure and NonSecure state. */ if ((ss == ARMSS_Root || ss == ARMSS_Realm) && - ((timeridx ==GTIMER_VIRT && (cnthctl &CNTHCTL_CNTVMASK )) || - (timeridx ==GTIMER_PHYS && (cnthctl &CNTHCTL_CNTPMASK )))) { + ((timeridx ==GTIMER_VIRT && (cnthctl &R_CNTHCTL_CNTVMASK_MASK )) || + (timeridx ==GTIMER_PHYS && (cnthctl &R_CNTHCTL_CNTPMASK_MASK )))) { irqstate =0 ; }
@@ -2968,12 +2968,11 @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, {ARMCPU *cpu =env_archcpu (env);uint32_t oldval = env->cp15.cnthctl_el2; -raw_write (env, ri, value); -if ((oldval ^ value) &CNTHCTL_CNTVMASK ) { +if ((oldval ^ value) &R_CNTHCTL_CNTVMASK_MASK ) {gt_update_irq (cpu,GTIMER_VIRT ); - }else if ((oldval ^ value) &CNTHCTL_CNTPMASK ) { + }else if ((oldval ^ value) &R_CNTHCTL_CNTPMASK_MASK ) {gt_update_irq (cpu,GTIMER_PHYS ); } }
Signature · 1 line
2.34.1
Re: [PATCH 3/8] target/arm: use FIELD macro for CNTHCTL bit definitions
Quoted 8 lines · Peter Maydell
We prefer the FIELD macro over ad-hoc #defines for register bits; switch CNTHCTL to that style before we add any more bits.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 19 +++++++++++++++++-- target/arm/helper.c | 9 ++++----- 2 files changed, 21 insertions(+), 7 deletions(-)
Re: [PATCH 3/8] target/arm: use FIELD macro for CNTHCTL bit definitions
In reply to Peter MaydellQuoted 8 lines · Peter Maydell
We prefer the FIELD macro over ad-hoc #defines for register bits; switch CNTHCTL to that style before we add any more bits.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/internals.h | 19 +++++++++++++++++-- target/arm/helper.c | 9 ++++----- 2 files changed, 21 insertions(+), 7 deletions(-)
r~
Re: [PATCH 3/8] target/arm: use FIELD macro for CNTHCTL bit definitions
In reply to Peter MaydellQuoted 23 lines · Peter Maydell
We prefer the FIELD macro over ad-hoc #defines for register bits; switch CNTHCTL to that style before we add any more bits.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 19 +++++++++++++++++-- target/arm/helper.c | 9 ++++----- 2 files changed, 21 insertions(+), 7 deletions(-)target/arm/internals.h +4
-2@@ -224,8 +224,23 @@ FIELD(VTCR, SL2, 33, 1)#define HSTR_TTEE (1 << 16)#define HSTR_TJDBX (1 << 17) -#define CNTHCTL_CNTVMASK (1 << 18) -#define CNTHCTL_CNTPMASK (1 << 19) +FIELD(CNTHCTL, EL0PCTEN, 0, 1) +FIELD(CNTHCTL, EL0VCTEN, 1, 1) +FIELD(CNTHCTL, EVNTEN, 2, 1) +FIELD (CNTHCTL ,EVNTDIR ,3 ,1 )
...
target/arm/internals.h FIELD(VTCR, SL2, 33, 1) · line 235
Quoted 4 lines
target/arm/internals.h +4
-0+FIELD(CNTHCTL, EL0VTEN, 8, 1) +FIELD(CNTHCTL, EL0PTEN, 9, 1) +FIELD(CNTHCTL, EL1PCTEN, 10, 1) +FIELD (CNTHCTL ,EL1PTEN ,11 ,1 )
These bits change definition based on HCR_E2H, which I remembered when I got to patch 5, which adds code nearby the existing tests of these bits.
It might be confusing to only provide the E2H versions, without some extra suffix?
r~
Re: [PATCH 3/8] target/arm: use FIELD macro for CNTHCTL bit definitions
Quoted 34 lines · Richard Henderson
Quoted 23 lines · Peter Maydell
We prefer the FIELD macro over ad-hoc #defines for register bits; switch CNTHCTL to that style before we add any more bits.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 19 +++++++++++++++++-- target/arm/helper.c | 9 ++++----- 2 files changed, 21 insertions(+), 7 deletions(-)target/arm/internals.h +4
-2@@ -224,8 +224,23 @@ FIELD(VTCR, SL2, 33, 1)#define HSTR_TTEE (1 << 16)#define HSTR_TJDBX (1 << 17) -#define CNTHCTL_CNTVMASK (1 << 18) -#define CNTHCTL_CNTPMASK (1 << 19) +FIELD(CNTHCTL, EL0PCTEN, 0, 1) +FIELD(CNTHCTL, EL0VCTEN, 1, 1) +FIELD(CNTHCTL, EVNTEN, 2, 1) +FIELD (CNTHCTL ,EVNTDIR ,3 ,1 )...
target/arm/internals.h FIELD(VTCR, SL2, 33, 1) · line 235
Quoted 4 lines
target/arm/internals.h +4
-0+FIELD(CNTHCTL, EL0VTEN, 8, 1) +FIELD(CNTHCTL, EL0PTEN, 9, 1) +FIELD(CNTHCTL, EL1PCTEN, 10, 1) +FIELD (CNTHCTL ,EL1PTEN ,11 ,1 )These bits change definition based on
HCR_E2H, which I remembered when I got to patch 5, which adds code nearby the existing tests of these bits.
Quoted 1 line
It might be confusing to only provide the E2H versions, without some extra suffix?
Yeah, bits 8..11 are RES0 if E2H is 0; bits 3 and 2 are the same; bits 0 and 1 change (to EL1PCTEN and EL1PCEN, so bit 0 when E2H is 0 has the same name as bit 10 when E2H is 1).
I don't see the need to suffix the bits that are only relevant in one context and RES0 in the other, only the ones where the bit has the same name but a different location, or where the same bit number has two names. So:
+/*
+ * Depending on the value of HCR_EL2.E2H, bits 0 and 1
+ * have different bit definitions, and EL1PCTEN might be
+ * bit 0 or bit 10. We use _E2H1 and _E2H0 suffixes to
+ * disambiguate if necessary.
+ */
+FIELD(CNTHCTL, EL0PCTEN_E2H1, 0, 1) +FIELD(CNTHCTL, EL0VCTEN_E2H1, 1, 1) +FIELD(CNTHCTL, EL1PCTEN_E2H0, 0, 1) +FIELD(CNTHCTL, EL1PCEN_E2H0, 1, 1) +FIELD(CNTHCTL, EVNTEN, 2, 1)
+FIELD(CNTHCTL, EVNTDIR, 3, 1)
+FIELD(CNTHCTL, EVNTI, 4, 4)
+FIELD(CNTHCTL, EL0VTEN, 8, 1)
+FIELD(CNTHCTL, EL0PTEN, 9, 1)
+FIELD(CNTHCTL, EL1PCTEN_E2H1, 10, 1) +FIELD(CNTHCTL, EL1PTEN, 11, 1)
+FIELD(CNTHCTL, ECV, 12, 1)
+FIELD(CNTHCTL, EL1TVT, 13, 1)
+FIELD(CNTHCTL, EL1TVCT, 14, 1)
+FIELD(CNTHCTL, EL1NVPCT, 15, 1)
+FIELD(CNTHCTL, EL1NVVCT, 16, 1)
+FIELD(CNTHCTL, EVNTIS, 17, 1)
+FIELD(CNTHCTL, CNTVMASK, 18, 1)
+FIELD(CNTHCTL, CNTPMASK, 19, 1)
(and updating the uses in following patches as needed) ?
thanks
-- PMM
Re: [PATCH 3/8] target/arm: use FIELD macro for CNTHCTL bit definitions
Quoted 73 lines · Peter Maydell
Quoted 34 lines · Richard Henderson
Quoted 23 lines · Peter Maydell
We prefer the FIELD macro over ad-hoc #defines for register bits; switch CNTHCTL to that style before we add any more bits.
Signed-off-by Peter Maydell <[email protected]>--- target/arm/internals.h | 19 +++++++++++++++++-- target/arm/helper.c | 9 ++++----- 2 files changed, 21 insertions(+), 7 deletions(-)target/arm/internals.h +4
-2@@ -224,8 +224,23 @@ FIELD(VTCR, SL2, 33, 1)#define HSTR_TTEE (1 << 16)#define HSTR_TJDBX (1 << 17) -#define CNTHCTL_CNTVMASK (1 << 18) -#define CNTHCTL_CNTPMASK (1 << 19) +FIELD(CNTHCTL, EL0PCTEN, 0, 1) +FIELD(CNTHCTL, EL0VCTEN, 1, 1) +FIELD(CNTHCTL, EVNTEN, 2, 1) +FIELD (CNTHCTL ,EVNTDIR ,3 ,1 )...
target/arm/internals.h FIELD(VTCR, SL2, 33, 1) · line 235
Quoted 4 lines
target/arm/internals.h +4
-0+FIELD(CNTHCTL, EL0VTEN, 8, 1) +FIELD(CNTHCTL, EL0PTEN, 9, 1) +FIELD(CNTHCTL, EL1PCTEN, 10, 1) +FIELD (CNTHCTL ,EL1PTEN ,11 ,1 )These bits change definition based on
HCR_E2H, which I remembered when I got to patch 5, which adds code nearby the existing tests of these bits.Quoted 1 line
It might be confusing to only provide the E2H versions, without some extra suffix?
Yeah, bits 8..11 are RES0 if E2H is 0; bits 3 and 2 are the same; bits 0 and 1 change (to EL1PCTEN and EL1PCEN, so bit 0 when E2H is 0 has the same name as bit 10 when E2H is 1).
I don't see the need to suffix the bits that are only relevant in one context and RES0 in the other, only the ones where the bit has the same name but a different location, or where the same bit number has two names. So:
target/arm/internals.h +25
-0+/* +* Depending on the value of HCR_EL2.E2H, bits 0 and 1 +* have different bit definitions, and EL1PCTEN might be +* bit 0 or bit 10. We use _E2H1 and _E2H0 suffixes to +* disambiguate if necessary. +*/ +FIELD(CNTHCTL, EL0PCTEN_E2H1, 0, 1) +FIELD(CNTHCTL, EL0VCTEN_E2H1, 1, 1) +FIELD(CNTHCTL, EL1PCTEN_E2H0, 0, 1) +FIELD(CNTHCTL, EL1PCEN_E2H0, 1, 1) +FIELD(CNTHCTL, EVNTEN, 2, 1) +FIELD(CNTHCTL, EVNTDIR, 3, 1) +FIELD(CNTHCTL, EVNTI, 4, 4) +FIELD(CNTHCTL, EL0VTEN, 8, 1) +FIELD(CNTHCTL, EL0PTEN, 9, 1) +FIELD(CNTHCTL, EL1PCTEN_E2H1, 10, 1) +FIELD(CNTHCTL, EL1PTEN, 11, 1) +FIELD(CNTHCTL, ECV, 12, 1) +FIELD(CNTHCTL, EL1TVT, 13, 1) +FIELD(CNTHCTL, EL1TVCT, 14, 1) +FIELD(CNTHCTL, EL1NVPCT, 15, 1) +FIELD(CNTHCTL, EL1NVVCT, 16, 1) +FIELD(CNTHCTL, EVNTIS, 17, 1) +FIELD(CNTHCTL, CNTVMASK, 18, 1) +FIELD (CNTHCTL ,CNTPMASK ,19 ,1 )
Quoted 1 line
(and updating the uses in following patches as needed) ?
Looks good, thanks.
r~
PATCH 4/8 target/arm: Don't allow RES0 CNTHCTL_EL2 bits to be written
In reply to Peter MaydellDon't allow the guest to write CNTHCTL_EL2 bits which don't exist. This is not strictly architecturally required, but it is how we've tended to implement registers more recently.
In particular, bits [19:18] are only present with FEAT_RME, and bits [17:12] will only be present with FEAT_ECV.
--- target/arm/helper.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
target/arm/helper.c +18 -0
@@ -2968,6 +2968,24 @@ static void gt_cnthctl_write(CPUARMState *env, const ARMCPRegInfo *ri, {ARMCPU *cpu =env_archcpu (env);uint32_t oldval = env->cp15.cnthctl_el2; +uint32_t valid_mask = +R_CNTHCTL_EL0PCTEN_MASK | +R_CNTHCTL_EL0VCTEN_MASK | +R_CNTHCTL_EVNTEN_MASK | +R_CNTHCTL_EVNTDIR_MASK | +R_CNTHCTL_EVNTI_MASK | +R_CNTHCTL_EL0VTEN_MASK | +R_CNTHCTL_EL0PTEN_MASK | +R_CNTHCTL_EL1PCTEN_MASK | +R_CNTHCTL_EL1PTEN_MASK ; + +if (cpu_isar_feature (aa64_rme, cpu)) { + valid_mask |=R_CNTHCTL_CNTVMASK_MASK |R_CNTHCTL_CNTPMASK_MASK ; + } + +/* Clear RES0 bits */ + value &= valid_mask; +raw_write (env, ri, value);if ((oldval ^ value) &R_CNTHCTL_CNTVMASK_MASK ) {
Signature · 1 line
2.34.1
Re: [PATCH 4/8] target/arm: Don't allow RES0 CNTHCTL_EL2 bits to be written
Quoted 11 lines · Peter Maydell
Don't allow the guest to write
CNTHCTL_EL2bits which don't exist. This is not strictly architecturally required, but it is how we've tended to implement registers more recently.In particular, bits [19:18] are only present with
FEAT_RME, and bits [17:12] will only be present withFEAT_ECV.Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
r~
PATCH 5/8 target/arm: Implement new FEAT_ECV trap bits
In reply to Peter MaydellThe functionality defined by ID_AA64MMFR0_EL1.ECV == 1 is:
* four new trap bits for various counter and timer registers
* the CNTHCTL_EL2.EVNTIS and CNTKCTL_EL1.EVNTIS bits which control scaling of the event stream. This is a no-op for us, because we don't implement the event stream (our WFE is a NOP): all we need to do is allow CNTHCTL_EL2.ENVTIS to be read and written.
* extensions to PMSCR_EL1.PCT, PMSCR_EL2.PCT, TRFCR_EL1.TS and TRFCR_EL2.TS: these are all no-ops for us, because we don't implement FEAT_SPE or FEAT_TRF.
* new registers CNTPCTSS_EL0 and NCTVCTSS_EL0 which are "self-sychronizing" views of the CNTPCT_EL0 and CNTVCT_EL0, meaning that no barriers are needed around their accesses. For us these are just the same as the normal views, because all our sysregs are inherently self-sychronizing.
In this commit we implement the trap handling and permit the new CNTHCTL_EL2 bits to be written.
--- target/arm/cpu-features.h | 5 ++++ target/arm/helper.c | 51 +++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-)
target/arm/cpu-features.h +5 -0
@@ -741,6 +741,11 @@ static inline bool isar_feature_aa64_fgt(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64mmfr0,ID_AA64MMFR0 ,FGT ) !=0 ; } +static inline bool isar_feature_aa64_ecv_traps (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64mmfr0,ID_AA64MMFR0 ,ECV ) >0 ; +} +static inline bool isar_feature_aa64_vh (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64mmfr1,ID_AA64MMFR1 ,VH ) !=0 ;
target/arm/helper.c +46 -5
105 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 5/8] target/arm: Implement new FEAT_ECV trap bits
Quoted 15 lines · Peter Maydell
The functionality defined by ID_AA64MMFR0_EL1.ECV == 1 is:
* four new trap bits for various counter and timer registers
* the CNTHCTL_EL2.EVNTIS and CNTKCTL_EL1.EVNTIS bits which control scaling of the event stream. This is a no-op for us, because we don't implement the event stream (our WFE is a NOP): all we need to do is allow CNTHCTL_EL2.ENVTIS to be read and written.
* extensions to PMSCR_EL1.PCT, PMSCR_EL2.PCT, TRFCR_EL1.TS and TRFCR_EL2.TS: these are all no-ops for us, because we don't implementFEAT_SPEorFEAT_TRF.
* new registersCNTPCTSS_EL0andNCTVCTSS_EL0which are "self-sychronizing" views of theCNTPCT_EL0andCNTVCT_EL0, meaning that no barriers are needed around their accesses. For us these are just the same as the normal views, because all our sysregs are inherently self-sychronizing.
Quoted 8 lines
In this commit we implement the trap handling and permit the new
CNTHCTL_EL2bits to be written.Signed-off-by Peter Maydell<[email protected]>--- target/arm/cpu-features.h | 5 ++++ target/arm/helper.c | 51 +++++++++++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 5 deletions(-)
r~
PATCH 6/8 target/arm: Define CNTPCTSS_EL0 and CNTVCTSS_EL0
In reply to Peter MaydellFor FEAT_ECV, new registers CNTPCTSS_EL0 and CNTVCTSS_EL0 are defined, which are "self-synchronized" views of the physical and virtual counts as seen in the CNTPCT_EL0 and CNTVCT_EL0 registers (meaning that no barriers are needed around accesses to them to ensure that reads of them do not occur speculatively and out-of-order with other instructions).
For QEMU, all our system registers are self-synchronized, so we can simply copy the existing implementation of CNTPCT_EL0 and CNTVCT_EL0 to the new register encodings.
This means we now implement all the functionality required for ID_AA64MMFR0_EL1.ECV == 0b0001.
--- target/arm/helper.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
target/arm/helper.c +43 -0
@@ -3389,6 +3389,34 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { }, }; +/* +* FEAT_ECV adds extra views of CNTVCT_EL0 and CNTPCT_EL0 which +* are "self-synchronizing". For QEMU all sysregs are self-synchronizing, +* so our implementations here are identical to the normal registers. +*/ +static const ARMCPRegInfo gen_timer_ecv_cp_reginfo[] = { + { .name ="CNTVCTSS" , .cp =15 , .crm =14 , .opc1 =9 , + .access =PL0_R , .type =ARM_CP_64BIT |ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = gt_vct_access, + .readfn = gt_virt_cnt_read, .resetfn = arm_cp_reset_ignore, + }, + { .name ="CNTVCTSS_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =14 , .crm =0 , .opc2 =6 , + .access =PL0_R , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = gt_vct_access, .readfn = gt_virt_cnt_read, + }, + { .name ="CNTPCTSS" , .cp =15 , .crm =14 , .opc1 =8 , + .access =PL0_R , .type =ARM_CP_64BIT |ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = gt_pct_access, + .readfn = gt_cnt_read, .resetfn = arm_cp_reset_ignore, + }, + { .name ="CNTPCTSS_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =14 , .crm =0 , .opc2 =5 , + .access =PL0_R , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .accessfn = gt_pct_access, .readfn = gt_cnt_read, + }, +}; +#else /*
@@ -3422,6 +3450,18 @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { }, }; +/* +* CNTVCTSS_EL0 has the same trap conditions as CNTVCT_EL0, so it also +* is exposed to userspace by Linux. +*/ +static const ARMCPRegInfo gen_timer_ecv_cp_reginfo[] = { + { .name ="CNTVCTSS_EL0" , .state =ARM_CP_STATE_AA64 , + .opc0 =3 , .opc1 =3 , .crn =14 , .crm =0 , .opc2 =6 , + .access =PL0_R , .type =ARM_CP_NO_RAW |ARM_CP_IO , + .readfn = gt_virt_cnt_read, + }, +}; +#endif static void par_write (CPUARMState *env,const ARMCPRegInfo *ri,uint64_t value)
@@ -9258,6 +9298,9 @@ void register_cp_regs_for_features(ARMCPU *cpu)if (arm_feature (env,ARM_FEATURE_GENERIC_TIMER )) {define_arm_cp_regs (cpu, generic_timer_cp_reginfo); } +if (cpu_isar_feature (aa64_ecv_traps, cpu)) { +define_arm_cp_regs (cpu, gen_timer_ecv_cp_reginfo); + }if (arm_feature (env,ARM_FEATURE_VAPA )) {ARMCPRegInfo vapa_cp_reginfo[] = { { .name ="PAR" , .cp =15 , .crn =7 , .crm =4 , .opc1 =0 , .opc2 =0 ,
Signature · 1 line
2.34.1
Re: [PATCH 6/8] target/arm: Define CNTPCTSS_EL0 and CNTVCTSS_EL0
Quoted 11 lines · Peter Maydell
For
FEAT_ECV, new registersCNTPCTSS_EL0andCNTVCTSS_EL0are defined, which are "self-synchronized" views of the physical and virtual counts as seen in theCNTPCT_EL0andCNTVCT_EL0registers (meaning that no barriers are needed around accesses to them to ensure that reads of them do not occur speculatively and out-of-order with other instructions).For QEMU, all our system registers are self-synchronized, so we can simply copy the existing implementation of
CNTPCT_EL0andCNTVCT_EL0to the new register encodings.
Quoted 7 lines
This means we now implement all the functionality required for ID_AA64MMFR0_EL1.ECV == 0b0001.
Signed-off-by Peter Maydell<[email protected]>--- target/arm/helper.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
r~
PATCH 7/8 target/arm: Implement FEAT_ECV CNTPOFF_EL2 handling
In reply to Peter MaydellWhen ID_AA64MMFR0_EL1.ECV is 0b0010, a new register CNTPOFF_EL2 is implemented. This is similar to the existing CNTVOFF_EL2, except that it controls a hypervisor-adjustable offset made to the physical counter and timer.
Implement the handling for this register, which includes control/trap bits in SCR_EL3 and CNTHCTL_EL2.
--- target/arm/cpu-features.h | 5 +++ target/arm/cpu.h | 1 + target/arm/helper.c | 68 +++++++++++++++++++++++++++++++++++++-- target/arm/trace-events | 1 + 4 files changed, 73 insertions(+), 2 deletions(-)
target/arm/cpu-features.h +5 -0
@@ -746,6 +746,11 @@ static inline bool isar_feature_aa64_ecv_traps(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64mmfr0,ID_AA64MMFR0 ,ECV ) >0 ; } +static inline bool isar_feature_aa64_ecv (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64mmfr0,ID_AA64MMFR0 ,ECV ) >1 ; +} +static inline bool isar_feature_aa64_vh (const ARMISARegisters *id) {return FIELD_EX64 (id->id_aa64mmfr1,ID_AA64MMFR1 ,VH ) !=0 ;
target/arm/cpu.h +1 -0
@@ -453,6 +453,7 @@ typedef struct CPUArchState {uint64_t c14_cntkctl;/* Timer Control register */ uint64_t cnthctl_el2;/* Counter/Timer Hyp Control register */ uint64_t cntvoff_el2;/* Counter Virtual Offset register */ +uint64_t cntpoff_el2;/* Counter Physical Offset register */ ARMGenericTimer c14_timer[NUM_GTIMERS ];uint32_t c15_cpar;/* XScale Coprocessor Access Register */ uint32_t c15_ticonfig;/* TI925T configuration byte. */
target/arm/helper.c +66 -2
122 lines not on this page · raw message
target/arm/trace-events +1 -0
@@ -8,6 +8,7 @@ arm_gt_tval_write(int timer, uint64_t value) "gt_tval_write: timer %d value 0x%" arm_gt_ctl_write(int timer, uint64_t value) "gt_ctl_write: timer %d value 0x%" PRIx64 arm_gt_imask_toggle(int timer) "gt_ctl_write: timer %d IMASK toggle" arm_gt_cntvoff_write(uint64_t value) "gt_cntvoff_write: value 0x%" PRIx64 +arm_gt_cntpoff_write(uint64_t value) "gt_cntpoff_write: value 0x%" PRIx64 arm_gt_update_irq(int timer, int irqstate) "gt_update_irq: timer %d irqstate %d" # kvm.c
Signature · 1 line
2.34.1
Re: [PATCH 7/8] target/arm: Implement FEAT_ECV CNTPOFF_EL2 handling
target/arm/helper.c void gt_rme_post_el_change(ARMCPU *cpu, void *ignored) · line 2693
Quoted 6 lines · Peter Maydell
target/arm/helper.c +6
-0+static uint64_t gt_phys_raw_cnt_offset (CPUARMState *env) +{ +if ((env->cp15.scr_el3 &SCR_ECVEN ) && +FIELD_EX64 (env->cp15.cnthctl_el2,CNTHCTL ,ECV ) && +arm_is_el2_enabled (env) && + (arm_hcr_el2_eff (env) & (HCR_E2H |HCR_TGE )) != (HCR_E2H |HCR_TGE )) {
arm_hcr_el2_eff checks arm_is_el2_enabled and returns 0 if disabled.
Anyway,
r~
Re: [PATCH 7/8] target/arm: Implement FEAT_ECV CNTPOFF_EL2 handling
Quoted 10 lines · Richard Henderson
target/arm/helper.c void gt_rme_post_el_change(ARMCPU *cpu, void *ignored) · line 2693
Quoted 6 lines · Peter Maydell
target/arm/helper.c +6
-0+static uint64_t gt_phys_raw_cnt_offset (CPUARMState *env) +{ +if ((env->cp15.scr_el3 &SCR_ECVEN ) && +FIELD_EX64 (env->cp15.cnthctl_el2,CNTHCTL ,ECV ) && +arm_is_el2_enabled (env) && + (arm_hcr_el2_eff (env) & (HCR_E2H |HCR_TGE )) != (HCR_E2H |HCR_TGE )) {
arm_hcr_el2_effchecksarm_is_el2_enabledand returns 0 if disabled.
Yes, and if it returns 0 then the E2H|TGE bits will not be E2H|TGE, and so we'll incorrectly apply the CNTPOFF value. We can only elide the arm_is_el2_enabled() test if we're checking for some HCR bit being 1. (I also initially thought the arm_is_el2_enabled() check was redundant and then found it was not :-))
-- PMM
PATCH 8/8 target/arm: Enable FEAT_ECV for 'max' CPU
In reply to Peter MaydellEnable all FEAT_ECV features on the 'max' CPU.
--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 1 + 2 files changed, 2 insertions(+)
docs/system/arm/emulation.rst +1 -0
@@ -28,6 +28,7 @@ the following architecture extensions: - FEAT_DotProd (Advanced SIMD dot product instructions) - FEAT_DoubleFault (Double Fault Extension) - FEAT_E0PD (Preventing EL0 access to halves of address maps) +- FEAT_ECV (Enhanced Counter Virtualization) - FEAT_EPAC (Enhanced pointer authentication) - FEAT_ETS (Enhanced Translation Synchronization) - FEAT_EVT (Enhanced Virtualization Traps)
target/arm/tcg/cpu64.c +1 -0
@@ -1184,6 +1184,7 @@ void aarch64_max_tcg_initfn(Object *obj) t =FIELD_DP64 (t,ID_AA64MMFR0 ,TGRAN64_2 ,2 );/* 64k stage2 supported */ t =FIELD_DP64 (t,ID_AA64MMFR0 ,TGRAN4_2 ,2 );/* 4k stage2 supported */ t =FIELD_DP64 (t,ID_AA64MMFR0 ,FGT ,1 );/* FEAT_FGT */ + t =FIELD_DP64 (t,ID_AA64MMFR0 ,ECV ,2 );/* FEAT_ECV */ cpu->isar.id_aa64mmfr0 = t; t = cpu->isar.id_aa64mmfr1;
Signature · 1 line
2.34.1
Re: [PATCH 8/8] target/arm: Enable FEAT_ECV for 'max' CPU
Quoted 7 lines · Peter Maydell
Enable all
FEAT_ECVfeatures on the 'max' CPU.Signed-off-by Peter Maydell <[email protected]>--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 1 + 2 files changed, 2 insertions(+)
Re: [PATCH 8/8] target/arm: Enable FEAT_ECV for 'max' CPU
In reply to Peter MaydellQuoted 7 lines · Peter Maydell
Enable all
FEAT_ECVfeatures on the 'max' CPU.Signed-off-by Peter Maydell<[email protected]>--- docs/system/arm/emulation.rst | 1 + target/arm/tcg/cpu64.c | 1 + 2 files changed, 2 insertions(+)
r~