diff mbox

[U-Boot,4/9] ARM: non-sec: reset CNTVOFF to zero

Message ID 1385024402-23585-5-git-send-email-marc.zyngier@arm.com
State Superseded
Delegated to: Albert ARIBAUD
Headers show

Commit Message

Marc Zyngier Nov. 21, 2013, 8:59 a.m. UTC
Before switching to non-secure, make sure that CNTVOFF is set
to zero on all CPUs. Otherwise, kernel running in non-secure
without HYP enabled (hence using virtual timers) may observe
timers that are not synchronized, effectively seeing time
going backward...

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 arch/arm/cpu/armv7/nonsec_virt.S | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Andre Przywara Nov. 26, 2013, 2:41 p.m. UTC | #1
On 11/21/2013 09:59 AM, Marc Zyngier wrote:
> Before switching to non-secure, make sure that CNTVOFF is set
> to zero on all CPUs. Otherwise, kernel running in non-secure
> without HYP enabled (hence using virtual timers) may observe
> timers that are not synchronized, effectively seeing time
> going backward...

Under what circumstances would native Linux use the virtual timers? When 
VIRT_EXT is not defined?

Regards,
Andre.

>
> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
> ---
>   arch/arm/cpu/armv7/nonsec_virt.S | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/arch/arm/cpu/armv7/nonsec_virt.S b/arch/arm/cpu/armv7/nonsec_virt.S
> index 648066f..bbacbce 100644
> --- a/arch/arm/cpu/armv7/nonsec_virt.S
> +++ b/arch/arm/cpu/armv7/nonsec_virt.S
> @@ -53,7 +53,14 @@ _secure_monitor:
>   	mrceq	p15, 0, r0, c12, c0, 1		@ get MVBAR value
>   	mcreq	p15, 4, r0, c12, c0, 0		@ write HVBAR
>   #endif
> +	bne	1f
>
> +	@ Reset CNTVOFF to 0 before leaving monitor mode
> +	mrc	p15, 0, r0, c0, c1, 1		@ read ID_PFR1
> +	ands	r0, r0, #CPUID_ARM_GENTIMER_MASK	@ test arch timer bits
> +	movne	r0, #0
> +	mcrrne	p15, 4, r0, r0, c14		@ Reset CNTVOFF to zero
> +1:
>   	movs	pc, lr				@ return to non-secure SVC
>
>   _hyp_trap:
>
Marc Zyngier Nov. 26, 2013, 2:46 p.m. UTC | #2
On 26/11/13 14:41, Andre Przywara wrote:
> On 11/21/2013 09:59 AM, Marc Zyngier wrote:
>> Before switching to non-secure, make sure that CNTVOFF is set
>> to zero on all CPUs. Otherwise, kernel running in non-secure
>> without HYP enabled (hence using virtual timers) may observe
>> timers that are not synchronized, effectively seeing time
>> going backward...
> 
> Under what circumstances would native Linux use the virtual timers? When 
> VIRT_EXT is not defined?

Yes. In general, when the kernel is not entered in HYP mode.

	M.

> Regards,
> Andre.
> 
>>
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> ---
>>   arch/arm/cpu/armv7/nonsec_virt.S | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/arch/arm/cpu/armv7/nonsec_virt.S b/arch/arm/cpu/armv7/nonsec_virt.S
>> index 648066f..bbacbce 100644
>> --- a/arch/arm/cpu/armv7/nonsec_virt.S
>> +++ b/arch/arm/cpu/armv7/nonsec_virt.S
>> @@ -53,7 +53,14 @@ _secure_monitor:
>>   	mrceq	p15, 0, r0, c12, c0, 1		@ get MVBAR value
>>   	mcreq	p15, 4, r0, c12, c0, 0		@ write HVBAR
>>   #endif
>> +	bne	1f
>>
>> +	@ Reset CNTVOFF to 0 before leaving monitor mode
>> +	mrc	p15, 0, r0, c0, c1, 1		@ read ID_PFR1
>> +	ands	r0, r0, #CPUID_ARM_GENTIMER_MASK	@ test arch timer bits
>> +	movne	r0, #0
>> +	mcrrne	p15, 4, r0, r0, c14		@ Reset CNTVOFF to zero
>> +1:
>>   	movs	pc, lr				@ return to non-secure SVC
>>
>>   _hyp_trap:
>>
> 
>
diff mbox

Patch

diff --git a/arch/arm/cpu/armv7/nonsec_virt.S b/arch/arm/cpu/armv7/nonsec_virt.S
index 648066f..bbacbce 100644
--- a/arch/arm/cpu/armv7/nonsec_virt.S
+++ b/arch/arm/cpu/armv7/nonsec_virt.S
@@ -53,7 +53,14 @@  _secure_monitor:
 	mrceq	p15, 0, r0, c12, c0, 1		@ get MVBAR value
 	mcreq	p15, 4, r0, c12, c0, 0		@ write HVBAR
 #endif
+	bne	1f
 
+	@ Reset CNTVOFF to 0 before leaving monitor mode
+	mrc	p15, 0, r0, c0, c1, 1		@ read ID_PFR1
+	ands	r0, r0, #CPUID_ARM_GENTIMER_MASK	@ test arch timer bits
+	movne	r0, #0
+	mcrrne	p15, 4, r0, r0, c14		@ Reset CNTVOFF to zero
+1:
 	movs	pc, lr				@ return to non-secure SVC
 
 _hyp_trap: