entry-kvm.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_ENTRYKVM_H
  3. #define __LINUX_ENTRYKVM_H
  4. #include <linux/static_call_types.h>
  5. #include <linux/resume_user_mode.h>
  6. #include <linux/syscalls.h>
  7. #include <linux/seccomp.h>
  8. #include <linux/sched.h>
  9. #include <linux/tick.h>
  10. /* Transfer to guest mode work */
  11. #ifdef CONFIG_KVM_XFER_TO_GUEST_WORK
  12. #ifndef ARCH_XFER_TO_GUEST_MODE_WORK
  13. # define ARCH_XFER_TO_GUEST_MODE_WORK (0)
  14. #endif
  15. #define XFER_TO_GUEST_MODE_WORK \
  16. (_TIF_NEED_RESCHED | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL | \
  17. _TIF_NOTIFY_RESUME | ARCH_XFER_TO_GUEST_MODE_WORK)
  18. struct kvm_vcpu;
  19. /**
  20. * arch_xfer_to_guest_mode_handle_work - Architecture specific xfer to guest
  21. * mode work handling function.
  22. * @vcpu: Pointer to current's VCPU data
  23. * @ti_work: Cached TIF flags gathered in xfer_to_guest_mode_handle_work()
  24. *
  25. * Invoked from xfer_to_guest_mode_handle_work(). Defaults to NOOP. Can be
  26. * replaced by architecture specific code.
  27. */
  28. static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu,
  29. unsigned long ti_work);
  30. #ifndef arch_xfer_to_guest_mode_work
  31. static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu,
  32. unsigned long ti_work)
  33. {
  34. return 0;
  35. }
  36. #endif
  37. /**
  38. * xfer_to_guest_mode_handle_work - Check and handle pending work which needs
  39. * to be handled before going to guest mode
  40. * @vcpu: Pointer to current's VCPU data
  41. *
  42. * Returns: 0 or an error code
  43. */
  44. int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu);
  45. /**
  46. * xfer_to_guest_mode_prepare - Perform last minute preparation work that
  47. * need to be handled while IRQs are disabled
  48. * upon entering to guest.
  49. *
  50. * Has to be invoked with interrupts disabled before the last call
  51. * to xfer_to_guest_mode_work_pending().
  52. */
  53. static inline void xfer_to_guest_mode_prepare(void)
  54. {
  55. lockdep_assert_irqs_disabled();
  56. tick_nohz_user_enter_prepare();
  57. }
  58. /**
  59. * __xfer_to_guest_mode_work_pending - Check if work is pending
  60. *
  61. * Returns: True if work pending, False otherwise.
  62. *
  63. * Bare variant of xfer_to_guest_mode_work_pending(). Can be called from
  64. * interrupt enabled code for racy quick checks with care.
  65. */
  66. static inline bool __xfer_to_guest_mode_work_pending(void)
  67. {
  68. unsigned long ti_work = read_thread_flags();
  69. return !!(ti_work & XFER_TO_GUEST_MODE_WORK);
  70. }
  71. /**
  72. * xfer_to_guest_mode_work_pending - Check if work is pending which needs to be
  73. * handled before returning to guest mode
  74. *
  75. * Returns: True if work pending, False otherwise.
  76. *
  77. * Has to be invoked with interrupts disabled before the transition to
  78. * guest mode.
  79. */
  80. static inline bool xfer_to_guest_mode_work_pending(void)
  81. {
  82. lockdep_assert_irqs_disabled();
  83. return __xfer_to_guest_mode_work_pending();
  84. }
  85. #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */
  86. #endif