1 // SPDX-License-Identifier: GPL-2.0 2 #include <linux/moduleparam.h> 3 4 #include "x86_ops.h" 5 #include "vmx.h" 6 #include "nested.h" 7 #include "pmu.h" 8 #include "posted_intr.h" 9 10 #define VMX_REQUIRED_APICV_INHIBITS \ 11 (BIT(APICV_INHIBIT_REASON_DISABLED) | \ 12 BIT(APICV_INHIBIT_REASON_ABSENT) | \ 13 BIT(APICV_INHIBIT_REASON_HYPERV) | \ 14 BIT(APICV_INHIBIT_REASON_BLOCKIRQ) | \ 15 BIT(APICV_INHIBIT_REASON_PHYSICAL_ID_ALIASED) | \ 16 BIT(APICV_INHIBIT_REASON_APIC_ID_MODIFIED) | \ 17 BIT(APICV_INHIBIT_REASON_APIC_BASE_MODIFIED)) 18 19 struct kvm_x86_ops vt_x86_ops __initdata = { 20 .name = KBUILD_MODNAME, 21 22 .check_processor_compatibility = vmx_check_processor_compat, 23 24 .hardware_unsetup = vmx_hardware_unsetup, 25 26 .hardware_enable = vmx_hardware_enable, 27 .hardware_disable = vmx_hardware_disable, 28 .has_emulated_msr = vmx_has_emulated_msr, 29 30 .vm_size = sizeof(struct kvm_vmx), 31 .vm_init = vmx_vm_init, 32 .vm_destroy = vmx_vm_destroy, 33 34 .vcpu_precreate = vmx_vcpu_precreate, 35 .vcpu_create = vmx_vcpu_create, 36 .vcpu_free = vmx_vcpu_free, 37 .vcpu_reset = vmx_vcpu_reset, 38 39 .prepare_switch_to_guest = vmx_prepare_switch_to_guest, 40 .vcpu_load = vmx_vcpu_load, 41 .vcpu_put = vmx_vcpu_put, 42 43 .update_exception_bitmap = vmx_update_exception_bitmap, 44 .get_msr_feature = vmx_get_msr_feature, 45 .get_msr = vmx_get_msr, 46 .set_msr = vmx_set_msr, 47 .get_segment_base = vmx_get_segment_base, 48 .get_segment = vmx_get_segment, 49 .set_segment = vmx_set_segment, 50 .get_cpl = vmx_get_cpl, 51 .get_cs_db_l_bits = vmx_get_cs_db_l_bits, 52 .is_valid_cr0 = vmx_is_valid_cr0, 53 .set_cr0 = vmx_set_cr0, 54 .is_valid_cr4 = vmx_is_valid_cr4, 55 .set_cr4 = vmx_set_cr4, 56 .set_efer = vmx_set_efer, 57 .get_idt = vmx_get_idt, 58 .set_idt = vmx_set_idt, 59 .get_gdt = vmx_get_gdt, 60 .set_gdt = vmx_set_gdt, 61 .set_dr7 = vmx_set_dr7, 62 .sync_dirty_debug_regs = vmx_sync_dirty_debug_regs, 63 .cache_reg = vmx_cache_reg, 64 .get_rflags = vmx_get_rflags, 65 .set_rflags = vmx_set_rflags, 66 .get_if_flag = vmx_get_if_flag, 67 68 .flush_tlb_all = vmx_flush_tlb_all, 69 .flush_tlb_current = vmx_flush_tlb_current, 70 .flush_tlb_gva = vmx_flush_tlb_gva, 71 .flush_tlb_guest = vmx_flush_tlb_guest, 72 73 .vcpu_pre_run = vmx_vcpu_pre_run, 74 .vcpu_run = vmx_vcpu_run, 75 .handle_exit = vmx_handle_exit, 76 .skip_emulated_instruction = vmx_skip_emulated_instruction, 77 .update_emulated_instruction = vmx_update_emulated_instruction, 78 .set_interrupt_shadow = vmx_set_interrupt_shadow, 79 .get_interrupt_shadow = vmx_get_interrupt_shadow, 80 .patch_hypercall = vmx_patch_hypercall, 81 .inject_irq = vmx_inject_irq, 82 .inject_nmi = vmx_inject_nmi, 83 .inject_exception = vmx_inject_exception, 84 .cancel_injection = vmx_cancel_injection, 85 .interrupt_allowed = vmx_interrupt_allowed, 86 .nmi_allowed = vmx_nmi_allowed, 87 .get_nmi_mask = vmx_get_nmi_mask, 88 .set_nmi_mask = vmx_set_nmi_mask, 89 .enable_nmi_window = vmx_enable_nmi_window, 90 .enable_irq_window = vmx_enable_irq_window, 91 .update_cr8_intercept = vmx_update_cr8_intercept, 92 .set_virtual_apic_mode = vmx_set_virtual_apic_mode, 93 .set_apic_access_page_addr = vmx_set_apic_access_page_addr, 94 .refresh_apicv_exec_ctrl = vmx_refresh_apicv_exec_ctrl, 95 .load_eoi_exitmap = vmx_load_eoi_exitmap, 96 .apicv_pre_state_restore = vmx_apicv_pre_state_restore, 97 .required_apicv_inhibits = VMX_REQUIRED_APICV_INHIBITS, 98 .hwapic_irr_update = vmx_hwapic_irr_update, 99 .hwapic_isr_update = vmx_hwapic_isr_update, 100 .sync_pir_to_irr = vmx_sync_pir_to_irr, 101 .deliver_interrupt = vmx_deliver_interrupt, 102 .dy_apicv_has_pending_interrupt = pi_has_pending_interrupt, 103 104 .set_tss_addr = vmx_set_tss_addr, 105 .set_identity_map_addr = vmx_set_identity_map_addr, 106 .get_mt_mask = vmx_get_mt_mask, 107 108 .get_exit_info = vmx_get_exit_info, 109 110 .vcpu_after_set_cpuid = vmx_vcpu_after_set_cpuid, 111 112 .has_wbinvd_exit = cpu_has_vmx_wbinvd_exit, 113 114 .get_l2_tsc_offset = vmx_get_l2_tsc_offset, 115 .get_l2_tsc_multiplier = vmx_get_l2_tsc_multiplier, 116 .write_tsc_offset = vmx_write_tsc_offset, 117 .write_tsc_multiplier = vmx_write_tsc_multiplier, 118 119 .load_mmu_pgd = vmx_load_mmu_pgd, 120 121 .check_intercept = vmx_check_intercept, 122 .handle_exit_irqoff = vmx_handle_exit_irqoff, 123 124 .cpu_dirty_log_size = PML_ENTITY_NUM, 125 .update_cpu_dirty_logging = vmx_update_cpu_dirty_logging, 126 127 .nested_ops = &vmx_nested_ops, 128 129 .pi_update_irte = vmx_pi_update_irte, 130 .pi_start_assignment = vmx_pi_start_assignment, 131 132 #ifdef CONFIG_X86_64 133 .set_hv_timer = vmx_set_hv_timer, 134 .cancel_hv_timer = vmx_cancel_hv_timer, 135 #endif 136 137 .setup_mce = vmx_setup_mce, 138 139 #ifdef CONFIG_KVM_SMM 140 .smi_allowed = vmx_smi_allowed, 141 .enter_smm = vmx_enter_smm, 142 .leave_smm = vmx_leave_smm, 143 .enable_smi_window = vmx_enable_smi_window, 144 #endif 145 146 .check_emulate_instruction = vmx_check_emulate_instruction, 147 .apic_init_signal_blocked = vmx_apic_init_signal_blocked, 148 .migrate_timers = vmx_migrate_timers, 149 150 .msr_filter_changed = vmx_msr_filter_changed, 151 .complete_emulated_msr = kvm_complete_insn_gp, 152 153 .vcpu_deliver_sipi_vector = kvm_vcpu_deliver_sipi_vector, 154 155 .get_untagged_addr = vmx_get_untagged_addr, 156 }; 157 158 struct kvm_x86_init_ops vt_init_ops __initdata = { 159 .hardware_setup = vmx_hardware_setup, 160 .handle_intel_pt_intr = NULL, 161 162 .runtime_ops = &vt_x86_ops, 163 .pmu_ops = &intel_pmu_ops, 164 }; 165