Re: [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386
From: Tina Zhang
Date: Thu Nov 19 2026 - 20:51:31 EST
Hi Dave,
On 11/19/2026 11:28 PM, Dave Hansen wrote:
Agreed. I was trying to explain both why the workaround is needed and+#define X86_MATCH_HYGON_MODEL_STEP_UCODE(model, step, ucode) \
+ X86_MATCH_VFM_STEPS(VFM_MAKE(X86_VENDOR_HYGON, 0x18, model), \
+ step, step, ucode)
+
+static const struct x86_cpu_id erratum_1386_microcode[] = {
+ X86_MATCH_HYGON_MODEL_STEP_UCODE(0x04, 0x00, 0x9040000f),
+ X86_MATCH_HYGON_MODEL_STEP_UCODE(0x04, 0x01, 0x9041000f),
+ X86_MATCH_HYGON_MODEL_STEP_UCODE(0x06, 0x00, 0x9060000f),
+ X86_MATCH_HYGON_MODEL_STEP_UCODE(0x06, 0x01, 0x9061000f),
+ X86_MATCH_HYGON_MODEL_STEP_UCODE(0x10, 0x00, 0x91000004),
+ {}
+};
This part is good.
+static void fix_erratum_1386(struct cpuinfo_x86 *c)
+{
+ /*
+ * Affected processors enumerate no supervisor XSAVE state components,
+ * so XSAVEC is equivalent and is not affected by Erratum 1386.
+ * Disable XSAVES unless the microcode is known to contain the fix.
+ */
This comment is in the wrong place and is really hard to read. I think
you're somehow trying to say here that the kernel *COULD* just use
XSAVEC instead of XSAVES instead of disabling XSAVES.
But this isn't the place to litigate your solution. That's for the
changelog. This just needs to say what it does.
why falling back to XSAVEC is safe, but that rationale belongs in the changelog. I'll reduce the comment to:
/*
* Work around Erratum 1386. The XSAVES instruction may fail to save
* XMM register state on affected processors.
*
* Clear the feature flag on affected processors without fixed
* microcode.
*/
Right.
+ if (c->x86 != 0x18)
+ return;
+
+ /* Models affected by Erratum 1386. */
+ switch (c->x86_model) {
+ case 0x00 ... 0x06:
+ case 0x10:
+ break;
+ default:
+ return;
+ }
This part is not.
Why do you need an explicit 0x18 check if there's already an implicit
one in x86_match_min_microcode_rev()? If there are unfixed
model/steppings, then list those too.
Agreed. I'll move the affected CPU selection into the table, including fallback entries for affected models.
I also don't get what the switch statement does.
+ if (x86_match_min_microcode_rev(erratum_1386_microcode))
+ return;
+
+ clear_cpu_cap(c, X86_FEATURE_XSAVES);
+}
My overall suggestion is to do more in erratum_1386_microcode[] and less
in code.
Thanks,
Tina