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