]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/amd: Address AMD erratum #1485
authorAlejandro Vallejo <alejandro.vallejo@cloud.com>
Fri, 13 Oct 2023 15:38:01 +0000 (16:38 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 18 Oct 2023 14:44:31 +0000 (15:44 +0100)
This erratum has been observed to cause #UD exceptions.

Fix adapted off Linux's mailing list:
  https://lore.kernel.org/lkml/D99589F4-BC5D-430B-87B2-72C20370CF57@exactcode.com/T/#u

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Release-acked-by: Henry Wang <Henry.Wang@arm.com>
xen/arch/x86/cpu/amd.c
xen/arch/x86/include/asm/amd.h
xen/arch/x86/include/asm/msr-index.h

index 4f27187f92ecc8d1cec4a44bdea57d83739101b6..0f305312ff2aad03c95b0085b3869641b5eb6753 100644 (file)
@@ -1004,6 +1004,27 @@ static void cf_check zen2_disable_c6(void *arg)
        wrmsrl(MSR_AMD_CSTATE_CFG, val & mask);
 }
 
+static void amd_check_erratum_1485(void)
+{
+       uint64_t val, chickenbit = (1 << 5);
+
+       if (cpu_has_hypervisor || boot_cpu_data.x86 != 0x19 || !is_zen4_uarch())
+               return;
+
+       rdmsrl(MSR_AMD64_BP_CFG, val);
+
+       if (val & chickenbit)
+               return;
+
+       /*
+        * BP_CFG is a core-scoped MSR. There's a benign race on this write
+        * on the case where 2 threads perform the previous check at the
+        * same time before the chickenbit is set. It's benign because the
+        * value being written is the same on both.
+        */
+       wrmsrl(MSR_AMD64_BP_CFG, val | chickenbit);
+}
+
 static void cf_check init_amd(struct cpuinfo_x86 *c)
 {
        u32 l, h;
@@ -1271,6 +1292,7 @@ static void cf_check init_amd(struct cpuinfo_x86 *c)
                disable_c1_ramping();
 
        amd_check_zenbleed();
+       amd_check_erratum_1485();
 
        if (zen2_c6_disabled)
                zen2_disable_c6(NULL);
index d862cb7972a1ca39de399f0fdddf840e3591163d..07008275616bcc15f6d44660eeacde47f2f795d3 100644 (file)
  * Hygon (Fam18h) but without simple model number rules.  Instead, use STIBP
  * as a heuristic that distinguishes the two.
  *
+ * For Zen3 and Zen4 (Fam19h) the heuristic is the presence of AutoIBRS, as
+ * it's Zen4-specific.
+ *
  * The caller is required to perform the appropriate vendor/family checks
  * first.
  */
 #define is_zen1_uarch() (!boot_cpu_has(X86_FEATURE_AMD_STIBP))
 #define is_zen2_uarch()   boot_cpu_has(X86_FEATURE_AMD_STIBP)
+#define is_zen3_uarch() (!boot_cpu_has(X86_FEATURE_AUTO_IBRS))
+#define is_zen4_uarch()   boot_cpu_has(X86_FEATURE_AUTO_IBRS)
 
 struct cpuinfo_x86;
 int cpu_has_amd_erratum(const struct cpuinfo_x86 *, int, ...);
index 11ffed543afb039103514684a3f25e2fb5a997d9..7b3490bfb154615c51213b90cb588c02cb7d7c35 100644 (file)
 #define MSR_AMD64_DE_CFG               0xc0011029
 #define AMD64_DE_CFG_LFENCE_SERIALISE  (_AC(1, ULL) << 1)
 #define MSR_AMD64_EX_CFG               0xc001102c
+#define MSR_AMD64_BP_CFG               0xc001102e
 #define MSR_AMD64_DE_CFG2              0xc00110e3
 
 #define MSR_AMD64_DR0_ADDRESS_MASK     0xc0011027