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 extern void kvmclock_init(void);
10 extern int kvm_register_clock(char *txt
);
12 #ifdef CONFIG_KVM_GUEST
13 bool kvm_check_and_clear_guest_paused(void);
15 static inline bool kvm_check_and_clear_guest_paused(void)
19 #endif /* CONFIG_KVM_GUEST */
21 #define KVM_HYPERCALL \
22 ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL)
24 /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
25 * instruction. The hypervisor may replace it with something else but only the
26 * instructions are guaranteed to be supported.
28 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
29 * The hypercall number should be placed in rax and the return value will be
30 * placed in rax. No other registers will be clobbered unless explicitly
31 * noted by the particular hypercall.
34 static inline long kvm_hypercall0(unsigned int nr
)
37 asm volatile(KVM_HYPERCALL
44 static inline long kvm_hypercall1(unsigned int nr
, unsigned long p1
)
47 asm volatile(KVM_HYPERCALL
54 static inline long kvm_hypercall2(unsigned int nr
, unsigned long p1
,
58 asm volatile(KVM_HYPERCALL
60 : "a"(nr
), "b"(p1
), "c"(p2
)
65 static inline long kvm_hypercall3(unsigned int nr
, unsigned long p1
,
66 unsigned long p2
, unsigned long p3
)
69 asm volatile(KVM_HYPERCALL
71 : "a"(nr
), "b"(p1
), "c"(p2
), "d"(p3
)
76 static inline long kvm_hypercall4(unsigned int nr
, unsigned long p1
,
77 unsigned long p2
, unsigned long p3
,
81 asm volatile(KVM_HYPERCALL
83 : "a"(nr
), "b"(p1
), "c"(p2
), "d"(p3
), "S"(p4
)
88 #ifdef CONFIG_KVM_GUEST
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(u32 token
, int interrupt_kernel
);
93 void kvm_async_pf_task_wake(u32 token
);
94 u32
kvm_read_and_reset_pf_reason(void);
95 extern void kvm_disable_steal_time(void);
97 #ifdef CONFIG_PARAVIRT_SPINLOCKS
98 void __init
kvm_spinlock_init(void);
99 #else /* !CONFIG_PARAVIRT_SPINLOCKS */
100 static inline void kvm_spinlock_init(void)
103 #endif /* CONFIG_PARAVIRT_SPINLOCKS */
105 #else /* CONFIG_KVM_GUEST */
106 #define kvm_async_pf_task_wait(T, I) do {} while(0)
107 #define kvm_async_pf_task_wake(T) do {} while(0)
109 static inline bool kvm_para_available(void)
114 static inline unsigned int kvm_arch_para_features(void)
119 static inline unsigned int kvm_arch_para_hints(void)
124 static inline u32
kvm_read_and_reset_pf_reason(void)
129 static inline void kvm_disable_steal_time(void)
135 #endif /* _ASM_X86_KVM_PARA_H */