arm64: Work around C1-Pro erratum 4193714 (CVE-2026-0995)
Subsystems (2)
Catalin Marinas
maintainerv5 cover arm64: Work around C1-Pro erratum 4193714 (CVE-2026-0995)
That's version 5 of the C1-Pro workaround. Version 3 here:
https://lore.kernel.org/r/[email protected]
Changes since v4:
- Static sme_dvmsync_cpus mask to avoid allocating under stop_machine(). Sashiko was right, even GFP_ATOMIC won't work under a raw_spin_lock()
- batch->cpumask allocated lazily on arch_tlbbatch_add_pending() only to avoid a potential leak in case of task cloning failure. That's mostly theoretical as the (mobile) systems affected are expected to be built with CPUMASK_OFFSTACK=n (the GKI kernel defaults to NR_CPUS=32)
The other Sashiko report about the DSB in arch_tlbbatch_add_pending() is correct but it's not much we can do about it. I don't expect this to be noticeable at all on systems with a small number of CPUs.
As with v4, there's no longer a global sme_active_cpus mask, reducing the risk DoS from a malicious app using SME.
Erratum description:
Arm C1-Pro prior to r1p3 has an erratum (4193714) where a TLBI+DSB sequence might fail to ensure the completion of all outstanding SME (Scalable Matrix Extension) memory accesses. The DVMSync message is acknowledged before the SME accesses have fully completed, potentially allowing pages to be reused before all in-flight accesses are done.
The workaround consists of executing a DSB locally (via IPI) on all affected CPUs running with SME enabled, after the TLB invalidation. This ensures the SME accesses have completed before the IPI is acknowledged.
This has been assigned CVE-2026-0995:
https://developer.arm.com/documentation/111823/latest/
Catalin Marinas (4):
arm64: tlb: Introduce __tlbi_sync_s1ish_{kernel,batch}() for TLB
maintenance
arm64: tlb: Pass the corresponding mm to __tlbi_sync_s1ish()
arm64: cputype: Add C1-Pro definitions
arm64: errata: Work around early CME DVMSync acknowledgement
Documentation/arch/arm64/silicon-errata.rst | 2 + arch/arm64/Kconfig | 12 +++ arch/arm64/include/asm/cpucaps.h | 2 + arch/arm64/include/asm/cputype.h | 2 + arch/arm64/include/asm/fpsimd.h | 21 +++++ arch/arm64/include/asm/tlbbatch.h | 10 ++- arch/arm64/include/asm/tlbflush.h | 96 +++++++++++++++++++-- arch/arm64/kernel/cpu_errata.c | 30 +++++++ arch/arm64/kernel/entry-common.c | 3 + arch/arm64/kernel/fpsimd.c | 79 +++++++++++++++++ arch/arm64/kernel/process.c | 36 ++++++++ arch/arm64/kernel/sys_compat.c | 2 +- arch/arm64/tools/cpucaps | 1 + 13 files changed, 285 insertions(+), 11 deletions(-)
Catalin Marinas
maintainerPATCH v5 1/4 arm64: tlb: Introduce __tlbi_sync_s1ish_{kernel,batch}() for TLB maintenance
Add __tlbi_sync_s1ish_kernel() similar to __tlbi_sync_s1ish() and use it for kernel TLB maintenance. Also use this function in flush_tlb_all() which is only used in relation to kernel mappings. Subsequent patches can differentiate between workarounds that apply to user only or both user and kernel.
A subsequent patch will add mm_struct to __tlbi_sync_s1ish(). Since arch_tlbbatch_flush() is not specific to an mm, add a corresponding __tlbi_sync_s1ish_batch() helper.
--- arch/arm64/include/asm/tlbflush.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
arch/arm64/include/asm/tlbflush.h +16 -4
@@ -191,6 +191,18 @@ static inline void __tlbi_sync_s1ish(void)__repeat_tlbi_sync (vale1is,0 ); } +static inline void __tlbi_sync_s1ish_batch (void ) +{ +dsb (ish); +__repeat_tlbi_sync (vale1is,0 ); +} + +static inline void __tlbi_sync_s1ish_kernel (void ) +{ +dsb (ish); +__repeat_tlbi_sync (vale1is,0 ); +} +/* * Complete broadcast TLB maintenance issued by hyp code which invalidates * stage 1 translation information in any translation regime.
@@ -299,7 +311,7 @@ static inline void flush_tlb_all(void) {dsb (ishst);__tlbi (vmalle1is); -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish_kernel ();isb (); }
@@ -385,7 +397,7 @@ static inline bool arch_tlbbatch_should_defer(struct mm_struct *mm)*/ static inline void arch_tlbbatch_flush (struct arch_tlbflush_unmap_batch *batch) { -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish_batch (); }/*
@@ -568,7 +580,7 @@ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long enddsb (ishst);__flush_tlb_range_op (vaale1is, start, pages, stride,0 ,TLBI_TTL_UNKNOWN , false,lpa2_is_enabled ()); -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish_kernel ();isb (); }
@@ -582,7 +594,7 @@ static inline void __flush_tlb_kernel_pgtable(unsigned long kaddr)dsb (ishst);__tlbi (vaae1is, addr); -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish_kernel ();isb (); }
Catalin Marinas
maintainerPATCH v5 2/4 arm64: tlb: Pass the corresponding mm to __tlbi_sync_s1ish()
In reply to Catalin MarinasThe mm structure will be used for workarounds that need limiting to specific tasks.
--- arch/arm64/include/asm/tlbflush.h | 8 ++++---- arch/arm64/kernel/sys_compat.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
arch/arm64/include/asm/tlbflush.h +4 -4
@@ -185,7 +185,7 @@ do { \* Complete broadcast TLB maintenance issued by the host which invalidates * stage 1 information in the host's own translation regime. */ -static inline void __tlbi_sync_s1ish (void ) +static inline void __tlbi_sync_s1ish (struct mm_struct *mm) {dsb (ish);__repeat_tlbi_sync (vale1is,0 );
@@ -323,7 +323,7 @@ static inline void flush_tlb_mm(struct mm_struct *mm) asid =__TLBI_VADDR (0 ,ASID (mm));__tlbi (aside1is, asid);__tlbi_user (aside1is, asid); -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish (mm);mmu_notifier_arch_invalidate_secondary_tlbs (mm,0 ,-1UL ); }
@@ -377,7 +377,7 @@ static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) {flush_tlb_page_nosync (vma, uaddr); -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish (vma->vm_mm); }static inline bool arch_tlbbatch_should_defer (struct mm_struct *mm)
@@ -532,7 +532,7 @@ static inline void __flush_tlb_range(struct vm_area_struct *vma, {__flush_tlb_range_nosync (vma->vm_mm, start, end, stride, last_level, tlb_level); -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish (vma->vm_mm); } static inline void local_flush_tlb_contpte(struct vm_area_struct *vma,
arch/arm64/kernel/sys_compat.c +1 -1
@@ -37,7 +37,7 @@ __do_compat_cache_op(unsigned long start, unsigned long end)* We pick the reserved-ASID to minimise the impact. */ __tlbi (aside1is,__TLBI_VADDR (0 ,0 )); -__tlbi_sync_s1ish (); +__tlbi_sync_s1ish (current->mm); } ret =caches_clean_inval_user_pou (start, start + chunk);
Catalin Marinas
maintainerPATCH v5 3/4 arm64: cputype: Add C1-Pro definitions
In reply to Catalin MarinasAdd cputype definitions for C1-Pro. These will be used for errata detection in subsequent patches.
These values can be found in "Table A-303: MIDR_EL1 bit descriptions" in issue 07 of the C1-Pro TRM:
https://documentation-service.arm.com/static/6930126730f8f55a656570af
--- arch/arm64/include/asm/cputype.h | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/include/asm/cputype.h +2 -0
@@ -98,6 +98,7 @@#define ARM_CPU_PART_CORTEX_A725 0xD87#define ARM_CPU_PART_CORTEX_A720AE 0xD89#define ARM_CPU_PART_NEOVERSE_N3 0xD8E +#define ARM_CPU_PART_C1_PRO 0xD8B#define APM_CPU_PART_XGENE 0x000#define APM_CPU_VAR_POTENZA 0x00
@@ -189,6 +190,7 @@#define MIDR_CORTEX_A725 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A725)#define MIDR_CORTEX_A720AE MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A720AE)#define MIDR_NEOVERSE_N3 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N3) +#define MIDR_C1_PRO MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_C1_PRO)#define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX)#define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)#define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX)
Catalin Marinas
maintainerPATCH v5 4/4 arm64: errata: Work around early CME DVMSync acknowledgement
In reply to Catalin MarinasC1-Pro acknowledges DVMSync messages before completing the SME/CME memory accesses. Work around this by issuing an IPI to the affected CPUs if they are running in EL0 with SME enabled.
Note that we avoid the local DSB in the IPI handler as the kernel runs with SCTLR_EL1.IESB=1. This is sufficient to complete SME memory accesses at EL0 on taking an exception to EL1. On the return to user path, no barrier is necessary either. See the comment in sme_set_active() and the more detailed explanation in the link below.
To avoid a potential IPI flood from malicious applications (e.g. madvise(MADV_PAGEOUT) in a tight loop), track where a process is active via mm_cpumask() and only interrupt those CPUs.
--- Documentation/arch/arm64/silicon-errata.rst | 2 + arch/arm64/Kconfig | 12 ++++ arch/arm64/include/asm/cpucaps.h | 2 + arch/arm64/include/asm/fpsimd.h | 21 ++++++ arch/arm64/include/asm/tlbbatch.h | 10 ++- arch/arm64/include/asm/tlbflush.h | 72 ++++++++++++++++++- arch/arm64/kernel/cpu_errata.c | 30 ++++++++ arch/arm64/kernel/entry-common.c | 3 + arch/arm64/kernel/fpsimd.c | 79 +++++++++++++++++++++ arch/arm64/kernel/process.c | 36 ++++++++++ arch/arm64/tools/cpucaps | 1 + 11 files changed, 264 insertions(+), 4 deletions(-)
Documentation/arch/arm64/silicon-errata.rst +2 -0
@@ -202,6 +202,8 @@ stable kernels. +----------------+-----------------+-----------------+-----------------------------+ | ARM | Neoverse-V3AE | #3312417 | ARM64_ERRATUM_3194386 | +----------------+-----------------+-----------------+-----------------------------+ +| ARM | C1-Pro | #4193714 | ARM64_ERRATUM_4193714 | ++----------------+-----------------+-----------------+-----------------------------+ | ARM | MMU-500 | #841119,826419 | ARM_SMMU_MMU_500_CPRE_ERRATA| | | | #562869,1047329 | | +----------------+-----------------+-----------------+-----------------------------+
arch/arm64/Kconfig +12 -0
@@ -1175,6 +1175,18 @@ config ARM64_ERRATUM_4311569 If unsure, say Y. +config ARM64_ERRATUM_4193714 + bool "C1-Pro: 4193714: SME DVMSync early acknowledgement" + depends on ARM64_SME + default y + help + Enable workaround for C1-Pro acknowledging the DVMSync before + the SME memory accesses are complete. This will cause TLB + maintenance for processes using SME to also issue an IPI to + the affected CPUs. + + If unsure, say Y. + config CAVIUM_ERRATUM_22375 bool "Cavium erratum 22375, 24313" default y
arch/arm64/include/asm/cpucaps.h +2 -0
@@ -64,6 +64,8 @@ cpucap_is_possible(const unsigned int cap)return IS_ENABLED (CONFIG_ARM64_WORKAROUND_REPEAT_TLBI );case ARM64_WORKAROUND_SPECULATIVE_SSBS :return IS_ENABLED (CONFIG_ARM64_ERRATUM_3194386 ); +case ARM64_WORKAROUND_4193714 : +return IS_ENABLED (CONFIG_ARM64_ERRATUM_4193714 );case ARM64_MPAM :/* * KVM MPAM support doesn't rely on the host kernel supporting MPAM.
arch/arm64/include/asm/fpsimd.h +21 -0
@@ -428,6 +428,24 @@ static inline size_t sme_state_size(struct task_struct const *task) return __sme_state_size(task_get_sme_vl(task)); } +void sme_enable_dvmsync (void ); +void sme_set_active (void ); +void sme_clear_active (void ); + +static inline void sme_enter_from_user_mode (void ) +{ +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 ) && +test_thread_flag (TIF_SME )) +sme_clear_active (); +} + +static inline void sme_exit_to_user_mode (void ) +{ +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 ) && +test_thread_flag (TIF_SME )) +sme_set_active (); +} +#else static inline void sme_user_disable (void ) {BUILD_BUG (); }
@@ -456,6 +474,9 @@ static inline size_t sme_state_size(struct task_struct const *task) return 0; } +static inline void sme_enter_from_user_mode (void ) { } +static inline void sme_exit_to_user_mode (void ) { } +#endif /* ! CONFIG_ARM64_SME */ /* For use by EFI runtime services calls only */
arch/arm64/include/asm/tlbbatch.h +8 -2
@@ -2,11 +2,17 @@#ifndef _ARCH_ARM64_TLBBATCH_H#define _ARCH_ARM64_TLBBATCH_H +#include <linux/cpumask.h> +struct arch_tlbflush_unmap_batch { +#ifdef CONFIG_ARM64_ERRATUM_4193714 /* -* For arm64, HW can do tlb shootdown, so we don't -* need to record cpumask for sending IPI +* Track CPUs that need SME DVMSync on completion of this batch. +* Otherwise, the arm64 HW can do tlb shootdown, so we don't need to +* record cpumask for sending IPI */ +cpumask_var_t cpumask; +#endif };#endif /* _ARCH_ARM64_TLBBATCH_H */
arch/arm64/include/asm/tlbflush.h +70 -2
101 lines not on this page · raw message
arch/arm64/kernel/cpu_errata.c +30 -0
@@ -11,6 +11,7 @@#include <asm/cpu.h> #include <asm/cputype.h> #include <asm/cpufeature.h> +#include <asm/fpsimd.h> #include <asm/kvm_asm.h> #include <asm/smp_plat.h>
@@ -575,6 +576,23 @@ static const struct midr_range erratum_spec_ssbs_list[] = { };#endif +#ifdef CONFIG_ARM64_ERRATUM_4193714 +static bool has_sme_dvmsync_erratum (const struct arm64_cpu_capabilities *entry, +int scope) +{ +if (!id_aa64pfr1_sme (read_sanitised_ftr_reg (SYS_ID_AA64PFR1_EL1 ))) +return false; + +return is_affected_midr_range (entry, scope); +} + +static void cpu_enable_sme_dvmsync (const struct arm64_cpu_capabilities *__unused) +{ +if (this_cpu_has_cap (ARM64_WORKAROUND_4193714 )) +sme_enable_dvmsync (); +} +#endif +#ifdef CONFIG_AMPERE_ERRATUM_AC03_CPU_38 static const struct midr_range erratum_ac03_cpu_38_list[] = { MIDR_ALL_VERSIONS(MIDR_AMPERE1),
@@ -901,6 +919,18 @@ const struct arm64_cpu_capabilities arm64_errata[] = { .matches = need_arm_si_l1_workaround_4311569, },#endif +#ifdef CONFIG_ARM64_ERRATUM_4193714 + { + .desc = "C1-Pro SME DVMSync early acknowledgement", + .capability = ARM64_WORKAROUND_4193714, + .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, + .matches = has_sme_dvmsync_erratum, + .cpu_enable = cpu_enable_sme_dvmsync, +/* C1-Pro r0p0 - r1p2 (the latter only when REVIDR_EL1[0]==0) */ + .midr_range =MIDR_RANGE (MIDR_C1_PRO ,0 ,0 ,1 ,2 ), +MIDR_FIXED (MIDR_CPU_VAR_REV (1 ,2 ),BIT (0 )), + }, +#endif #ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_UNPRIV_LOAD { .desc = "ARM errata 2966298, 3117295",
arch/arm64/kernel/entry-common.c +3 -0
@@ -21,6 +21,7 @@#include <asm/daifflags.h> #include <asm/esr.h> #include <asm/exception.h> +#include <asm/fpsimd.h> #include <asm/irq_regs.h> #include <asm/kprobes.h> #include <asm/mmu.h>
@@ -67,6 +68,7 @@ static __always_inline void arm64_enter_from_user_mode(struct pt_regs *regs) {enter_from_user_mode (regs);mte_disable_tco_entry (current); +sme_enter_from_user_mode (); }/*
@@ -80,6 +82,7 @@ static __always_inline void arm64_exit_to_user_mode(struct pt_regs *regs)local_irq_disable ();exit_to_user_mode_prepare_legacy (regs);local_daif_mask (); +sme_exit_to_user_mode ();mte_check_tfsr_exit ();exit_to_user_mode (); }
arch/arm64/kernel/fpsimd.c +79 -0
97 lines not on this page · raw message
arch/arm64/kernel/process.c +36 -0
@@ -26,6 +26,7 @@#include <linux/reboot.h> #include <linux/interrupt.h> #include <linux/init.h> +#include <linux/cpumask.h> #include <linux/cpu.h> #include <linux/elfcore.h> #include <linux/pm.h>
@@ -339,8 +340,41 @@ void flush_thread(void)flush_gcs (); } +#ifdef CONFIG_ARM64_ERRATUM_4193714 + +static void arch_dup_tlbbatch_mask (struct task_struct *dst) +{ +/* +* Clear the inherited cpumask with memset() to cover both cases where +* cpumask_var_t is a pointer or an array. It will be allocated lazily +* in sme_dvmsync_add_pending() if CPUMASK_OFFSTACK=y. +*/ +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) +memset (&dst->tlb_ubc.arch.cpumask,0 , +sizeof (dst->tlb_ubc.arch.cpumask)); +} + +static void arch_release_tlbbatch_mask (struct task_struct *tsk) +{ +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) +free_cpumask_var (tsk->tlb_ubc.arch.cpumask); +} + +#else + +static void arch_dup_tlbbatch_mask (struct task_struct *dst) +{ +} + +static void arch_release_tlbbatch_mask (struct task_struct *tsk) +{ +} + +#endif /* CONFIG_ARM64_ERRATUM_4193714 */ +void arch_release_task_struct (struct task_struct *tsk) { +arch_release_tlbbatch_mask (tsk);fpsimd_release_task (tsk); }
@@ -356,6 +390,8 @@ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) *dst = *src; +arch_dup_tlbbatch_mask (dst); +/* * Drop stale reference to src's sve_state and convert dst to * non-streaming FPSIMD mode.
arch/arm64/tools/cpucaps +1 -0
@@ -105,6 +105,7 @@ WORKAROUND_2077057 WORKAROUND_2457168 WORKAROUND_2645198 WORKAROUND_2658417 +WORKAROUND_4193714 WORKAROUND_4311569 WORKAROUND_AMPERE_AC03_CPU_38 WORKAROUND_AMPERE_AC04_CPU_23
Will Deacon
maintainerRe: [PATCH v5 4/4] arm64: errata: Work around early CME DVMSync acknowledgement
Quoted 33 lines · Catalin Marinas
C1-Pro acknowledges DVMSync messages before completing the SME/CME memory accesses. Work around this by issuing an IPI to the affected CPUs if they are running in EL0 with SME enabled.
Note that we avoid the local DSB in the IPI handler as the kernel runs with SCTLR_EL1.IESB=1. This is sufficient to complete SME memory accesses at EL0 on taking an exception to EL1. On the return to user path, no barrier is necessary either. See the comment in
sme_set_active()and the more detailed explanation in the link below.To avoid a potential IPI flood from malicious applications (e.g.
madvise(MADV_PAGEOUT)in a tight loop), track where a process is active viamm_cpumask()and only interrupt those CPUs.Signed-off-by Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Mark Rutland <[email protected]>Cc James Morse <[email protected]>Cc Mark Brown <[email protected]>--- Documentation/arch/arm64/silicon-errata.rst | 2 + arch/arm64/Kconfig | 12 ++++ arch/arm64/include/asm/cpucaps.h | 2 + arch/arm64/include/asm/fpsimd.h | 21 ++++++ arch/arm64/include/asm/tlbbatch.h | 10 ++- arch/arm64/include/asm/tlbflush.h | 72 ++++++++++++++++++- arch/arm64/kernel/cpu_errata.c | 30 ++++++++ arch/arm64/kernel/entry-common.c | 3 + arch/arm64/kernel/fpsimd.c | 79 +++++++++++++++++++++ arch/arm64/kernel/process.c | 36 ++++++++++ arch/arm64/tools/cpucaps | 1 + 11 files changed, 264 insertions(+), 4 deletions(-)
[...]
Quoted 18 lines
arch/arm64/kernel/process.c +3
-0@@ -26,6 +26,7 @@#include <linux/reboot.h> #include <linux/interrupt.h> #include <linux/init.h> +#include <linux/cpumask.h> #include <linux/cpu.h> #include <linux/elfcore.h> #include <linux/pm.h> @@ -339,8 +340,41 @@ void flush_thread(void)flush_gcs (); } +#ifdef CONFIG_ARM64_ERRATUM_4193714 +
arch/arm64/kernel/process.c void flush_thread(void) · line 354
Quoted 10 lines
arch/arm64/kernel/process.c +10
-0+static void arch_dup_tlbbatch_mask (struct task_struct *dst) +{ +/* +* Clear the inherited cpumask with memset() to cover both cases where +* cpumask_var_t is a pointer or an array. It will be allocated lazily +* in sme_dvmsync_add_pending() if CPUMASK_OFFSTACK=y. +*/ +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) +memset (&dst->tlb_ubc.arch.cpumask,0 , +sizeof (dst->tlb_ubc.arch.cpumask));
nit: use cpumask_clear() instead?
Will
Catalin Marinas
maintainerRe: [PATCH v5 4/4] arm64: errata: Work around early CME DVMSync acknowledgement
Quoted 17 lines · Will Deacon
Quoted 16 lines · Catalin Marinas
arch/arm64/kernel/process.c +1
-0@@ -26,6 +26,7 @@#include <linux/reboot.h> #include <linux/interrupt.h> #include <linux/init.h> +#include <linux/cpumask.h> #include <linux/cpu.h> #include <linux/elfcore.h> #include <linux/pm.h> @@ -339,8 +340,41 @@ void flush_thread(void)flush_gcs (); }
Quoted 14 lines
arch/arm64/kernel/process.c void flush_thread(void) · line 354
Quoted 12 lines
arch/arm64/kernel/process.c +12
-0+#ifdef CONFIG_ARM64_ERRATUM_4193714 + +static void arch_dup_tlbbatch_mask (struct task_struct *dst) +{ +/* +* Clear the inherited cpumask with memset() to cover both cases where +* cpumask_var_t is a pointer or an array. It will be allocated lazily +* in sme_dvmsync_add_pending() if CPUMASK_OFFSTACK=y. +*/ +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) +memset (&dst->tlb_ubc.arch.cpumask,0 , +sizeof (dst->tlb_ubc.arch.cpumask));nit: use
cpumask_clear()instead?
I tried to explain in the comment above. The memset() is on purpose to avoid #ifdef CPUMASK_OFFSTACK. When enabled, cpumask_var_t is a pointer and we want it set to NULL (for later lazy allocation) rather than clearing the parent's cpumask. I had the diff below initially but it looked uglier. Or we make the erratum dependent on !CPUMASK_OFFSTACK but it won't get compile coverage with defconfig.
arch/arm64/kernel/process.c +11 -6
@@ -345,13 +345,18 @@ void flush_thread(void)static void arch_dup_tlbbatch_mask (struct task_struct *dst) {/* -* Clear the inherited cpumask with memset() to cover both cases where -* cpumask_var_t is a pointer or an array. It will be allocated lazily -* in sme_dvmsync_add_pending() if CPUMASK_OFFSTACK=y. +* Don't inherit the parent's tlbbatch cpumask. +* +* With CPUMASK_OFFSTACK=y, cpumask_var_t is a pointer. Reset it so +* that it will be allocated lazily in sme_dvmsync_add_pending(). */ -if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) -memset (&dst->tlb_ubc.arch.cpumask,0 , -sizeof (dst->tlb_ubc.arch.cpumask)); +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) { +#ifdef CONFIG_CPUMASK_OFFSTACK + dst->tlb_ubc.arch.cpumask =NULL ; +#else +cpumask_clear (dst->tlb_ubc.arch.cpumask); +#endif + } }static void arch_release_tlbbatch_mask (struct task_struct *tsk)
Signature · 1 line
Catalin
Will Deacon
maintainerRe: [PATCH v5 4/4] arm64: errata: Work around early CME DVMSync acknowledgement
Quoted 33 lines · Catalin Marinas
Quoted 17 lines · Will Deacon
Quoted 16 lines · Catalin Marinas
arch/arm64/kernel/process.c +1
-0@@ -26,6 +26,7 @@#include <linux/reboot.h> #include <linux/interrupt.h> #include <linux/init.h> +#include <linux/cpumask.h> #include <linux/cpu.h> #include <linux/elfcore.h> #include <linux/pm.h> @@ -339,8 +340,41 @@ void flush_thread(void)flush_gcs (); }Quoted 14 lines
arch/arm64/kernel/process.c void flush_thread(void) · line 354
Quoted 12 lines
arch/arm64/kernel/process.c +12
-0+#ifdef CONFIG_ARM64_ERRATUM_4193714 + +static void arch_dup_tlbbatch_mask (struct task_struct *dst) +{ +/* +* Clear the inherited cpumask with memset() to cover both cases where +* cpumask_var_t is a pointer or an array. It will be allocated lazily +* in sme_dvmsync_add_pending() if CPUMASK_OFFSTACK=y. +*/ +if (alternative_has_cap_unlikely (ARM64_WORKAROUND_4193714 )) +memset (&dst->tlb_ubc.arch.cpumask,0 , +sizeof (dst->tlb_ubc.arch.cpumask));nit: use
cpumask_clear()instead?
Quoted 6 lines
I tried to explain in the comment above. The
memset()is on purpose to avoid #ifdefCPUMASK_OFFSTACK. When enabled,cpumask_var_tis a pointer and we want it set to NULL (for later lazy allocation) rather than clearing the parent's cpumask. I had the diff below initially but it looked uglier. Or we make the erratum dependent on !CPUMASK_OFFSTACK but it won't get compile coverage with defconfig.
Sorry, my mistake. I was focussing on the mm_cpumask() changes since v3 (which always seem to be embedded as part of the 'mm_struct' allocation) and didn't realise that this memset() is operating on the TLB batch cpumask.
So it looks like v5 is the charm :)
Will
Quoted 3 lines · Catalin Marinas
That's version 5 of the C1-Pro workaround. Version 3 here:
I left a nit on the final patch but, regardless, this looks good to me so:
Will
Quoted 10 lines · Catalin Marinas
That's version 5 of the C1-Pro workaround. Version 3 here:
https://lore.kernel.org/r/[email protected]
Changes since v4:
- Static
sme_dvmsync_cpusmask to avoid allocating understop_machine(). Sashiko was right, evenGFP_ATOMICwon't work under araw_spin_lock()[...]
Applied to arm64 (for-next/c1-pro-erratum-4193714). I won't push it to Linus in the first round, waiting for a bit more testing from Will. If all goes well, I'll send it in the second part of the merging window.
[1/4] arm64: tlb: Introduce __tlbi_sync_s1ish_{kernel,batch}() for TLB maintenance
https://git.kernel.org/arm64/c/6bfbf574a391 [2/4] arm64: tlb: Pass the corresponding mm to __tlbi_sync_s1ish() https://git.kernel.org/arm64/c/d9fb08ba946a [3/4] arm64: cputype: Add C1-Pro definitions https://git.kernel.org/arm64/c/2c99561016c5 [4/4] arm64: errata: Work around early CME DVMSync acknowledgement https://git.kernel.org/arm64/c/0baba94a9779