mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Tavis Ormandy <taviso@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>, <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Alexander Monakov <amonakov@ispras.ru>
Subject: [PATCH] x86/amd: Work around Erratum 1386 - XSAVES malfunction on context switch
Date: Tue, 7 Mar 2023 17:46:43 +0000	[thread overview]
Message-ID: <20230307174643.1240184-1-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <Y/W4x7/KFqmDmmR7@thinkstation.cmpxchg8b.net>

AMD Erratum 1386 is summarised as:

  XSAVES Instruction May Fail to Save XMM Registers to the Provided
  State Save Area

This piece of accidental chronomancy causes the %xmm registers to
occasionally reset back to an older value.

Ignore the XSAVES feature on all AMD Zen1/2 hardware.  The XSAVEC
instruction (which works fine) is equivalent on affected parts.

Reported-by: Tavis Ormandy <taviso@gmail.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: Dave Hansen <dave.hansen@linux.intel.com>
CC: x86@kernel.org
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: linux-kernel@vger.kernel.org
CC: Tavis Ormandy <taviso@gmail.com>
CC: Alexander Monakov <amonakov@ispras.ru>

Only compile tested.

This wants backporting to all stable trees that understand XSAVES, but
before 5.19(?) needs the XSAVEC support backporting too...
---
 arch/x86/kernel/cpu/amd.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 380753b14cab..f3a4bb479fd5 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -890,6 +890,17 @@ static void init_amd_zn(struct cpuinfo_x86 *c)
 	node_reclaim_distance = 32;
 #endif
 
+	/*
+	 * Work around Erratum 1386.  The XSAVES instruction malfunctions in
+	 * certain circumstances on Zen1/2 uarch, and not all parts have had
+	 * updated microcode at the time of writing (March 2023).
+	 *
+	 * Affected parts all have no supervisor XSAVE states, meaning that
+	 * the XSAVEC instruction (which works fine) is equivelent.
+	 */
+	if (c->x86 == 0x17)
+		clear_cpu_cap(c, X86_FEATURE_XSAVES);
+
 	/* Fix up CPUID bits, but only if not virtualised. */
 	if (!cpu_has(c, X86_FEATURE_HYPERVISOR)) {
 
-- 
2.30.2


  parent reply	other threads:[~2023-03-07 17:52 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-22  6:40 x86: AMD Zen2 ymm registers rolling back Tavis Ormandy
2023-02-22  8:33 ` Borislav Petkov
2023-02-22  9:14   ` Borislav Petkov
2023-02-22  9:38     ` Andrew Cooper
2023-02-22 10:09       ` Borislav Petkov
2023-02-22 21:26         ` Tavis Ormandy
2023-02-22 22:17           ` Andrew Cooper
2023-02-22 22:26             ` Borislav Petkov
2023-02-22 22:25           ` Borislav Petkov
2023-02-28 18:47         ` Alexander Monakov
2023-02-28 19:20           ` Borislav Petkov
2023-02-28 19:24             ` Alexander Monakov
2023-02-28 19:25               ` Borislav Petkov
2023-02-28 19:29                 ` Alexander Monakov
2023-02-28 19:38                   ` Andrew Cooper
2023-02-28 21:45                     ` Alexander Monakov
2023-02-28 20:56                   ` Borislav Petkov
2023-02-28 21:16                     ` Alexander Monakov
2023-03-01  0:23                       ` Andrew Cooper
2023-03-01  8:54                         ` Borislav Petkov
2023-03-07 16:45                           ` Tavis Ormandy
2023-03-07 17:46 ` Andrew Cooper [this message]
2023-03-07 17:50   ` [PATCH] x86/amd: Work around Erratum 1386 - XSAVES malfunction on context switch Borislav Petkov
2023-03-07 18:22     ` Andrew Cooper
2023-03-07 18:56       ` Borislav Petkov
2023-03-07 20:01         ` Andrew Cooper
2023-03-07 20:09           ` Borislav Petkov
2023-03-14 16:01           ` Dave Hansen
2023-03-08 16:23   ` [tip: x86/urgent] x86/CPU/AMD: Disable XSAVES on AMD family 0x17 tip-bot2 for Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230307174643.1240184-1-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=amonakov@ispras.ru \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=taviso@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®