0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef __ARCH_X86_KVM_HYPERV_H__
0022 #define __ARCH_X86_KVM_HYPERV_H__
0023
0024 #include <linux/kvm_host.h>
0025
0026
0027
0028
0029
0030
0031
0032 #define HYPERV_CPUID_SYNDBG_VENDOR_AND_MAX_FUNCTIONS 0x40000080
0033 #define HYPERV_CPUID_SYNDBG_INTERFACE 0x40000081
0034 #define HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES 0x40000082
0035
0036
0037
0038
0039
0040 #define HV_X64_SYNDBG_CAP_ALLOW_KERNEL_DEBUGGING BIT(1)
0041
0042
0043 #define HV_X64_MSR_SYNDBG_CONTROL 0x400000F1
0044 #define HV_X64_MSR_SYNDBG_STATUS 0x400000F2
0045 #define HV_X64_MSR_SYNDBG_SEND_BUFFER 0x400000F3
0046 #define HV_X64_MSR_SYNDBG_RECV_BUFFER 0x400000F4
0047 #define HV_X64_MSR_SYNDBG_PENDING_BUFFER 0x400000F5
0048 #define HV_X64_MSR_SYNDBG_OPTIONS 0x400000FF
0049
0050
0051 #define HV_X64_SYNDBG_OPTION_USE_HCALLS BIT(2)
0052
0053 static inline struct kvm_hv *to_kvm_hv(struct kvm *kvm)
0054 {
0055 return &kvm->arch.hyperv;
0056 }
0057
0058 static inline struct kvm_vcpu_hv *to_hv_vcpu(struct kvm_vcpu *vcpu)
0059 {
0060 return vcpu->arch.hyperv;
0061 }
0062
0063 static inline struct kvm_vcpu_hv_synic *to_hv_synic(struct kvm_vcpu *vcpu)
0064 {
0065 struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
0066
0067 return &hv_vcpu->synic;
0068 }
0069
0070 static inline struct kvm_vcpu *hv_synic_to_vcpu(struct kvm_vcpu_hv_synic *synic)
0071 {
0072 struct kvm_vcpu_hv *hv_vcpu = container_of(synic, struct kvm_vcpu_hv, synic);
0073
0074 return hv_vcpu->vcpu;
0075 }
0076
0077 static inline struct kvm_hv_syndbg *to_hv_syndbg(struct kvm_vcpu *vcpu)
0078 {
0079 return &vcpu->kvm->arch.hyperv.hv_syndbg;
0080 }
0081
0082 static inline u32 kvm_hv_get_vpindex(struct kvm_vcpu *vcpu)
0083 {
0084 struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
0085
0086 return hv_vcpu ? hv_vcpu->vp_index : vcpu->vcpu_idx;
0087 }
0088
0089 int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host);
0090 int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host);
0091
0092 static inline bool kvm_hv_hypercall_enabled(struct kvm_vcpu *vcpu)
0093 {
0094 return vcpu->arch.hyperv_enabled && to_kvm_hv(vcpu->kvm)->hv_guest_os_id;
0095 }
0096
0097 int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
0098
0099 void kvm_hv_irq_routing_update(struct kvm *kvm);
0100 int kvm_hv_synic_set_irq(struct kvm *kvm, u32 vcpu_id, u32 sint);
0101 void kvm_hv_synic_send_eoi(struct kvm_vcpu *vcpu, int vector);
0102 int kvm_hv_activate_synic(struct kvm_vcpu *vcpu, bool dont_zero_synic_pages);
0103
0104 void kvm_hv_vcpu_uninit(struct kvm_vcpu *vcpu);
0105
0106 bool kvm_hv_assist_page_enabled(struct kvm_vcpu *vcpu);
0107 bool kvm_hv_get_assist_page(struct kvm_vcpu *vcpu,
0108 struct hv_vp_assist_page *assist_page);
0109
0110 static inline struct kvm_vcpu_hv_stimer *to_hv_stimer(struct kvm_vcpu *vcpu,
0111 int timer_index)
0112 {
0113 return &to_hv_vcpu(vcpu)->stimer[timer_index];
0114 }
0115
0116 static inline struct kvm_vcpu *hv_stimer_to_vcpu(struct kvm_vcpu_hv_stimer *stimer)
0117 {
0118 struct kvm_vcpu_hv *hv_vcpu;
0119
0120 hv_vcpu = container_of(stimer - stimer->index, struct kvm_vcpu_hv,
0121 stimer[0]);
0122 return hv_vcpu->vcpu;
0123 }
0124
0125 static inline bool kvm_hv_has_stimer_pending(struct kvm_vcpu *vcpu)
0126 {
0127 struct kvm_vcpu_hv *hv_vcpu = to_hv_vcpu(vcpu);
0128
0129 if (!hv_vcpu)
0130 return false;
0131
0132 return !bitmap_empty(hv_vcpu->stimer_pending_bitmap,
0133 HV_SYNIC_STIMER_COUNT);
0134 }
0135
0136 void kvm_hv_process_stimers(struct kvm_vcpu *vcpu);
0137
0138 void kvm_hv_setup_tsc_page(struct kvm *kvm,
0139 struct pvclock_vcpu_time_info *hv_clock);
0140 void kvm_hv_request_tsc_page_update(struct kvm *kvm);
0141
0142 void kvm_hv_init_vm(struct kvm *kvm);
0143 void kvm_hv_destroy_vm(struct kvm *kvm);
0144 void kvm_hv_set_cpuid(struct kvm_vcpu *vcpu);
0145 int kvm_hv_set_enforce_cpuid(struct kvm_vcpu *vcpu, bool enforce);
0146 int kvm_vm_ioctl_hv_eventfd(struct kvm *kvm, struct kvm_hyperv_eventfd *args);
0147 int kvm_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid,
0148 struct kvm_cpuid_entry2 __user *entries);
0149
0150 #endif