Hi,
On 2/26/19 7:05 PM, Jeremy Linton wrote:
Return status based on ssbd_state and the arm64 SSBS feature. If
the mitigation is disabled, or the firmware isn't responding then
return the expected machine state based on a new blacklist of known
vulnerable cores.
Signed-off-by: Jeremy Linton <jeremy.linton@xxxxxxx>
---
 arch/arm64/kernel/cpu_errata.c | 43 ++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
index 5f5611d17dc1..e1b03f643799 100644
--- a/arch/arm64/kernel/cpu_errata.c
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -279,6 +279,7 @@ static int detect_harden_bp_fw(void)
 DEFINE_PER_CPU_READ_MOSTLY(u64, arm64_ssbd_callback_required);
 int ssbd_state __read_mostly = ARM64_SSBD_KERNEL;
+static bool __ssb_safe = true;
 static const struct ssbd_options {
ÂÂÂÂÂ const charÂÂÂ *str;
@@ -387,6 +388,9 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry,
ÂÂÂÂÂ WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
+ÂÂÂ if (is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list))
+ÂÂÂÂÂÂÂ __ssb_safe = false;
Is that the only place where we set it to false?
What about if firmware reports that (at least one core) is vulnerable?
+
ÂÂÂÂÂ if (this_cpu_has_cap(ARM64_SSBS)) {
ÂÂÂÂÂÂÂÂÂ required = false;
ÂÂÂÂÂÂÂÂÂ goto out_printmsg;
@@ -420,6 +424,7 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry,
ÂÂÂÂÂÂÂÂÂ ssbd_state = ARM64_SSBD_UNKNOWN;
ÂÂÂÂÂÂÂÂÂ return false;
+ÂÂÂ /* machines with mixed mitigation requirements must not return this */
ÂÂÂÂÂ case SMCCC_RET_NOT_REQUIRED:
ÂÂÂÂÂÂÂÂÂ pr_info_once("%s mitigation not required\n", entry->desc);
ÂÂÂÂÂÂÂÂÂ ssbd_state = ARM64_SSBD_MITIGATED;
@@ -475,6 +480,16 @@ static bool has_ssbd_mitigation(const struct arm64_cpu_capabilities *entry,
ÂÂÂÂÂ return required;
 }
+/* known vulnerable cores */
+static const struct midr_range arm64_ssb_cpus[] = {
+ÂÂÂ MIDR_ALL_VERSIONS(MIDR_CORTEX_A57),
+ÂÂÂ MIDR_ALL_VERSIONS(MIDR_CORTEX_A72),
+ÂÂÂ MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
+ÂÂÂ MIDR_ALL_VERSIONS(MIDR_CORTEX_A75),
+ÂÂÂ MIDR_ALL_VERSIONS(MIDR_CORTEX_A76),
+ÂÂÂ {},
+};
+
 static void __maybe_unused
 cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused)
 {
@@ -770,6 +785,7 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
ÂÂÂÂÂÂÂÂÂ .capability = ARM64_SSBD,
ÂÂÂÂÂÂÂÂÂ .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
ÂÂÂÂÂÂÂÂÂ .matches = has_ssbd_mitigation,
+ÂÂÂÂÂÂÂ .midr_range_list = arm64_ssb_cpus,
ÂÂÂÂÂ },
 #ifdef CONFIG_ARM64_ERRATUM_1188873
ÂÂÂÂÂ {
@@ -808,3 +824,30 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
ÂÂÂÂÂ return sprintf(buf, "Vulnerable\n");
 }
+
+ssize_t cpu_show_spec_store_bypass(struct device *dev,
+ÂÂÂÂÂÂÂ struct device_attribute *attr, char *buf)
+{
+ÂÂÂ /*
+ÂÂÂÂ *Â Two assumptions: First, ssbd_state reflects the worse case
+ÂÂÂÂ *Â for hetrogenous machines, and that if SSBS is supported its
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ heterogeneous
Cheers,
Andre.
+ÂÂÂÂ *Â supported by all cores.
+ÂÂÂÂ */
+ÂÂÂ switch (ssbd_state) {
+ÂÂÂ case ARM64_SSBD_MITIGATED:
+ÂÂÂÂÂÂÂ return sprintf(buf, "Not affected\n");
+
+ÂÂÂ case ARM64_SSBD_KERNEL:
+ÂÂÂ case ARM64_SSBD_FORCE_ENABLE:
+ÂÂÂÂÂÂÂ if (cpus_have_cap(ARM64_SSBS))
+ÂÂÂÂÂÂÂÂÂÂÂ return sprintf(buf, "Not affected\n");
+ÂÂÂÂÂÂÂ if (IS_ENABLED(CONFIG_ARM64_SSBD))
+ÂÂÂÂÂÂÂÂÂÂÂ return sprintf(buf,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ "Mitigation: Speculative Store Bypass disabled\n");
+ÂÂÂ }
+
+ÂÂÂ if (__ssb_safe)
+ÂÂÂÂÂÂÂ return sprintf(buf, "Not affected\n");
+
+ÂÂÂ return sprintf(buf, "Vulnerable\n");
+}