1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
3 #include <linux/tick.h>
4 #include <linux/percpu-defs.h>
7 #include <xen/interface/xen.h>
8 #include <xen/grant_table.h>
9 #include <xen/events.h>
11 #include <asm/cpufeatures.h>
12 #include <asm/msr-index.h>
13 #include <asm/xen/hypercall.h>
14 #include <asm/xen/page.h>
15 #include <asm/fixmap.h>
19 static DEFINE_PER_CPU(u64
, spec_ctrl
);
21 void xen_arch_pre_suspend(void)
23 xen_save_time_memory_area();
29 void xen_arch_post_suspend(int cancelled
)
32 xen_pv_post_suspend(cancelled
);
34 xen_hvm_post_suspend(cancelled
);
36 xen_restore_time_memory_area();
39 static void xen_vcpu_notify_restore(void *data
)
41 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL
))
42 wrmsrl(MSR_IA32_SPEC_CTRL
, this_cpu_read(spec_ctrl
));
44 /* Boot processor notified via generic timekeeping_resume() */
45 if (smp_processor_id() == 0)
51 static void xen_vcpu_notify_suspend(void *data
)
57 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL
)) {
58 rdmsrl(MSR_IA32_SPEC_CTRL
, tmp
);
59 this_cpu_write(spec_ctrl
, tmp
);
60 wrmsrl(MSR_IA32_SPEC_CTRL
, 0);
64 void xen_arch_resume(void)
68 on_each_cpu(xen_vcpu_notify_restore
, NULL
, 1);
70 for_each_online_cpu(cpu
)
74 void xen_arch_suspend(void)
78 for_each_online_cpu(cpu
)
81 on_each_cpu(xen_vcpu_notify_suspend
, NULL
, 1);