1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
4 * Copyright © 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
9 #ifndef __ARCH_X86_KVM_XEN_H__
10 #define __ARCH_X86_KVM_XEN_H__
13 #include <linux/jump_label_ratelimit.h>
15 extern struct static_key_false_deferred kvm_xen_enabled;
17 int __kvm_xen_has_interrupt(struct kvm_vcpu *vcpu);
18 int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data);
19 int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data);
20 int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data);
21 int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data);
22 int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data);
23 int kvm_xen_hvm_config(struct kvm *kvm, struct kvm_xen_hvm_config *xhc);
24 void kvm_xen_destroy_vm(struct kvm *kvm);
26 static inline bool kvm_xen_msr_enabled(struct kvm *kvm)
28 return static_branch_unlikely(&kvm_xen_enabled.key) &&
29 kvm->arch.xen_hvm_config.msr;
32 static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm)
34 return static_branch_unlikely(&kvm_xen_enabled.key) &&
35 (kvm->arch.xen_hvm_config.flags &
36 KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL);
39 static inline int kvm_xen_has_interrupt(struct kvm_vcpu *vcpu)
41 if (static_branch_unlikely(&kvm_xen_enabled.key) &&
42 vcpu->arch.xen.vcpu_info_set && vcpu->kvm->arch.xen.upcall_vector)
43 return __kvm_xen_has_interrupt(vcpu);
48 static inline int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
53 static inline void kvm_xen_destroy_vm(struct kvm *kvm)
57 static inline bool kvm_xen_msr_enabled(struct kvm *kvm)
62 static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm)
67 static inline int kvm_xen_has_interrupt(struct kvm_vcpu *vcpu)
73 int kvm_xen_hypercall(struct kvm_vcpu *vcpu);
75 #include <asm/pvclock-abi.h>
76 #include <asm/xen/interface.h>
77 #include <xen/interface/vcpu.h>
79 void kvm_xen_update_runstate_guest(struct kvm_vcpu *vcpu, int state);
81 static inline void kvm_xen_runstate_set_running(struct kvm_vcpu *vcpu)
83 kvm_xen_update_runstate_guest(vcpu, RUNSTATE_running);
86 static inline void kvm_xen_runstate_set_preempted(struct kvm_vcpu *vcpu)
89 * If the vCPU wasn't preempted but took a normal exit for
90 * some reason (hypercalls, I/O, etc.), that is accounted as
91 * still RUNSTATE_running, as the VMM is still operating on
92 * behalf of the vCPU. Only if the VMM does actually block
93 * does it need to enter RUNSTATE_blocked.
96 kvm_xen_update_runstate_guest(vcpu, RUNSTATE_runnable);
99 /* 32-bit compatibility definitions, also used natively in 32-bit build */
100 struct compat_arch_vcpu_info {
105 struct compat_vcpu_info {
106 uint8_t evtchn_upcall_pending;
107 uint8_t evtchn_upcall_mask;
109 uint32_t evtchn_pending_sel;
110 struct compat_arch_vcpu_info arch;
111 struct pvclock_vcpu_time_info time;
112 }; /* 64 bytes (x86) */
114 struct compat_arch_shared_info {
115 unsigned int max_pfn;
116 unsigned int pfn_to_mfn_frame_list_list;
117 unsigned int nmi_reason;
118 unsigned int p2m_cr3;
119 unsigned int p2m_vaddr;
120 unsigned int p2m_generation;
124 struct compat_shared_info {
125 struct compat_vcpu_info vcpu_info[MAX_VIRT_CPUS];
126 uint32_t evtchn_pending[32];
127 uint32_t evtchn_mask[32];
128 struct pvclock_wall_clock wc;
129 struct compat_arch_shared_info arch;
132 struct compat_vcpu_runstate_info {
134 uint64_t state_entry_time;
136 } __attribute__((packed));
138 #endif /* __ARCH_X86_KVM_XEN_H__ */