kvm_para.h 3.0 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
H
H. Peter Anvin 已提交
2 3
#ifndef _ASM_X86_KVM_PARA_H
#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
extern void kvmclock_init(void);
10
extern int kvm_register_clock(char *txt);
11

12
#ifdef CONFIG_KVM_GUEST
13 14 15 16 17 18
bool kvm_check_and_clear_guest_paused(void);
#else
static inline bool kvm_check_and_clear_guest_paused(void)
{
	return false;
}
19
#endif /* CONFIG_KVM_GUEST */
20

21 22
#define KVM_HYPERCALL \
        ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL)
23

24
/* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
25 26 27 28 29
 * instruction.  The hypervisor may replace it with something else but only the
 * instructions are guaranteed to be supported.
 *
 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
 * 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 32 33 34 35 36 37 38
 * noted by the particular hypercall.
 */

static inline long kvm_hypercall0(unsigned int nr)
{
	long ret;
	asm volatile(KVM_HYPERCALL
		     : "=a"(ret)
39 40
		     : "a"(nr)
		     : "memory");
41 42 43 44 45 46 47 48
	return ret;
}

static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
{
	long ret;
	asm volatile(KVM_HYPERCALL
		     : "=a"(ret)
49 50
		     : "a"(nr), "b"(p1)
		     : "memory");
51 52 53 54 55 56 57 58 59
	return ret;
}

static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
				  unsigned long p2)
{
	long ret;
	asm volatile(KVM_HYPERCALL
		     : "=a"(ret)
60 61
		     : "a"(nr), "b"(p1), "c"(p2)
		     : "memory");
62 63 64 65 66 67 68 69 70
	return ret;
}

static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
				  unsigned long p2, unsigned long p3)
{
	long ret;
	asm volatile(KVM_HYPERCALL
		     : "=a"(ret)
71 72
		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
		     : "memory");
73 74 75 76 77 78 79 80 81 82
	return ret;
}

static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
				  unsigned long p2, unsigned long p3,
				  unsigned long p4)
{
	long ret;
	asm volatile(KVM_HYPERCALL
		     : "=a"(ret)
83 84
		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
		     : "memory");
85 86 87
	return ret;
}

88
#ifdef CONFIG_KVM_GUEST
89
bool kvm_para_available(void);
90
unsigned int kvm_arch_para_features(void);
91
void kvm_async_pf_task_wait(u32 token, int interrupt_kernel);
G
Gleb Natapov 已提交
92 93
void kvm_async_pf_task_wake(u32 token);
u32 kvm_read_and_reset_pf_reason(void);
94
extern void kvm_disable_steal_time(void);
95 96 97 98 99 100 101 102 103 104

#ifdef CONFIG_PARAVIRT_SPINLOCKS
void __init kvm_spinlock_init(void);
#else /* !CONFIG_PARAVIRT_SPINLOCKS */
static inline void kvm_spinlock_init(void)
{
}
#endif /* CONFIG_PARAVIRT_SPINLOCKS */

#else /* CONFIG_KVM_GUEST */
105
#define kvm_async_pf_task_wait(T, I) do {} while(0)
G
Gleb Natapov 已提交
106
#define kvm_async_pf_task_wake(T) do {} while(0)
107

108 109
static inline bool kvm_para_available(void)
{
110
	return false;
111 112
}

113 114 115 116 117
static inline unsigned int kvm_arch_para_features(void)
{
	return 0;
}

118
static inline u32 kvm_read_and_reset_pf_reason(void)
G
Gleb Natapov 已提交
119 120 121
{
	return 0;
}
122 123 124 125 126

static inline void kvm_disable_steal_time(void)
{
	return;
}
127 128
#endif

H
H. Peter Anvin 已提交
129
#endif /* _ASM_X86_KVM_PARA_H */