suspend.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include "mmu.h"
  16. #include "pmu.h"
  17. static DEFINE_PER_CPU(u64, spec_ctrl);
  18. void xen_arch_pre_suspend(void)
  19. {
  20. xen_save_time_memory_area();
  21. if (xen_pv_domain())
  22. xen_pv_pre_suspend();
  23. }
  24. void xen_arch_post_suspend(int cancelled)
  25. {
  26. if (xen_pv_domain())
  27. xen_pv_post_suspend(cancelled);
  28. else
  29. xen_hvm_post_suspend(cancelled);
  30. xen_restore_time_memory_area();
  31. }
  32. static void xen_vcpu_notify_restore(void *data)
  33. {
  34. if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
  35. wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
  36. /* Boot processor notified via generic timekeeping_resume() */
  37. if (smp_processor_id() == 0)
  38. return;
  39. tick_resume_local();
  40. }
  41. static void xen_vcpu_notify_suspend(void *data)
  42. {
  43. u64 tmp;
  44. tick_suspend_local();
  45. if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
  46. rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
  47. this_cpu_write(spec_ctrl, tmp);
  48. wrmsrl(MSR_IA32_SPEC_CTRL, 0);
  49. }
  50. }
  51. void xen_arch_resume(void)
  52. {
  53. int cpu;
  54. on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
  55. for_each_online_cpu(cpu)
  56. xen_pmu_init(cpu);
  57. }
  58. void xen_arch_suspend(void)
  59. {
  60. int cpu;
  61. for_each_online_cpu(cpu)
  62. xen_pmu_finish(cpu);
  63. on_each_cpu(xen_vcpu_notify_suspend, NULL, 1);
  64. }