xref: /linux/arch/x86/kvm/x86.h (revision 404d5d7bff0d419fe11c7eaebca9ec8f25258f95)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
226eef70cSAvi Kivity #ifndef ARCH_X86_KVM_X86_H
326eef70cSAvi Kivity #define ARCH_X86_KVM_X86_H
426eef70cSAvi Kivity 
526eef70cSAvi Kivity #include <linux/kvm_host.h>
68d93c874SMarcelo Tosatti #include <asm/pvclock.h>
73eeb3288SAvi Kivity #include "kvm_cache_regs.h"
82f728d66SSean Christopherson #include "kvm_emulate.h"
926eef70cSAvi Kivity 
10c8e88717SBabu Moger #define KVM_DEFAULT_PLE_GAP		128
11c8e88717SBabu Moger #define KVM_VMX_DEFAULT_PLE_WINDOW	4096
12c8e88717SBabu Moger #define KVM_DEFAULT_PLE_WINDOW_GROW	2
13c8e88717SBabu Moger #define KVM_DEFAULT_PLE_WINDOW_SHRINK	0
14c8e88717SBabu Moger #define KVM_VMX_DEFAULT_PLE_WINDOW_MAX	UINT_MAX
158566ac8bSBabu Moger #define KVM_SVM_DEFAULT_PLE_WINDOW_MAX	USHRT_MAX
168566ac8bSBabu Moger #define KVM_SVM_DEFAULT_PLE_WINDOW	3000
17c8e88717SBabu Moger 
18c8e88717SBabu Moger static inline unsigned int __grow_ple_window(unsigned int val,
19c8e88717SBabu Moger 		unsigned int base, unsigned int modifier, unsigned int max)
20c8e88717SBabu Moger {
21c8e88717SBabu Moger 	u64 ret = val;
22c8e88717SBabu Moger 
23c8e88717SBabu Moger 	if (modifier < 1)
24c8e88717SBabu Moger 		return base;
25c8e88717SBabu Moger 
26c8e88717SBabu Moger 	if (modifier < base)
27c8e88717SBabu Moger 		ret *= modifier;
28c8e88717SBabu Moger 	else
29c8e88717SBabu Moger 		ret += modifier;
30c8e88717SBabu Moger 
31c8e88717SBabu Moger 	return min(ret, (u64)max);
32c8e88717SBabu Moger }
33c8e88717SBabu Moger 
34c8e88717SBabu Moger static inline unsigned int __shrink_ple_window(unsigned int val,
35c8e88717SBabu Moger 		unsigned int base, unsigned int modifier, unsigned int min)
36c8e88717SBabu Moger {
37c8e88717SBabu Moger 	if (modifier < 1)
38c8e88717SBabu Moger 		return base;
39c8e88717SBabu Moger 
40c8e88717SBabu Moger 	if (modifier < base)
41c8e88717SBabu Moger 		val /= modifier;
42c8e88717SBabu Moger 	else
43c8e88717SBabu Moger 		val -= modifier;
44c8e88717SBabu Moger 
45c8e88717SBabu Moger 	return max(val, min);
46c8e88717SBabu Moger }
47c8e88717SBabu Moger 
4874545705SRadim Krčmář #define MSR_IA32_CR_PAT_DEFAULT  0x0007040600070406ULL
4974545705SRadim Krčmář 
5026eef70cSAvi Kivity static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)
5126eef70cSAvi Kivity {
525c7d4f9aSLiran Alon 	vcpu->arch.exception.pending = false;
53664f8e26SWanpeng Li 	vcpu->arch.exception.injected = false;
5426eef70cSAvi Kivity }
5526eef70cSAvi Kivity 
5666fd3f7fSGleb Natapov static inline void kvm_queue_interrupt(struct kvm_vcpu *vcpu, u8 vector,
5766fd3f7fSGleb Natapov 	bool soft)
58937a7eaeSAvi Kivity {
5904140b41SLiran Alon 	vcpu->arch.interrupt.injected = true;
6066fd3f7fSGleb Natapov 	vcpu->arch.interrupt.soft = soft;
61937a7eaeSAvi Kivity 	vcpu->arch.interrupt.nr = vector;
62937a7eaeSAvi Kivity }
63937a7eaeSAvi Kivity 
64937a7eaeSAvi Kivity static inline void kvm_clear_interrupt_queue(struct kvm_vcpu *vcpu)
65937a7eaeSAvi Kivity {
6604140b41SLiran Alon 	vcpu->arch.interrupt.injected = false;
67937a7eaeSAvi Kivity }
68937a7eaeSAvi Kivity 
693298b75cSGleb Natapov static inline bool kvm_event_needs_reinjection(struct kvm_vcpu *vcpu)
703298b75cSGleb Natapov {
7104140b41SLiran Alon 	return vcpu->arch.exception.injected || vcpu->arch.interrupt.injected ||
723298b75cSGleb Natapov 		vcpu->arch.nmi_injected;
733298b75cSGleb Natapov }
7466fd3f7fSGleb Natapov 
7566fd3f7fSGleb Natapov static inline bool kvm_exception_is_soft(unsigned int nr)
7666fd3f7fSGleb Natapov {
7766fd3f7fSGleb Natapov 	return (nr == BP_VECTOR) || (nr == OF_VECTOR);
7866fd3f7fSGleb Natapov }
79fc61b800SGleb Natapov 
803eeb3288SAvi Kivity static inline bool is_protmode(struct kvm_vcpu *vcpu)
813eeb3288SAvi Kivity {
823eeb3288SAvi Kivity 	return kvm_read_cr0_bits(vcpu, X86_CR0_PE);
833eeb3288SAvi Kivity }
843eeb3288SAvi Kivity 
85836a1b3cSAvi Kivity static inline int is_long_mode(struct kvm_vcpu *vcpu)
86836a1b3cSAvi Kivity {
87836a1b3cSAvi Kivity #ifdef CONFIG_X86_64
88f6801dffSAvi Kivity 	return vcpu->arch.efer & EFER_LMA;
89836a1b3cSAvi Kivity #else
90836a1b3cSAvi Kivity 	return 0;
91836a1b3cSAvi Kivity #endif
92836a1b3cSAvi Kivity }
93836a1b3cSAvi Kivity 
945777392eSNadav Amit static inline bool is_64_bit_mode(struct kvm_vcpu *vcpu)
955777392eSNadav Amit {
965777392eSNadav Amit 	int cs_db, cs_l;
975777392eSNadav Amit 
985777392eSNadav Amit 	if (!is_long_mode(vcpu))
995777392eSNadav Amit 		return false;
100afaf0b2fSSean Christopherson 	kvm_x86_ops.get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
1015777392eSNadav Amit 	return cs_l;
1025777392eSNadav Amit }
1035777392eSNadav Amit 
104855feb67SYu Zhang static inline bool is_la57_mode(struct kvm_vcpu *vcpu)
105855feb67SYu Zhang {
106855feb67SYu Zhang #ifdef CONFIG_X86_64
107855feb67SYu Zhang 	return (vcpu->arch.efer & EFER_LMA) &&
108855feb67SYu Zhang 		 kvm_read_cr4_bits(vcpu, X86_CR4_LA57);
109855feb67SYu Zhang #else
110855feb67SYu Zhang 	return 0;
111855feb67SYu Zhang #endif
112855feb67SYu Zhang }
113855feb67SYu Zhang 
1140447378aSMarc Orr static inline bool x86_exception_has_error_code(unsigned int vector)
1150447378aSMarc Orr {
1160447378aSMarc Orr 	static u32 exception_has_error_code = BIT(DF_VECTOR) | BIT(TS_VECTOR) |
1170447378aSMarc Orr 			BIT(NP_VECTOR) | BIT(SS_VECTOR) | BIT(GP_VECTOR) |
1180447378aSMarc Orr 			BIT(PF_VECTOR) | BIT(AC_VECTOR);
1190447378aSMarc Orr 
1200447378aSMarc Orr 	return (1U << vector) & exception_has_error_code;
1210447378aSMarc Orr }
1220447378aSMarc Orr 
1236539e738SJoerg Roedel static inline bool mmu_is_nested(struct kvm_vcpu *vcpu)
1246539e738SJoerg Roedel {
1256539e738SJoerg Roedel 	return vcpu->arch.walk_mmu == &vcpu->arch.nested_mmu;
1266539e738SJoerg Roedel }
1276539e738SJoerg Roedel 
128eeeb4f67SSean Christopherson static inline void kvm_vcpu_flush_tlb_current(struct kvm_vcpu *vcpu)
129eeeb4f67SSean Christopherson {
130eeeb4f67SSean Christopherson 	++vcpu->stat.tlb_flush;
131eeeb4f67SSean Christopherson 	kvm_x86_ops.tlb_flush_current(vcpu);
132eeeb4f67SSean Christopherson }
133eeeb4f67SSean Christopherson 
134836a1b3cSAvi Kivity static inline int is_pae(struct kvm_vcpu *vcpu)
135836a1b3cSAvi Kivity {
136836a1b3cSAvi Kivity 	return kvm_read_cr4_bits(vcpu, X86_CR4_PAE);
137836a1b3cSAvi Kivity }
138836a1b3cSAvi Kivity 
139836a1b3cSAvi Kivity static inline int is_pse(struct kvm_vcpu *vcpu)
140836a1b3cSAvi Kivity {
141836a1b3cSAvi Kivity 	return kvm_read_cr4_bits(vcpu, X86_CR4_PSE);
142836a1b3cSAvi Kivity }
143836a1b3cSAvi Kivity 
144836a1b3cSAvi Kivity static inline int is_paging(struct kvm_vcpu *vcpu)
145836a1b3cSAvi Kivity {
146c36fc04eSDavidlohr Bueso 	return likely(kvm_read_cr0_bits(vcpu, X86_CR0_PG));
147836a1b3cSAvi Kivity }
148836a1b3cSAvi Kivity 
149bf03d4f9SPaolo Bonzini static inline bool is_pae_paging(struct kvm_vcpu *vcpu)
150bf03d4f9SPaolo Bonzini {
151bf03d4f9SPaolo Bonzini 	return !is_long_mode(vcpu) && is_pae(vcpu) && is_paging(vcpu);
152bf03d4f9SPaolo Bonzini }
153bf03d4f9SPaolo Bonzini 
154fd8cb433SYu Zhang static inline u8 vcpu_virt_addr_bits(struct kvm_vcpu *vcpu)
155fd8cb433SYu Zhang {
156fd8cb433SYu Zhang 	return kvm_read_cr4_bits(vcpu, X86_CR4_LA57) ? 57 : 48;
157fd8cb433SYu Zhang }
158fd8cb433SYu Zhang 
159fd8cb433SYu Zhang static inline u64 get_canonical(u64 la, u8 vaddr_bits)
160fd8cb433SYu Zhang {
161fd8cb433SYu Zhang 	return ((int64_t)la << (64 - vaddr_bits)) >> (64 - vaddr_bits);
162fd8cb433SYu Zhang }
163fd8cb433SYu Zhang 
164fd8cb433SYu Zhang static inline bool is_noncanonical_address(u64 la, struct kvm_vcpu *vcpu)
165fd8cb433SYu Zhang {
166fd8cb433SYu Zhang 	return get_canonical(la, vcpu_virt_addr_bits(vcpu)) != la;
167fd8cb433SYu Zhang }
168fd8cb433SYu Zhang 
169bebb106aSXiao Guangrong static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
170bebb106aSXiao Guangrong 					gva_t gva, gfn_t gfn, unsigned access)
171bebb106aSXiao Guangrong {
172ddfd1730SSean Christopherson 	u64 gen = kvm_memslots(vcpu->kvm)->generation;
173ddfd1730SSean Christopherson 
174361209e0SSean Christopherson 	if (unlikely(gen & KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS))
175ddfd1730SSean Christopherson 		return;
176ddfd1730SSean Christopherson 
1779034e6e8SPaolo Bonzini 	/*
1789034e6e8SPaolo Bonzini 	 * If this is a shadow nested page table, the "GVA" is
1799034e6e8SPaolo Bonzini 	 * actually a nGPA.
1809034e6e8SPaolo Bonzini 	 */
1819034e6e8SPaolo Bonzini 	vcpu->arch.mmio_gva = mmu_is_nested(vcpu) ? 0 : gva & PAGE_MASK;
182871bd034SSean Christopherson 	vcpu->arch.mmio_access = access;
183bebb106aSXiao Guangrong 	vcpu->arch.mmio_gfn = gfn;
184ddfd1730SSean Christopherson 	vcpu->arch.mmio_gen = gen;
18556f17dd3SDavid Matlack }
18656f17dd3SDavid Matlack 
18756f17dd3SDavid Matlack static inline bool vcpu_match_mmio_gen(struct kvm_vcpu *vcpu)
18856f17dd3SDavid Matlack {
18956f17dd3SDavid Matlack 	return vcpu->arch.mmio_gen == kvm_memslots(vcpu->kvm)->generation;
190bebb106aSXiao Guangrong }
191bebb106aSXiao Guangrong 
192bebb106aSXiao Guangrong /*
19356f17dd3SDavid Matlack  * Clear the mmio cache info for the given gva. If gva is MMIO_GVA_ANY, we
19456f17dd3SDavid Matlack  * clear all mmio cache info.
195bebb106aSXiao Guangrong  */
19656f17dd3SDavid Matlack #define MMIO_GVA_ANY (~(gva_t)0)
19756f17dd3SDavid Matlack 
198bebb106aSXiao Guangrong static inline void vcpu_clear_mmio_info(struct kvm_vcpu *vcpu, gva_t gva)
199bebb106aSXiao Guangrong {
20056f17dd3SDavid Matlack 	if (gva != MMIO_GVA_ANY && vcpu->arch.mmio_gva != (gva & PAGE_MASK))
201bebb106aSXiao Guangrong 		return;
202bebb106aSXiao Guangrong 
203bebb106aSXiao Guangrong 	vcpu->arch.mmio_gva = 0;
204bebb106aSXiao Guangrong }
205bebb106aSXiao Guangrong 
206bebb106aSXiao Guangrong static inline bool vcpu_match_mmio_gva(struct kvm_vcpu *vcpu, unsigned long gva)
207bebb106aSXiao Guangrong {
20856f17dd3SDavid Matlack 	if (vcpu_match_mmio_gen(vcpu) && vcpu->arch.mmio_gva &&
20956f17dd3SDavid Matlack 	      vcpu->arch.mmio_gva == (gva & PAGE_MASK))
210bebb106aSXiao Guangrong 		return true;
211bebb106aSXiao Guangrong 
212bebb106aSXiao Guangrong 	return false;
213bebb106aSXiao Guangrong }
214bebb106aSXiao Guangrong 
215bebb106aSXiao Guangrong static inline bool vcpu_match_mmio_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)
216bebb106aSXiao Guangrong {
21756f17dd3SDavid Matlack 	if (vcpu_match_mmio_gen(vcpu) && vcpu->arch.mmio_gfn &&
21856f17dd3SDavid Matlack 	      vcpu->arch.mmio_gfn == gpa >> PAGE_SHIFT)
219bebb106aSXiao Guangrong 		return true;
220bebb106aSXiao Guangrong 
221bebb106aSXiao Guangrong 	return false;
222bebb106aSXiao Guangrong }
223bebb106aSXiao Guangrong 
224489cbcf0SSean Christopherson static inline unsigned long kvm_register_readl(struct kvm_vcpu *vcpu, int reg)
2255777392eSNadav Amit {
2265777392eSNadav Amit 	unsigned long val = kvm_register_read(vcpu, reg);
2275777392eSNadav Amit 
2285777392eSNadav Amit 	return is_64_bit_mode(vcpu) ? val : (u32)val;
2295777392eSNadav Amit }
2305777392eSNadav Amit 
23127e6fb5dSNadav Amit static inline void kvm_register_writel(struct kvm_vcpu *vcpu,
232489cbcf0SSean Christopherson 				       int reg, unsigned long val)
23327e6fb5dSNadav Amit {
23427e6fb5dSNadav Amit 	if (!is_64_bit_mode(vcpu))
23527e6fb5dSNadav Amit 		val = (u32)val;
23627e6fb5dSNadav Amit 	return kvm_register_write(vcpu, reg, val);
23727e6fb5dSNadav Amit }
23827e6fb5dSNadav Amit 
23941dbc6bcSPaolo Bonzini static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk)
24041dbc6bcSPaolo Bonzini {
24141dbc6bcSPaolo Bonzini 	return !(kvm->arch.disabled_quirks & quirk);
24241dbc6bcSPaolo Bonzini }
24341dbc6bcSPaolo Bonzini 
24427cbe7d6SLiran Alon static inline bool kvm_vcpu_latch_init(struct kvm_vcpu *vcpu)
24527cbe7d6SLiran Alon {
246afaf0b2fSSean Christopherson 	return is_smm(vcpu) || kvm_x86_ops.apic_init_signal_blocked(vcpu);
24727cbe7d6SLiran Alon }
24827cbe7d6SLiran Alon 
249bab5bb39SNicholas Krause void kvm_set_pending_timer(struct kvm_vcpu *vcpu);
2509497e1f2SSean Christopherson void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);
251ff9d07a0SZhang, Yanmin 
2528fe8ab46SWill Auld void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr);
253108b249cSPaolo Bonzini u64 get_kvmclock_ns(struct kvm *kvm);
25499e3e30aSZachary Amsden 
255ce14e868SPaolo Bonzini int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
256064aea77SNadav Har'El 	gva_t addr, void *val, unsigned int bytes,
257064aea77SNadav Har'El 	struct x86_exception *exception);
258064aea77SNadav Har'El 
259ce14e868SPaolo Bonzini int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu,
2606a4d7550SNadav Har'El 	gva_t addr, void *val, unsigned int bytes,
2616a4d7550SNadav Har'El 	struct x86_exception *exception);
2626a4d7550SNadav Har'El 
263082d06edSWanpeng Li int handle_ud(struct kvm_vcpu *vcpu);
264082d06edSWanpeng Li 
265da998b46SJim Mattson void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu);
266da998b46SJim Mattson 
26719efffa2SXiao Guangrong void kvm_vcpu_mtrr_init(struct kvm_vcpu *vcpu);
268ff53604bSXiao Guangrong u8 kvm_mtrr_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
2694566654bSNadav Amit bool kvm_mtrr_valid(struct kvm_vcpu *vcpu, u32 msr, u64 data);
270ff53604bSXiao Guangrong int kvm_mtrr_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data);
271ff53604bSXiao Guangrong int kvm_mtrr_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
2726a39bbc5SXiao Guangrong bool kvm_mtrr_check_gfn_range_consistency(struct kvm_vcpu *vcpu, gfn_t gfn,
2736a39bbc5SXiao Guangrong 					  int page_num);
27452004014SFeng Wu bool kvm_vector_hashing_enabled(void);
275736c291cSSean Christopherson int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
276c60658d1SSean Christopherson 			    int emulation_type, void *insn, int insn_len);
277*404d5d7bSWanpeng Li fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu);
2784566654bSNadav Amit 
27900b27a3eSAvi Kivity extern u64 host_xcr0;
280cfc48181SSean Christopherson extern u64 supported_xcr0;
281408e9a31SPaolo Bonzini extern u64 supported_xss;
2824ff41732SPaolo Bonzini 
283615a4ae1SSean Christopherson static inline bool kvm_mpx_supported(void)
284615a4ae1SSean Christopherson {
285615a4ae1SSean Christopherson 	return (supported_xcr0 & (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR))
286615a4ae1SSean Christopherson 		== (XFEATURE_MASK_BNDREGS | XFEATURE_MASK_BNDCSR);
287615a4ae1SSean Christopherson }
288615a4ae1SSean Christopherson 
2899ed96e87SMarcelo Tosatti extern unsigned int min_timer_period_us;
2909ed96e87SMarcelo Tosatti 
291c4ae60e4SLiran Alon extern bool enable_vmware_backdoor;
292c4ae60e4SLiran Alon 
2930c5f81daSWanpeng Li extern int pi_inject_timer;
2940c5f81daSWanpeng Li 
29554e9818fSGleb Natapov extern struct static_key kvm_no_apic_vcpu;
296b51012deSPaolo Bonzini 
2978d93c874SMarcelo Tosatti static inline u64 nsec_to_cycles(struct kvm_vcpu *vcpu, u64 nsec)
2988d93c874SMarcelo Tosatti {
2998d93c874SMarcelo Tosatti 	return pvclock_scale_delta(nsec, vcpu->arch.virtual_tsc_mult,
3008d93c874SMarcelo Tosatti 				   vcpu->arch.virtual_tsc_shift);
3018d93c874SMarcelo Tosatti }
3028d93c874SMarcelo Tosatti 
303b51012deSPaolo Bonzini /* Same "calling convention" as do_div:
304b51012deSPaolo Bonzini  * - divide (n << 32) by base
305b51012deSPaolo Bonzini  * - put result in n
306b51012deSPaolo Bonzini  * - return remainder
307b51012deSPaolo Bonzini  */
308b51012deSPaolo Bonzini #define do_shl32_div32(n, base)					\
309b51012deSPaolo Bonzini 	({							\
310b51012deSPaolo Bonzini 	    u32 __quot, __rem;					\
311b51012deSPaolo Bonzini 	    asm("divl %2" : "=a" (__quot), "=d" (__rem)		\
312b51012deSPaolo Bonzini 			: "rm" (base), "0" (0), "1" ((u32) n));	\
313b51012deSPaolo Bonzini 	    n = __quot;						\
314b51012deSPaolo Bonzini 	    __rem;						\
315b51012deSPaolo Bonzini 	 })
316b51012deSPaolo Bonzini 
3174d5422ceSWanpeng Li static inline bool kvm_mwait_in_guest(struct kvm *kvm)
318668fffa3SMichael S. Tsirkin {
3194d5422ceSWanpeng Li 	return kvm->arch.mwait_in_guest;
320668fffa3SMichael S. Tsirkin }
321668fffa3SMichael S. Tsirkin 
322caa057a2SWanpeng Li static inline bool kvm_hlt_in_guest(struct kvm *kvm)
323caa057a2SWanpeng Li {
324caa057a2SWanpeng Li 	return kvm->arch.hlt_in_guest;
325caa057a2SWanpeng Li }
326caa057a2SWanpeng Li 
327b31c114bSWanpeng Li static inline bool kvm_pause_in_guest(struct kvm *kvm)
328b31c114bSWanpeng Li {
329b31c114bSWanpeng Li 	return kvm->arch.pause_in_guest;
330b31c114bSWanpeng Li }
331b31c114bSWanpeng Li 
332b5170063SWanpeng Li static inline bool kvm_cstate_in_guest(struct kvm *kvm)
333b5170063SWanpeng Li {
334b5170063SWanpeng Li 	return kvm->arch.cstate_in_guest;
335b5170063SWanpeng Li }
336b5170063SWanpeng Li 
337dd60d217SAndi Kleen DECLARE_PER_CPU(struct kvm_vcpu *, current_vcpu);
338dd60d217SAndi Kleen 
339dd60d217SAndi Kleen static inline void kvm_before_interrupt(struct kvm_vcpu *vcpu)
340dd60d217SAndi Kleen {
341dd60d217SAndi Kleen 	__this_cpu_write(current_vcpu, vcpu);
342dd60d217SAndi Kleen }
343dd60d217SAndi Kleen 
344dd60d217SAndi Kleen static inline void kvm_after_interrupt(struct kvm_vcpu *vcpu)
345dd60d217SAndi Kleen {
346dd60d217SAndi Kleen 	__this_cpu_write(current_vcpu, NULL);
347dd60d217SAndi Kleen }
348dd60d217SAndi Kleen 
349674ea351SPaolo Bonzini 
350674ea351SPaolo Bonzini static inline bool kvm_pat_valid(u64 data)
351674ea351SPaolo Bonzini {
352674ea351SPaolo Bonzini 	if (data & 0xF8F8F8F8F8F8F8F8ull)
353674ea351SPaolo Bonzini 		return false;
354674ea351SPaolo Bonzini 	/* 0, 1, 4, 5, 6, 7 are valid values.  */
355674ea351SPaolo Bonzini 	return (data | ((data & 0x0202020202020202ull) << 1)) == data;
356674ea351SPaolo Bonzini }
357674ea351SPaolo Bonzini 
3589b5e8532SSean Christopherson static inline bool kvm_dr7_valid(u64 data)
359b91991bfSKrish Sadhukhan {
360b91991bfSKrish Sadhukhan 	/* Bits [63:32] are reserved */
361b91991bfSKrish Sadhukhan 	return !(data >> 32);
362b91991bfSKrish Sadhukhan }
363b91991bfSKrish Sadhukhan 
364139a12cfSAaron Lewis void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu);
365139a12cfSAaron Lewis void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu);
3666441fa61SPaolo Bonzini u64 kvm_spec_ctrl_valid_bits(struct kvm_vcpu *vcpu);
3675a9f5443SWanpeng Li bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu);
368674ea351SPaolo Bonzini 
36926eef70cSAvi Kivity #endif
370