Skip to content

Commit 7187bb7

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64: errata: Add workaround for Arm errata 3194386 and 3312417
Cortex-X4 and Neoverse-V3 suffer from errata whereby an MSR to the SSBS special-purpose register does not affect subsequent speculative instructions, permitting speculative store bypassing for a window of time. This is described in their Software Developer Errata Notice (SDEN) documents: * Cortex-X4 SDEN v8.0, erratum 3194386: https://developer.arm.com/documentation/SDEN-2432808/0800/ * Neoverse-V3 SDEN v6.0, erratum 3312417: https://developer.arm.com/documentation/SDEN-2891958/0600/ To workaround these errata, it is necessary to place a speculation barrier (SB) after MSR to the SSBS special-purpose register. This patch adds the requisite SB after writes to SSBS within the kernel, and hides the presence of SSBS from EL0 such that userspace software which cares about SSBS will manipulate this via prctl(PR_GET_SPECULATION_CTRL, ...). Signed-off-by: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: James Morse <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 0ce85db commit 7187bb7

File tree

7 files changed

+88
-0
lines changed

7 files changed

+88
-0
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
@@ -1064,6 +1064,48 @@ config ARM64_ERRATUM_3117295
10641064

10651065
If unsure, say Y.
10661066

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

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/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/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

arch/arm64/tools/cpucaps

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ WORKAROUND_NVIDIA_CARMEL_CNP
102102
WORKAROUND_QCOM_FALKOR_E1003
103103
WORKAROUND_REPEAT_TLBI
104104
WORKAROUND_SPECULATIVE_AT
105+
WORKAROUND_SPECULATIVE_SSBS
105106
WORKAROUND_SPECULATIVE_UNPRIV_LOAD

0 commit comments

Comments
 (0)