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 <uapi/asm/kvm_para.h>
9 #ifdef CONFIG_KVM_GUEST
10 bool kvm_check_and_clear_guest_paused(void);
12 static inline bool kvm_check_and_clear_guest_paused(void)
16 #endif /* CONFIG_KVM_GUEST */
18 #define KVM_HYPERCALL \
19 ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL)
21 /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
22 * instruction. The hypervisor may replace it with something else but only the
23 * instructions are guaranteed to be supported.
25 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
26 * The hypercall number should be placed in rax and the return value will be
27 * placed in rax. No other registers will be clobbered unless explicitly
28 * noted by the particular hypercall.
31 static inline long kvm_hypercall0(unsigned int nr)
34 asm volatile(KVM_HYPERCALL
41 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
44 asm volatile(KVM_HYPERCALL
51 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
55 asm volatile(KVM_HYPERCALL
57 : "a"(nr), "b"(p1), "c"(p2)
62 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
63 unsigned long p2, unsigned long p3)
66 asm volatile(KVM_HYPERCALL
68 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
73 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
74 unsigned long p2, unsigned long p3,
78 asm volatile(KVM_HYPERCALL
80 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
85 #ifdef CONFIG_KVM_GUEST
86 void kvmclock_init(void);
87 void kvmclock_disable(void);
88 bool kvm_para_available(void);
89 unsigned int kvm_arch_para_features(void);
90 unsigned int kvm_arch_para_hints(void);
91 void kvm_async_pf_task_wait(u32 token, int interrupt_kernel);
92 void kvm_async_pf_task_wake(u32 token);
93 u32 kvm_read_and_reset_pf_reason(void);
94 void do_async_page_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
96 #ifdef CONFIG_PARAVIRT_SPINLOCKS
97 void __init kvm_spinlock_init(void);
98 #else /* !CONFIG_PARAVIRT_SPINLOCKS */
99 static inline void kvm_spinlock_init(void)
102 #endif /* CONFIG_PARAVIRT_SPINLOCKS */
104 #else /* CONFIG_KVM_GUEST */
105 #define kvm_async_pf_task_wait(T, I) do {} while(0)
106 #define kvm_async_pf_task_wake(T) do {} while(0)
108 static inline bool kvm_para_available(void)
113 static inline unsigned int kvm_arch_para_features(void)
118 static inline unsigned int kvm_arch_para_hints(void)
123 static inline u32 kvm_read_and_reset_pf_reason(void)
129 #endif /* _ASM_X86_KVM_PARA_H */