arm64: Work around Falkor erratum 1003
Subsystems (2)
PATCH v5 1/2 arm64: Work around Falkor erratum 1003
The Qualcomm Datacenter Technologies Falkor v1 CPU may allocate TLB entries using an incorrect ASID when TTBRx_EL1 is being updated. When the erratum is triggered, page table entries using the new translation table base address (BADDR) will be allocated into the TLB using the old ASID. All circumstances leading to the incorrect ASID being cached in the TLB arise when software writes TTBRx_EL1[ASID] and TTBRx_EL1[BADDR], a memory operation is in the process of performing a translation using the specific TTBRx_EL1 being written, and the memory operation uses a translation table descriptor designated as non-global. EL2 and EL3 code changing the EL1&0 ASID is not subject to this erratum because hardware is prohibited from performing translations from an out-of-context translation regime.
Consider the following pseudo code.
write new BADDR and ASID values to TTBRx_EL1
Replacing the above sequence with the one below will ensure that no TLB entries with an incorrect ASID are used by software.
write reserved value to TTBRx_EL1[ASID]
ISB
write new value to TTBRx_EL1[BADDR]
ISB
write new value to TTBRx_EL1[ASID]
ISB
When the above sequence is used, page table entries using the new BADDR value may still be incorrectly allocated into the TLB using the reserved ASID. Yet this will not reduce functionality, since TLB entries incorrectly tagged with the reserved ASID will never be hit by a later instruction.
Based on work by Shanker Donthineni <[email protected]>
---
Based on https://git.kernel.org/cgit/linux/kernel/git/arm64/linux.git/log/?h=for-next/core
--- Documentation/arm64/silicon-errata.txt | 1 + arch/arm64/Kconfig | 11 +++++++++++ arch/arm64/include/asm/assembler.h | 23 +++++++++++++++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/mmu_context.h | 8 +++++++- arch/arm64/kernel/cpu_errata.c | 9 +++++++++ arch/arm64/mm/context.c | 11 +++++++++++ arch/arm64/mm/proc.S | 1 + 8 files changed, 65 insertions(+), 2 deletions(-)
Documentation/arm64/silicon-errata.txt +1 -0
@@ -63,3 +63,4 @@ stable kernels. | Cavium | ThunderX SMMUv2 | #27704 | N/A | | | | | | | Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 | +| Qualcomm Tech. | Falkor v1 | E1003 | QCOM_FALKOR_ERRATUM_1003|
arch/arm64/Kconfig +11 -0
@@ -480,6 +480,17 @@ config CAVIUM_ERRATUM_27456 If unsure, say Y. +config QCOM_FALKOR_ERRATUM_1003 + bool "Falkor E1003: Incorrect translation due to ASID change" + default y + help + On Falkor v1, an incorrect ASID may be cached in the TLB when ASID + and BADDR are changed together in TTBRx_EL1. The workaround for this + issue is to use a reserved ASID in cpu_do_switch_mm() before + switching to the new ASID. + + If unsure, say Y. + endmenu
arch/arm64/include/asm/assembler.h +23 -0
@@ -25,6 +25,7 @@#include <asm/asm-offsets.h> #include <asm/cpufeature.h> +#include <asm/mmu_context.h> #include <asm/page.h> #include <asm/pgtable-hwdef.h> #include <asm/ptrace.h>
@@ -423,6 +424,28 @@ alternative_endif .endm /* + * Errata workaround prior to TTBR0_EL1 update + * + * val: TTBR value with new BADDR, preserved + * tmp0: temporary register, clobbered + * tmp1: other temporary register, clobbered + */ + .macro pre_ttbr0_update_workaround, val, tmp0, tmp1 +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 +alternative_if ARM64_WORKAROUND_QCOM_FALKOR_E1003 + mrs \tmp0, ttbr0_el1 + mov \tmp1, #FALKOR_RESERVED_ASID + bfi \tmp0, \tmp1, #48, #16 // reserved ASID + old BADDR + msr ttbr0_el1, \tmp0 + isb + bfi \tmp0, \val, #0, #48 // reserved ASID + new BADDR + msr ttbr0_el1, \tmp0 + isb +alternative_else_nop_endif +#endif + .endm + +/* * Errata workaround post TTBR0_EL1 update. */ .macro post_ttbr0_update_workaround
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -35,7 +35,8 @@#define ARM64_HYP_OFFSET_LOW 14#define ARM64_MISMATCHED_CACHE_LINE_SIZE 15#define ARM64_HAS_NO_FPSIMD 16 +#define ARM64_WORKAROUND_QCOM_FALKOR_E1003 17 -#define ARM64_NCAPS 17 +#define ARM64_NCAPS 18#endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/mmu_context.h +7 -1
@@ -19,6 +19,10 @@#ifndef __ASM_MMU_CONTEXT_H#define __ASM_MMU_CONTEXT_H +#define FALKOR_RESERVED_ASID 1 + +#ifndef __ASSEMBLY__ +#include <linux/compiler.h> #include <linux/sched.h>
@@ -220,4 +224,6 @@ switch_mm(struct mm_struct *prev, struct mm_struct *next,void verify_cpu_asid_bits (void ); -#endif +#endif /* !__ASSEMBLY__ */ + +#endif /* !__ASM_MMU_CONTEXT_H */
arch/arm64/kernel/cpu_errata.c +9 -0
@@ -133,6 +133,15 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .def_scope = SCOPE_LOCAL_CPU, .enable = cpu_enable_trap_ctr_access, }, +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003 + { + .desc = "Qualcomm Technologies Falkor erratum 1003", + .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003, + MIDR_RANGE(MIDR_QCOM_FALKOR_V1, + MIDR_CPU_VAR_REV(0, 0), + MIDR_CPU_VAR_REV(0, 0)), + }, +#endif { } };
arch/arm64/mm/context.c +11 -0
@@ -79,6 +79,13 @@ void verify_cpu_asid_bits(void) } } +static void set_reserved_asid_bits (void ) +{ +if (IS_ENABLED (CONFIG_QCOM_FALKOR_ERRATUM_1003 ) && +cpus_have_cap (ARM64_WORKAROUND_QCOM_FALKOR_E1003 )) +__set_bit (FALKOR_RESERVED_ASID , asid_map); +} +static void flush_context (unsigned int cpu) {int i;
@@ -87,6 +94,8 @@ static void flush_context(unsigned int cpu)/* Update the list of reserved ASIDs and the ASID bitmap. */ bitmap_clear (asid_map,0 ,NUM_USER_ASIDS ); +set_reserved_asid_bits (); +/* * Ensure the generation bump is observed before we xchg the * active_asids.
@@ -244,6 +253,8 @@ static int asids_init(void)panic ("Failed to allocate bitmap for %lu ASIDs\n" ,NUM_USER_ASIDS ); +set_reserved_asid_bits (); +pr_info ("ASID allocator initialised with %lu entries\n" ,NUM_USER_ASIDS );return 0 ; }
arch/arm64/mm/proc.S +1 -0
@@ -138,6 +138,7 @@ ENDPROC(cpu_do_resume) * - pgd_phys - physical address of new TTB */ ENTRY(cpu_do_switch_mm) + pre_ttbr0_update_workaround x0, x1, x2 mmid x1, x1 // get mm->context.id bfi x0, x1, #48, #16 // set the ASID msr ttbr0_el1, x0 // set TTBR0
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v5 2/2 arm64: Work around Falkor erratum 1009
During a TLB invalidate sequence targeting the inner shareable domain, Falkor may prematurely complete the DSB before all loads and stores using the old translation are observed. Instruction fetches are not subject to the conditions of this erratum. If the original code sequence includes multiple TLB invalidate instructions followed by a single DSB, onle one of the TLB instructions needs to be repeated to work around this erratum. While the erratum only applies to cases in which the TLBI specifies the inner-shareable domain (*IS form of TLBI) and the DSB is ISH form or stronger (OSH, SYS), this changes applies the workaround overabundantly-- to local TLBI, DSB NSH sequences as well--for simplicity.
Based on work by Shanker Donthineni <[email protected]>
---
Based on https://git.kernel.org/cgit/linux/kernel/git/arm64/linux.git/log/?h=for-next/core
--- Documentation/arm64/silicon-errata.txt | 1 + arch/arm64/Kconfig | 10 ++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/tlbflush.h | 18 +++++++++++++++--- arch/arm64/kernel/cpu_errata.c | 9 +++++++++ 5 files changed, 37 insertions(+), 4 deletions(-)
Documentation/arm64/silicon-errata.txt +1 -0
@@ -64,3 +64,4 @@ stable kernels. | | | | | | Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 | | Qualcomm Tech. | Falkor v1 | E1003 | QCOM_FALKOR_ERRATUM_1003| +| Qualcomm Tech. | Falkor v1 | E1009 | QCOM_FALKOR_ERRATUM_1009|
arch/arm64/Kconfig +10 -0
@@ -491,6 +491,16 @@ config QCOM_FALKOR_ERRATUM_1003 If unsure, say Y. +config QCOM_FALKOR_ERRATUM_1009 + bool "Falkor E1009: Prematurely complete a DSB after a TLBI" + default y + help + On Falkor v1, the CPU may prematurely complete a DSB following a + TLBI xxIS invalidate maintenance operation. Repeat the TLBI operation + one more time to fix the issue. + + If unsure, say Y. + endmenu
arch/arm64/include/asm/cpucaps.h +2 -1
@@ -36,7 +36,8 @@#define ARM64_MISMATCHED_CACHE_LINE_SIZE 15#define ARM64_HAS_NO_FPSIMD 16#define ARM64_WORKAROUND_QCOM_FALKOR_E1003 17 +#define ARM64_WORKAROUND_REPEAT_TLBI 18 -#define ARM64_NCAPS 18 +#define ARM64_NCAPS 19#endif /* __ASM_CPUCAPS_H */
arch/arm64/include/asm/tlbflush.h +15 -3
@@ -36,9 +36,21 @@* not. The macros handles invoking the asm with or without the * register argument as appropriate. */ -#define __TLBI_0 (op, arg) asm ("tlbi " #op) -#define __TLBI_1 (op, arg) asm ("tlbi " #op ", %0" : : "r" (arg)) -#define __TLBI_N (op, arg, n, ...) __TLBI_##n(op, arg) +#define __TLBI_0 (op, arg) asm volatile ("tlbi " #op "\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op, \ + ARM64_WORKAROUND_REPEAT_TLBI, \ + CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : ) + +#define __TLBI_1 (op, arg) asm volatile ("tlbi " #op ", %0\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op ", %0", \ + ARM64_WORKAROUND_REPEAT_TLBI, \ + CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : "r" (arg)) + +#define __TLBI_N (op, arg, n, ...) __TLBI_##n(op, arg)#define __tlbi (op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0)
arch/arm64/kernel/cpu_errata.c +9 -0
@@ -142,6 +142,15 @@ const struct arm64_cpu_capabilities arm64_errata[] = { MIDR_CPU_VAR_REV(0, 0)), },#endif +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009 + { + .desc = "Qualcomm Technologies Falkor erratum 1009", + .capability = ARM64_WORKAROUND_REPEAT_TLBI, + MIDR_RANGE(MIDR_QCOM_FALKOR_V1, + MIDR_CPU_VAR_REV(0, 0), + MIDR_CPU_VAR_REV(0, 0)), + }, +#endif { } };
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v5 2/2] arm64: Work around Falkor erratum 1009
Quoted 11 lines · Christopher Covington
During a TLB invalidate sequence targeting the inner shareable domain, Falkor may prematurely complete the DSB before all loads and stores using the old translation are observed. Instruction fetches are not subject to the conditions of this erratum. If the original code sequence includes multiple TLB invalidate instructions followed by a single DSB, onle one of the TLB instructions needs to be repeated to work around this erratum. While the erratum only applies to cases in which the TLBI specifies the inner-shareable domain (*IS form of TLBI) and the DSB is ISH form or stronger (OSH, SYS), this changes applies the workaround overabundantly-- to local TLBI, DSB NSH sequences as well--for simplicity.
Quoted 3 lines
Based on work by Shanker Donthineni <[email protected]>
Signed-off-by Christopher Covington <[email protected]>
This looks simple, self-contained, and correct, so FWIW:
Catalin/Will, since we may see a documentation conflict against a timer erratum, would you be hapyp to pick up [1] first, fixing up this patch as necessary?
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/484594.html
Thanks,
Mark.
Quoted 108 lines
---
Based on https://git.kernel.org/cgit/linux/kernel/git/arm64/linux.git/log/?h=for-next/core--- Documentation/arm64/silicon-errata.txt | 1 + arch/arm64/Kconfig | 10 ++++++++++ arch/arm64/include/asm/cpucaps.h | 3 ++- arch/arm64/include/asm/tlbflush.h | 18 +++++++++++++++--- arch/arm64/kernel/cpu_errata.c | 9 +++++++++ 5 files changed, 37 insertions(+), 4 deletions(-)Documentation/arm64/silicon-errata.txt +1
-0@@ -64,3 +64,4 @@ stable kernels. | | | | | | Freescale/NXP | LS2080A/LS1043A | A-008585 | FSL_ERRATUM_A008585 | | Qualcomm Tech. | Falkor v1 | E1003 | QCOM_FALKOR_ERRATUM_1003| +| Qualcomm Tech. | Falkor v1 | E1009 | QCOM_FALKOR_ERRATUM_1009|arch/arm64/Kconfig +10
-0@@ -491,6 +491,16 @@ config QCOM_FALKOR_ERRATUM_1003 If unsure, say Y. +config QCOM_FALKOR_ERRATUM_1009 + bool "Falkor E1009: Prematurely complete a DSB after a TLBI" + default y + help + On Falkor v1, the CPU may prematurely complete a DSB following a + TLBI xxIS invalidate maintenance operation. Repeat the TLBI operation + one more time to fix the issue. + + If unsure, say Y. + endmenuarch/arm64/include/asm/cpucaps.h +2
-1@@ -36,7 +36,8 @@#define ARM64_MISMATCHED_CACHE_LINE_SIZE 15#define ARM64_HAS_NO_FPSIMD 16#define ARM64_WORKAROUND_QCOM_FALKOR_E1003 17 +#define ARM64_WORKAROUND_REPEAT_TLBI 18 -#define ARM64_NCAPS 18 +#define ARM64_NCAPS 19#endif /* __ASM_CPUCAPS_H */ arch/arm64/include/asm/tlbflush.h +15
-3@@ -36,9 +36,21 @@* not. The macros handles invoking the asm with or without the * register argument as appropriate. */ -#define __TLBI_0 (op, arg) asm ("tlbi " #op) -#define __TLBI_1 (op, arg) asm ("tlbi " #op ", %0" : : "r" (arg)) -#define __TLBI_N (op, arg, n, ...) __TLBI_##n(op, arg) +#define __TLBI_0 (op, arg) asm volatile ("tlbi " #op "\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op, \ + ARM64_WORKAROUND_REPEAT_TLBI, \ + CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : ) + +#define __TLBI_1 (op, arg) asm volatile ("tlbi " #op ", %0\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op ", %0", \ + ARM64_WORKAROUND_REPEAT_TLBI, \ + CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : "r" (arg)) + +#define __TLBI_N (op, arg, n, ...) __TLBI_##n(op, arg)#define __tlbi (op, ...) __TLBI_N(op, ##__VA_ARGS__, 1, 0)arch/arm64/kernel/cpu_errata.c +9
-0@@ -142,6 +142,15 @@ const struct arm64_cpu_capabilities arm64_errata[] = { MIDR_CPU_VAR_REV(0, 0)), },#endif +#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009 + { + .desc = "Qualcomm Technologies Falkor erratum 1009", + .capability = ARM64_WORKAROUND_REPEAT_TLBI, + MIDR_RANGE(MIDR_QCOM_FALKOR_V1, + MIDR_CPU_VAR_REV(0, 0), + MIDR_CPU_VAR_REV(0, 0)), + }, +#endif { } };Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH v5 2/2] arm64: Work around Falkor erratum 1009
Quoted 18 lines · Mark Rutland
Quoted 11 lines · Christopher Covington
During a TLB invalidate sequence targeting the inner shareable domain, Falkor may prematurely complete the DSB before all loads and stores using the old translation are observed. Instruction fetches are not subject to the conditions of this erratum. If the original code sequence includes multiple TLB invalidate instructions followed by a single DSB, onle one of the TLB instructions needs to be repeated to work around this erratum. While the erratum only applies to cases in which the TLBI specifies the inner-shareable domain (*IS form of TLBI) and the DSB is ISH form or stronger (OSH, SYS), this changes applies the workaround overabundantly-- to local TLBI, DSB NSH sequences as well--for simplicity.
Quoted 3 lines
Based on work by Shanker Donthineni <[email protected]>
Signed-off-by Christopher Covington <[email protected]>This looks simple, self-contained, and correct, so FWIW:
Quoted 7 lines
Acked-by Mark Rutland <[email protected]>Catalin/Will, since we may see a documentation conflict against a timer erratum, would you be hapyp to pick up [1] first, fixing up this patch as necessary?
[1] http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/484594.html
I replied over there, but I'd rather just take all the silicon-errata.txt changes because I don't see them as being dependent on the rest of the series.
For this patch specifically, I can't merge it until you're happy with the other workaround, since they conflict.
Will
Re: [PATCH v5 2/2] arm64: Work around Falkor erratum 1009
In reply to Christopher CovingtonQuoted 15 lines · Christopher Covington
arch/arm64/include/asm/tlbflush.h +4
-3@@ -36,9 +36,21 @@* not. The macros handles invoking the asm with or without the * register argument as appropriate. */ -#define __TLBI_0 (op, arg) asm ("tlbi " #op) -#define __TLBI_1 (op, arg) asm ("tlbi " #op ", %0" : : "r" (arg)) -#define __TLBI_N (op, arg, n, ...) __TLBI_##n(op, arg) +#define __TLBI_0 (op, arg) asm volatile ("tlbi " #op "\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op, \ + ARM64_WORKAROUND_REPEAT_TLBI, \
arch/arm64/include/asm/tlbflush.h line 52
Quoted 10 lines
arch/arm64/include/asm/tlbflush.h +10
-0+ CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : ) + +#define __TLBI_1 (op, arg) asm volatile ("tlbi " #op ", %0\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op ", %0", \ + ARM64_WORKAROUND_REPEAT_TLBI, \ + CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : "r" (arg)) +
Why are these now volatile? I asked the same question on the previous version but didn't get a response:
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/483579.html
Will
Re: [PATCH v5 2/2] arm64: Work around Falkor erratum 1009
Quoted 30 lines · Will Deacon
Quoted 15 lines · Christopher Covington
arch/arm64/include/asm/tlbflush.h +4
-3@@ -36,9 +36,21 @@* not. The macros handles invoking the asm with or without the * register argument as appropriate. */ -#define __TLBI_0 (op, arg) asm ("tlbi " #op) -#define __TLBI_1 (op, arg) asm ("tlbi " #op ", %0" : : "r" (arg)) -#define __TLBI_N (op, arg, n, ...) __TLBI_##n(op, arg) +#define __TLBI_0 (op, arg) asm volatile ("tlbi " #op "\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op, \ + ARM64_WORKAROUND_REPEAT_TLBI, \arch/arm64/include/asm/tlbflush.h line 52
Quoted 10 lines
arch/arm64/include/asm/tlbflush.h +10
-0+ CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : ) + +#define __TLBI_1 (op, arg) asm volatile ("tlbi " #op ", %0\n" \ + ALTERNATIVE("nop\n nop", \ + "dsb ish\n tlbi " #op ", %0", \ + ARM64_WORKAROUND_REPEAT_TLBI, \ + CONFIG_QCOM_FALKOR_ERRATUM_1009) \ + : : "r" (arg)) +Why are these now volatile? I asked the same question on the previous version but didn't get a response:
D'oh! Will fix in v6. Sorry about that.
Cov
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.