x86/suspend: Fix restoration of guest state across S3/S4
PATCH 1/1 x86/suspend: Fix restoration of guest state across S3/S4
The call to freeze_domains() in enter_state() guarentees that we are running in idle context for the duration of S3/S4.
In restore_rest_processor_state(), the stts() is problematic as it unilaterally sets %cr0.ts even in fully_eager FPU context. It also fails to account for the non-lazy xsave state. Luckily, these are both latent bugs, as the FPU state is corrected by the subsequent context switch away from the idle vcpu.
Another aspect is that the !is_idle_vcpu(curr) paths in restore_rest_processor_state() are actually dead code, and removing these highlights that the segment saving logic is also unused.
---
CC: Jan Beulich <[email protected]>
CC: Juergen Gross <[email protected]>
Only compile tested by me at this point. I'm looking into the EFI side of things, but that is more complicated to fix.
--- xen/arch/x86/acpi/suspend.c | 31 ------------------------------- 1 file changed, 31 deletions(-)
xen/arch/x86/acpi/suspend.c +0 -31
@@ -18,16 +18,10 @@static unsigned long saved_lstar, saved_cstar;static unsigned long saved_sysenter_esp, saved_sysenter_eip;static unsigned long saved_fs_base, saved_gs_base, saved_kernel_gs_base; -static uint16_t saved_segs[4 ];static uint64_t saved_xcr0;void save_rest_processor_state (void ) { -vcpu_save_fpu (current); - - asmvolatile ( -"movw %%ds,(%0); movw %%es,2(%0); movw %%fs,4(%0); movw %%gs,6(%0)" - : :"r" (saved_segs) :"memory" ); saved_fs_base =rdfsbase (); saved_gs_base =rdgsbase ();rdmsrl (MSR_SHADOW_GS_BASE , saved_kernel_gs_base);
@@ -46,8 +40,6 @@ void save_rest_processor_state(void)void restore_rest_processor_state (void ) { -struct vcpu *curr = current; -load_TR ();/* Recover syscall MSRs */
@@ -69,32 +61,9 @@ void restore_rest_processor_state(void)wrmsr (MSR_IA32_SYSENTER_CS , __HYPERVISOR_CS,0 ); } -if ( !is_idle_vcpu (curr) ) - { - asmvolatile ( -"movw (%0),%%ds; movw 2(%0),%%es; movw 4(%0),%%fs" - : :"r" (saved_segs) :"memory" ); -do_set_segment_base (SEGBASE_GS_USER_SEL , saved_segs[3 ]); - } -if ( cpu_has_xsave && !set_xcr0 (saved_xcr0) )BUG (); -/* Maybe load the debug registers. */ -BUG_ON (!is_pv_vcpu (curr)); -if ( !is_idle_vcpu (curr) && curr->arch.debugreg[7 ] ) - { -write_debugreg (0 , curr->arch.debugreg[0 ]); -write_debugreg (1 , curr->arch.debugreg[1 ]); -write_debugreg (2 , curr->arch.debugreg[2 ]); -write_debugreg (3 , curr->arch.debugreg[3 ]); -write_debugreg (6 , curr->arch.debugreg[6 ]); -write_debugreg (7 , curr->arch.debugreg[7 ]); - } - -/* Reload FPU state on next FPU use. */ -stts (); -if (cpu_has_pat)wrmsrl (MSR_IA32_CR_PAT , host_pat);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Andrew Cooper
The call to
freeze_domains()inenter_state()guarentees that we are running in idle context for the duration of S3/S4.In
restore_rest_processor_state(), thestts()is problematic as it unilaterally sets %cr0.ts even infully_eagerFPU context. It also fails to account for the non-lazy xsave state. Luckily, these are both latent bugs, as the FPU state is corrected by the subsequent context switch away from the idle vcpu.
Quoted 5 lines
Another aspect is that the !is_idle_vcpu(curr) paths in
restore_rest_processor_state()are actually dead code, and removing these highlights that the segment saving logic is also unused.Signed-off-by Andrew Cooper <[email protected]>
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.06.18 at 12:12, <[email protected]> wrote:
The call to
freeze_domains()inenter_state()guarentees that we are running in idle context for the duration of S3/S4.In
restore_rest_processor_state(), thestts()is problematic as it unilaterally sets %cr0.ts even infully_eagerFPU context. It also fails to account for the non-lazy xsave state. Luckily, these are both latent bugs, as the FPU state is corrected by the subsequent context switch away from the idle vcpu.
Quoted 5 lines
Another aspect is that the !is_idle_vcpu(curr) paths in
restore_rest_processor_state()are actually dead code, and removing these highlights that the segment saving logic is also unused.Signed-off-by Andrew Cooper <[email protected]>
For 4.12:
As mentioned elsewhere (and despite having seen Jürgen's R-a-b) I'm not convinced this is an appropriate change to make for 4.11, considering how late in the process we are. If we want to consider this instead of my much smaller suggested change, then we will want to have someone actively using S3 test this thoroughly. Don't forget that whatever we do on 4.11 to address the regression will also want backporting.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 16 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.06.18 at 12:12, <[email protected]> wrote:
The call to
freeze_domains()inenter_state()guarentees that we are running in idle context for the duration of S3/S4.In
restore_rest_processor_state(), thestts()is problematic as it unilaterally sets %cr0.ts even infully_eagerFPU context. It also fails to account for the non-lazy xsave state. Luckily, these are both latent bugs, as the FPU state is corrected by the subsequent context switch away from the idle vcpu.Quoted 5 lines
Another aspect is that the !is_idle_vcpu(curr) paths in
restore_rest_processor_state()are actually dead code, and removing these highlights that the segment saving logic is also unused.Signed-off-by Andrew Cooper <[email protected]>For 4.12:
Quoted 8 lines
Reviewed-by Jan Beulich <[email protected]>As mentioned elsewhere (and despite having seen Jürgen's R-a-b) I'm not convinced this is an appropriate change to make for 4.11, considering how late in the process we are. If we want to consider this instead of my much smaller suggested change, then we will want to have someone actively using S3 test this thoroughly. Don't forget that whatever we do on 4.11 to address the regression will also want backporting.
Yes - considering how this patch ended up, I withdraw the 4.11 part of it. An earlier development version had a functional fix for lazy segment restoration which is why I thought it was going to be properly needed for 4.11
As this is straight deletion, it can wait until 4.12
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 21.06.18 at 10:37, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 20.06.18 at 12:12, <[email protected]> wrote:
The call to
freeze_domains()inenter_state()guarentees that we are running in idle context for the duration of S3/S4.In
restore_rest_processor_state(), thestts()is problematic as it unilaterally sets %cr0.ts even infully_eagerFPU context. It also fails to account for the non-lazy xsave state. Luckily, these are both latent bugs, as the FPU state is corrected by the subsequent context switch away from the idle vcpu.Quoted 5 lines
Another aspect is that the !is_idle_vcpu(curr) paths in
restore_rest_processor_state()are actually dead code, and removing these highlights that the segment saving logic is also unused.Signed-off-by Andrew Cooper <[email protected]>For 4.12:
Quoted 8 lines
Reviewed-by Jan Beulich <[email protected]>As mentioned elsewhere (and despite having seen Jürgen's R-a-b) I'm not convinced this is an appropriate change to make for 4.11, considering how late in the process we are. If we want to consider this instead of my much smaller suggested change, then we will want to have someone actively using S3 test this thoroughly. Don't forget that whatever we do on 4.11 to address the regression will also want backporting.
Quoted 6 lines
Yes - considering how this patch ended up, I withdraw the 4.11 part of it. An earlier development version had a functional fix for lazy segment restoration which is why I thought it was going to be properly needed for 4.11
As this is straight deletion, it can wait until 4.12
Thanks. With the moved (in the EFI patch) assertion, mine can actually be further simplified. I'll submit this in a minute.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 35 lines
Quoted 10 lines
Quoted 2 lines · On 21.06.18 at 11:28, <[email protected]> wrote:
Quoted 1 line · On 21.06.18 at 10:37, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 20.06.18 at 12:12, <[email protected]> wrote:
The call to
freeze_domains()inenter_state()guarentees that we are running in idle context for the duration of S3/S4.In
restore_rest_processor_state(), thestts()is problematic as it unilaterally sets %cr0.ts even infully_eagerFPU context. It also fails to account for the non-lazy xsave state. Luckily, these are both latent bugs,as
Quoted 1 line
Quoted 1 line
Quoted 1 line
the FPU state is corrected by the subsequent context switch away from the
idle
Quoted 22 lines
Quoted 8 lines
Quoted 7 lines
vcpu.
Another aspect is that the !is_idle_vcpu(curr) paths in
restore_rest_processor_state()are actually dead code, and removing these highlights that the segment saving logic is also unused.Signed-off-by Andrew Cooper <[email protected]>For 4.12:
Quoted 8 lines
Reviewed-by Jan Beulich <[email protected]>As mentioned elsewhere (and despite having seen Jürgen's R-a-b) I'm not convinced this is an appropriate change to make for 4.11, considering how late in the process we are. If we want to consider this instead of my much smaller suggested change, then we will want to have someone actively using S3 test this thoroughly. Don't forget that whatever we do on 4.11 to address the regression will also want backporting.
Yes - considering how this patch ended up, I withdraw the 4.11 part of it. An earlier development version had a functional fix for lazy segment restoration which is why I thought it was going to be properly needed for 4.11
Quoted 4 lines
Quoted 1 line
As this is straight deletion, it can wait until 4.12
Thanks. With the moved (in the EFI patch) assertion, mine can actually be further simplified. I'll submit this in a minute.
Actually I think no fix is needed there at all if we're always on an idle
vCPU: Nothing needs to be restored, and afaict CR0.TS is set already anyway (due to the stts() in vcpu_save_fpu(), which was invoked when the last non-idle vCPU was taken off of that CPU). So I won't submit anything here for the moment, but I'll see about addressing the further EFI issue mentioned on irc.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel