Re: [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386

From: Dave Hansen

Date: Thu Nov 19 2026 - 10:29:11 EST


> +#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.

> + 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.

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.