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>
if ( res )
panic("Timer: Cannot initialize platform timer");
- boot_count = READ_SYSREG64(CNTPCT_EL0);
+ boot_count = get_cycles();
}
static void __init init_dt_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);
}
#ifndef __ARM_TIME_H__
#define __ARM_TIME_H__
+#include <asm/system.h>
+
#define DT_MATCH_TIMER \
DT_MATCH_COMPATIBLE("arm,armv7-timer"), \
DT_MATCH_COMPATIBLE("arm,armv8-timer")
static inline cycles_t get_cycles (void)
{
- return 0;
+ isb();
+ return READ_SYSREG64(CNTPCT_EL0);
}
/* List of timer's IRQ */