kvm.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/entry-kvm.h>
  3. #include <linux/kvm_host.h>
  4. static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
  5. {
  6. do {
  7. int ret;
  8. if (ti_work & _TIF_SIGPENDING) {
  9. kvm_handle_signal_exit(vcpu);
  10. return -EINTR;
  11. }
  12. if (ti_work & _TIF_NEED_RESCHED)
  13. schedule();
  14. if (ti_work & _TIF_NOTIFY_RESUME) {
  15. tracehook_notify_resume(NULL);
  16. rseq_handle_notify_resume(NULL, NULL);
  17. }
  18. ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work);
  19. if (ret)
  20. return ret;
  21. ti_work = READ_ONCE(current_thread_info()->flags);
  22. } while (ti_work & XFER_TO_GUEST_MODE_WORK || need_resched());
  23. return 0;
  24. }
  25. int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu)
  26. {
  27. unsigned long ti_work;
  28. /*
  29. * This is invoked from the outer guest loop with interrupts and
  30. * preemption enabled.
  31. *
  32. * KVM invokes xfer_to_guest_mode_work_pending() with interrupts
  33. * disabled in the inner loop before going into guest mode. No need
  34. * to disable interrupts here.
  35. */
  36. ti_work = READ_ONCE(current_thread_info()->flags);
  37. if (!(ti_work & XFER_TO_GUEST_MODE_WORK))
  38. return 0;
  39. return xfer_to_guest_mode_work(vcpu, ti_work);
  40. }
  41. EXPORT_SYMBOL_GPL(xfer_to_guest_mode_handle_work);