Skip to content

Commit 2b7ced1

Browse files
committed
Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
Pull arm64 fixes from Will Deacon: "The major fix here is for a filesystem corruption issue reported on Apple M1 as a result of buggy management of the floating point register state introduced in 6.8. I initially reverted one of the offending patches, but in the end Ard cooked a proper fix so there's a revert+reapply in the series. Aside from that, we've got some CPU errata workarounds and misc other fixes. - Fix broken FP register state tracking which resulted in filesystem corruption when dm-crypt is used - Workarounds for Arm CPU errata affecting the SSBS Spectre mitigation - Fix lockdep assertion in DMC620 memory controller PMU driver - Fix alignment of BUG table when CONFIG_DEBUG_BUGVERBOSE is disabled" * tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux: arm64/fpsimd: Avoid erroneous elide of user state reload Reapply "arm64: fpsimd: Implement lazy restore for kernel mode FPSIMD" arm64: asm-bug: Add .align 2 to the end of __BUG_ENTRY perf/arm-dmc620: Fix lockdep assert in ->event_init() Revert "arm64: fpsimd: Implement lazy restore for kernel mode FPSIMD" arm64: errata: Add workaround for Arm errata 3194386 and 3312417 arm64: cputype: Add Neoverse-V3 definitions arm64: cputype: Add Cortex-X4 definitions arm64: barrier: Restore spec_bar() macro
2 parents 2ef32ad + e92bee9 commit 2b7ced1

File tree

12 files changed

+125
-25
lines changed

12 files changed

+125
-25
lines changed

Documentation/arch/arm64/silicon-errata.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ stable kernels.
140140
+----------------+-----------------+-----------------+-----------------------------+
141141
| ARM | Cortex-X2 | #2224489 | ARM64_ERRATUM_2224489 |
142142
+----------------+-----------------+-----------------+-----------------------------+
143+
| ARM | Cortex-X4 | #3194386 | ARM64_ERRATUM_3194386 |
144+
+----------------+-----------------+-----------------+-----------------------------+
143145
| ARM | Neoverse-N1 | #1188873,1418040| ARM64_ERRATUM_1418040 |
144146
+----------------+-----------------+-----------------+-----------------------------+
145147
| ARM | Neoverse-N1 | #1349291 | N/A |
@@ -156,6 +158,8 @@ stable kernels.
156158
+----------------+-----------------+-----------------+-----------------------------+
157159
| ARM | Neoverse-V1 | #1619801 | N/A |
158160
+----------------+-----------------+-----------------+-----------------------------+
161+
| ARM | Neoverse-V3 | #3312417 | ARM64_ERRATUM_3312417 |
162+
+----------------+-----------------+-----------------+-----------------------------+
159163
| ARM | MMU-500 | #841119,826419 | N/A |
160164
+----------------+-----------------+-----------------+-----------------------------+
161165
| ARM | MMU-600 | #1076982,1209401| N/A |

arch/arm64/Kconfig

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,48 @@ config ARM64_ERRATUM_3117295
10671067

10681068
If unsure, say Y.
10691069

1070+
config ARM64_WORKAROUND_SPECULATIVE_SSBS
1071+
bool
1072+
1073+
config ARM64_ERRATUM_3194386
1074+
bool "Cortex-X4: 3194386: workaround for MSR SSBS not self-synchronizing"
1075+
select ARM64_WORKAROUND_SPECULATIVE_SSBS
1076+
default y
1077+
help
1078+
This option adds the workaround for ARM Cortex-X4 erratum 3194386.
1079+
1080+
On affected cores "MSR SSBS, #0" instructions may not affect
1081+
subsequent speculative instructions, which may permit unexepected
1082+
speculative store bypassing.
1083+
1084+
Work around this problem by placing a speculation barrier after
1085+
kernel changes to SSBS. The presence of the SSBS special-purpose
1086+
register is hidden from hwcaps and EL0 reads of ID_AA64PFR1_EL1, such
1087+
that userspace will use the PR_SPEC_STORE_BYPASS prctl to change
1088+
SSBS.
1089+
1090+
If unsure, say Y.
1091+
1092+
config ARM64_ERRATUM_3312417
1093+
bool "Neoverse-V3: 3312417: workaround for MSR SSBS not self-synchronizing"
1094+
select ARM64_WORKAROUND_SPECULATIVE_SSBS
1095+
default y
1096+
help
1097+
This option adds the workaround for ARM Neoverse-V3 erratum 3312417.
1098+
1099+
On affected cores "MSR SSBS, #0" instructions may not affect
1100+
subsequent speculative instructions, which may permit unexepected
1101+
speculative store bypassing.
1102+
1103+
Work around this problem by placing a speculation barrier after
1104+
kernel changes to SSBS. The presence of the SSBS special-purpose
1105+
register is hidden from hwcaps and EL0 reads of ID_AA64PFR1_EL1, such
1106+
that userspace will use the PR_SPEC_STORE_BYPASS prctl to change
1107+
SSBS.
1108+
1109+
If unsure, say Y.
1110+
1111+
10701112
config CAVIUM_ERRATUM_22375
10711113
bool "Cavium erratum 22375, 24313"
10721114
default y

