Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_ENTRYKVM_H
0003 #define __LINUX_ENTRYKVM_H
0004 
0005 #include <linux/static_call_types.h>
0006 #include <linux/resume_user_mode.h>
0007 #include <linux/syscalls.h>
0008 #include <linux/seccomp.h>
0009 #include <linux/sched.h>
0010 #include <linux/tick.h>
0011 
0012 /* Transfer to guest mode work */
0013 #ifdef CONFIG_KVM_XFER_TO_GUEST_WORK
0014 
0015 #ifndef ARCH_XFER_TO_GUEST_MODE_WORK
0016 # define ARCH_XFER_TO_GUEST_MODE_WORK   (0)
0017 #endif
0018 
0019 #define XFER_TO_GUEST_MODE_WORK                     \
0020     (_TIF_NEED_RESCHED | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL | \
0021      _TIF_NOTIFY_RESUME | ARCH_XFER_TO_GUEST_MODE_WORK)
0022 
0023 struct kvm_vcpu;
0024 
0025 /**
0026  * arch_xfer_to_guest_mode_handle_work - Architecture specific xfer to guest
0027  *                   mode work handling function.
0028  * @vcpu:   Pointer to current's VCPU data
0029  * @ti_work:    Cached TIF flags gathered in xfer_to_guest_mode_handle_work()
0030  *
0031  * Invoked from xfer_to_guest_mode_handle_work(). Defaults to NOOP. Can be
0032  * replaced by architecture specific code.
0033  */
0034 static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu,
0035                               unsigned long ti_work);
0036 
0037 #ifndef arch_xfer_to_guest_mode_work
0038 static inline int arch_xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu,
0039                               unsigned long ti_work)
0040 {
0041     return 0;
0042 }
0043 #endif
0044 
0045 /**
0046  * xfer_to_guest_mode_handle_work - Check and handle pending work which needs
0047  *                  to be handled before going to guest mode
0048  * @vcpu:   Pointer to current's VCPU data
0049  *
0050  * Returns: 0 or an error code
0051  */
0052 int xfer_to_guest_mode_handle_work(struct kvm_vcpu *vcpu);
0053 
0054 /**
0055  * xfer_to_guest_mode_prepare - Perform last minute preparation work that
0056  *              need to be handled while IRQs are disabled
0057  *              upon entering to guest.
0058  *
0059  * Has to be invoked with interrupts disabled before the last call
0060  * to xfer_to_guest_mode_work_pending().
0061  */
0062 static inline void xfer_to_guest_mode_prepare(void)
0063 {
0064     lockdep_assert_irqs_disabled();
0065     tick_nohz_user_enter_prepare();
0066 }
0067 
0068 /**
0069  * __xfer_to_guest_mode_work_pending - Check if work is pending
0070  *
0071  * Returns: True if work pending, False otherwise.
0072  *
0073  * Bare variant of xfer_to_guest_mode_work_pending(). Can be called from
0074  * interrupt enabled code for racy quick checks with care.
0075  */
0076 static inline bool __xfer_to_guest_mode_work_pending(void)
0077 {
0078     unsigned long ti_work = read_thread_flags();
0079 
0080     return !!(ti_work & XFER_TO_GUEST_MODE_WORK);
0081 }
0082 
0083 /**
0084  * xfer_to_guest_mode_work_pending - Check if work is pending which needs to be
0085  *                   handled before returning to guest mode
0086  *
0087  * Returns: True if work pending, False otherwise.
0088  *
0089  * Has to be invoked with interrupts disabled before the transition to
0090  * guest mode.
0091  */
0092 static inline bool xfer_to_guest_mode_work_pending(void)
0093 {
0094     lockdep_assert_irqs_disabled();
0095     return __xfer_to_guest_mode_work_pending();
0096 }
0097 #endif /* CONFIG_KVM_XFER_TO_GUEST_WORK */
0098 
0099 #endif