Joao Martins | 23200b7 | 2018-06-13 09:55:44 -0400 | [diff] [blame] | 1 | // 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 Woodhouse | 7d6bbeb | 2021-02-02 15:48:05 +0000 | [diff] [blame] | 12 | #include <linux/jump_label_ratelimit.h> |
| 13 | |
| 14 | extern struct static_key_false_deferred kvm_xen_enabled; |
| 15 | |
David Woodhouse | 40da8cc | 2020-12-09 20:08:30 +0000 | [diff] [blame] | 16 | int __kvm_xen_has_interrupt(struct kvm_vcpu *vcpu); |
David Woodhouse | 3e32461 | 2021-02-02 16:53:25 +0000 | [diff] [blame] | 17 | int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data); |
| 18 | int kvm_xen_vcpu_get_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data); |
Joao Martins | a76b964 | 2020-12-03 15:52:25 +0000 | [diff] [blame] | 19 | int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data); |
| 20 | int kvm_xen_hvm_get_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data); |
Joao Martins | 23200b7 | 2018-06-13 09:55:44 -0400 | [diff] [blame] | 21 | int kvm_xen_hypercall(struct kvm_vcpu *vcpu); |
| 22 | int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data); |
David Woodhouse | 78e9878 | 2021-02-02 13:19:35 +0000 | [diff] [blame] | 23 | int kvm_xen_hvm_config(struct kvm *kvm, struct kvm_xen_hvm_config *xhc); |
David Woodhouse | 7d6bbeb | 2021-02-02 15:48:05 +0000 | [diff] [blame] | 24 | void kvm_xen_destroy_vm(struct kvm *kvm); |
Joao Martins | 23200b7 | 2018-06-13 09:55:44 -0400 | [diff] [blame] | 25 | |
| 26 | static inline bool kvm_xen_hypercall_enabled(struct kvm *kvm) |
| 27 | { |
David Woodhouse | 7d6bbeb | 2021-02-02 15:48:05 +0000 | [diff] [blame] | 28 | return static_branch_unlikely(&kvm_xen_enabled.key) && |
| 29 | (kvm->arch.xen_hvm_config.flags & |
| 30 | KVM_XEN_HVM_CONFIG_INTERCEPT_HCALL); |
Joao Martins | 23200b7 | 2018-06-13 09:55:44 -0400 | [diff] [blame] | 31 | } |
| 32 | |
David Woodhouse | 40da8cc | 2020-12-09 20:08:30 +0000 | [diff] [blame] | 33 | static 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 Woodhouse | 1ea9f2e | 2020-12-03 18:45:22 +0000 | [diff] [blame] | 41 | |
| 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 | |
| 46 | struct compat_arch_vcpu_info { |
| 47 | unsigned int cr2; |
| 48 | unsigned int pad[5]; |
| 49 | }; |
| 50 | |
| 51 | struct compat_vcpu_info { |
Sean Christopherson | 7137b7a | 2021-02-10 10:26:09 -0800 | [diff] [blame^] | 52 | 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 Woodhouse | 1ea9f2e | 2020-12-03 18:45:22 +0000 | [diff] [blame] | 58 | }; /* 64 bytes (x86) */ |
| 59 | |
| 60 | struct 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 | |
| 70 | struct 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 Martins | 23200b7 | 2018-06-13 09:55:44 -0400 | [diff] [blame] | 78 | #endif /* __ARCH_X86_KVM_XEN_H__ */ |