Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / x86 / xen / suspend.c
blob1d83152c761bcb1f74929006fbe52d450d68b81c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/types.h>
3 #include <linux/tick.h>
4 #include <linux/percpu-defs.h>
6 #include <xen/xen.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>
17 #include "xen-ops.h"
18 #include "mmu.h"
19 #include "pmu.h"
21 static DEFINE_PER_CPU(u64, spec_ctrl);
23 void xen_arch_pre_suspend(void)
25 xen_save_time_memory_area();
27 if (xen_pv_domain())
28 xen_pv_pre_suspend();
31 void xen_arch_post_suspend(int cancelled)
33 if (xen_pv_domain())
34 xen_pv_post_suspend(cancelled);
35 else
36 xen_hvm_post_suspend(cancelled);
38 xen_restore_time_memory_area();
41 static void xen_vcpu_notify_restore(void *data)
43 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
44 wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
46 /* Boot processor notified via generic timekeeping_resume() */
47 if (smp_processor_id() == 0)
48 return;
50 tick_resume_local();
53 static void xen_vcpu_notify_suspend(void *data)
55 u64 tmp;
57 tick_suspend_local();
59 if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
60 rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
61 this_cpu_write(spec_ctrl, tmp);
62 wrmsrl(MSR_IA32_SPEC_CTRL, 0);
66 void xen_arch_resume(void)
68 int cpu;
70 on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
72 for_each_online_cpu(cpu)
73 xen_pmu_init(cpu);
76 void xen_arch_suspend(void)
78 int cpu;
80 for_each_online_cpu(cpu)
81 xen_pmu_finish(cpu);
83 on_each_cpu(xen_vcpu_notify_suspend, NULL, 1);