x86/xstate: reset cached register values on resume
PATCH v2 1/1 x86/xstate: reset cached register values on resume
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
---
Changes in v2:
- adjust xss init value per Jan request
For 4.16: this unbreaks S3 resume, it was posted initially back in August and is shipped in Qubes since September (although backported to 4.14, not unstable) with no reported regressions.
--- xen/arch/x86/xstate.c | 7 +++++++ 1 file changed, 7 insertions(+)
xen/arch/x86/xstate.c +7 -0
@@ -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));
Signature · 1 line
2.31.1
Marek Marczykowski-Górecki writes ("[PATCH-4.16 v2] x86/xstate: reset cached register values on resume"):
Quoted 17 lines
set_xcr0()andset_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()andget_msr_xss()too, but:
-set_xcr0()is called few lines below inxstate_init(), so it will update the cache with appropriate value
-get_msr_xss()is not used anywhere - and thus not before anyset_msr_xss()that will fill the cacheFixes aca2a985a55a "xen: don't free percpu areas during suspend"Signed-off-by Marek Marczykowski-Górecki <[email protected]>Reviewed-by Jan Beulich <[email protected]>
Quoted 7 lines
---
Changes in v2:
- adjust xss init value per Jan requestFor 4.16: this unbreaks S3 resume, it was posted initially back in August and is shipped in Qubes since September (although backported to 4.14, not unstable) with no reported regressions.
Thank you. I went back and read the thread. Thanks to everyone who contributed there.