blob: b66a921776f43037abdfacafd1947d814c68398f [file] [log] [blame]
Joao Martins23200b72018-06-13 09:55:44 -04001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright © 2019 Oracle and/or its affiliates. All rights reserved.
4 * Copyright © 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 *
6 * KVM Xen emulation
7 */
8
9#ifndef __ARCH_X86_KVM_XEN_H__
10#define __ARCH_X86_KVM_XEN_H__
11
David Woodhouse7d6bbeb2021-02-02 15:48:05 +000012#include <linux/jump_label_ratelimit.h>
13
14extern struct static_key_false_deferred kvm_xen_enabled;
15
David Woodhouse40da8cc2020-12-09 20:08:30 +000016int __kvm_xen_has_interrupt(struct kvm_vcpu *vcpu);
David Woodhouse3e324612021-02-02 16:53:25 +000017int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data);
18int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data);
Joao Martinsa76b9642020-12-03 15:52:25 +000019int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data);
20int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data);
Joao Martins23200b72018-06-13 09:55:44 -040021int kvm_xen_hypercall(struct kvm_vcpu *vcpu);
22int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data);
David Woodhouse78e98782021-02-02 13:19:35 +000023int kvm_xen_hvm_config(struct kvm *kvm, struct kvm_xen_hvm_config *xhc);
David Woodhouse7d6bbeb2021-02-02 15:48:05 +000024void kvm_xen_destroy_vm(struct kvm *kvm);
Joao Martins23200b72018-06-13 09:55:44 -040025
26static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm)
27{
David Woodhouse7d6bbeb2021-02-02 15:48:05 +000028 return static_branch_unlikely(&kvm_xen_enabled.key) &&
29 (kvm->arch.xen_hvm_config.flags &
30 KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL);
Joao Martins23200b72018-06-13 09:55:44 -040031}
32
David Woodhouse40da8cc2020-12-09 20:08:30 +000033static inline int kvm_xen_has_interrupt(struct kvm_vcpu *vcpu)
34{
35 if (static_branch_unlikely(&kvm_xen_enabled.key) &&
36 vcpu->arch.xen.vcpu_info_set && vcpu->kvm->arch.xen.upcall_vector)
37 return __kvm_xen_has_interrupt(vcpu);
38
39 return 0;
40}
David Woodhouse1ea9f2e2020-12-03 18:45:22 +000041
42/* 32-bit compatibility definitions, also used natively in 32-bit build */
43#include <asm/pvclock-abi.h>
44#include <asm/xen/interface.h>
45
46struct compat_arch_vcpu_info {
47 unsigned int cr2;
48 unsigned int pad[5];
49};
50
51struct compat_vcpu_info {
Sean Christopherson7137b7a2021-02-10 10:26:09 -080052 uint8_t evtchn_upcall_pending;
53 uint8_t evtchn_upcall_mask;
54 uint16_t pad;
55 uint32_t evtchn_pending_sel;
56 struct compat_arch_vcpu_info arch;
57 struct pvclock_vcpu_time_info time;
David Woodhouse1ea9f2e2020-12-03 18:45:22 +000058}; /* 64 bytes (x86) */
59
60struct compat_arch_shared_info {
61 unsigned int max_pfn;
62 unsigned int pfn_to_mfn_frame_list_list;
63 unsigned int nmi_reason;
64 unsigned int p2m_cr3;
65 unsigned int p2m_vaddr;
66 unsigned int p2m_generation;
67 uint32_t wc_sec_hi;
68};
69
70struct compat_shared_info {
71 struct compat_vcpu_info vcpu_info[MAX_VIRT_CPUS];
72 uint32_t evtchn_pending[32];
73 uint32_t evtchn_mask[32];
74 struct pvclock_wall_clock wc;
75 struct compat_arch_shared_info arch;
76};
77
Joao Martins23200b72018-06-13 09:55:44 -040078#endif /* __ARCH_X86_KVM_XEN_H__ */