entry-kvm.h 2.2 KB

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