1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_KVM_PARA_H
3 #define _ASM_X86_KVM_PARA_H
4
5 #include <asm/processor.h>
6 #include <asm/alternative.h>
7 #include <uapi/asm/kvm_para.h>
8
9 #ifdef CONFIG_KVM_GUEST
10 bool kvm_check_and_clear_guest_paused(void);
11 #else
kvm_check_and_clear_guest_paused(void)12 static inline bool kvm_check_and_clear_guest_paused(void)
13 {
14 return false;
15 }
16 #endif /* CONFIG_KVM_GUEST */
17
18 #define KVM_HYPERCALL \
19 ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL)
20
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.
24 *
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.
29 */
30
kvm_hypercall0(unsigned int nr)31 static inline long kvm_hypercall0(unsigned int nr)
32 {
33 long ret;
34 asm volatile(KVM_HYPERCALL
35 : "=a"(ret)
36 : "a"(nr)
37 : "memory");
38 return ret;
39 }
40
kvm_hypercall1(unsigned int nr,unsigned long p1)41 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
42 {
43 long ret;
44 asm volatile(KVM_HYPERCALL
45 : "=a"(ret)
46 : "a"(nr), "b"(p1)
47 : "memory");
48 return ret;
49 }
50
kvm_hypercall2(unsigned int nr,unsigned long p1,unsigned long p2)51 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
52 unsigned long p2)
53 {
54 long ret;
55 asm volatile(KVM_HYPERCALL
56 : "=a"(ret)
57 : "a"(nr), "b"(p1), "c"(p2)
58 : "memory");
59 return ret;
60 }
61
kvm_hypercall3(unsigned int nr,unsigned long p1,unsigned long p2,unsigned long p3)62 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
63 unsigned long p2, unsigned long p3)
64 {
65 long ret;
66 asm volatile(KVM_HYPERCALL
67 : "=a"(ret)
68 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
69 : "memory");
70 return ret;
71 }
72
kvm_hypercall4(unsigned int nr,unsigned long p1,unsigned long p2,unsigned long p3,unsigned long p4)73 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
74 unsigned long p2, unsigned long p3,
75 unsigned long p4)
76 {
77 long ret;
78 asm volatile(KVM_HYPERCALL
79 : "=a"(ret)
80 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
81 : "memory");
82 return ret;
83 }
84
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);
95
96 #ifdef CONFIG_PARAVIRT_SPINLOCKS
97 void __init kvm_spinlock_init(void);
98 #else /* !CONFIG_PARAVIRT_SPINLOCKS */
kvm_spinlock_init(void)99 static inline void kvm_spinlock_init(void)
100 {
101 }
102 #endif /* CONFIG_PARAVIRT_SPINLOCKS */
103
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)
107
kvm_para_available(void)108 static inline bool kvm_para_available(void)
109 {
110 return false;
111 }
112
kvm_arch_para_features(void)113 static inline unsigned int kvm_arch_para_features(void)
114 {
115 return 0;
116 }
117
kvm_arch_para_hints(void)118 static inline unsigned int kvm_arch_para_hints(void)
119 {
120 return 0;
121 }
122
kvm_read_and_reset_pf_reason(void)123 static inline u32 kvm_read_and_reset_pf_reason(void)
124 {
125 return 0;
126 }
127 #endif
128
129 #endif /* _ASM_X86_KVM_PARA_H */
130