All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/xstate: reset cached register values on resume
@ 2021-08-18 11:30 Marek Marczykowski-Górecki
  2021-08-18 12:05 ` Jan Beulich
  2021-08-18 12:44 ` Andrew Cooper
  0 siblings, 2 replies; 14+ messages in thread
From: Marek Marczykowski-Górecki @ 2021-08-18 11:30 UTC (permalink / raw)
  To: xen-devel
  Cc: Marek Marczykowski-Górecki, Jan Beulich, Andrew Cooper,
	Roger Pau Monné,
	Wei Liu

set_xcr0() and set_msr_xss() use cached value to avoid setting the
register to the same value over and over. But suspend/resume implicitly
reset the registers and since percpu areas are not deallocated on
suspend anymore, the cache gets stale.
Reset the cache on resume, to ensure the next write will really hit the
hardware. Choose value 0, as it will never be a legitimate write to
those registers - and so, will force write (and cache update).

Note the cache is used io get_xcr0() and get_msr_xss() too, but:
- set_xcr0() is called few lines below in xstate_init(), so it will
  update the cache with appropriate value
- get_msr_xss() is not used anywhere - and thus not before any
  set_msr_xss() that will fill the cache

Fixes: aca2a985a55a "xen: don't free percpu areas during suspend"
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 xen/arch/x86/xstate.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index 6aaf9a2f1546..28726d8fbf2b 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -642,6 +642,13 @@ void xstate_init(struct cpuinfo_x86 *c)
         return;
     }
 
+    /*
+     * Clear the cached value 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));
-- 
2.31.1



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

end of thread, other threads:[~2021-11-03 11:32 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 11:30 [PATCH] x86/xstate: reset cached register values on resume Marek Marczykowski-Górecki
2021-08-18 12:05 ` Jan Beulich
2021-08-18 12:07   ` Marek Marczykowski-Górecki
2021-08-18 12:44 ` Andrew Cooper
2021-08-19 11:41   ` Marek Marczykowski-Górecki
2021-08-24 21:11   ` Andrew Cooper
2021-08-25 15:02     ` Jan Beulich
2021-08-25 16:49       ` Andrew Cooper
2021-08-26  7:40         ` Jan Beulich
2021-08-26  8:50           ` Andrew Cooper
2021-10-18  8:21     ` Ping: " Jan Beulich
2021-10-21 13:44       ` Roger Pau Monné
2021-11-01 13:40         ` Marek Marczykowski-Górecki
2021-11-03 11:31           ` Jan Beulich

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.