arch/arm64/include/asm/asm-bug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
14470: .long 14471f - .; \
2929
_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \
3030
.short flags; \
31+
.align 2; \
3132
.popsection; \
3233
14471:
3334
#else

arch/arm64/include/asm/barrier.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
*/
4141
#define dgh() asm volatile("hint #6" : : : "memory")
4242

43+
#define spec_bar() asm volatile(ALTERNATIVE("dsb nsh\nisb\n", \
44+
SB_BARRIER_INSN"nop\n", \
45+
ARM64_HAS_SB))
46+
4347
#ifdef CONFIG_ARM64_PSEUDO_NMI
4448
#define pmr_sync() \
4549
do { \

arch/arm64/include/asm/cpucaps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ cpucap_is_possible(const unsigned int cap)
5858
return IS_ENABLED(CONFIG_NVIDIA_CARMEL_CNP_ERRATUM);
5959
case ARM64_WORKAROUND_REPEAT_TLBI:
6060
return IS_ENABLED(CONFIG_ARM64_WORKAROUND_REPEAT_TLBI);
61+
case ARM64_WORKAROUND_SPECULATIVE_SSBS:
62+
return IS_ENABLED(CONFIG_ARM64_WORKAROUND_SPECULATIVE_SSBS);
6163
}
6264

6365
return true;

arch/arm64/include/asm/cputype.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
#define ARM_CPU_PART_NEOVERSE_N2 0xD49
8888
#define ARM_CPU_PART_CORTEX_A78C 0xD4B
8989
#define ARM_CPU_PART_NEOVERSE_V2 0xD4F
90+
#define ARM_CPU_PART_CORTEX_X4 0xD82
91+
#define ARM_CPU_PART_NEOVERSE_V3 0xD84
9092

9193
#define APM_CPU_PART_XGENE 0x000
9294
#define APM_CPU_VAR_POTENZA 0x00
@@ -161,6 +163,8 @@
161163
#define MIDR_NEOVERSE_N2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N2)
162164
#define MIDR_CORTEX_A78C MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A78C)
163165
#define MIDR_NEOVERSE_V2 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_V2)
166+
#define MIDR_CORTEX_X4 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_X4)
167+
#define MIDR_NEOVERSE_V3 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_V3)
164168
#define MIDR_THUNDERX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX)
165169
#define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)
166170
#define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX)

arch/arm64/kernel/cpu_errata.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,18 @@ static const struct midr_range erratum_spec_unpriv_load_list[] = {
432432
};
433433
#endif
434434

435+
#ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_SSBS
436+
static const struct midr_range erratum_spec_ssbs_list[] = {
437+
#ifdef CONFIG_ARM64_ERRATUM_3194386
438+
MIDR_ALL_VERSIONS(MIDR_CORTEX_X4),
439+
#endif
440+
#ifdef CONFIG_ARM64_ERRATUM_3312417
441+
MIDR_ALL_VERSIONS(MIDR_NEOVERSE_V3),
442+
#endif
443+
{}
444+
};
445+
#endif
446+
435447
const struct arm64_cpu_capabilities arm64_errata[] = {
436448
#ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE
437449
{
@@ -729,6 +741,13 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
729741
MIDR_FIXED(MIDR_CPU_VAR_REV(1,1), BIT(25)),
730742
},
731743
#endif
744+
#ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_SSBS
745+
{
746+
.desc = "ARM errata 3194386, 3312417",
747+
.capability = ARM64_WORKAROUND_SPECULATIVE_SSBS,
748+
ERRATA_MIDR_RANGE_LIST(erratum_spec_ssbs_list),
749+
},
750+
#endif
732751
#ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_UNPRIV_LOAD
733752
{
734753
.desc = "ARM errata 2966298, 3117295",

arch/arm64/kernel/cpufeature.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,14 @@ static void user_feature_fixup(void)
23072307
if (regp)
23082308
regp->user_mask &= ~ID_AA64ISAR1_EL1_BF16_MASK;
23092309
}
2310+
2311+
if (cpus_have_cap(ARM64_WORKAROUND_SPECULATIVE_SSBS)) {
2312+
struct arm64_ftr_reg *regp;
2313+
2314+
regp = get_arm64_ftr_reg(SYS_ID_AA64PFR1_EL1);
2315+
if (regp)
2316+
regp->user_mask &= ~ID_AA64PFR1_EL1_SSBS_MASK;
2317+
}
23102318
}
23112319

