#ifndef __SVM_SVM_H
#define __SVM_SVM_H
#include <linux/kvm_types.h>
#include <linux/kvm_host.h>
#include <linux/bits.h>
#include <asm/svm.h>
#include <asm/sev-common.h>
#include "cpuid.h"
#include "kvm_cache_regs.h"
#define __sme_page_pa(x) …
#define IOPM_SIZE …
#define MSRPM_SIZE …
#define MAX_DIRECT_ACCESS_MSRS …
#define MSRPM_OFFSETS …
extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
extern bool npt_enabled;
extern int nrips;
extern int vgif;
extern bool intercept_smi;
extern bool x2avic_enabled;
extern bool vnmi;
extern int lbrv;
enum { … };
#define VMCB_ALL_CLEAN_MASK …
#define VMCB_ALWAYS_DIRTY_MASK …
struct kvm_sev_info { … };
struct kvm_svm { … };
struct kvm_vcpu;
struct kvm_vmcb_info { … };
struct vmcb_save_area_cached { … };
struct vmcb_ctrl_area_cached { … };
struct svm_nested_state { … };
struct vcpu_sev_es_state { … };
struct vcpu_svm { … };
struct svm_cpu_data { … };
DECLARE_PER_CPU(struct svm_cpu_data, svm_data);
void recalc_intercepts(struct vcpu_svm *svm);
static __always_inline struct kvm_svm *to_kvm_svm(struct kvm *kvm)
{ … }
static __always_inline struct kvm_sev_info *to_kvm_sev_info(struct kvm *kvm)
{ … }
static __always_inline bool sev_guest(struct kvm *kvm)
{ … }
static __always_inline bool sev_es_guest(struct kvm *kvm)
{ … }
static __always_inline bool sev_snp_guest(struct kvm *kvm)
{ … }
static inline bool ghcb_gpa_is_registered(struct vcpu_svm *svm, u64 val)
{ … }
static inline void vmcb_mark_all_dirty(struct vmcb *vmcb)
{ … }
static inline void vmcb_mark_all_clean(struct vmcb *vmcb)
{ … }
static inline void vmcb_mark_dirty(struct vmcb *vmcb, int bit)
{ … }
static inline bool vmcb_is_dirty(struct vmcb *vmcb, int bit)
{ … }
static __always_inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
{ … }
#define SVM_REGS_LAZY_LOAD_SET …
static inline void vmcb_set_intercept(struct vmcb_control_area *control, u32 bit)
{ … }
static inline void vmcb_clr_intercept(struct vmcb_control_area *control, u32 bit)
{ … }
static inline bool vmcb_is_intercept(struct vmcb_control_area *control, u32 bit)
{ … }
static inline bool vmcb12_is_intercept(struct vmcb_ctrl_area_cached *control, u32 bit)
{ … }
static inline void set_exception_intercept(struct vcpu_svm *svm, u32 bit)
{ … }
static inline void clr_exception_intercept(struct vcpu_svm *svm, u32 bit)
{ … }
static inline void svm_set_intercept(struct vcpu_svm *svm, int bit)
{ … }
static inline void svm_clr_intercept(struct vcpu_svm *svm, int bit)
{ … }
static inline bool svm_is_intercept(struct vcpu_svm *svm, int bit)
{ … }
static inline bool nested_vgif_enabled(struct vcpu_svm *svm)
{ … }
static inline struct vmcb *get_vgif_vmcb(struct vcpu_svm *svm)
{ … }
static inline void enable_gif(struct vcpu_svm *svm)
{ … }
static inline void disable_gif(struct vcpu_svm *svm)
{ … }
static inline bool gif_set(struct vcpu_svm *svm)
{ … }
static inline bool nested_npt_enabled(struct vcpu_svm *svm)
{ … }
static inline bool nested_vnmi_enabled(struct vcpu_svm *svm)
{ … }
static inline bool is_x2apic_msrpm_offset(u32 offset)
{ … }
static inline struct vmcb *get_vnmi_vmcb_l1(struct vcpu_svm *svm)
{ … }
static inline bool is_vnmi_enabled(struct vcpu_svm *svm)
{ … }
#define MSR_INVALID …
#define DEBUGCTL_RESERVED_BITS …
extern bool dump_invalid_vmcb;
u32 svm_msrpm_offset(u32 msr);
u32 *svm_vcpu_alloc_msrpm(void);
void svm_vcpu_init_msrpm(struct kvm_vcpu *vcpu, u32 *msrpm);
void svm_vcpu_free_msrpm(u32 *msrpm);
void svm_copy_lbrs(struct vmcb *to_vmcb, struct vmcb *from_vmcb);
void svm_enable_lbrv(struct kvm_vcpu *vcpu);
void svm_update_lbrv(struct kvm_vcpu *vcpu);
int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer);
void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
void disable_nmi_singlestep(struct vcpu_svm *svm);
bool svm_smi_blocked(struct kvm_vcpu *vcpu);
bool svm_nmi_blocked(struct kvm_vcpu *vcpu);
bool svm_interrupt_blocked(struct kvm_vcpu *vcpu);
void svm_set_gif(struct vcpu_svm *svm, bool value);
int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 exit_code);
void set_msr_interception(struct kvm_vcpu *vcpu, u32 *msrpm, u32 msr,
int read, int write);
void svm_set_x2apic_msr_interception(struct vcpu_svm *svm, bool disable);
void svm_complete_interrupt_delivery(struct kvm_vcpu *vcpu, int delivery_mode,
int trig_mode, int vec);
#define NESTED_EXIT_HOST …
#define NESTED_EXIT_DONE …
#define NESTED_EXIT_CONTINUE …
static inline bool nested_svm_virtualize_tpr(struct kvm_vcpu *vcpu)
{ … }
static inline bool nested_exit_on_smi(struct vcpu_svm *svm)
{ … }
static inline bool nested_exit_on_intr(struct vcpu_svm *svm)
{ … }
static inline bool nested_exit_on_nmi(struct vcpu_svm *svm)
{ … }
int enter_svm_guest_mode(struct kvm_vcpu *vcpu,
u64 vmcb_gpa, struct vmcb *vmcb12, bool from_vmrun);
void svm_leave_nested(struct kvm_vcpu *vcpu);
void svm_free_nested(struct vcpu_svm *svm);
int svm_allocate_nested(struct vcpu_svm *svm);
int nested_svm_vmrun(struct kvm_vcpu *vcpu);
void svm_copy_vmrun_state(struct vmcb_save_area *to_save,
struct vmcb_save_area *from_save);
void svm_copy_vmloadsave_state(struct vmcb *to_vmcb, struct vmcb *from_vmcb);
int nested_svm_vmexit(struct vcpu_svm *svm);
static inline int nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit_code)
{ … }
int nested_svm_exit_handled(struct vcpu_svm *svm);
int nested_svm_check_permissions(struct kvm_vcpu *vcpu);
int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
bool has_error_code, u32 error_code);
int nested_svm_exit_special(struct vcpu_svm *svm);
void nested_svm_update_tsc_ratio_msr(struct kvm_vcpu *vcpu);
void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu);
void nested_copy_vmcb_control_to_cache(struct vcpu_svm *svm,
struct vmcb_control_area *control);
void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm,
struct vmcb_save_area *save);
void nested_sync_control_from_vmcb02(struct vcpu_svm *svm);
void nested_vmcb02_compute_g_pat(struct vcpu_svm *svm);
void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb);
extern struct kvm_x86_nested_ops svm_nested_ops;
#define AVIC_REQUIRED_APICV_INHIBITS …
bool avic_hardware_setup(void);
int avic_ga_log_notifier(u32 ga_tag);
void avic_vm_destroy(struct kvm *kvm);
int avic_vm_init(struct kvm *kvm);
void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb);
int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu);
int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu);
int avic_init_vcpu(struct vcpu_svm *svm);
void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
void avic_vcpu_put(struct kvm_vcpu *vcpu);
void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu);
void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu);
int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
uint32_t guest_irq, bool set);
void avic_vcpu_blocking(struct kvm_vcpu *vcpu);
void avic_vcpu_unblocking(struct kvm_vcpu *vcpu);
void avic_ring_doorbell(struct kvm_vcpu *vcpu);
unsigned long avic_vcpu_get_apicv_inhibit_reasons(struct kvm_vcpu *vcpu);
void avic_refresh_virtual_apic_mode(struct kvm_vcpu *vcpu);
void pre_sev_run(struct vcpu_svm *svm, int cpu);
void sev_init_vmcb(struct vcpu_svm *svm);
void sev_vcpu_after_set_cpuid(struct vcpu_svm *svm);
int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in);
void sev_es_vcpu_reset(struct vcpu_svm *svm);
void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector);
void sev_es_prepare_switch_to_guest(struct vcpu_svm *svm, struct sev_es_save_area *hostsa);
void sev_es_unmap_ghcb(struct vcpu_svm *svm);
#ifdef CONFIG_KVM_AMD_SEV
int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp);
int sev_mem_enc_register_region(struct kvm *kvm,
struct kvm_enc_region *range);
int sev_mem_enc_unregister_region(struct kvm *kvm,
struct kvm_enc_region *range);
int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd);
int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd);
void sev_guest_memory_reclaimed(struct kvm *kvm);
int sev_handle_vmgexit(struct kvm_vcpu *vcpu);
struct page *snp_safe_alloc_page_node(int node, gfp_t gfp);
static inline struct page *snp_safe_alloc_page(void)
{ … }
void sev_free_vcpu(struct kvm_vcpu *vcpu);
void sev_vm_destroy(struct kvm *kvm);
void __init sev_set_cpu_caps(void);
void __init sev_hardware_setup(void);
void sev_hardware_unsetup(void);
int sev_cpu_init(struct svm_cpu_data *sd);
int sev_dev_get_attr(u32 group, u64 attr, u64 *val);
extern unsigned int max_sev_asid;
void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code);
void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu);
int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order);
void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end);
int sev_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn);
#else
static inline struct page *snp_safe_alloc_page_node(int node, gfp_t gfp)
{
return alloc_pages_node(node, gfp | __GFP_ZERO, 0);
}
static inline struct page *snp_safe_alloc_page(void)
{
return snp_safe_alloc_page_node(numa_node_id(), GFP_KERNEL_ACCOUNT);
}
static inline void sev_free_vcpu(struct kvm_vcpu *vcpu) {}
static inline void sev_vm_destroy(struct kvm *kvm) {}
static inline void __init sev_set_cpu_caps(void) {}
static inline void __init sev_hardware_setup(void) {}
static inline void sev_hardware_unsetup(void) {}
static inline int sev_cpu_init(struct svm_cpu_data *sd) { return 0; }
static inline int sev_dev_get_attr(u32 group, u64 attr, u64 *val) { return -ENXIO; }
#define max_sev_asid …
static inline void sev_handle_rmp_fault(struct kvm_vcpu *vcpu, gpa_t gpa, u64 error_code) {}
static inline void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu) {}
static inline int sev_gmem_prepare(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order)
{
return 0;
}
static inline void sev_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end) {}
static inline int sev_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn)
{
return 0;
}
#endif
void __svm_sev_es_vcpu_run(struct vcpu_svm *svm, bool spec_ctrl_intercepted,
struct sev_es_save_area *hostsa);
void __svm_vcpu_run(struct vcpu_svm *svm, bool spec_ctrl_intercepted);
#define DEFINE_KVM_GHCB_ACCESSORS(field) … \
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
DEFINE_KVM_GHCB_ACCESSORS(…) …
#endif