[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging] xen/arm: Add an isb() before reading CNTPCT_EL0 to prevent re-ordering



commit 5e1b9cb0f29d6b52bd603d22bca4ae4cfeef9e74
Author:     Julien Grall <julien.grall@xxxxxxx>
AuthorDate: Mon Apr 29 15:05:16 2019 +0100
Commit:     Julien Grall <julien.grall@xxxxxxx>
CommitDate: Fri Jun 14 14:27:32 2019 +0100

    xen/arm: Add an isb() before reading CNTPCT_EL0 to prevent re-ordering
    
    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@xxxxxxx>
    Acked-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
---
 xen/arch/arm/time.c        | 4 ++--
 xen/include/asm-arm/time.h | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/time.c b/xen/arch/arm/time.c
index bbccee742e..739bcf186c 100644
--- a/xen/arch/arm/time.c
+++ b/xen/arch/arm/time.c
@@ -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);
 }
 
diff --git a/xen/include/asm-arm/time.h b/xen/include/asm-arm/time.h
index 9a7071a546..9cb6f9b0b4 100644
--- a/xen/include/asm-arm/time.h
+++ b/xen/include/asm-arm/time.h
@@ -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);
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.