mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386
@ 2026-10-28 23:57 Tina Zhang
  2026-11-19 15:28 ` Dave Hansen
  2026-11-20  9:46 ` David Laight
  0 siblings, 2 replies; 6+ messages in thread
From: Tina Zhang @ 2026-10-28 23:57 UTC (permalink / raw)
  To: x86
  Cc: puwen, tglx, mingo, bp, dave.hansen, hpa, linux-kernel, yangzhen,
	dengqiming, Tina Zhang, stable

The XSAVES malfunction described in AMD Erratum 1386 also affects
certain Hygon Family 18h processors. Under specific conditions, XSAVES
may fail to save XMM register state, allowing stale register values to
reappear after the state is restored.

None of the affected processors enumerate supervisor XSAVE state
components. XSAVEC is therefore equivalent for their enabled state
components and is not affected by the erratum.

Family 18h models 00h through 06h and model 10h are affected. Other
Family 18h models contain the fix in hardware.

For the following model and stepping combinations, the minimum
microcode revisions containing the fix are:

  Model  Stepping  Microcode
  04h    0         0x9040000f
  04h    1         0x9041000f
  06h    0         0x9060000f
  06h    1         0x9061000f
  10h    0         0x91000004

These are the only known steppings for those models.

Disable XSAVES on affected processors unless a matching model and
stepping entry identifies a sufficiently recent microcode revision
containing the fix. This allows the x86 FPU code to use XSAVEC
instead.

Signed-off-by: Tina Zhang <zhang_wei@open-hieco.net>
Tested-by: Qiming Deng <dengqiming@hygon.cn>
Reviewed-by: Zhen Yang <yangzhen@hygon.cn>
Cc: stable@vger.kernel.org
---
 arch/x86/kernel/cpu/hygon.c | 40 +++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index ec51c2b9a257..0967b0f181dc 100644
--- a/arch/x86/kernel/cpu/hygon.c
+++ b/arch/x86/kernel/cpu/hygon.c
@@ -10,6 +10,7 @@
 
 #include <asm/apic.h>
 #include <asm/cpu.h>
+#include <asm/cpu_device_id.h>
 #include <asm/cpuid/api.h>
 #include <asm/smp.h>
 #include <asm/numa.h>
@@ -170,11 +171,50 @@ static void early_init_hygon(struct cpuinfo_x86 *c)
 	set_cpu_cap(c, X86_FEATURE_VMMCALL);
 }
 
