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