From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 1/7] x86/xstate: Fix initialisation of XSS cache
Date: Thu, 23 May 2024 12:16:21 +0100 [thread overview]
Message-ID: <20240523111627.28896-2-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20240523111627.28896-1-andrew.cooper3@citrix.com>
The clobbering of this_cpu(xcr0) and this_cpu(xss) to architecturally invalid
values is to force the subsequent set_xcr0() and set_msr_xss() to reload the
hardware register.
While XCR0 is reloaded in xstate_init(), MSR_XSS isn't. This causes
get_msr_xss() to return the invalid value, and logic of the form:
old = get_msr_xss();
set_msr_xss(new);
...
set_msr_xss(old);
to try and restore the architecturally invalid value.
The architecturally invalid value must be purged from the cache, meaning the
hardware register must be written at least once. This in turn highlights that
the invalid value must only be used in the case that the hardware register is
available.
Fixes: f7f4a523927f ("x86/xstate: reset cached register values on resume")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
v3:
* Split out of later patch
---
xen/arch/x86/xstate.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index 99cedb4f5e24..75788147966a 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -641,13 +641,6 @@ void xstate_init(struct cpuinfo_x86 *c)
return;
}
- /*
- * Zap the cached values to make set_xcr0() and set_msr_xss() really
- * write it.
- */
- this_cpu(xcr0) = 0;
- this_cpu(xss) = ~0;
-
cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
feature_mask = (((u64)edx << 32) | eax) & XCNTXT_MASK;
BUG_ON(!valid_xcr0(feature_mask));
@@ -657,8 +650,19 @@ void xstate_init(struct cpuinfo_x86 *c)
* Set CR4_OSXSAVE and run "cpuid" to get xsave_cntxt_size.
*/
set_in_cr4(X86_CR4_OSXSAVE);
+
+ /*
+ * Zap the cached values to make set_xcr0() and set_msr_xss() really write
+ * the hardware register.
+ */
+ this_cpu(xcr0) = 0;
if ( !set_xcr0(feature_mask) )
BUG();
+ if ( cpu_has_xsaves )
+ {
+ this_cpu(xss) = ~0;
+ set_msr_xss(0);
+ }
if ( bsp )
{
--
2.30.2
next prev parent reply other threads:[~2024-05-23 11:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-23 11:16 [PATCH for-4.19 v3 0/7] x86/xstate: Fixes to size calculations Andrew Cooper
2024-05-23 11:16 ` Andrew Cooper [this message]
2024-05-23 15:09 ` [PATCH 1/7] x86/xstate: Fix initialisation of XSS cache Jan Beulich
2024-05-23 11:16 ` [PATCH 2/7] x86/xstate: Cross-check dynamic XSTATE sizes at boot Andrew Cooper
2024-05-23 15:34 ` Jan Beulich
2024-06-14 13:56 ` Andrew Cooper
2024-06-17 10:08 ` Jan Beulich
2024-05-23 11:16 ` [PATCH 3/7] x86/boot: Collect the Raw CPU Policy earlier on boot Andrew Cooper
2024-05-23 15:44 ` Jan Beulich
2024-06-14 18:26 ` Andrew Cooper
2024-06-17 10:25 ` Jan Beulich
2024-06-17 17:30 ` Andrew Cooper
2024-06-18 7:04 ` Jan Beulich
2024-05-23 11:16 ` [PATCH 4/7] x86/xstate: Rework xstate_ctxt_size() as xstate_uncompressed_size() Andrew Cooper
2024-05-23 16:09 ` Jan Beulich
2024-06-14 13:56 ` Andrew Cooper
2024-05-23 11:16 ` [PATCH 5/7] x86/cpu-policy: Simplify recalculate_xstate() Andrew Cooper
2024-05-23 11:16 ` [PATCH 6/7] x86/cpuid: Fix handling of XSAVE dynamic leaves Andrew Cooper
2024-05-23 16:16 ` Jan Beulich
2024-06-14 14:06 ` Andrew Cooper
2024-05-23 11:16 ` [PATCH 7/7] x86/defns: Clean up X86_{XCR0,XSS}_* constants Andrew Cooper
2024-05-23 15:46 ` Jan Beulich
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=20240523111627.28896-2-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.