Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
7/* Transfer to guest mode work */
8#ifdef CONFIG_KVM_XFER_TO_GUEST_WORK
9
10#ifndef ARCH_XFER_TO_GUEST_MODE_WORK
11# define ARCH_XFER_TO_GUEST_MODE_WORK (0)
12#endif
13
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)
17
18struct kvm_vcpu;
19
20/**
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()
25 *
26 * Invoked from xfer_to_guest_mode_handle_work(). Defaults to NOOP. Can be
27 * replaced by architecture specific code.
28 */
29static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu,
30 unsigned long ti_work);
31
32#ifndef arch_xfer_to_guest_mode_work
33static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu,
34 unsigned long ti_work)
35{
36 return 0;
37}
38#endif
39
40/**
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
44 *
45 * Returns: 0 or an error code
46 */
47int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu);
48
49/**
50 * xfer_to_guest_mode_prepare - Perform last minute preparation work that
51 * need to be handled while IRQs are disabled
52 * upon entering to guest.
53 *
54 * Has to be invoked with interrupts disabled before the last call
55 * to xfer_to_guest_mode_work_pending().
56 */
57static inline void xfer_to_guest_mode_prepare(void)
58{
59 lockdep_assert_irqs_disabled();
60 rcu_nocb_flush_deferred_wakeup();
61}
62
63/**
64 * __xfer_to_guest_mode_work_pending - Check if work is pending
65 *
66 * Returns: True if work pending, False otherwise.
67 *
68 * Bare variant of xfer_to_guest_mode_work_pending(). Can be called from
69 * interrupt enabled code for racy quick checks with care.
70 */
71static inline bool __xfer_to_guest_mode_work_pending(void)
72{
73 unsigned long ti_work = READ_ONCE(current_thread_info()->flags);
74
75 return !!(ti_work & XFER_TO_GUEST_MODE_WORK);
76}
77
78/**
79 * xfer_to_guest_mode_work_pending - Check if work is pending which needs to be
80 * handled before returning to guest mode
81 *
82 * Returns: True if work pending, False otherwise.
83 *
84 * Has to be invoked with interrupts disabled before the transition to
85 * guest mode.
86 */
87static inline bool xfer_to_guest_mode_work_pending(void)
88{
89 lockdep_assert_irqs_disabled();
90 return __xfer_to_guest_mode_work_pending();
91}
92#endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */
93
94#endif