Skip to content

Commit 6df696c

Browse files
committed
arm64: errata: Mitigate Ampere1 erratum AC03_CPU_38 at stage-2
AmpereOne has an erratum in its implementation of FEAT_HAFDBS that required disabling the feature on the design. This was done by reporting the feature as not implemented in the ID register, although the corresponding control bits were not actually RES0. This does not align well with the requirements of the architecture, which mandates these bits be RES0 if HAFDBS isn't implemented. The kernel's use of stage-1 is unaffected, as the HA and HD bits are only set if HAFDBS is detected in the ID register. KVM, on the other hand, relies on the RES0 behavior at stage-2 to use the same value for VTCR_EL2 on any cpu in the system. Mitigate the non-RES0 behavior by leaving VTCR_EL2.HA clear on affected systems. Cc: stable@vger.kernel.org Cc: D Scott Phillips <scott@os.amperecomputing.com> Cc: Darren Hart <darren@os.amperecomputing.com> Acked-by: D Scott Phillips <scott@os.amperecomputing.com> Acked-by: Catalin Marinas <catalin.marinas@arm.com> Link: https://lore.kernel.org/r/20230609220104.1836988-2-oliver.upton@linux.dev Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 44c026a commit 6df696c

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

Documentation/arm64/silicon-errata.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ stable kernels.
5252
| Allwinner | A64/R18 | UNKNOWN1 | SUN50I_ERRATUM_UNKNOWN1 |
5353
+----------------+-----------------+-----------------+-----------------------------+
5454
+----------------+-----------------+-----------------+-----------------------------+
55+
| Ampere | AmpereOne | AC03_CPU_38 | AMPERE_ERRATUM_AC03_CPU_38 |
56+
+----------------+-----------------+-----------------+-----------------------------+
57+
+----------------+-----------------+-----------------+-----------------------------+
5558
| ARM | Cortex-A510 | #2457168 | ARM64_ERRATUM_2457168 |
5659
+----------------+-----------------+-----------------+-----------------------------+
5760
| ARM | Cortex-A510 | #2064142 | ARM64_ERRATUM_2064142 |

arch/arm64/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,25 @@ menu "Kernel Features"
406406

407407
menu "ARM errata workarounds via the alternatives framework"
408408

409+
config AMPERE_ERRATUM_AC03_CPU_38
410+
bool "AmpereOne: AC03_CPU_38: Certain bits in the Virtualization Translation Control Register and Translation Control Registers do not follow RES0 semantics"
411+
default y
412+
help
413+
This option adds an alternative code sequence to work around Ampere
414+
erratum AC03_CPU_38 on AmpereOne.
415+
416+
The affected design reports FEAT_HAFDBS as not implemented in
417+
ID_AA64MMFR1_EL1.HAFDBS, but (V)TCR_ELx.{HA,HD} are not RES0
418+
as required by the architecture. The unadvertised HAFDBS
419+
implementation suffers from an additional erratum where hardware
420+
A/D updates can occur after a PTE has been marked invalid.
421+
422+
The workaround forces KVM to explicitly set VTCR_EL2.HA to 0,
423+
which avoids enabling unadvertised hardware Access Flag management
424+
at stage-2.
425+
426+
If unsure, say Y.
427+
409428
config ARM64_WORKAROUND_CLEAN_CACHE
410429
bool
411430

arch/arm64/kernel/cpu_errata.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
729729
MIDR_FIXED(MIDR_CPU_VAR_REV(1,1), BIT(25)),
730730
.cpu_enable = cpu_clear_bf16_from_user_emulation,
731731
},
732+
#endif
733+
#ifdef CONFIG_AMPERE_ERRATUM_AC03_CPU_38
734+
{
735+
.desc = "AmpereOne erratum AC03_CPU_38",
736+
.capability = ARM64_WORKAROUND_AMPERE_AC03_CPU_38,
737+
ERRATA_MIDR_ALL_VERSIONS(MIDR_AMPERE1),
738+
},
732739
#endif
733740
{
734741
}

arch/arm64/kvm/hyp/pgtable.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,18 @@ u64 kvm_get_vtcr(u64 mmfr0, u64 mmfr1, u32 phys_shift)
611611
#ifdef CONFIG_ARM64_HW_AFDBM
612612
/*
613613
* Enable the Hardware Access Flag management, unconditionally
614-
* on all CPUs. The features is RES0 on CPUs without the support
615-
* and must be ignored by the CPUs.
614+
* on all CPUs. In systems that have asymmetric support for the feature
615+
* this allows KVM to leverage hardware support on the subset of cores
616+
* that implement the feature.
617+
*
618+
* The architecture requires VTCR_EL2.HA to be RES0 (thus ignored by
619+
* hardware) on implementations that do not advertise support for the
620+
* feature. As such, setting HA unconditionally is safe, unless you
621+
* happen to be running on a design that has unadvertised support for
622+
* HAFDBS. Here be dragons.
616623
*/
617-
vtcr |= VTCR_EL2_HA;
624+
if (!cpus_have_final_cap(ARM64_WORKAROUND_AMPERE_AC03_CPU_38))
625+
vtcr |= VTCR_EL2_HA;
618626
#endif /* CONFIG_ARM64_HW_AFDBM */
619627

620628
/* Set the vmid bits */

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ WORKAROUND_2077057
7777
WORKAROUND_2457168
7878
WORKAROUND_2645198
7979
WORKAROUND_2658417
80+
WORKAROUND_AMPERE_AC03_CPU_38
8081
WORKAROUND_TRBE_OVERWRITE_FILL_MODE
8182
WORKAROUND_TSB_FLUSH_FAILURE
8283
WORKAROUND_TRBE_WRITE_OUT_OF_RANGE

0 commit comments

Comments
 (0)