Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1#ifndef _ASM_X86_KVM_PARA_H
  2#define _ASM_X86_KVM_PARA_H
  3
  4#include <asm/processor.h>
  5#include <asm/alternative.h>
 
  6#include <uapi/asm/kvm_para.h>
  7
  8extern void kvmclock_init(void);
  9extern int kvm_register_clock(char *txt);
 10
 11#ifdef CONFIG_KVM_GUEST
 12bool kvm_check_and_clear_guest_paused(void);
 13#else
 14static inline bool kvm_check_and_clear_guest_paused(void)
 15{
 16	return false;
 17}
 18#endif /* CONFIG_KVM_GUEST */
 19
 20#define KVM_HYPERCALL \
 21        ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL)
 22
 23/* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
 24 * instruction.  The hypervisor may replace it with something else but only the
 25 * instructions are guaranteed to be supported.
 26 *
 27 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
 28 * The hypercall number should be placed in rax and the return value will be
 29 * placed in rax.  No other registers will be clobbered unless explicitly
 30 * noted by the particular hypercall.
 31 */
 32
 33static inline long kvm_hypercall0(unsigned int nr)
 34{
 35	long ret;
 
 
 
 
 36	asm volatile(KVM_HYPERCALL
 37		     : "=a"(ret)
 38		     : "a"(nr)
 39		     : "memory");
 40	return ret;
 41}
 42
 43static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
 44{
 45	long ret;
 
 
 
 
 46	asm volatile(KVM_HYPERCALL
 47		     : "=a"(ret)
 48		     : "a"(nr), "b"(p1)
 49		     : "memory");
 50	return ret;
 51}
 52
 53static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
 54				  unsigned long p2)
 55{
 56	long ret;
 
 
 
 
 57	asm volatile(KVM_HYPERCALL
 58		     : "=a"(ret)
 59		     : "a"(nr), "b"(p1), "c"(p2)
 60		     : "memory");
 61	return ret;
 62}
 63
 64static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
 65				  unsigned long p2, unsigned long p3)
 66{
 67	long ret;
 
 
 
 
 68	asm volatile(KVM_HYPERCALL
 69		     : "=a"(ret)
 70		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
 71		     : "memory");
 72	return ret;
 73}
 74
 75static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
 76				  unsigned long p2, unsigned long p3,
 77				  unsigned long p4)
 78{
 79	long ret;
 
 
 
 
 80	asm volatile(KVM_HYPERCALL
 81		     : "=a"(ret)
 82		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
 83		     : "memory");
 84	return ret;
 85}
 86
 
 
 
 
 
 
 
 
 
 
 
 
 87#ifdef CONFIG_KVM_GUEST
 
 
 88bool kvm_para_available(void);
 89unsigned int kvm_arch_para_features(void);
 90void __init kvm_guest_init(void);
 91void kvm_async_pf_task_wait(u32 token);
 92void kvm_async_pf_task_wake(u32 token);
 93u32 kvm_read_and_reset_pf_reason(void);
 94extern void kvm_disable_steal_time(void);
 
 
 
 
 
 
 
 
 
 
 95
 96#ifdef CONFIG_PARAVIRT_SPINLOCKS
 97void __init kvm_spinlock_init(void);
 98#else /* !CONFIG_PARAVIRT_SPINLOCKS */
 99static inline void kvm_spinlock_init(void)
