arm64: KVM: Propagate full Spectre v2 workaround state to KVM guests
[linux-2.6-microblaze.git] / arch / arm64 / kernel / cpu_errata.c
index ca11ff7..1e43ba5 100644 (file)
@@ -554,6 +554,17 @@ cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused)
 static bool __hardenbp_enab = true;
 static bool __spectrev2_safe = true;
 
+int get_spectre_v2_workaround_state(void)
+{
+       if (__spectrev2_safe)
+               return ARM64_BP_HARDEN_NOT_REQUIRED;
+
+       if (!__hardenbp_enab)
+               return ARM64_BP_HARDEN_UNKNOWN;
+
+       return ARM64_BP_HARDEN_WA_NEEDED;
+}
+
 /*
  * List of CPUs that do not need any Spectre-v2 mitigation at all.
  */
@@ -854,13 +865,15 @@ ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
 ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
                char *buf)
 {
-       if (__spectrev2_safe)
+       switch (get_spectre_v2_workaround_state()) {
+       case ARM64_BP_HARDEN_NOT_REQUIRED:
                return sprintf(buf, "Not affected\n");
-
-       if (__hardenbp_enab)
+        case ARM64_BP_HARDEN_WA_NEEDED:
                return sprintf(buf, "Mitigation: Branch predictor hardening\n");
-
-       return sprintf(buf, "Vulnerable\n");
+        case ARM64_BP_HARDEN_UNKNOWN:
+       default:
+               return sprintf(buf, "Vulnerable\n");
+       }
 }
 
 ssize_t cpu_show_spec_store_bypass(struct device *dev,