arm64: errata: Work around AmpereOne's erratum AC04_CPU_23
PATCH v2 1/1 arm64: errata: Work around AmpereOne's erratum AC04_CPU_23
Updates to HCR_EL2 can rarely corrupt simultaneous translations for data addresses initiated by load/store instructions. Only instruction initiated translations are vulnerable, not translations from prefetches for example. A DSB before the store to HCR_EL2 is sufficient to prevent older instructions from hitting the window for corruption, and an ISB after is sufficient to prevent younger instructions from hitting the window for corruption.
---
v1: https://lore.kernel.org/kvmarm/[email protected]/
Changes since v1:
- Add a write_sysreg_hcr() helper (Oliver)
- Add more specific wording in the errata description (Oliver & Marc)
arch/arm64/Kconfig | 17 +++++++++++++++++ arch/arm64/include/asm/hardirq.h | 4 ++-- arch/arm64/include/asm/sysreg.h | 10 ++++++++++ arch/arm64/kernel/cpu_errata.c | 14 ++++++++++++++ arch/arm64/kvm/at.c | 8 ++++---- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/nvhe/switch.c | 2 +- arch/arm64/kvm/hyp/vhe/switch.c | 2 +- arch/arm64/kvm/hyp/vhe/tlb.c | 4 ++-- arch/arm64/tools/cpucaps | 1 + 11 files changed, 54 insertions(+), 12 deletions(-)
arch/arm64/Kconfig +17 -0
@@ -464,6 +464,23 @@ config AMPERE_ERRATUM_AC03_CPU_38 If unsure, say Y. +config AMPERE_ERRATUM_AC04_CPU_23 + bool "AmpereOne: AC04_CPU_23: Failure to synchronize writes to HCR_EL2 may corrupt address translations." + default y + help + This option adds an alternative code sequence to work around Ampere + errata AC04_CPU_23 on AmpereOne. + + Updates to HCR_EL2 can rarely corrupt simultaneous translations for + data addresses initiated by load/store instructions. Only + instruction initiated translations are vulnerable, not translations + from prefetches for example. A DSB before the store to HCR_EL2 is + sufficient to prevent older instructions from hitting the window + for corruption, and an ISB after is sufficient to prevent younger + instructions from hitting the window for corruption. + + If unsure, say Y. + config ARM64_WORKAROUND_CLEAN_CACHE bool
arch/arm64/include/asm/hardirq.h +2 -2
@@ -41,7 +41,7 @@ do { \ \ ___hcr =read_sysreg (hcr_el2); \if (!(___hcr &HCR_TGE )) { \ -write_sysreg (___hcr |HCR_TGE , hcr_el2); \ +write_sysreg_hcr (___hcr |HCR_TGE ); \isb (); \ } \/* \
@@ -82,7 +82,7 @@ do { \*/ \barrier (); \if (!___ctx->cnt && !(___hcr &HCR_TGE )) \ -write_sysreg (___hcr, hcr_el2); \ +write_sysreg_hcr (___hcr); \ }while (0 ) static inline void ack_bad_irq(unsigned int irq)
arch/arm64/include/asm/sysreg.h +10 -0
@@ -1185,6 +1185,16 @@write_sysreg_s (__scs_new, sysreg); \ } while (0) +#define write_sysreg_hcr (__val) do { \ + if(IS_ENABLED(CONFIG_AMPERE_ERRATUM_AC04_CPU_23) && \ + alternative_has_cap_unlikely(ARM64_WORKAROUND_AMPERE_AC04_CPU_23)) \ + asm volatile("dsb nsh; msr hcr_el2, %x0; isb" \ + : : "rZ" (__val)); \ + else \ + asm volatile("msr hcr_el2, %x0" \ + : : "rZ" (__val)); \ +} while (0) +#define read_sysreg_par () ({ \ u64 par; \ asm(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412)); \
arch/arm64/kernel/cpu_errata.c +14 -0
@@ -557,6 +557,13 @@ static const struct midr_range erratum_ac03_cpu_38_list[] = { };#endif +#ifdef CONFIG_AMPERE_ERRATUM_AC04_CPU_23 +static const struct midr_range erratum_ac04_cpu_23_list[] = { +MIDR_ALL_VERSIONS (MIDR_AMPERE1A ), + {}, +}; +#endif + const struct arm64_cpu_capabilities arm64_errata[] = {#ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE {
@@ -875,6 +882,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .capability = ARM64_WORKAROUND_AMPERE_AC03_CPU_38, ERRATA_MIDR_RANGE_LIST(erratum_ac03_cpu_38_list), }, +#endif +#ifdef CONFIG_AMPERE_ERRATUM_AC04_CPU_23 + { + .desc = "AmpereOne erratum AC04_CPU_23", + .capability =ARM64_WORKAROUND_AMPERE_AC04_CPU_23 , + ERRATA_MIDR_RANGE_LIST(erratum_ac04_cpu_23_list), + }, #endif { .desc = "Broken CNTVOFF_EL2",
arch/arm64/kvm/at.c +4 -4
@@ -516,7 +516,7 @@ static void __mmu_config_save(struct mmu_config *config)static void __mmu_config_restore (struct mmu_config *config) { -write_sysreg (config->hcr, hcr_el2); +write_sysreg_hcr (config->hcr);/* * ARM errata 1165522 and 1530923 require TGE to be 1 before
@@ -1267,7 +1267,7 @@ static u64 __kvm_at_s1e01_fast(struct kvm_vcpu *vcpu, u32 op, u64 vaddr) skip_mmu_switch:/* Clear TGE, enable S2 translation, we're rolling */ -write_sysreg ((config.hcr & ~HCR_TGE ) |HCR_VM , hcr_el2); +write_sysreg_hcr ((config.hcr & ~HCR_TGE ) |HCR_VM );isb ();switch (op) {
@@ -1350,7 +1350,7 @@ void __kvm_at_s1e2(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)if (!vcpu_el2_e2h_is_set (vcpu)) val |=HCR_NV |HCR_NV1 ; -write_sysreg (val, hcr_el2); +write_sysreg_hcr (val);isb (); par =SYS_PAR_EL1_F ;
@@ -1375,7 +1375,7 @@ void __kvm_at_s1e2(struct kvm_vcpu *vcpu, u32 op, u64 vaddr)if (!fail) par =read_sysreg_par (); -write_sysreg (hcr, hcr_el2); +write_sysreg_hcr (hcr);isb (); }
arch/arm64/kvm/hyp/include/hyp/switch.h +1 -1
@@ -301,7 +301,7 @@ static inline void ___activate_traps(struct kvm_vcpu *vcpu, u64 hcr)if (cpus_have_final_cap (ARM64_WORKAROUND_CAVIUM_TX2_219_TVM )) hcr |=HCR_TVM ; -write_sysreg (hcr, hcr_el2); +write_sysreg_hcr (hcr);if (cpus_have_final_cap (ARM64_HAS_RAS_EXTN ) && (hcr &HCR_VSE ))write_sysreg_s (vcpu->arch.vsesr_el2,SYS_VSESR_EL2 );
arch/arm64/kvm/hyp/nvhe/mem_protect.c +1 -1
@@ -309,7 +309,7 @@ int __pkvm_prot_finalize(void)*/ kvm_flush_dcache_to_poc (params,sizeof (*params)); -write_sysreg (params->hcr_el2, hcr_el2); +write_sysreg_hcr (params->hcr_el2);__load_stage2 (&host_mmu.arch.mmu, &host_mmu.arch);/*
arch/arm64/kvm/hyp/nvhe/switch.c +1 -1
@@ -142,7 +142,7 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)__deactivate_traps_common (vcpu); -write_sysreg (this_cpu_ptr (&kvm_init_params)->hcr_el2, hcr_el2); +write_sysreg_hcr (this_cpu_ptr (&kvm_init_params)->hcr_el2);__deactivate_cptr_traps (vcpu);write_sysreg (__kvm_hyp_host_vector, vbar_el2);
arch/arm64/kvm/hyp/vhe/switch.c +1 -1
@@ -184,7 +184,7 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)___deactivate_traps (vcpu); -write_sysreg (HCR_HOST_VHE_FLAGS , hcr_el2); +write_sysreg_hcr (HCR_HOST_VHE_FLAGS );if (has_cntpoff ()) {struct timer_map map;
arch/arm64/kvm/hyp/vhe/tlb.c +2 -2
@@ -63,7 +63,7 @@ static void enter_vmid_context(struct kvm_s2_mmu *mmu,__load_stage2 (mmu, mmu->arch); val =read_sysreg (hcr_el2); val &= ~HCR_TGE ; -write_sysreg (val, hcr_el2); +write_sysreg_hcr (val);isb (); }
@@ -73,7 +73,7 @@ static void exit_vmid_context(struct tlb_inv_context *cxt)* We're done with the TLB operation, let's restore the host's * view of HCR_EL2. */ -write_sysreg (HCR_HOST_VHE_FLAGS , hcr_el2); +write_sysreg_hcr (HCR_HOST_VHE_FLAGS );isb ();/* ... and the stage-2 MMU context that we switched away from */
arch/arm64/tools/cpucaps +1 -0
@@ -94,6 +94,7 @@ WORKAROUND_2457168 WORKAROUND_2645198 WORKAROUND_2658417 WORKAROUND_AMPERE_AC03_CPU_38 +WORKAROUND_AMPERE_AC04_CPU_23 WORKAROUND_TRBE_OVERWRITE_FILL_MODE WORKAROUND_TSB_FLUSH_FAILURE WORKAROUND_TRBE_WRITE_OUT_OF_RANGE
Signature · 1 line
2.49.0
Marc Zyngier
maintainerQuoted 87 lines · D Scott Phillips
Updates to
HCR_EL2can rarely corrupt simultaneous translations for data addresses initiated by load/store instructions. Only instruction initiated translations are vulnerable, not translations from prefetches for example. A DSB before the store toHCR_EL2is sufficient to prevent older instructions from hitting the window for corruption, and an ISB after is sufficient to prevent younger instructions from hitting the window for corruption.Signed-off-by D Scott Phillips <[email protected]>---
v1: https://lore.kernel.org/kvmarm/[email protected]/
Changes since v1:
- Add awrite_sysreg_hcr()helper (Oliver)
- Add more specific wording in the errata description (Oliver & Marc)arch/arm64/Kconfig | 17 +++++++++++++++++ arch/arm64/include/asm/hardirq.h | 4 ++-- arch/arm64/include/asm/sysreg.h | 10 ++++++++++ arch/arm64/kernel/cpu_errata.c | 14 ++++++++++++++ arch/arm64/kvm/at.c | 8 ++++---- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/nvhe/switch.c | 2 +- arch/arm64/kvm/hyp/vhe/switch.c | 2 +- arch/arm64/kvm/hyp/vhe/tlb.c | 4 ++-- arch/arm64/tools/cpucaps | 1 + 11 files changed, 54 insertions(+), 12 deletions(-)arch/arm64/Kconfig +17
-0@@ -464,6 +464,23 @@ config AMPERE_ERRATUM_AC03_CPU_38 If unsure, say Y. +config AMPERE_ERRATUM_AC04_CPU_23 + bool "AmpereOne: AC04_CPU_23: Failure to synchronize writes to HCR_EL2 may corrupt address translations." + default y + help + This option adds an alternative code sequence to work around Ampere + errata AC04_CPU_23 on AmpereOne. + + Updates to HCR_EL2 can rarely corrupt simultaneous translations for + data addresses initiated by load/store instructions. Only + instruction initiated translations are vulnerable, not translations + from prefetches for example. A DSB before the store to HCR_EL2 is + sufficient to prevent older instructions from hitting the window + for corruption, and an ISB after is sufficient to prevent younger + instructions from hitting the window for corruption. + + If unsure, say Y. + config ARM64_WORKAROUND_CLEAN_CACHE boolarch/arm64/include/asm/hardirq.h +2
-2@@ -41,7 +41,7 @@ do { \ \ ___hcr =read_sysreg (hcr_el2); \if (!(___hcr &HCR_TGE )) { \ -write_sysreg (___hcr |HCR_TGE , hcr_el2); \ +write_sysreg_hcr (___hcr |HCR_TGE ); \isb (); \ } \/* \ @@ -82,7 +82,7 @@ do { \*/ \barrier (); \if (!___ctx->cnt && !(___hcr &HCR_TGE )) \ -write_sysreg (___hcr, hcr_el2); \ +write_sysreg_hcr (___hcr); \ }while (0 ) static inline void ack_bad_irq(unsigned int irq)arch/arm64/include/asm/sysreg.h +0
-0@@ -1185,6 +1185,16 @@write_sysreg_s (__scs_new, sysreg); \ }while (0 )
arch/arm64/include/asm/sysreg.h line 1197
Quoted 10 lines
arch/arm64/include/asm/sysreg.h +10
-0+#define write_sysreg_hcr (__val) do { \ + if(IS_ENABLED(CONFIG_AMPERE_ERRATUM_AC04_CPU_23) && \ + alternative_has_cap_unlikely(ARM64_WORKAROUND_AMPERE_AC04_CPU_23)) \ + asm volatile("dsb nsh; msr hcr_el2, %x0; isb" \ + : : "rZ" (__val)); \ + else \ + asm volatile("msr hcr_el2, %x0" \ + : : "rZ" (__val)); \ +} while (0) +
I'm worried that some of these accesses may occur before we compute the capabilities. I'd be more confident if the default was to have the workaround, and only to relax it once we know we're not on a broken system.
But that leaves the question of the early stuff that runs before we get to C code. Are you sure this isn't affected by this issue (for example, the code in head.S, hyp-stub.S, and el2-setup.h)?
Quoted 23 lines
arch/arm64/include/asm/sysreg.h +0
-0#define read_sysreg_par () ({ \ u64 par; \ asm(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412)); \arch/arm64/kernel/cpu_errata.c +7
-0@@ -557,6 +557,13 @@ static const struct midr_range erratum_ac03_cpu_38_list[] = { };#endif +#ifdef CONFIG_AMPERE_ERRATUM_AC04_CPU_23 +static const struct midr_range erratum_ac04_cpu_23_list[] = { +MIDR_ALL_VERSIONS (MIDR_AMPERE1A ), + {}, +}; +#endif + const struct arm64_cpu_capabilities arm64_errata[] = {#ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE {@@ -875,6 +882,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .capability = ARM64_WORKAROUND_AMPERE_AC03_CPU_38,
arch/arm64/kernel/cpu_errata.c const struct arm64_cpu_capabilities arm64_errata[] = { · line 892
Quoted 10 lines
arch/arm64/kernel/cpu_errata.c +7
-0ERRATA_MIDR_RANGE_LIST(erratum_ac03_cpu_38_list), }, +#endif +#ifdef CONFIG_AMPERE_ERRATUM_AC04_CPU_23 + { + .desc = "AmpereOne erratum AC04_CPU_23", + .capability = ARM64_WORKAROUND_AMPERE_AC04_CPU_23, + ERRATA_MIDR_RANGE_LIST(erratum_ac04_cpu_23_list), + }, #endif
This needs to be captured in Documentation/arch/arm64/silicon-errata.rst.
Thanks,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
Quoted 89 lines · Marc Zyngier
Quoted 87 lines · D Scott Phillips
Updates to
HCR_EL2can rarely corrupt simultaneous translations for data addresses initiated by load/store instructions. Only instruction initiated translations are vulnerable, not translations from prefetches for example. A DSB before the store toHCR_EL2is sufficient to prevent older instructions from hitting the window for corruption, and an ISB after is sufficient to prevent younger instructions from hitting the window for corruption.Signed-off-by D Scott Phillips <[email protected]>---
v1: https://lore.kernel.org/kvmarm/[email protected]/
Changes since v1:
- Add awrite_sysreg_hcr()helper (Oliver)
- Add more specific wording in the errata description (Oliver & Marc)arch/arm64/Kconfig | 17 +++++++++++++++++ arch/arm64/include/asm/hardirq.h | 4 ++-- arch/arm64/include/asm/sysreg.h | 10 ++++++++++ arch/arm64/kernel/cpu_errata.c | 14 ++++++++++++++ arch/arm64/kvm/at.c | 8 ++++---- arch/arm64/kvm/hyp/include/hyp/switch.h | 2 +- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 2 +- arch/arm64/kvm/hyp/nvhe/switch.c | 2 +- arch/arm64/kvm/hyp/vhe/switch.c | 2 +- arch/arm64/kvm/hyp/vhe/tlb.c | 4 ++-- arch/arm64/tools/cpucaps | 1 + 11 files changed, 54 insertions(+), 12 deletions(-)arch/arm64/Kconfig +17
-0@@ -464,6 +464,23 @@ config AMPERE_ERRATUM_AC03_CPU_38 If unsure, say Y. +config AMPERE_ERRATUM_AC04_CPU_23 + bool "AmpereOne: AC04_CPU_23: Failure to synchronize writes to HCR_EL2 may corrupt address translations." + default y + help + This option adds an alternative code sequence to work around Ampere + errata AC04_CPU_23 on AmpereOne. + + Updates to HCR_EL2 can rarely corrupt simultaneous translations for + data addresses initiated by load/store instructions. Only + instruction initiated translations are vulnerable, not translations + from prefetches for example. A DSB before the store to HCR_EL2 is + sufficient to prevent older instructions from hitting the window + for corruption, and an ISB after is sufficient to prevent younger + instructions from hitting the window for corruption. + + If unsure, say Y. + config ARM64_WORKAROUND_CLEAN_CACHE boolarch/arm64/include/asm/hardirq.h +2
-2@@ -41,7 +41,7 @@ do { \ \ ___hcr =read_sysreg (hcr_el2); \if (!(___hcr &HCR_TGE )) { \ -write_sysreg (___hcr |HCR_TGE , hcr_el2); \ +write_sysreg_hcr (___hcr |HCR_TGE ); \isb (); \ } \/* \ @@ -82,7 +82,7 @@ do { \*/ \barrier (); \if (!___ctx->cnt && !(___hcr &HCR_TGE )) \ -write_sysreg (___hcr, hcr_el2); \ +write_sysreg_hcr (___hcr); \ }while (0 ) static inline void ack_bad_irq(unsigned int irq)arch/arm64/include/asm/sysreg.h +0
-0@@ -1185,6 +1185,16 @@write_sysreg_s (__scs_new, sysreg); \ }while (0 )
Quoted 15 lines
arch/arm64/include/asm/sysreg.h line 1197
Quoted 10 lines
arch/arm64/include/asm/sysreg.h +10
-0+#define write_sysreg_hcr (__val) do { \ + if(IS_ENABLED(CONFIG_AMPERE_ERRATUM_AC04_CPU_23) && \ + alternative_has_cap_unlikely(ARM64_WORKAROUND_AMPERE_AC04_CPU_23)) \ + asm volatile("dsb nsh; msr hcr_el2, %x0; isb" \ + : : "rZ" (__val)); \ + else \ + asm volatile("msr hcr_el2, %x0" \ + : : "rZ" (__val)); \ +} while (0) +I'm worried that some of these accesses may occur before we compute the capabilities. I'd be more confident if the default was to have the workaround, and only to relax it once we know we're not on a broken system.
OK, will do
Quoted 3 lines
But that leaves the question of the early stuff that runs before we get to C code. Are you sure this isn't affected by this issue (for example, the code in
head.S,hyp-stub.S, andel2-setup.h)?
Ya, that's a good point. The corrupted translations can happen speculatively, so there's every reason to think all those places also need to be considered. I'll take a look everywhere now, not just at C.
Quoted 27 lines
Quoted 27 lines
arch/arm64/include/asm/sysreg.h +0
-0#define read_sysreg_par () ({ \ u64 par; \ asm(ALTERNATIVE("nop", "dmb sy", ARM64_WORKAROUND_1508412)); \arch/arm64/kernel/cpu_errata.c +9
-0@@ -557,6 +557,13 @@ static const struct midr_range erratum_ac03_cpu_38_list[] = { };#endif +#ifdef CONFIG_AMPERE_ERRATUM_AC04_CPU_23 +static const struct midr_range erratum_ac04_cpu_23_list[] = { +MIDR_ALL_VERSIONS (MIDR_AMPERE1A ), + {}, +}; +#endif + const struct arm64_cpu_capabilities arm64_errata[] = {#ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE {@@ -875,6 +882,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .capability = ARM64_WORKAROUND_AMPERE_AC03_CPU_38, ERRATA_MIDR_RANGE_LIST(erratum_ac03_cpu_38_list), }, +#endif +#ifdef CONFIG_AMPERE_ERRATUM_AC04_CPU_23
Quoted 8 lines
arch/arm64/kernel/cpu_errata.c const struct arm64_cpu_capabilities arm64_errata[] = { · line 892
Quoted 6 lines
arch/arm64/kernel/cpu_errata.c +5
-0+ { + .desc = "AmpereOne erratum AC04_CPU_23", + .capability = ARM64_WORKAROUND_AMPERE_AC04_CPU_23, + ERRATA_MIDR_RANGE_LIST(erratum_ac04_cpu_23_list), + }, #endifThis needs to be captured in
Documentation/arch/arm64/silicon-errata.rst.
OK, will do, thanks Marc.