]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
xen/arm: Add an isb() before reading CNTPCT_EL0 to prevent re-ordering
authorJulien Grall <julien.grall@arm.com>
Mon, 29 Apr 2019 14:05:16 +0000 (15:05 +0100)
committerJulien Grall <julien.grall@arm.com>
Fri, 14 Jun 2019 13:27:32 +0000 (14:27 +0100)
Per D8.2.1 in ARM DDI 0487C.a, "a read to CNTPCT_EL0 can occur
speculatively and out of order relative to other instructions executed
on the same PE."

Add an instruction barrier to get accurate number of cycles when
requested in get_cycles(). For the other users of CNPCT_EL0, replace by
a call to get_cycles().

This is part of XSA-295.

Signed-off-by: Julien Grall <julien.grall@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
xen/arch/arm/time.c
xen/include/asm-arm/time.h

index bbccee742e80ccc920092b1fb274cc59212794b2..739bcf186c954701c99ae965e17c1b70951b97ef 100644 (file)
@@ -151,7 +151,7 @@ void __init preinit_xen_time(void)
     if ( res )
         panic("Timer: Cannot initialize platform timer\n");
 
-    boot_count = READ_SYSREG64(CNTPCT_EL0);
+    boot_count = get_cycles();
 }
 
 static void __init init_dt_xen_time(void)
@@ -192,7 +192,7 @@ int __init init_xen_time(void)
 /* Return number of nanoseconds since boot */
 s_time_t get_s_time(void)
 {
-    uint64_t ticks = READ_SYSREG64(CNTPCT_EL0) - boot_count;
+    uint64_t ticks = get_cycles() - boot_count;
     return ticks_to_ns(ticks);
 }
 
index 9a7071a5463089bcda200cc0639d63228dd8fc01..9cb6f9b0b4b7b7c1e7e77099d9b465e43dab6cd9 100644 (file)
@@ -2,6 +2,7 @@
 #define __ARM_TIME_H__
 
 #include <asm/sysregs.h>
+#include <asm/system.h>
 
 #define DT_MATCH_TIMER                      \
     DT_MATCH_COMPATIBLE("arm,armv7-timer"), \
@@ -11,6 +12,7 @@ typedef uint64_t cycles_t;
 
 static inline cycles_t get_cycles (void)
 {
+        isb();
         return READ_SYSREG64(CNTPCT_EL0);
 }