]> xenbits.xensource.com Git - xen.git/commitdiff
xen/arm: Add Cortex-A73 erratum 858921 workaround
authorPenny Zheng <penny.zheng@arm.com>
Mon, 9 Nov 2020 08:21:10 +0000 (16:21 +0800)
committerStefano Stabellini <sstabellini@kernel.org>
Fri, 19 Mar 2021 19:32:42 +0000 (12:32 -0700)
CNTVCT_EL0 or CNTPCT_EL0 counter read in Cortex-A73 (all versions)
might return a wrong value when the counter crosses a 32bit boundary.

Until now, there is no case for Xen itself to access CNTVCT_EL0,
and it also should be the Guest OS's responsibility to deal with
this part.

But for CNTPCT, there exists several cases in Xen involving reading
CNTPCT, so a possible workaround is that performing the read twice,
and to return one or the other depending on whether a transition has
taken place.

Signed-off-by: Penny Zheng <penny.zheng@arm.com>
Reviewed-by: Wei Chen <Wei.Chen@arm.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Acked-by: Julien Grall <jgrall@amazon.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
(cherry picked from commit 5505f5f8e7e805365cfe70b6a4af6115940bb749)

docs/misc/arm/silicon-errata.txt
xen/arch/arm/Kconfig
xen/arch/arm/cpuerrata.c
xen/arch/arm/vtimer.c
xen/include/asm-arm/cpuerrata.h
xen/include/asm-arm/cpufeature.h
xen/include/asm-arm/time.h

index 1f18a9df58957cc8de3afdd63333c44b36ddd9ca..552c4151d3780ed3e5d7f494ffac617af2bab9d5 100644 (file)
@@ -51,6 +51,7 @@ stable hypervisors.
 | ARM            | Cortex-A57      | #1319537        | N/A                     |
 | ARM            | Cortex-A72      | #1319367        | N/A                     |
 | ARM            | Cortex-A72      | #853709         | N/A                     |
+| ARM            | Cortex-A73      | #858921         | ARM_ERRATUM_858921      |
 | ARM            | Cortex-A76      | #1165522        | N/A                     |
 | ARM            | Neoverse-N1     | #1165522        | N/A
 | ARM            | MMU-500         | #842869         | N/A                     |
index 277738826581b738f667cbb045f81c877deb9592..f938dd21bd9566473ed1dbc859dc2c9e338f2dee 100644 (file)
@@ -226,6 +226,24 @@ config ARM64_ERRATUM_834220
 
          If unsure, say Y.
 
+config ARM_ERRATUM_858921
+       bool "Cortex-A73: 858921: Possible wrong read value for CNTVCT or CNTPCT"
+       default y
+       help
+         This option adds an alternative code sequence to work around ARM
+         erratum 858921 on Cortex-A73 (all versions).
+
+         Affected Cortex-A73 might return wrong read value for CNTVCT or CNTPCT
+         when the counter crosses a 32bit boundary.
+
+         The workaround involves performing the read twice, and to return
+         one or the other value depending on whether a transition has taken place.
+         Please note that this does not necessarily enable the workaround,
+         as it depends on the alternative framework, which will only patch
+         the kernel if an affected CPU is detected.
+
+         If unsure, say Y.
+
 endmenu
 
 config ARM64_HARDEN_BRANCH_PREDICTOR
index 6c0901751543a05c8a7847d79c8c7f2e565c436a..739d302c54e4b996cd26b5ee7cf9f20c6d4333d6 100644 (file)
@@ -475,6 +475,14 @@ static const struct arm_cpu_capabilities arm_errata[] = {
         .capability = ARM_SSBD,
         .matches = has_ssbd_mitigation,
     },
+#endif
+#ifdef CONFIG_ARM_ERRATUM_858921
+    {
+        /* Cortex-A73 (all versions) */
+        .desc = "ARM erratum 858921",
+        .capability = ARM_WORKAROUND_858921,
+        MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
+    },
 #endif
     {
         /* Neoverse r0p0 - r2p0 */
index 6d39fc944f888b30f992a4370909d33ff54ef2a5..c2b27915c67915cd1692a3a2b1f51202a7972858 100644 (file)
@@ -62,7 +62,7 @@ static void virt_timer_expired(void *data)
 
 int domain_vtimer_init(struct domain *d, struct xen_arch_domainconfig *config)
 {
-    d->arch.virt_timer_base.offset = READ_SYSREG64(CNTPCT_EL0);
+    d->arch.virt_timer_base.offset = get_cycles();
     d->time_offset.seconds = ticks_to_ns(d->arch.virt_timer_base.offset - boot_count);
     do_div(d->time_offset.seconds, 1000000000);
 
index 88ef3ca934745c81334f92c559f6d93aeba123c4..8d7e7b9375bd95b95d6003c2d2c972c12d7f2d42 100644 (file)
@@ -28,6 +28,8 @@ static inline bool check_workaround_##erratum(void)             \
 CHECK_WORKAROUND_HELPER(766422, ARM32_WORKAROUND_766422, CONFIG_ARM_32)
 CHECK_WORKAROUND_HELPER(834220, ARM64_WORKAROUND_834220, CONFIG_ARM_64)
 CHECK_WORKAROUND_HELPER(ssbd, ARM_SSBD, CONFIG_ARM_SSBD)
+CHECK_WORKAROUND_HELPER(858921, ARM_WORKAROUND_858921,
+                        CONFIG_ARM_ERRATUM_858921)
 
 #undef CHECK_WORKAROUND_HELPER
 
index 10878ead8a27b6f80004ed1366dd9c3f0df4aef5..016a9fe2039addd4f1604684248b9c416e0fc0d3 100644 (file)
@@ -45,8 +45,9 @@
 #define ARM_SSBD 7
 #define ARM_SMCCC_1_1 8
 #define ARM64_WORKAROUND_AT_SPECULATE 9
+#define ARM_WORKAROUND_858921 10
 
-#define ARM_NCAPS           10
+#define ARM_NCAPS           11
 
 #ifndef __ASSEMBLY__
 
index 9cb6f9b0b4b7b7c1e7e77099d9b465e43dab6cd9..1b2c13614b9c3872be5844d198aad6d7414e875e 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <asm/sysregs.h>
 #include <asm/system.h>
+#include <asm/cpuerrata.h>
 
 #define DT_MATCH_TIMER                      \
     DT_MATCH_COMPATIBLE("arm,armv7-timer"), \
@@ -13,7 +14,26 @@ typedef uint64_t cycles_t;
 static inline cycles_t get_cycles (void)
 {
         isb();
-        return READ_SYSREG64(CNTPCT_EL0);
+        /*
+         * ARM_WORKAROUND_858921: Cortex-A73 (all versions) counter read
+         * can return a wrong value when the counter crosses a 32bit boundary.
+         */
+        if ( !check_workaround_858921() )
+            return READ_SYSREG64(CNTPCT_EL0);
+        else
+        {
+            /*
+             * A recommended workaround for erratum 858921 is to:
+             *  1- Read twice CNTPCT.
+             *  2- Compare bit[32] of the two read values.
+             *      - If bit[32] is different, keep the old value.
+             *      - If bit[32] is the same, keep the new value.
+             */
+            cycles_t old, new;
+            old = READ_SYSREG64(CNTPCT_EL0);
+            new = READ_SYSREG64(CNTPCT_EL0);
+            return (((old ^ new) >> 32) & 1) ? old : new;
+        }
 }
 
 /* List of timer's IRQ */