x86/xstate: reset cached register values on resume
PATCH 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
--- 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
xen/arch/x86/xstate.c void xstate_init(struct cpuinfo_x86 *c) · line 649
Quoted 11 lines · Marek Marczykowski-Górecki
xen/arch/x86/xstate.c +5
-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 ;
While XCR0 cannot be successfully written with 0, ...
xen/arch/x86/xstate.c void xstate_init(struct cpuinfo_x86 *c) · line 650
Quoted 1 line
xen/arch/x86/xstate.c +1
-0+this_cpu (xss) =0 ;
... XSS can. XSS can't be written with various other values; I'd suggest using ~0 here. Then
and I'd be happy to make the adjustment while committing, so long as you agree.
Jan
Quoted 17 lines · Jan Beulich
xen/arch/x86/xstate.c void xstate_init(struct cpuinfo_x86 *c) · line 649
Quoted 11 lines · Marek Marczykowski-Górecki
xen/arch/x86/xstate.c +5
-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 ;While XCR0 cannot be successfully written with 0, ...
xen/arch/x86/xstate.c void xstate_init(struct cpuinfo_x86 *c) · line 650
Quoted 1 line
xen/arch/x86/xstate.c +1
-0+this_cpu (xss) =0 ;
Quoted 7 lines
... XSS can. XSS can't be written with various other values; I'd suggest using ~0 here. Then
Reviewed-by Jan Beulich <[email protected]>and I'd be happy to make the adjustment while committing, so long as you agree.
Yes, makes sense. Thanks!
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Quoted 8 lines · Marek Marczykowski-Górecki
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).
Quoted 8 lines
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]>
I'd prefer to do this differently. As I said in the thread, there are other registers such as MSR_TSC_AUX which fall into the same category, and I'd like to make something which works systematically.
~Andrew
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Marek Marczykowski-Górecki
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 cache
Quoted 6 lines
Quoted 2 lines
Fixes aca2a985a55a "xen: don't free percpu areas during suspend"Signed-off-by Marek Marczykowski-Górecki <[email protected]>I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.
I'm not sure if I understand your message: do you want me to do things differently, or are you working on an alternative fix yourself?
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Marek Marczykowski-Górecki
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 cache
Quoted 5 lines
Quoted 2 lines
Fixes aca2a985a55a "xen: don't free percpu areas during suspend"Signed-off-by Marek Marczykowski-Górecki <[email protected]>I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.
Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks); cpu/common.c:120:static DEFINE_PER_CPU(uint64_t, msr_misc_features); msr.c:35:DEFINE_PER_CPU(uint32_t, tsc_aux); xstate.c:36:static DEFINE_PER_CPU(uint64_t, xcr0); xstate.c:79:static DEFINE_PER_CPU(uint64_t, xss);
There is also:
traps.c:100:DEFINE_PER_CPU(uint64_t, efer);
which we *almost* handle correctly, but fail to update the cache on the BSP out of S3.
For the APIC, I think we have issues with:
irq.c:1083:static DEFINE_PER_CPU(struct pending_eoi, pending_eoi[NR_DYNAMIC_VECTORS]);
because we don't defer S3 until all pending EOIs are complete.
I gave up trying to figure out the MCE or power governor logic so we may have additional issues there.
Additionally,
flushtlb.c:34:DEFINE_PER_CPU(u32, tlbflush_time);
really does need setting appropriately, although I think the only fallout is a few unnecessary TLB flushes.
~Andrew
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Marek Marczykowski-Górecki
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]>
Quoted 7 lines
Quoted 3 lines
I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks);
Don't we have a problem here even during initial boot? I can't see the per-CPU variable to get filled by what the registers hold. If the register started out non-zero (the default on AMD iirc, as it's not really masks there) but the first value to be written was zero, we'd skip the write.
Quoted 1 line
cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features);
Almost the same here - we only initialize the variable on the BSP afaics.
Quoted 1 line
msr.c:35:DEFINE_PER_CPU(uint32_t,
tsc_aux);
And again no boot time setup at all for this one as it looks. Not sure how likely it is for firmware or bootloaders to use this MSR (and then leave it non-zero).
Jan
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Marek Marczykowski-Górecki
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]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks);
Don't we have a problem here even during initial boot? I can't see the per-CPU variable to get filled by what the registers hold.
No, I don't think so, but it is a roundabout route.
Quoted 4 lines
If
the register started out non-zero (the default on AMD iirc, as it's not really masks there) but the first value to be written was zero, we'd skip the write.
There is cpuidmask_defaults which does get filled from the MSRs on boot.
AMD are real CPUID settings, while Intel is an and-mask. i.e. they're both non-zero (unless someone does something silly with the command line arguments, and I don't expect Xen to be happy booting if the leaves all read 0).
Each early_init_*() has an explicit ctxt_switch_levelling(NULL) call which, given non-zero content in cpuidmask_defaults should latch each one appropriately in the the per-cpu variable.
Thinking about it some more, we load cpuidmask_defaults in IDLE and HVM context, while PV guests (even PV dom0) will have non-default cpuidmask's, so with a PV dom0, things ought to correct themselves fairly promptly after S3, but not as early as we expect.
Quoted 3 lines
Quoted 1 line
cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features);Almost the same here - we only initialize the variable on the BSP afaics.
No - way way way worse, I think.
For all APs, we write 0 or MSR_MISC_FEATURES_CPUID_FAULTING into MSR_INTEL_MISC_FEATURES_ENABLES, which amongst other things turns off Fast String Enable.
I think it might be time to expand the "MSR consistency across the system" logic from test-tsx to rather more MSRs..
Quoted 4 lines
Quoted 1 line
msr.c:35:DEFINE_PER_CPU(uint32_t,
tsc_aux);And again no boot time setup at all for this one as it looks. Not sure how likely it is for firmware or bootloaders to use this MSR (and then leave it non-zero).
Regular firmware I'd expect it to be 0. Linuxboot, I'd expect whatever value Linux last left in there for userspace.
~Andrew
Quoted 23 lines · Andrew Cooper
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Andrew Cooper
Quoted 20 lines · Andrew Cooper
Quoted 8 lines · Marek Marczykowski-Górecki
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).Quoted 8 lines
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]>I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks);
Don't we have a problem here even during initial boot? I can't see the per-CPU variable to get filled by what the registers hold.
No, I don't think so, but it is a roundabout route.
So where do you see it getting filled?
Quoted 11 lines
Quoted 4 lines
If
the register started out non-zero (the default on AMD iirc, as it's not really masks there) but the first value to be written was zero, we'd skip the write.There is
cpuidmask_defaultswhich does get filled from the MSRs on boot.AMD are real CPUID settings, while Intel is an and-mask. i.e. they're both non-zero (unless someone does something silly with the command line arguments, and I don't expect Xen to be happy booting if the leaves all read 0).
Surely not all of them together, but I don't think it's completely unreasonable for one (say the XSAVE one, if e.g. XSAVE is to be turned off altogether for guests) to be all zero.
Quoted 3 lines
Each early_init_*() has an explicit
ctxt_switch_levelling(NULL)call which, given non-zero content incpuidmask_defaultsshould latch each one appropriately in the the per-cpu variable.
Well, as you say - provided the individual fields are all non-zero.
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features);Almost the same here - we only initialize the variable on the BSP afaics.
No - way way way worse, I think.
For all APs, we write 0 or
MSR_MISC_FEATURES_CPUID_FAULTINGintoMSR_INTEL_MISC_FEATURES_ENABLES, which amongst other things turns off Fast String Enable.
Urgh, indeed. Prior to 6e2fdc0f8902 there was a read-modify-write operation. With the introduction of the cache variable this went away, while the cache gets filled for BSP only.
Jan
Quoted 13 lines · Jan Beulich
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich
On 24.08.2021 23:11, Andrew Cooper wrote:
If
the register started out non-zero (the default on AMD iirc, as it's not really masks there) but the first value to be written was zero, we'd skip the write.Quoted 6 lines
There is
cpuidmask_defaultswhich does get filled from the MSRs on boot.AMD are real CPUID settings, while Intel is an and-mask. i.e. they're both non-zero (unless someone does something silly with the command line arguments, and I don't expect Xen to be happy booting if the leaves all read 0).
Quoted 8 lines
Surely not all of them together, but I don't think it's completely unreasonable for one (say the XSAVE one, if e.g. XSAVE is to be turned off altogether for guests) to be all zero.
Quoted 3 lines
Each early_init_*() has an explicit
ctxt_switch_levelling(NULL)call which, given non-zero content incpuidmask_defaultsshould latch each one appropriately in the the per-cpu variable.Well, as you say - provided the individual fields are all non-zero.
The MSRs only exist on CPUs which have non-zero features in the relevant leaves.
The XSAVE and Therm registers could plausibly be 0. Dom0 is first to boot and won't expect to have XSAVE hidden, but we do zero all of leaf 6 in recalculate_misc()
There are certainly corner cases here to improve, but I think all registers will latch on the first early_init_*(), except for Therm on AMD which will latch on the first context switch from a PV guest back to idle.
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features);Almost the same here - we only initialize the variable on the BSP afaics.
No - way way way worse, I think.
For all APs, we write 0 or
MSR_MISC_FEATURES_CPUID_FAULTINGintoMSR_INTEL_MISC_FEATURES_ENABLES, which amongst other things turns off Fast String Enable.Urgh, indeed. Prior to
6e2fdc0f8902there was a read-modify-write operation. With the introduction of the cache variable this went away, while the cache gets filled for BSP only.
Yeah - I really screwed up on that one... It was also part of the PV Shim work done in a hurry in the lead up to Spectre/Meltdown.
MSR_INTEL_MISC_FEATURES_ENABLES is a lot like MSR_{TSX_FORCE_ABORT,TSX_CTRL,MCU_OPT_CTRL} and the MTRRs.
Most of the content wants to be identical on all cores, so we do want to fix up AP values with the BSP value if they differ, but we also want a software cache covering at least the CPUID_FAULTING bit so we don't have a unnecessary MSR read on the context switch path.
I'll try to do something better.
~Andrew
Ping: [PATCH] x86/xstate: reset cached register values on resume
In reply to Andrew CooperQuoted 38 lines · Andrew Cooper
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Marek Marczykowski-Górecki
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 cacheQuoted 5 lines
Quoted 2 lines
Fixes aca2a985a55a "xen: don't free percpu areas during suspend"Signed-off-by Marek Marczykowski-Górecki <[email protected]>I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks); cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features); msr.c:35:DEFINE_PER_CPU(uint32_t,tsc_aux); xstate.c:36:staticDEFINE_PER_CPU(uint64_t, xcr0); xstate.c:79:staticDEFINE_PER_CPU(uint64_t, xss);There is also:
traps.c:100:DEFINE_PER_CPU(uint64_t, efer);
which we *almost* handle correctly, but fail to update the cache on the BSP out of S3.
Quoted 6 lines
For the APIC, I think we have issues with:
irq.c:1083:static
DEFINE_PER_CPU(struct pending_eoi, pending_eoi[NR_DYNAMIC_VECTORS]);because we don't defer S3 until all pending EOIs are complete.
As your planned more extensive rework appears to not have made much progress yet, may I suggest that we go with Marek's fix for 4.16, with the one adjustment I suggested alongside giving my R-b?
Jan
Quoted 13 lines
I gave up trying to figure out the MCE or power governor logic so we may have additional issues there.
Additionally,
flushtlb.c:34:DEFINE_PER_CPU(u32,
tlbflush_time);really does need setting appropriately, although I think the only fallout is a few unnecessary TLB flushes.
~Andrew
Re: Ping: [PATCH] x86/xstate: reset cached register values on resume
Quoted 41 lines · Jan Beulich
Quoted 40 lines · Andrew Cooper
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Marek Marczykowski-Górecki
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 cacheQuoted 5 lines
Quoted 2 lines
Fixes aca2a985a55a "xen: don't free percpu areas during suspend"Signed-off-by Marek Marczykowski-Górecki <[email protected]>I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks); cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features); msr.c:35:DEFINE_PER_CPU(uint32_t,tsc_aux); xstate.c:36:staticDEFINE_PER_CPU(uint64_t, xcr0); xstate.c:79:staticDEFINE_PER_CPU(uint64_t, xss);There is also:
traps.c:100:DEFINE_PER_CPU(uint64_t, efer);
which we *almost* handle correctly, but fail to update the cache on the BSP out of S3.
For the APIC, I think we have issues with:
Quoted 8 lines
Quoted 4 lines
irq.c:1083:static
DEFINE_PER_CPU(struct pending_eoi, pending_eoi[NR_DYNAMIC_VECTORS]);because we don't defer S3 until all pending EOIs are complete.
As your planned more extensive rework appears to not have made much progress yet, may I suggest that we go with Marek's fix for 4.16, with the one adjustment I suggested alongside giving my R-b?
I think that's the only viable solution in order to avoid shipping a broken 4.16 so we should go ahead with it.
Thanks, Roger.
Re: Ping: [PATCH] x86/xstate: reset cached register values on resume
Quoted 45 lines · Roger Pau Monné
Quoted 44 lines · Jan Beulich
Quoted 43 lines · Andrew Cooper
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Marek Marczykowski-Górecki
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 cacheQuoted 5 lines
Quoted 2 lines
Fixes aca2a985a55a "xen: don't free percpu areas during suspend"Signed-off-by Marek Marczykowski-Górecki <[email protected]>I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks); cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features); msr.c:35:DEFINE_PER_CPU(uint32_t,tsc_aux); xstate.c:36:staticDEFINE_PER_CPU(uint64_t, xcr0); xstate.c:79:staticDEFINE_PER_CPU(uint64_t, xss);There is also:
traps.c:100:DEFINE_PER_CPU(uint64_t, efer);
which we *almost* handle correctly, but fail to update the cache on the BSP out of S3.
For the APIC, I think we have issues with:
irq.c:1083:static
DEFINE_PER_CPU(struct pending_eoi, pending_eoi[NR_DYNAMIC_VECTORS]);
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
because we don't defer S3 until all pending EOIs are complete.
As your planned more extensive rework appears to not have made much progress yet, may I suggest that we go with Marek's fix for 4.16, with the one adjustment I suggested alongside giving my R-b?
I think that's the only viable solution in order to avoid shipping a broken 4.16 so we should go ahead with it.
Do you want me to post v2 with this_cpu(xss) = ~0 change? IIUC that's the only thing requested in this patch specifically.
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Re: Ping: [PATCH] x86/xstate: reset cached register values on resume
Quoted 52 lines · Marek Marczykowski-Górecki
Quoted 51 lines · Roger Pau Monné
Quoted 49 lines · Jan Beulich
Quoted 38 lines · Andrew Cooper
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Marek Marczykowski-Górecki
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 cacheQuoted 5 lines
Quoted 2 lines
Fixes aca2a985a55a "xen: don't free percpu areas during suspend"Signed-off-by Marek Marczykowski-Górecki <[email protected]>I'd prefer to do this differently. As I said in the thread, there are other registers such as
MSR_TSC_AUXwhich fall into the same category, and I'd like to make something which works systematically.Ok - after some searching, I think we have problems with:
cpu/common.c:47:DEFINE_PER_CPU(struct cpuidmasks, cpuidmasks); cpu/common.c:120:static
DEFINE_PER_CPU(uint64_t, msr_misc_features); msr.c:35:DEFINE_PER_CPU(uint32_t,tsc_aux); xstate.c:36:staticDEFINE_PER_CPU(uint64_t, xcr0); xstate.c:79:staticDEFINE_PER_CPU(uint64_t, xss);There is also:
traps.c:100:DEFINE_PER_CPU(uint64_t, efer);
which we *almost* handle correctly, but fail to update the cache on the BSP out of S3.
Quoted 6 lines
For the APIC, I think we have issues with:
irq.c:1083:static
DEFINE_PER_CPU(struct pending_eoi, pending_eoi[NR_DYNAMIC_VECTORS]);because we don't defer S3 until all pending EOIs are complete.
As your planned more extensive rework appears to not have made much progress yet, may I suggest that we go with Marek's fix for 4.16, with the one adjustment I suggested alongside giving my R-b?
Quoted 5 lines
Quoted 2 lines
I think that's the only viable solution in order to avoid shipping a broken 4.16 so we should go ahead with it.
Do you want me to post v2 with
this_cpu(xss) = ~0change? IIUC that's the only thing requested in this patch specifically.
Since Ian in particular prefers to see the full final version on the list, and since at this point you will need his release ack for the patch to go in, I think re-sending with the adjustment and tag(s) added would be the best course of action.
Jan