100{
101}
102#endif /* CONFIG_PARAVIRT_SPINLOCKS */
103
104#else /* CONFIG_KVM_GUEST */
105#define kvm_guest_init() do {} while (0)
106#define kvm_async_pf_task_wait(T) do {} while(0)
107#define kvm_async_pf_task_wake(T) do {} while(0)
108
109static inline bool kvm_para_available(void)
110{
111	return false;
112}
113
114static inline unsigned int kvm_arch_para_features(void)
115{
116	return 0;
117}
118
119static inline u32 kvm_read_and_reset_pf_reason(void)
120{
121	return 0;
122}
123
124static inline void kvm_disable_steal_time(void)
125{
126	return;
 
 
 
 
 
127}
128#endif
129
130#endif /* _ASM_X86_KVM_PARA_H */
v6.2
  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 <linux/interrupt.h>
  8#include <uapi/asm/kvm_para.h>
  9
 10#include <asm/tdx.h>
 
 11
 12#ifdef CONFIG_KVM_GUEST
 13bool kvm_check_and_clear_guest_paused(void);
 14#else
 15static inline bool kvm_check_and_clear_guest_paused(void)
 16{
 17	return false;
 18}
 19#endif /* CONFIG_KVM_GUEST */
 20
 21#define KVM_HYPERCALL \
 22        ALTERNATIVE("vmcall", "vmmcall", X86_FEATURE_VMMCALL)
 23
 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.
 27 *
 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.
 32 */
 33
 34static inline long kvm_hypercall0(unsigned int nr)
 35{
 36	long ret;
 37
 38	if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
 39		return tdx_kvm_hypercall(nr, 0, 0, 0, 0);
 40
 41	asm volatile(KVM_HYPERCALL
 42		     : "=a"(ret)
 43		     : "a"(nr)
 44		     : "memory");
 45	return ret;
 46}
 47
 48static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
 49{
 50	long ret;
 51
 52	if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
 53		return tdx_kvm_hypercall(nr, p1, 0, 0, 0);
 54
 55	asm volatile(KVM_HYPERCALL
 56		     : "=a"(ret)
 57		     : "a"(nr), "b"(p1)
 58		     : "memory");
 59	return ret;
 60}
 61
 62static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
 63				  unsigned long p2)
 64{
 65	long ret;
 66
 67	if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
 68		return tdx_kvm_hypercall(nr, p1, p2, 0, 0);
 69
 70	asm volatile(KVM_HYPERCALL
 71		     : "=a"(ret)
 72		     : "a"(nr), "b"(p1), "c"(p2)
 73		     : "memory");
 74	return ret;
 75}
 76
 77static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
 78				  unsigned long p2, unsigned long p3)
 79{
 80	long ret;
 81
 82	if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
 83		return tdx_kvm_hypercall(nr, p1, p2, p3, 0);
 84
 85	asm volatile(KVM_HYPERCALL
 86		     : "=a"(ret)
 87		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
 88		     : "memory");
 89	return ret;
 90}
 91
 92static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
 93				  unsigned long p2, unsigned long p3,
 94				  unsigned long p4)
 95{
 96	long ret;
 97
 98	if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST))
 99		return tdx_kvm_hypercall(nr, p1, p2, p3, p4);
100
101	asm volatile(KVM_HYPERCALL
102		     : "=a"(ret)
103		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
104		     : "memory");
105	return ret;
106}
107
108static inline long kvm_sev_hypercall3(unsigned int nr, unsigned long p1,
109				      unsigned long p2, unsigned long p3)
110{
111	long ret;
112
113	asm volatile("vmmcall"
114		     : "=a"(ret)
115		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
116		     : "memory");
117	return ret;
118}
119
120#ifdef CONFIG_KVM_GUEST
121void kvmclock_init(void);
122void kvmclock_disable(void);
123bool kvm_para_available(void);
124unsigned int kvm_arch_para_features(void);
125unsigned int kvm_arch_para_hints(void);
126void kvm_async_pf_task_wait_schedule(u32 token);
127void kvm_async_pf_task_wake(u32 token);
128u32 kvm_read_and_reset_apf_flags(void);
129bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token);
130
131DECLARE_STATIC_KEY_FALSE(kvm_async_pf_enabled);
132
133static __always_inline bool kvm_handle_async_pf(struct pt_regs *regs, u32 token)
134{
135	if (static_branch_unlikely(&kvm_async_pf_enabled))
136		return __kvm_handle_async_pf(regs, token);
137	else
138		return false;
139}
140
141#ifdef CONFIG_PARAVIRT_SPINLOCKS
142void __init kvm_spinlock_init(void);
143#else /* !CONFIG_PARAVIRT_SPINLOCKS */
144static inline void kvm_spinlock_init(void)
145{
146}
147#endif /* CONFIG_PARAVIRT_SPINLOCKS */
148
149#else /* CONFIG_KVM_GUEST */
150#define kvm_async_pf_task_wait_schedule(T) do {} while(0)
 
151#define kvm_async_pf_task_wake(T) do {} while(0)
152
153static inline bool kvm_para_available(void)
154{
155	return false;
156}
157
158static inline unsigned int kvm_arch_para_features(void)
159{
160	return 0;
161}
162
163static inline unsigned int kvm_arch_para_hints(void)
164{
165	return 0;
166}
167
168static inline u32 kvm_read_and_reset_apf_flags(void)
169{
170	return 0;
171}
172
173static __always_inline bool kvm_handle_async_pf(struct pt_regs *regs, u32 token)
174{
175	return false;
176}
177#endif
178
179#endif /* _ASM_X86_KVM_PARA_H */