+#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),
+	{}
+};
+
+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.
+	 */
+	if (c->x86 != 0x18)
+		return;
+
+	/* Models affected by Erratum 1386. */
+	switch (c->x86_model) {
+	case 0x00 ... 0x06:
+	case 0x10:
+		break;
+	default:
+		return;
+	}
+
+	if (x86_match_min_microcode_rev(erratum_1386_microcode))
+		return;
+
+	clear_cpu_cap(c, X86_FEATURE_XSAVES);
+}
+
 static void init_hygon(struct cpuinfo_x86 *c)
 {
 	u64 vm_cr;
 
 	early_init_hygon(c);
+	fix_erratum_1386(c);
 
 	set_cpu_cap(c, X86_FEATURE_REP_GOOD);
 
-- 
2.43.7


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386
  2026-10-28 23:57 [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386 Tina Zhang
@ 2026-11-19 15:28 ` Dave Hansen
  2026-11-20  1:51   ` Tina Zhang
  2026-11-20  9:46 ` David Laight
  1 sibling, 1 reply; 6+ messages in thread
From: Dave Hansen @ 2026-11-19 15:28 UTC (permalink / raw)
  To: Tina Zhang, x86
  Cc: puwen, tglx, mingo, bp, dave.hansen, hpa, linux-kernel, yangzhen,
	dengqiming, stable

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386
  2026-11-19 15:28 ` Dave Hansen
@ 2026-11-20  1:51   ` Tina Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Tina Zhang @ 2026-11-20  1:51 UTC (permalink / raw)
  To: Dave Hansen, x86
  Cc: puwen, tglx, mingo, bp, dave.hansen, hpa, linux-kernel, yangzhen,
	dengqiming, stable, zhang_wei

Hi Dave,

On 11/19/2026 11:28 PM, Dave Hansen wrote:
>> +#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.
Agreed. I was trying to explain both why the workaround is needed and
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.
    */

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

> 
> 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.
Agreed. I'll move the affected CPU selection into the table, including 
fallback entries for affected models.


Thanks,
Tina

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386
  2026-10-28 23:57 [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386 Tina Zhang
  2026-11-19 15:28 ` Dave Hansen
@ 2026-11-20  9:46 ` David Laight
  2026-11-20 14:12   ` Tina Zhang
  1 sibling, 1 reply; 6+ messages in thread
From: David Laight @ 2026-11-20  9:46 UTC (permalink / raw)
  To: Tina Zhang
  Cc: x86, puwen, tglx, mingo, bp, dave.hansen, hpa, linux-kernel,
	yangzhen, dengqiming, stable

On Thu, 29 Oct 2026 07:57:12 +0800
Tina Zhang <zhang_wei@open-hieco.net> wrote:

> The XSAVES malfunction described in AMD Erratum 1386 also affects
> certain Hygon Family 18h processors. Under specific conditions, XSAVES
> may fail to save XMM register state, allowing stale register values to
> reappear after the state is restored.
> 
> None of the affected processors enumerate supervisor XSAVE state
> components. XSAVEC is therefore equivalent for their enabled state
> components and is not affected by the erratum.

Would it just make sense to use XSAVES unless there are bits set in XSS
MSR that the kernel might need to request be saved?

That is 'use XSAVES unless you need to use XSAVEC'.
Then you don't have to worry about cpu models and microcode versions.

David

> 
> Family 18h models 00h through 06h and model 10h are affected. Other
> Family 18h models contain the fix in hardware.
> 
> For the following model and stepping combinations, the minimum
> microcode revisions containing the fix are:
> 
>   Model  Stepping  Microcode
>   04h    0         0x9040000f
>   04h    1         0x9041000f
>   06h    0         0x9060000f
>   06h    1         0x9061000f
>   10h    0         0x91000004
> 
> These are the only known steppings for those models.
> 
> Disable XSAVES on affected processors unless a matching model and
> stepping entry identifies a sufficiently recent microcode revision
> containing the fix. This allows the x86 FPU code to use XSAVEC
> instead.
...

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386
  2026-11-20  9:46 ` David Laight
@ 2026-11-20 14:12   ` Tina Zhang
  2026-11-20 14:44     ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Tina Zhang @ 2026-11-20 14:12 UTC (permalink / raw)
  To: David Laight
  Cc: x86, puwen, tglx, mingo, bp, dave.hansen, hpa, linux-kernel,
	yangzhen, dengqiming, stable

Hi David,


On 11/20/2026 5:46 PM, David Laight wrote:
> On Thu, 29 Oct 2026 07:57:12 +0800
> Tina Zhang<zhang_wei@open-hieco.net> wrote:
> 
>> The XSAVES malfunction described in AMD Erratum 1386 also affects
>> certain Hygon Family 18h processors. Under specific conditions, XSAVES
>> may fail to save XMM register state, allowing stale register values to
>> reappear after the state is restored.
>>
>> None of the affected processors enumerate supervisor XSAVE state
>> components. XSAVEC is therefore equivalent for their enabled state
>> components and is not affected by the erratum.
> Would it just make sense to use XSAVES unless there are bits set in XSS
> MSR that the kernel might need to request be saved?

Did you mean that the kernel could prefer XSAVEC when no supervisor 
XSAVE state needs to be saved, rather than clearing X86_FEATURE_XSAVES 
on the affected processors?

That sounds reasonable in principle, although IIUC it would require 
changes to the current xstate instruction selection logic.

Thanks,
Tina


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386
  2026-11-20 14:12   ` Tina Zhang
@ 2026-11-20 14:44     ` David Laight
  0 siblings, 0 replies; 6+ messages in thread
From: David Laight @ 2026-11-20 14:44 UTC (permalink / raw)
  To: Tina Zhang
  Cc: x86, puwen, tglx, mingo, bp, dave.hansen, hpa, linux-kernel,
	yangzhen, dengqiming, stable

On Fri, 20 Nov 2026 22:12:59 +0800
Tina Zhang <zhang_wei@open-hieco.net> wrote:

> Hi David,
> 
> 
> On 11/20/2026 5:46 PM, David Laight wrote:
> > On Thu, 29 Oct 2026 07:57:12 +0800
> > Tina Zhang<zhang_wei@open-hieco.net> wrote:
> >   
> >> The XSAVES malfunction described in AMD Erratum 1386 also affects
> >> certain Hygon Family 18h processors. Under specific conditions, XSAVES
> >> may fail to save XMM register state, allowing stale register values to
> >> reappear after the state is restored.
> >>
> >> None of the affected processors enumerate supervisor XSAVE state
> >> components. XSAVEC is therefore equivalent for their enabled state
> >> components and is not affected by the erratum.  
> > Would it just make sense to use XSAVES unless there are bits set in XSS
> > MSR that the kernel might need to request be saved?  
> 
> Did you mean that the kernel could prefer XSAVEC when no supervisor 
> XSAVE state needs to be saved, rather than clearing X86_FEATURE_XSAVES 
> on the affected processors?

Or when there can never be any supervisor XSAVE state to be saved.
I rather lost track of these instructions after XSAVEOPT.

David

> 
> That sounds reasonable in principle, although IIUC it would require 
> changes to the current xstate instruction selection logic.
> 
> Thanks,
> Tina
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-20 14:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28 23:57 [PATCH] x86/cpu/hygon: Work around XSAVES Erratum 1386 Tina Zhang
2026-11-19 15:28 ` Dave Hansen
2026-11-20  1:51   ` Tina Zhang
2026-11-20  9:46 ` David Laight
2026-11-20 14:12   ` Tina Zhang
2026-11-20 14:44     ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®