1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_KVM_PARA_H
3 #define _ASM_X86_KVM_PARA_H
5 #include <asm/processor.h>
6 #include <asm/alternative.h>
7 #include <linux/interrupt.h>
8 #include <uapi/asm/kvm_para.h>
10 #ifdef CONFIG_KVM_GUEST
11 bool kvm_check_and_clear_guest_paused(void);
13 static inline bool kvm_check_and_clear_guest_paused(void)
17 #endif /* CONFIG_KVM_GUEST */
19 #define KVM_HYPERCALL \
20 ALTERNATIVE("vmcall", "vmmcall", X86_FEATURE_VMMCALL)
22 /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
23 * instruction. The hypervisor may replace it with something else but only the
24 * instructions are guaranteed to be supported.
26 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
27 * The hypercall number should be placed in rax and the return value will be
28 * placed in rax. No other registers will be clobbered unless explicitly
29 * noted by the particular hypercall.
32 static inline long kvm_hypercall0(unsigned int nr)
35 asm volatile(KVM_HYPERCALL
42 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
45 asm volatile(KVM_HYPERCALL
52 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
56 asm volatile(KVM_HYPERCALL
58 : "a"(nr), "b"(p1), "c"(p2)
63 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
64 unsigned long p2, unsigned long p3)
67 asm volatile(KVM_HYPERCALL
69 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
74 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
75 unsigned long p2, unsigned long p3,
79 asm volatile(KVM_HYPERCALL
81 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
86 #ifdef CONFIG_KVM_GUEST
87 void kvmclock_init(void);
88 void kvmclock_disable(void);
89 bool kvm_para_available(void);
90 unsigned int kvm_arch_para_features(void);
91 unsigned int kvm_arch_para_hints(void);
92 void kvm_async_pf_task_wait_schedule(u32 token);
93 void kvm_async_pf_task_wake(u32 token);
94 u32 kvm_read_and_reset_apf_flags(void);
95 bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token);
97 DECLARE_STATIC_KEY_FALSE(kvm_async_pf_enabled);
99 static __always_inline bool kvm_handle_async_pf(struct pt_regs *regs, u32 token)
101 if (static_branch_unlikely(&kvm_async_pf_enabled))
102 return __kvm_handle_async_pf(regs, token);
107 #ifdef CONFIG_PARAVIRT_SPINLOCKS
108 void __init kvm_spinlock_init(void);
109 #else /* !CONFIG_PARAVIRT_SPINLOCKS */
110 static inline void kvm_spinlock_init(void)
113 #endif /* CONFIG_PARAVIRT_SPINLOCKS */
115 #else /* CONFIG_KVM_GUEST */
116 #define kvm_async_pf_task_wait_schedule(T) do {} while(0)
117 #define kvm_async_pf_task_wake(T) do {} while(0)
119 static inline bool kvm_para_available(void)
124 static inline unsigned int kvm_arch_para_features(void)
129 static inline unsigned int kvm_arch_para_hints(void)
134 static inline u32 kvm_read_and_reset_apf_flags(void)
139 static __always_inline bool kvm_handle_async_pf(struct pt_regs *regs, u32 token)
145 #endif /* _ASM_X86_KVM_PARA_H */