14228Sphk/* SPDX-License-Identifier: GPL-2.0 */
23027Srgrimes#ifndef __KVM_X86_VMX_HYPERV_H
33027Srgrimes#define __KVM_X86_VMX_HYPERV_H
44211Sjkh
54211Sjkh#include <linux/kvm_host.h>
64211Sjkh#include "vmcs12.h"
73884Sphk#include "vmx.h"
83884Sphk
93884Sphk#define EVMPTR_INVALID (-1ULL)
103884Sphk#define EVMPTR_MAP_PENDING (-2ULL)
113884Sphk
124191Sjkhenum nested_evmptrld_status {
133884Sphk	EVMPTRLD_DISABLED,
144191Sjkh	EVMPTRLD_SUCCEEDED,
154191Sjkh	EVMPTRLD_VMFAIL,
163884Sphk	EVMPTRLD_ERROR,
173884Sphk};
183884Sphk
193993Sphk#ifdef CONFIG_KVM_HYPERV
203993Sphkstatic inline bool evmptr_is_valid(u64 evmptr)
214222Sphk{
223884Sphk	return evmptr != EVMPTR_INVALID && evmptr != EVMPTR_MAP_PENDING;
234150Sphk}
244228Sphk
253884Sphkstatic inline bool nested_vmx_is_evmptr12_valid(struct vcpu_vmx *vmx)
263027Srgrimes{
273027Srgrimes	return evmptr_is_valid(vmx->nested.hv_evmcs_vmptr);
283030Srgrimes}
293469Srgrimes
303469Srgrimesstatic inline bool evmptr_is_set(u64 evmptr)
313469Srgrimes{
323027Srgrimes	return evmptr != EVMPTR_INVALID;
333469Srgrimes}
343027Srgrimes
353469Srgrimesstatic inline bool nested_vmx_is_evmptr12_set(struct vcpu_vmx *vmx)
363469Srgrimes{
373884Sphk	return evmptr_is_set(vmx->nested.hv_evmcs_vmptr);
383884Sphk}
393884Sphk
403884Sphkstatic inline struct hv_enlightened_vmcs *nested_vmx_evmcs(struct vcpu_vmx *vmx)
413884Sphk{
424222Sphk	return vmx->nested.hv_evmcs;
433884Sphk}
443884Sphk
454222Sphkstatic inline bool guest_cpuid_has_evmcs(struct kvm_vcpu *vcpu)
463884Sphk{
473884Sphk	/*
483884Sphk	 * eVMCS is exposed to the guest if Hyper-V is enabled in CPUID and
494222Sphk	 * eVMCS has been explicitly enabled by userspace.
503884Sphk	 */
513884Sphk	return vcpu->arch.hyperv_enabled &&
523884Sphk	       to_vmx(vcpu)->nested.enlightened_vmcs_enabled;
533884Sphk}
543884Sphk
553993Sphku64 nested_get_evmptr(struct kvm_vcpu *vcpu);
563884Sphkuint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu);
573884Sphkint nested_enable_evmcs(struct kvm_vcpu *vcpu,
583884Sphk			uint16_t *vmcs_version);
593884Sphkvoid nested_evmcs_filter_control_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
603884Sphkint nested_evmcs_check_controls(struct vmcs12 *vmcs12);
613884Sphkbool nested_evmcs_l2_tlb_flush_enabled(struct kvm_vcpu *vcpu);
623884Sphkvoid vmx_hv_inject_synthetic_vmexit_post_tlb_flush(struct kvm_vcpu *vcpu);
634196Sjkh#else
644198Sjkhstatic inline bool evmptr_is_valid(u64 evmptr)
654198Sjkh{
664198Sjkh	return false;
674198Sjkh}
684198Sjkh
694198Sjkhstatic inline bool nested_vmx_is_evmptr12_valid(struct vcpu_vmx *vmx)
703884Sphk{
713884Sphk	return false;
723884Sphk}
734228Sphk
744228Sphkstatic inline bool evmptr_is_set(u64 evmptr)
754222Sphk{
763884Sphk	return false;
773884Sphk}
784219Sphk
793993Sphkstatic inline bool nested_vmx_is_evmptr12_set(struct vcpu_vmx *vmx)
804219Sphk{
814219Sphk	return false;
823884Sphk}
833884Sphk
843884Sphkstatic inline struct hv_enlightened_vmcs *nested_vmx_evmcs(struct vcpu_vmx *vmx)
853884Sphk{
863884Sphk	return NULL;
873884Sphk}
883884Sphk#endif
893884Sphk
903884Sphk#endif /* __KVM_X86_VMX_HYPERV_H */
913993Sphk