target/arm: implement SEL2 physical and virtual timers
v2 cover target/arm: implement SEL2 physical and virtual timers
Follow Peter's review I've split this into a several patches as there are some other fixes that should be made to other EL2 times that shouldn't be rolled together.
v2
- split machine enabling into patches
- rename IRQ
- use CP_ACCESS_TRAP_UNCATEGORIZED for UNDEF cases
v1
- improve GTIMER docs
- fix gt_recalc bug
- address review comments for the main patch
- cc qemu-stable (no rush for 9.2.0)
The following still need review:
hw/arm: enable secure EL2 timers for sbsa machine hw/arm: enable secure EL2 timers for virt machine target/arm: implement SEL2 physical and virtual timers target/arm: ensure cntvoff_el2 also used for EL2 virt timer
Alex.
Alex Bennée (5):
target/arm: document the architectural names of our GTIMERs target/arm: ensure cntvoff_el2 also used for EL2 virt timer target/arm: implement SEL2 physical and virtual timers hw/arm: enable secure EL2 timers for virt machine hw/arm: enable secure EL2 timers for sbsa machine
include/hw/arm/bsa.h | 2 + target/arm/cpu.h | 2 + target/arm/gtimer.h | 14 ++-- hw/arm/sbsa-ref.c | 2 + hw/arm/virt.c | 2 + target/arm/cpu.c | 4 + target/arm/helper.c | 179 +++++++++++++++++++++++++++++++++++++++++-- 7 files changed, 194 insertions(+), 11 deletions(-)
Signature · 1 line
2.39.5
PATCH v2 1/5 target/arm: document the architectural names of our GTIMERs
As we are about to add more physical and virtual timers lets make it clear what each timer does.
--- target/arm/gtimer.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target/arm/gtimer.h +5 -5
@@ -10,11 +10,11 @@#define TARGET_ARM_GTIMER_H enum { -GTIMER_PHYS =0 , -GTIMER_VIRT =1 , -GTIMER_HYP =2 , -GTIMER_SEC =3 , -GTIMER_HYPVIRT =4 , +GTIMER_PHYS =0 ,/* EL1 physical timer */ +GTIMER_VIRT =1 ,/* EL1 virtual timer */ +GTIMER_HYP =2 ,/* EL2 physical timer */ +GTIMER_SEC =3 ,/* EL3 physical timer */ +GTIMER_HYPVIRT =4 ,/* EL2 virtual timer */ #define NUM_GTIMERS 5 };
Signature · 1 line
2.39.5
PATCH v2 2/5 target/arm: ensure cntvoff_el2 also used for EL2 virt timer
In reply to Alex BennéeWe were missing this case and will shortly be adding another. Re-arrange the code and use a switch statement to group the virtual timers.
--- target/arm/helper.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
target/arm/helper.c +16 -5
@@ -2465,16 +2465,27 @@ static void gt_recalc_timer(ARMCPU *cpu, int timeridx)ARMGenericTimer *gt = &cpu->env.cp15.c14_timer[timeridx];if (gt->ctl &1 ) { +uint64_t count =gt_get_countervalue (&cpu->env); +uint64_t offset; +uint64_t nexttick; +int istatus; +/* * Timer enabled: calculate and set current ISTATUS, irq, and * reset timer to when ISTATUS next has to change */ -uint64_t offset = timeridx ==GTIMER_VIRT ? - cpu->env.cp15.cntvoff_el2 :gt_phys_raw_cnt_offset (&cpu->env); -uint64_t count =gt_get_countervalue (&cpu->env); +switch (timeridx) { +case GTIMER_VIRT : +case GTIMER_HYPVIRT : + offset = cpu->env.cp15.cntvoff_el2; +break ; +default : + offset =gt_phys_raw_cnt_offset (&cpu->env); +break ; + } +/* Note that this must be unsigned 64 bit arithmetic: */ -int istatus = count - offset >= gt->cval; -uint64_t nexttick; + istatus = count - offset >= gt->cval; gt->ctl =deposit32 (gt->ctl,2 ,1 , istatus);
Signature · 1 line
2.39.5
PATCH v2 3/5 target/arm: implement SEL2 physical and virtual timers
In reply to Alex BennéeWhen FEAT_SEL2 was implemented the SEL2 timers where missed. This shows up when building the latest Hafnium with SPMC_AT_EL=2. The actual implementation utilises the same logic as the rest of the timers so all we need to do is:
- define the timers and their access functions
- conditionally add the correct system registers
- create a new accessfn as the rules are subtly different to the existing secure timer
---
v1
- add better comments to GTIMER descriptions
- also define new timers for sbsa-ref
- don't conditionally gate qemu_timer creation on the feature
- take cntvoff_el2 int account for SEC_VEL2 in gt_recalc/g_tval_[read|write]
v2
- rename IRQ to ARCH_TIMER_S_EL2_VIRT_IRQ
- split machine enablement into separate patches
- return CP_ACCESS_TRAP_UNCATEGORIZED for UNDEF cases
--- include/hw/arm/bsa.h | 2 + target/arm/cpu.h | 2 + target/arm/gtimer.h | 4 +- target/arm/cpu.c | 4 ++ target/arm/helper.c | 158 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 169 insertions(+), 1 deletion(-)
include/hw/arm/bsa.h +2 -0
@@ -22,6 +22,8 @@#define QEMU_ARM_BSA_H /* These are architectural INTID values */ +#define ARCH_TIMER_S_EL2_VIRT_IRQ 19 +#define ARCH_TIMER_S_EL2_IRQ 20#define VIRTUAL_PMU_IRQ 23#define ARCH_GIC_MAINT_IRQ 25#define ARCH_TIMER_NS_EL2_IRQ 26
target/arm/cpu.h +2 -0
@@ -1139,6 +1139,8 @@ void arm_gt_vtimer_cb(void *opaque);void arm_gt_htimer_cb (void *opaque);void arm_gt_stimer_cb (void *opaque);void arm_gt_hvtimer_cb (void *opaque); +void arm_gt_sel2timer_cb (void *opaque); +void arm_gt_sel2vtimer_cb (void *opaque);unsigned int gt_cntfrq_period_ns (ARMCPU *cpu);void gt_rme_post_el_change (ARMCPU *cpu,void *opaque);
target/arm/gtimer.h +3 -1
@@ -15,7 +15,9 @@ enum {GTIMER_HYP =2 ,/* EL2 physical timer */ GTIMER_SEC =3 ,/* EL3 physical timer */ GTIMER_HYPVIRT =4 ,/* EL2 virtual timer */ -#define NUM_GTIMERS 5 +GTIMER_SEC_PEL2 =5 ,/* Secure EL2 physical timer */ +GTIMER_SEC_VEL2 =6 ,/* Secure EL2 virtual timer */ +#define NUM_GTIMERS 7 };#endif
target/arm/cpu.c +4 -0
@@ -2088,6 +2088,10 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) arm_gt_stimer_cb, cpu); cpu->gt_timer[GTIMER_HYPVIRT ] =timer_new (QEMU_CLOCK_VIRTUAL , scale, arm_gt_hvtimer_cb, cpu); + cpu->gt_timer[GTIMER_SEC_PEL2 ] =timer_new (QEMU_CLOCK_VIRTUAL , scale, + arm_gt_sel2timer_cb, cpu); + cpu->gt_timer[GTIMER_SEC_VEL2 ] =timer_new (QEMU_CLOCK_VIRTUAL , scale, + arm_gt_sel2vtimer_cb, cpu); }#endif
target/arm/helper.c +158 -0
200 lines not on this page · raw message
Signature · 1 line
2.39.5
Quoted 41 lines · Alex Bennée
When
FEAT_SEL2was implemented the SEL2 timers where missed. This shows up when building the latest Hafnium with SPMC_AT_EL=2. The actual implementation utilises the same logic as the rest of the timers so all we need to do is:- define the timers and their access functions
- conditionally add the correct system registers
- create a new accessfn as the rules are subtly different to the existing secure timerFixes e9152ee91c (target/arm: add ARMv8.4-SEL2 system registers)Signed-off-by Alex Bennée <[email protected]>Cc Andrei Homescu <[email protected]>Cc Arve Hjønnevåg <[email protected]>Cc Rémi Denis-Courmont <[email protected]>---
v1
- add better comments to GTIMER descriptions
- also define new timers for sbsa-ref
- don't conditionally gateqemu_timercreation on the feature
- takecntvoff_el2int account forSEC_VEL2in gt_recalc/g_tval_[read|write]
v2
- rename IRQ toARCH_TIMER_S_EL2_VIRT_IRQ
- split machine enablement into separate patches
- returnCP_ACCESS_TRAP_UNCATEGORIZEDfor UNDEF cases--- include/hw/arm/bsa.h | 2 + target/arm/cpu.h | 2 + target/arm/gtimer.h | 4 +- target/arm/cpu.c | 4 ++ target/arm/helper.c | 158 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 169 insertions(+), 1 deletion(-)target/arm/gtimer.h +0
-0
target/arm/gtimer.h enum { · line 16
Quoted 2 lines
target/arm/gtimer.h +0
-0@@ -15,7 +15,9 @@ enum {GTIMER_HYP =2 ,/* EL2 physical timer */ GTIMER_SEC = 3, /* EL3 physical timer */
Should we rename as GTIMER_SEC_PEL3 for consistency?
target/arm/gtimer.h enum { · line 17
Quoted 1 line
target/arm/gtimer.h +0
-0GTIMER_HYPVIRT = 4, /* EL2 virtual timer */
Also GTIMER_HYP -> GTIMER_PEL2,
GTIMER_HYPVIRT -> GTIMER_VEL2?
Quoted 7 lines
target/arm/gtimer.h +3
-1-#define NUM_GTIMERS 5 + GTIMER_SEC_PEL2 = 5, /* Secure EL2 physical timer */ + GTIMER_SEC_VEL2 = 6, /* Secure EL2 virtual timer */ +#define NUM_GTIMERS 7 };#endif |
It's not the context that lacks its the protocol.. lol. I wish I was good with words and a genius... oh no wait. It's easier being simple..you think.u could find the s
B listers. There's gotta b a mpatch
Quoted 62 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Alex Bennée
When
FEAT_SEL2was implemented the SEL2 timers where missed. This shows up when building the latest Hafnium with SPMC_AT_EL=2. The actual implementation utilises the same logic as the rest of the timers so all we need to do is:- define the timers and their access functions
- conditionally add the correct system registers
- create a new accessfn as the rules are subtly different to the existing secure timerFixes e9152ee91c (target/arm: add ARMv8.4-SEL2 system registers)Signed-off-by Alex Bennée <[email protected]>Cc Andrei Homescu <[email protected]>Cc Arve Hjønnevåg <[email protected]>Cc Rémi Denis-Courmont <[email protected]>Quoted 6 lines
---
v1
- add better comments to GTIMER descriptions
- also define new timers for sbsa-ref
- don't conditionally gateqemu_timercreation on the feature
- takecntvoff_el2int account forSEC_VEL2ingt_recalc/g_tval_[read|write]
Quoted 18 lines
v2
- rename IRQ toARCH_TIMER_S_EL2_VIRT_IRQ
- split machine enablement into separate patches
- returnCP_ACCESS_TRAP_UNCATEGORIZEDfor UNDEF cases--- include/hw/arm/bsa.h | 2 + target/arm/cpu.h | 2 + target/arm/gtimer.h | 4 +- target/arm/cpu.c | 4 ++ target/arm/helper.c | 158 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 169 insertions(+), 1 deletion(-)target/arm/gtimer.h +0
-0target/arm/gtimer.h enum { · line 16
Quoted 2 lines
target/arm/gtimer.h +0
-0@@ -15,7 +15,9 @@ enum {GTIMER_HYP =2 ,/* EL2 physical timer */ GTIMER_SEC = 3, /* EL3 physical timer */Should we rename as
GTIMER_SEC_PEL3for consistency?target/arm/gtimer.h enum { · line 17
Quoted 1 line
target/arm/gtimer.h +0
-0GTIMER_HYPVIRT = 4, /* EL2 virtual timer */Also
GTIMER_HYP->GTIMER_PEL2,GTIMER_HYPVIRT -> GTIMER_VEL2?Quoted 7 lines
target/arm/gtimer.h +3
-1-#define NUM_GTIMERS 5 + GTIMER_SEC_PEL2 = 5, /* Secure EL2 physical timer */ + GTIMER_SEC_VEL2 = 6, /* Secure EL2 virtual timer */ +#define NUM_GTIMERS 7 };#endif |
Quoted 54 lines · Alex Bennée
When
FEAT_SEL2was implemented the SEL2 timers where missed. This shows up when building the latest Hafnium with SPMC_AT_EL=2. The actual implementation utilises the same logic as the rest of the timers so all we need to do is:- define the timers and their access functions
- conditionally add the correct system registers
- create a new accessfn as the rules are subtly different to the existing secure timerFixes e9152ee91c (target/arm: add ARMv8.4-SEL2 system registers)Signed-off-by Alex Bennée <[email protected]>Cc Andrei Homescu <[email protected]>Cc Arve Hjønnevåg <[email protected]>Cc Rémi Denis-Courmont <[email protected]>---
v1
- add better comments to GTIMER descriptions
- also define new timers for sbsa-ref
- don't conditionally gateqemu_timercreation on the feature
- takecntvoff_el2int account forSEC_VEL2in gt_recalc/g_tval_[read|write]
v2
- rename IRQ toARCH_TIMER_S_EL2_VIRT_IRQ
- split machine enablement into separate patches
- returnCP_ACCESS_TRAP_UNCATEGORIZEDfor UNDEF cases
---target/arm/helper.c +24
-0+static CPAccessResult gt_sel2timer_access (CPUARMState *env, +const ARMCPRegInfo *ri, +bool isread) +{ +/* +* The AArch64 register view of the secure EL2 timers are mostly +* accessible from EL3 and EL2 although can also be trapped to EL2 +* from EL1 depending on nested virt config. +*/ +switch (arm_current_el (env)) { +case 0 : +return CP_ACCESS_TRAP ; +case 1 : +if (!arm_is_secure (env)) { +return CP_ACCESS_TRAP_UNCATEGORIZED ; + }else if (arm_hcr_el2_eff (env) &HCR_NV ) { +return CP_ACCESS_TRAP_EL2 ; + } +return CP_ACCESS_TRAP ; +case 2 : +if (!arm_is_secure (env)) { +return CP_ACCESS_TRAP_UNCATEGORIZED ; + } +return CP_ACCESS_OK ;
target/arm/helper.c static CPAccessResult gt_stimer_access(CPUARMState *env, · line 2437
Quoted 10 lines
target/arm/helper.c +10
-0+case 3 : +if (env->cp15.scr_el3 &SCR_EEL2 ) { +return CP_ACCESS_OK ; + }else { +return CP_ACCESS_TRAP_UNCATEGORIZED ; + } +default : +g_assert_not_reached (); + } +}
This code is still using CP_ACCESS_TRAP in some codepaths, which isn't correct. Either:
* you want an UNDEF: that's CP_ACCESS_TRAP_UNCATEGORIZED
* you want to trap to some specific EL: that's CP_ACCESS_TRAP_EL2 or CP_ACCESS_TRAP_EL3 depending on where you need to trap to.
thanks
-- PMM
PATCH v2 4/5 hw/arm: enable secure EL2 timers for virt machine
In reply to Alex Bennée--- hw/arm/virt.c | 2 ++ 1 file changed, 2 insertions(+)
hw/arm/virt.c +2 -0
@@ -873,6 +873,8 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ, + [GTIMER_SEC_PEL2] = ARCH_TIMER_S_EL2_IRQ, + [GTIMER_SEC_VEL2] = ARCH_TIMER_S_EL2_VIRT_IRQ, };for (unsigned irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) {
Signature · 1 line
2.39.5
Re: [PATCH v2 4/5] hw/arm: enable secure EL2 timers for virt machine
Quoted 12 lines · Alex Bennée
Signed-off-by Alex Bennée <[email protected]>--- hw/arm/virt.c | 2 ++ 1 file changed, 2 insertions(+)hw/arm/virt.c +0
-0
hw/arm/virt.c static void create_gic(VirtMachineState *vms, MemoryRegion *mem) · line 880
Quoted 8 lines
hw/arm/virt.c +2
-0@@ -873,6 +873,8 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ, + [GTIMER_SEC_PEL2] = ARCH_TIMER_S_EL2_IRQ, + [GTIMER_SEC_VEL2] = ARCH_TIMER_S_EL2_VIRT_IRQ, };for (unsigned irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) {
Do these timer interrupts have a defined devicetree binding that we need to set up in fdt_add_timer_nodes()? How about ACPI?
thanks
-- PMM
Re: [PATCH v2 4/5] hw/arm: enable secure EL2 timers for virt machine
Quoted 20 lines · Peter Maydell
Quoted 19 lines · Alex Bennée
Signed-off-by Alex Bennée <[email protected]>--- hw/arm/virt.c | 2 ++ 1 file changed, 2 insertions(+)hw/arm/virt.c +2
-0@@ -873,6 +873,8 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem) [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ, + [GTIMER_SEC_PEL2] = ARCH_TIMER_S_EL2_IRQ, + [GTIMER_SEC_VEL2] = ARCH_TIMER_S_EL2_VIRT_IRQ, };
Quoted 4 lines
hw/arm/virt.c static void create_gic(VirtMachineState *vms, MemoryRegion *mem) · line 880
Quoted 1 line
hw/arm/virt.c +0
-0for (unsigned irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) {Do these timer interrupts have a defined devicetree binding that we need to set up in
fdt_add_timer_nodes()? How about ACPI?
The DT in the kernel doesn't care (why would it, it never sees the SEL2 timers). The hafnium test case works without it.
I'm not sure where there is a DT specification that describes what should be there for SEL2.
Quoted 3 lines
thanks
-- PMM
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH v2 5/5 hw/arm: enable secure EL2 timers for sbsa machine
In reply to Alex Bennée--- hw/arm/sbsa-ref.c | 2 ++ 1 file changed, 2 insertions(+)
hw/arm/sbsa-ref.c +2 -0
@@ -484,6 +484,8 @@ static void create_gic(SBSAMachineState *sms, MemoryRegion *mem) [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ, + [GTIMER_SEC_PEL2] = ARCH_TIMER_S_EL2_IRQ, + [GTIMER_SEC_VEL2] = ARCH_TIMER_S_EL2_VIRT_IRQ, };for (irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) {
Signature · 1 line
2.39.5
Re: [PATCH v2 5/5] hw/arm: enable secure EL2 timers for sbsa machine
Quoted 21 lines · Alex Bennée
Signed-off-by Alex Bennée <[email protected]>--- hw/arm/sbsa-ref.c | 2 ++ 1 file changed, 2 insertions(+)hw/arm/sbsa-ref.c +2
-1@@ -484,6 +484,8 @@ static void create_gic(SBSAMachineState *sms, MemoryRegion *mem) [GTIMER_HYP] = ARCH_TIMER_NS_EL2_IRQ, [GTIMER_SEC] = ARCH_TIMER_S_EL1_IRQ, [GTIMER_HYPVIRT] = ARCH_TIMER_NS_EL2_VIRT_IRQ, + [GTIMER_SEC_PEL2] = ARCH_TIMER_S_EL2_IRQ, + [GTIMER_SEC_VEL2] = ARCH_TIMER_S_EL2_VIRT_IRQ, };for (irq =0 ; irq <ARRAY_SIZE (timer_irq); irq++) { --
Quoted 1 line
2.39.5
thanks
-- PMM
Quoted 15 lines · Alex Bennée
Follow Peter's review I've split this into a several patches as there are some other fixes that should be made to other EL2 times that shouldn't be rolled together.
v2
- split machine enabling into patches
- rename IRQ
- useCP_ACCESS_TRAP_UNCATEGORIZEDfor UNDEF casesv1
- improve GTIMER docs
- fixgt_recalcbug
- address review comments for the main patch
- cc qemu-stable (no rush for 9.2.0)
Quoted 6 lines
The following still need review:
hw/arm: enable secure EL2 timers for sbsa machine hw/arm: enable secure EL2 timers for virt machine target/arm: implement SEL2 physical and virtual timers target/arm: ensure
cntvoff_el2also used for EL2 virt timer
Gentle ping - I think everything is ready for merging.
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 18 lines · Alex Bennée
Quoted 15 lines · Alex Bennée
Follow Peter's review I've split this into a several patches as there are some other fixes that should be made to other EL2 times that shouldn't be rolled together.
v2
- split machine enabling into patches
- rename IRQ
- useCP_ACCESS_TRAP_UNCATEGORIZEDfor UNDEF casesv1
- improve GTIMER docs
- fixgt_recalcbug
- address review comments for the main patch
- cc qemu-stable (no rush for 9.2.0)
Quoted 8 lines
Quoted 6 lines
The following still need review:
hw/arm: enable secure EL2 timers for sbsa machine hw/arm: enable secure EL2 timers for virt machine target/arm: implement SEL2 physical and virtual timers target/arm: ensure
cntvoff_el2also used for EL2 virt timerGentle ping - I think everything is ready for merging.
It's on my queue to test and review, but I'm likely to be lagging behind on code review til the end of the month :-)
-- PMM