23122320
static void elf_hwcap_fixup(void)

arch/arm64/kernel/fpsimd.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,27 @@ static void fpsimd_save_kernel_state(struct task_struct *task)
15351535
task->thread.kernel_fpsimd_cpu = smp_processor_id();
15361536
}
15371537

1538+
/*
1539+
* Invalidate any task's FPSIMD state that is present on this cpu.
1540+
* The FPSIMD context should be acquired with get_cpu_fpsimd_context()
1541+
* before calling this function.
1542+
*/
1543+
static void fpsimd_flush_cpu_state(void)
1544+
{
1545+
WARN_ON(!system_supports_fpsimd());
1546+
__this_cpu_write(fpsimd_last_state.st, NULL);
1547+
1548+
/*
1549+
* Leaving streaming mode enabled will cause issues for any kernel
1550+
* NEON and leaving streaming mode or ZA enabled may increase power
1551+
* consumption.
1552+
*/
1553+
if (system_supports_sme())
1554+
sme_smstop();
1555+
1556+
set_thread_flag(TIF_FOREIGN_FPSTATE);
1557+
}
1558+
15381559
void fpsimd_thread_switch(struct task_struct *next)
15391560
{
15401561
bool wrong_task, wrong_cpu;
@@ -1552,7 +1573,7 @@ void fpsimd_thread_switch(struct task_struct *next)
15521573

15531574
if (test_tsk_thread_flag(next, TIF_KERNEL_FPSTATE)) {
15541575
fpsimd_load_kernel_state(next);
1555-
set_tsk_thread_flag(next, TIF_FOREIGN_FPSTATE);
1576+
fpsimd_flush_cpu_state();
15561577
} else {
15571578
/*
15581579
* Fix up TIF_FOREIGN_FPSTATE to correctly describe next's
@@ -1842,27 +1863,6 @@ void fpsimd_flush_task_state(struct task_struct *t)
18421863
barrier();
18431864
}
18441865

1845-
/*
1846-
* Invalidate any task's FPSIMD state that is present on this cpu.
1847-
* The FPSIMD context should be acquired with get_cpu_fpsimd_context()
1848-
* before calling this function.
1849-
*/
1850-
static void fpsimd_flush_cpu_state(void)
1851-
{
1852-
WARN_ON(!system_supports_fpsimd());
1853-
__this_cpu_write(fpsimd_last_state.st, NULL);
1854-
1855-
/*
1856-
* Leaving streaming mode enabled will cause issues for any kernel
1857-
* NEON and leaving streaming mode or ZA enabled may increase power
1858-
* consumption.
1859-
*/
1860-
if (system_supports_sme())
1861-
sme_smstop();
1862-
1863-
set_thread_flag(TIF_FOREIGN_FPSTATE);
1864-
}
1865-
18661866
/*
18671867
* Save the FPSIMD state to memory and invalidate cpu view.
18681868
* This function must be called with preemption disabled.

arch/arm64/kernel/proton-pack.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,18 @@ static enum mitigation_state spectre_v4_enable_hw_mitigation(void)
558558

559559
/* SCTLR_EL1.DSSBS was initialised to 0 during boot */
560560
set_pstate_ssbs(0);
561+
562+
/*
563+
* SSBS is self-synchronizing and is intended to affect subsequent
564+
* speculative instructions, but some CPUs can speculate with a stale
565+
* value of SSBS.
566+
*
567+
* Mitigate this with an unconditional speculation barrier, as CPUs
568+
* could mis-speculate branches and bypass a conditional barrier.
569+
*/
570+
if (IS_ENABLED(CONFIG_ARM64_WORKAROUND_SPECULATIVE_SSBS))
571+
spec_bar();
572+
561573
return SPECTRE_MITIGATED;
562574
}
563575

0 commit comments

Comments
 (0)