mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] x86/cpu/hygon: Work around XSAVES Erratum 1386
@ 2026-11-27  0:38 Tina Zhang
  2026-11-27  1:54 ` [tip: x86/urgent] " tip-bot2 for Tina Zhang
  2026-11-30 17:45 ` [PATCH v4] " Dave Hansen
  0 siblings, 2 replies; 3+ messages in thread
From: Tina Zhang @ 2026-11-27  0:38 UTC (permalink / raw)
  To: x86
  Cc: puwen, tglx, mingo, bp, dave.hansen, andrew.cooper3,
	david.laight.linux, 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.

The failure mode is documented as Erratum 1386 in "Revision Guide for
AMD Family 19h Models 00h-0Fh Processors", Publication #56683 [1].

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.

[1] https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/revision-guides/56683.pdf

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
---
Changes in v4:
- Replace the affected CPU table and the model 00h special case with
  an explicit family and model check, as suggested by Boris.

v3: https://lore.kernel.org/r/20261124142632.844105-1-zhang_wei@open-hieco.net
v2: https://lore.kernel.org/r/20261121105320.478279-1-zhang_wei@open-hieco.net
v1: https://lore.kernel.org/r/20261028235712.383977-1-zhang_wei@open-hieco.net

Codex assisted with the implementation, changelog wording, and patch checks.

 arch/x86/kernel/cpu/hygon.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index ec51c2b9a257..0863dbaa6051 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,39 @@ 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)
+{
+	/*
+	 * Work around Erratum 1386.  The XSAVES instruction malfunctions in
+	 * certain circumstances on affected Hygon processors. Clear the feature
+	 * flag only on microcode revisions without the fix.
+	 */
+	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);
+	if (c->x86 == 0x18 && (c->x86_model <= 0x06 || c->x86_model == 0x10))
+		fix_erratum_1386(c);
 
 	set_cpu_cap(c, X86_FEATURE_REP_GOOD);
 

base-commit: c44104f3642da720164042623e4832836aefdd8e
-- 
2.43.7


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

* [tip: x86/urgent] x86/cpu/hygon: Work around XSAVES Erratum 1386
  2026-11-27  0:38 [PATCH v4] x86/cpu/hygon: Work around XSAVES Erratum 1386 Tina Zhang
@ 2026-11-27  1:54 ` tip-bot2 for Tina Zhang
  2026-11-30 17:45 ` [PATCH v4] " Dave Hansen
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Tina Zhang @ 2026-11-27  1:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Tina Zhang, Borislav Petkov (AMD),
	Zhen Yang, Qiming Deng, stable, x86, linux-kernel

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     d430c96a291a9c2e7f9a279e8bf9ec252d18c4a9
Gitweb:        https://git.kernel.org/tip/d430c96a291a9c2e7f9a279e8bf9ec252d18c4a9
Author:        Tina Zhang <zhang_wei@open-hieco.net>
AuthorDate:    Fri, 27 Nov 2026 08:38:17 +08:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Thu, 26 Nov 2026 17:39:54 -08:00

x86/cpu/hygon: Work around XSAVES Erratum 1386

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.

The failure mode is documented as Erratum 1386 in "Revision Guide for AMD
Family 19h Models 00h-0Fh Processors", Publication #56683.

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>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: Zhen Yang <yangzhen@hygon.cn>
Tested-by: Qiming Deng <dengqiming@hygon.cn>
Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261127003818.1208038-1-zhang_wei@open-hieco.net
---
 arch/x86/kernel/cpu/hygon.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index 0bccb93..ea37c48 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,39 @@ 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)
+{
+	/*
+	 * Work around Erratum 1386.  The XSAVES instruction malfunctions in
+	 * certain circumstances on affected Hygon processors. Clear the feature
+	 * flag only on microcode revisions without the fix.
+	 */
+	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);
+	if (c->x86 == 0x18 && (c->x86_model <= 0x06 || c->x86_model == 0x10))
+		fix_erratum_1386(c);
 
 	set_cpu_cap(c, X86_FEATURE_REP_GOOD);
 

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

* Re: [PATCH v4] x86/cpu/hygon: Work around XSAVES Erratum 1386
  2026-11-27  0:38 [PATCH v4] x86/cpu/hygon: Work around XSAVES Erratum 1386 Tina Zhang
  2026-11-27  1:54 ` [tip: x86/urgent] " tip-bot2 for Tina Zhang
@ 2026-11-30 17:45 ` Dave Hansen
  1 sibling, 0 replies; 3+ messages in thread
From: Dave Hansen @ 2026-11-30 17:45 UTC (permalink / raw)
  To: Tina Zhang, x86
  Cc: puwen, tglx, mingo, bp, dave.hansen, andrew.cooper3,
	david.laight.linux, hpa, linux-kernel, yangzhen, dengqiming,
	stable

On 11/26/26 16:38, Tina Zhang wrote:
> Family 18h models 00h through 06h and model 10h are affected. Other
> Family 18h models contain the fix in hardware.

BTW... Is Hygon the only vendor that has valid model 0's? This will
surely cause more problems going forward if so:

#define X86_MODEL_ANY  0


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

end of thread, other threads:[~2026-11-30 17:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27  0:38 [PATCH v4] x86/cpu/hygon: Work around XSAVES Erratum 1386 Tina Zhang
2026-11-27  1:54 ` [tip: x86/urgent] " tip-bot2 for Tina Zhang
2026-11-30 17:45 ` [PATCH v4] " Dave Hansen

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®