Thomas Gleixner | 935ace2 | 2020-07-22 23:59:59 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | |
| 3 | #include <linux/entry-kvm.h> |
| 4 | #include <linux/kvm_host.h> |
| 5 | |
| 6 | static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work) |
| 7 | { |
| 8 | do { |
| 9 | int ret; |
| 10 | |
Jens Axboe | 12db8b6 | 2020-10-26 14:32:28 -0600 | [diff] [blame] | 11 | if (ti_work & _TIF_NOTIFY_SIGNAL) |
| 12 | tracehook_notify_signal(); |
| 13 | |
Thomas Gleixner | 935ace2 | 2020-07-22 23:59:59 +0200 | [diff] [blame] | 14 | if (ti_work & _TIF_SIGPENDING) { |
| 15 | kvm_handle_signal_exit(vcpu); |
| 16 | return -EINTR; |
| 17 | } |
| 18 | |
| 19 | if (ti_work & _TIF_NEED_RESCHED) |
| 20 | schedule(); |
| 21 | |
Jens Axboe | 3c53279 | 2020-10-03 10:49:22 -0600 | [diff] [blame] | 22 | if (ti_work & _TIF_NOTIFY_RESUME) |
Thomas Gleixner | 935ace2 | 2020-07-22 23:59:59 +0200 | [diff] [blame] | 23 | tracehook_notify_resume(NULL); |
Thomas Gleixner | 935ace2 | 2020-07-22 23:59:59 +0200 | [diff] [blame] | 24 | |
| 25 | ret = arch_xfer_to_guest_mode_handle_work(vcpu, ti_work); |
| 26 | if (ret) |
| 27 | return ret; |
| 28 | |
Mark Rutland | 6ce8951 | 2021-11-29 13:06:44 +0000 | [diff] [blame] | 29 | ti_work = read_thread_flags(); |
Thomas Gleixner | 935ace2 | 2020-07-22 23:59:59 +0200 | [diff] [blame] | 30 | } while (ti_work & XFER_TO_GUEST_MODE_WORK || need_resched()); |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu) |
| 35 | { |
| 36 | unsigned long ti_work; |
| 37 | |
| 38 | /* |
| 39 | * This is invoked from the outer guest loop with interrupts and |
| 40 | * preemption enabled. |
| 41 | * |
| 42 | * KVM invokes xfer_to_guest_mode_work_pending() with interrupts |
| 43 | * disabled in the inner loop before going into guest mode. No need |
| 44 | * to disable interrupts here. |
| 45 | */ |
Mark Rutland | 6ce8951 | 2021-11-29 13:06:44 +0000 | [diff] [blame] | 46 | ti_work = read_thread_flags(); |
Thomas Gleixner | 935ace2 | 2020-07-22 23:59:59 +0200 | [diff] [blame] | 47 | if (!(ti_work & XFER_TO_GUEST_MODE_WORK)) |
| 48 | return 0; |
| 49 | |
| 50 | return xfer_to_guest_mode_work(vcpu, ti_work); |
| 51 | } |
| 52 | EXPORT_SYMBOL_GPL(xfer_to_guest_mode_handle_work); |