suspend.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/types.h>
  3. #include <linux/tick.h>
  4. #include <linux/percpu-defs.h>
  5. #include <xen/xen.h>
  6. #include <xen/interface/xen.h>
  7. #include <xen/grant_table.h>
  8. #include <xen/events.h>
  9. #include <asm/cpufeatures.h>
  10. #include <asm/msr-index.h>
  11. #include <asm/xen/hypercall.h>
  12. #include <asm/xen/page.h>
  13. #include <asm/fixmap.h>
  14. #include "xen-ops.h"
  15. static DEFINE_PER_CPU(u64, spec_ctrl);
  16. void xen_arch_pre_suspend(void)
  17. {
  18. xen_save_time_memory_area();
  19. if (xen_pv_domain())
  20. xen_pv_pre_suspend();
  21. }
  22. void xen_arch_post_suspend(int cancelled)
  23. {
  24. if (xen_pv_domain())
  25. xen_pv_post_suspend(cancelled);
  26. else
  27. xen_hvm_post_suspend(cancelled);
  28. xen_restore_time_memory_area();
  29. }
  30. static void xen_vcpu_notify_restore(void *data)
  31. {
  32. if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
  33. wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
  34. /* Boot processor notified via generic timekeeping_resume() */
  35. if (smp_processor_id() == 0)
  36. return;
  37. tick_resume_local();
  38. }
  39. static void xen_vcpu_notify_suspend(void *data)
  40. {
  41. u64 tmp;
  42. tick_suspend_local();
  43. if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
  44. rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
  45. this_cpu_write(spec_ctrl, tmp);
  46. wrmsrl(MSR_IA32_SPEC_CTRL, 0);
  47. }
  48. }
  49. void xen_arch_resume(void)
  50. {
  51. int cpu;
  52. on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
  53. for_each_online_cpu(cpu)
  54. xen_pmu_init(cpu);
  55. }
  56. void xen_arch_suspend(void)
  57. {
  58. int cpu;
  59. for_each_online_cpu(cpu)
  60. xen_pmu_finish(cpu);
  61. on_each_cpu(xen_vcpu_notify_suspend, NULL, 1);
  62. }