Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'kvm-x86-vmx-6.16' of https://github.com/kvm-x86/linux into HEAD

KVM VMX changes for 6.16:

- Explicitly check MSR load/store list counts to fix a potential overflow on
32-bit kernels.

- Flush shadow VMCSes on emergency reboot.

- Revert mem_enc_ioctl() back to an optional hook, as it's nullified when
SEV or TDX is disabled via Kconfig.

- Macrofy the handling of vt_x86_ops to eliminate a pile of boilerplate code
needed for TDX, and to optimize CONFIG_KVM_INTEL_TDX=n builds.

+142 -187
+1 -1
arch/x86/include/asm/kvm-x86-ops.h
··· 127 127 KVM_X86_OP(enable_smi_window) 128 128 #endif 129 129 KVM_X86_OP_OPTIONAL(dev_get_attr) 130 - KVM_X86_OP(mem_enc_ioctl) 130 + KVM_X86_OP_OPTIONAL(mem_enc_ioctl) 131 131 KVM_X86_OP_OPTIONAL(vcpu_mem_enc_ioctl) 132 132 KVM_X86_OP_OPTIONAL(mem_enc_register_region) 133 133 KVM_X86_OP_OPTIONAL(mem_enc_unregister_region)
+100 -102
arch/x86/kvm/vmx/main.c
··· 12 12 13 13 #ifdef CONFIG_KVM_INTEL_TDX 14 14 static_assert(offsetof(struct vcpu_vmx, vt) == offsetof(struct vcpu_tdx, vt)); 15 - #endif 16 15 17 16 static void vt_disable_virtualization_cpu(void) 18 17 { ··· 239 240 if (is_td_vcpu(vcpu)) 240 241 return tdx_complete_emulated_msr(vcpu, err); 241 242 242 - return kvm_complete_insn_gp(vcpu, err); 243 + return vmx_complete_emulated_msr(vcpu, err); 243 244 } 244 245 245 246 #ifdef CONFIG_KVM_SMM ··· 312 313 return; 313 314 314 315 return vmx_set_virtual_apic_mode(vcpu); 315 - } 316 - 317 - static void vt_apicv_pre_state_restore(struct kvm_vcpu *vcpu) 318 - { 319 - struct pi_desc *pi = vcpu_to_pi_desc(vcpu); 320 - 321 - pi_clear_on(pi); 322 - memset(pi->pir, 0, sizeof(pi->pir)); 323 316 } 324 317 325 318 static void vt_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr) ··· 879 888 return 0; 880 889 } 881 890 891 + #define vt_op(name) vt_##name 892 + #define vt_op_tdx_only(name) vt_##name 893 + #else /* CONFIG_KVM_INTEL_TDX */ 894 + #define vt_op(name) vmx_##name 895 + #define vt_op_tdx_only(name) NULL 896 + #endif /* CONFIG_KVM_INTEL_TDX */ 897 + 882 898 #define VMX_REQUIRED_APICV_INHIBITS \ 883 899 (BIT(APICV_INHIBIT_REASON_DISABLED) | \ 884 900 BIT(APICV_INHIBIT_REASON_ABSENT) | \ ··· 903 905 .hardware_unsetup = vmx_hardware_unsetup, 904 906 905 907 .enable_virtualization_cpu = vmx_enable_virtualization_cpu, 906 - .disable_virtualization_cpu = vt_disable_virtualization_cpu, 908 + .disable_virtualization_cpu = vt_op(disable_virtualization_cpu), 907 909 .emergency_disable_virtualization_cpu = vmx_emergency_disable_virtualization_cpu, 908 910 909 - .has_emulated_msr = vt_has_emulated_msr, 911 + .has_emulated_msr = vt_op(has_emulated_msr), 910 912 911 913 .vm_size = sizeof(struct kvm_vmx), 912 914 913 - .vm_init = vt_vm_init, 914 - .vm_pre_destroy = vt_vm_pre_destroy, 915 - .vm_destroy = vt_vm_destroy, 915 + .vm_init = vt_op(vm_init), 916 + .vm_destroy = vt_op(vm_destroy), 917 + .vm_pre_destroy = vt_op_tdx_only(vm_pre_destroy), 916 918 917 - .vcpu_precreate = vt_vcpu_precreate, 918 - .vcpu_create = vt_vcpu_create, 919 - .vcpu_free = vt_vcpu_free, 920 - .vcpu_reset = vt_vcpu_reset, 919 + .vcpu_precreate = vt_op(vcpu_precreate), 920 + .vcpu_create = vt_op(vcpu_create), 921 + .vcpu_free = vt_op(vcpu_free), 922 + .vcpu_reset = vt_op(vcpu_reset), 921 923 922 - .prepare_switch_to_guest = vt_prepare_switch_to_guest, 923 - .vcpu_load = vt_vcpu_load, 924 - .vcpu_put = vt_vcpu_put, 924 + .prepare_switch_to_guest = vt_op(prepare_switch_to_guest), 925 + .vcpu_load = vt_op(vcpu_load), 926 + .vcpu_put = vt_op(vcpu_put), 925 927 926 - .update_exception_bitmap = vt_update_exception_bitmap, 928 + .update_exception_bitmap = vt_op(update_exception_bitmap), 927 929 .get_feature_msr = vmx_get_feature_msr, 928 - .get_msr = vt_get_msr, 929 - .set_msr = vt_set_msr, 930 + .get_msr = vt_op(get_msr), 931 + .set_msr = vt_op(set_msr), 930 932 931 - .get_segment_base = vt_get_segment_base, 932 - .get_segment = vt_get_segment, 933 - .set_segment = vt_set_segment, 934 - .get_cpl = vt_get_cpl, 935 - .get_cpl_no_cache = vt_get_cpl_no_cache, 936 - .get_cs_db_l_bits = vt_get_cs_db_l_bits, 937 - .is_valid_cr0 = vt_is_valid_cr0, 938 - .set_cr0 = vt_set_cr0, 939 - .is_valid_cr4 = vt_is_valid_cr4, 940 - .set_cr4 = vt_set_cr4, 941 - .set_efer = vt_set_efer, 942 - .get_idt = vt_get_idt, 943 - .set_idt = vt_set_idt, 944 - .get_gdt = vt_get_gdt, 945 - .set_gdt = vt_set_gdt, 946 - .set_dr6 = vt_set_dr6, 947 - .set_dr7 = vt_set_dr7, 948 - .sync_dirty_debug_regs = vt_sync_dirty_debug_regs, 949 - .cache_reg = vt_cache_reg, 950 - .get_rflags = vt_get_rflags, 951 - .set_rflags = vt_set_rflags, 952 - .get_if_flag = vt_get_if_flag, 933 + .get_segment_base = vt_op(get_segment_base), 934 + .get_segment = vt_op(get_segment), 935 + .set_segment = vt_op(set_segment), 936 + .get_cpl = vt_op(get_cpl), 937 + .get_cpl_no_cache = vt_op(get_cpl_no_cache), 938 + .get_cs_db_l_bits = vt_op(get_cs_db_l_bits), 939 + .is_valid_cr0 = vt_op(is_valid_cr0), 940 + .set_cr0 = vt_op(set_cr0), 941 + .is_valid_cr4 = vt_op(is_valid_cr4), 942 + .set_cr4 = vt_op(set_cr4), 943 + .set_efer = vt_op(set_efer), 944 + .get_idt = vt_op(get_idt), 945 + .set_idt = vt_op(set_idt), 946 + .get_gdt = vt_op(get_gdt), 947 + .set_gdt = vt_op(set_gdt), 948 + .set_dr6 = vt_op(set_dr6), 949 + .set_dr7 = vt_op(set_dr7), 950 + .sync_dirty_debug_regs = vt_op(sync_dirty_debug_regs), 951 + .cache_reg = vt_op(cache_reg), 952 + .get_rflags = vt_op(get_rflags), 953 + .set_rflags = vt_op(set_rflags), 954 + .get_if_flag = vt_op(get_if_flag), 953 955 954 - .flush_tlb_all = vt_flush_tlb_all, 955 - .flush_tlb_current = vt_flush_tlb_current, 956 - .flush_tlb_gva = vt_flush_tlb_gva, 957 - .flush_tlb_guest = vt_flush_tlb_guest, 956 + .flush_tlb_all = vt_op(flush_tlb_all), 957 + .flush_tlb_current = vt_op(flush_tlb_current), 958 + .flush_tlb_gva = vt_op(flush_tlb_gva), 959 + .flush_tlb_guest = vt_op(flush_tlb_guest), 958 960 959 - .vcpu_pre_run = vt_vcpu_pre_run, 960 - .vcpu_run = vt_vcpu_run, 961 - .handle_exit = vt_handle_exit, 961 + .vcpu_pre_run = vt_op(vcpu_pre_run), 962 + .vcpu_run = vt_op(vcpu_run), 963 + .handle_exit = vt_op(handle_exit), 962 964 .skip_emulated_instruction = vmx_skip_emulated_instruction, 963 965 .update_emulated_instruction = vmx_update_emulated_instruction, 964 - .set_interrupt_shadow = vt_set_interrupt_shadow, 965 - .get_interrupt_shadow = vt_get_interrupt_shadow, 966 - .patch_hypercall = vt_patch_hypercall, 967 - .inject_irq = vt_inject_irq, 968 - .inject_nmi = vt_inject_nmi, 969 - .inject_exception = vt_inject_exception, 970 - .cancel_injection = vt_cancel_injection, 971 - .interrupt_allowed = vt_interrupt_allowed, 972 - .nmi_allowed = vt_nmi_allowed, 973 - .get_nmi_mask = vt_get_nmi_mask, 974 - .set_nmi_mask = vt_set_nmi_mask, 975 - .enable_nmi_window = vt_enable_nmi_window, 976 - .enable_irq_window = vt_enable_irq_window, 977 - .update_cr8_intercept = vt_update_cr8_intercept, 966 + .set_interrupt_shadow = vt_op(set_interrupt_shadow), 967 + .get_interrupt_shadow = vt_op(get_interrupt_shadow), 968 + .patch_hypercall = vt_op(patch_hypercall), 969 + .inject_irq = vt_op(inject_irq), 970 + .inject_nmi = vt_op(inject_nmi), 971 + .inject_exception = vt_op(inject_exception), 972 + .cancel_injection = vt_op(cancel_injection), 973 + .interrupt_allowed = vt_op(interrupt_allowed), 974 + .nmi_allowed = vt_op(nmi_allowed), 975 + .get_nmi_mask = vt_op(get_nmi_mask), 976 + .set_nmi_mask = vt_op(set_nmi_mask), 977 + .enable_nmi_window = vt_op(enable_nmi_window), 978 + .enable_irq_window = vt_op(enable_irq_window), 979 + .update_cr8_intercept = vt_op(update_cr8_intercept), 978 980 979 981 .x2apic_icr_is_split = false, 980 - .set_virtual_apic_mode = vt_set_virtual_apic_mode, 981 - .set_apic_access_page_addr = vt_set_apic_access_page_addr, 982 - .refresh_apicv_exec_ctrl = vt_refresh_apicv_exec_ctrl, 983 - .load_eoi_exitmap = vt_load_eoi_exitmap, 984 - .apicv_pre_state_restore = vt_apicv_pre_state_restore, 982 + .set_virtual_apic_mode = vt_op(set_virtual_apic_mode), 983 + .set_apic_access_page_addr = vt_op(set_apic_access_page_addr), 984 + .refresh_apicv_exec_ctrl = vt_op(refresh_apicv_exec_ctrl), 985 + .load_eoi_exitmap = vt_op(load_eoi_exitmap), 986 + .apicv_pre_state_restore = pi_apicv_pre_state_restore, 985 987 .required_apicv_inhibits = VMX_REQUIRED_APICV_INHIBITS, 986 - .hwapic_isr_update = vt_hwapic_isr_update, 987 - .sync_pir_to_irr = vt_sync_pir_to_irr, 988 - .deliver_interrupt = vt_deliver_interrupt, 988 + .hwapic_isr_update = vt_op(hwapic_isr_update), 989 + .sync_pir_to_irr = vt_op(sync_pir_to_irr), 990 + .deliver_interrupt = vt_op(deliver_interrupt), 989 991 .dy_apicv_has_pending_interrupt = pi_has_pending_interrupt, 990 992 991 - .set_tss_addr = vt_set_tss_addr, 992 - .set_identity_map_addr = vt_set_identity_map_addr, 993 + .set_tss_addr = vt_op(set_tss_addr), 994 + .set_identity_map_addr = vt_op(set_identity_map_addr), 993 995 .get_mt_mask = vmx_get_mt_mask, 994 996 995 - .get_exit_info = vt_get_exit_info, 996 - .get_entry_info = vt_get_entry_info, 997 + .get_exit_info = vt_op(get_exit_info), 998 + .get_entry_info = vt_op(get_entry_info), 997 999 998 - .vcpu_after_set_cpuid = vt_vcpu_after_set_cpuid, 1000 + .vcpu_after_set_cpuid = vt_op(vcpu_after_set_cpuid), 999 1001 1000 1002 .has_wbinvd_exit = cpu_has_vmx_wbinvd_exit, 1001 1003 1002 - .get_l2_tsc_offset = vt_get_l2_tsc_offset, 1003 - .get_l2_tsc_multiplier = vt_get_l2_tsc_multiplier, 1004 - .write_tsc_offset = vt_write_tsc_offset, 1005 - .write_tsc_multiplier = vt_write_tsc_multiplier, 1004 + .get_l2_tsc_offset = vt_op(get_l2_tsc_offset), 1005 + .get_l2_tsc_multiplier = vt_op(get_l2_tsc_multiplier), 1006 + .write_tsc_offset = vt_op(write_tsc_offset), 1007 + .write_tsc_multiplier = vt_op(write_tsc_multiplier), 1006 1008 1007 - .load_mmu_pgd = vt_load_mmu_pgd, 1009 + .load_mmu_pgd = vt_op(load_mmu_pgd), 1008 1010 1009 1011 .check_intercept = vmx_check_intercept, 1010 1012 .handle_exit_irqoff = vmx_handle_exit_irqoff, 1011 1013 1012 - .update_cpu_dirty_logging = vt_update_cpu_dirty_logging, 1014 + .update_cpu_dirty_logging = vt_op(update_cpu_dirty_logging), 1013 1015 1014 1016 .nested_ops = &vmx_nested_ops, 1015 1017 ··· 1017 1019 .pi_start_assignment = vmx_pi_start_assignment, 1018 1020 1019 1021 #ifdef CONFIG_X86_64 1020 - .set_hv_timer = vt_set_hv_timer, 1021 - .cancel_hv_timer = vt_cancel_hv_timer, 1022 + .set_hv_timer = vt_op(set_hv_timer), 1023 + .cancel_hv_timer = vt_op(cancel_hv_timer), 1022 1024 #endif 1023 1025 1024 - .setup_mce = vt_setup_mce, 1026 + .setup_mce = vt_op(setup_mce), 1025 1027 1026 1028 #ifdef CONFIG_KVM_SMM 1027 - .smi_allowed = vt_smi_allowed, 1028 - .enter_smm = vt_enter_smm, 1029 - .leave_smm = vt_leave_smm, 1030 - .enable_smi_window = vt_enable_smi_window, 1029 + .smi_allowed = vt_op(smi_allowed), 1030 + .enter_smm = vt_op(enter_smm), 1031 + .leave_smm = vt_op(leave_smm), 1032 + .enable_smi_window = vt_op(enable_smi_window), 1031 1033 #endif 1032 1034 1033 - .check_emulate_instruction = vt_check_emulate_instruction, 1034 - .apic_init_signal_blocked = vt_apic_init_signal_blocked, 1035 + .check_emulate_instruction = vt_op(check_emulate_instruction), 1036 + .apic_init_signal_blocked = vt_op(apic_init_signal_blocked), 1035 1037 .migrate_timers = vmx_migrate_timers, 1036 1038 1037 - .msr_filter_changed = vt_msr_filter_changed, 1038 - .complete_emulated_msr = vt_complete_emulated_msr, 1039 + .msr_filter_changed = vt_op(msr_filter_changed), 1040 + .complete_emulated_msr = vt_op(complete_emulated_msr), 1039 1041 1040 1042 .vcpu_deliver_sipi_vector = kvm_vcpu_deliver_sipi_vector, 1041 1043 1042 1044 .get_untagged_addr = vmx_get_untagged_addr, 1043 1045 1044 - .mem_enc_ioctl = vt_mem_enc_ioctl, 1045 - .vcpu_mem_enc_ioctl = vt_vcpu_mem_enc_ioctl, 1046 + .mem_enc_ioctl = vt_op_tdx_only(mem_enc_ioctl), 1047 + .vcpu_mem_enc_ioctl = vt_op_tdx_only(vcpu_mem_enc_ioctl), 1046 1048 1047 - .private_max_mapping_level = vt_gmem_private_max_mapping_level 1049 + .private_max_mapping_level = vt_op_tdx_only(gmem_private_max_mapping_level) 1048 1050 }; 1049 1051 1050 1052 struct kvm_x86_init_ops vt_init_ops __initdata = { 1051 - .hardware_setup = vt_hardware_setup, 1053 + .hardware_setup = vt_op(hardware_setup), 1052 1054 .handle_intel_pt_intr = NULL, 1053 1055 1054 1056 .runtime_ops = &vt_x86_ops,
+20 -11
arch/x86/kvm/vmx/nested.c
··· 824 824 return 0; 825 825 } 826 826 827 + static u32 nested_vmx_max_atomic_switch_msrs(struct kvm_vcpu *vcpu) 828 + { 829 + struct vcpu_vmx *vmx = to_vmx(vcpu); 830 + u64 vmx_misc = vmx_control_msr(vmx->nested.msrs.misc_low, 831 + vmx->nested.msrs.misc_high); 832 + 833 + return (vmx_misc_max_msr(vmx_misc) + 1) * VMX_MISC_MSR_LIST_MULTIPLIER; 834 + } 835 + 827 836 static int nested_vmx_check_msr_switch(struct kvm_vcpu *vcpu, 828 837 u32 count, u64 addr) 829 838 { 830 839 if (count == 0) 831 840 return 0; 841 + 842 + /* 843 + * Exceeding the limit results in architecturally _undefined_ behavior, 844 + * i.e. KVM is allowed to do literally anything in response to a bad 845 + * limit. Immediately generate a consistency check so that code that 846 + * consumes the count doesn't need to worry about extreme edge cases. 847 + */ 848 + if (count > nested_vmx_max_atomic_switch_msrs(vcpu)) 849 + return -EINVAL; 832 850 833 851 if (!kvm_vcpu_is_legal_aligned_gpa(vcpu, addr, 16) || 834 852 !kvm_vcpu_is_legal_gpa(vcpu, (addr + count * sizeof(struct vmx_msr_entry) - 1))) ··· 958 940 return 0; 959 941 } 960 942 961 - static u32 nested_vmx_max_atomic_switch_msrs(struct kvm_vcpu *vcpu) 962 - { 963 - struct vcpu_vmx *vmx = to_vmx(vcpu); 964 - u64 vmx_misc = vmx_control_msr(vmx->nested.msrs.misc_low, 965 - vmx->nested.msrs.misc_high); 966 - 967 - return (vmx_misc_max_msr(vmx_misc) + 1) * VMX_MISC_MSR_LIST_MULTIPLIER; 968 - } 969 - 970 943 /* 971 944 * Load guest's/host's msr at nested entry/exit. 972 945 * return 0 for success, entry index for failure. ··· 974 965 u32 max_msr_list_size = nested_vmx_max_atomic_switch_msrs(vcpu); 975 966 976 967 for (i = 0; i < count; i++) { 977 - if (unlikely(i >= max_msr_list_size)) 968 + if (WARN_ON_ONCE(i >= max_msr_list_size)) 978 969 goto fail; 979 970 980 971 if (kvm_vcpu_read_guest(vcpu, gpa + i * sizeof(e), ··· 1062 1053 u32 max_msr_list_size = nested_vmx_max_atomic_switch_msrs(vcpu); 1063 1054 1064 1055 for (i = 0; i < count; i++) { 1065 - if (unlikely(i >= max_msr_list_size)) 1056 + if (WARN_ON_ONCE(i >= max_msr_list_size)) 1066 1057 return -EINVAL; 1067 1058 1068 1059 if (!read_and_check_msr_entry(vcpu, gpa, i, &e))
+9 -1
arch/x86/kvm/vmx/posted_intr.c
··· 34 34 35 35 #define PI_LOCK_SCHED_OUT SINGLE_DEPTH_NESTING 36 36 37 - struct pi_desc *vcpu_to_pi_desc(struct kvm_vcpu *vcpu) 37 + static struct pi_desc *vcpu_to_pi_desc(struct kvm_vcpu *vcpu) 38 38 { 39 39 return &(to_vt(vcpu)->pi_desc); 40 40 } ··· 261 261 { 262 262 INIT_LIST_HEAD(&per_cpu(wakeup_vcpus_on_cpu, cpu)); 263 263 raw_spin_lock_init(&per_cpu(wakeup_vcpus_on_cpu_lock, cpu)); 264 + } 265 + 266 + void pi_apicv_pre_state_restore(struct kvm_vcpu *vcpu) 267 + { 268 + struct pi_desc *pi = vcpu_to_pi_desc(vcpu); 269 + 270 + pi_clear_on(pi); 271 + memset(pi->pir, 0, sizeof(pi->pir)); 264 272 } 265 273 266 274 bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu)
+1 -2
arch/x86/kvm/vmx/posted_intr.h
··· 5 5 #include <linux/bitmap.h> 6 6 #include <asm/posted_intr.h> 7 7 8 - struct pi_desc *vcpu_to_pi_desc(struct kvm_vcpu *vcpu); 9 - 10 8 void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu); 11 9 void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu); 12 10 void pi_wakeup_handler(void); 13 11 void __init pi_init_cpu(int cpu); 12 + void pi_apicv_pre_state_restore(struct kvm_vcpu *vcpu); 14 13 bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu); 15 14 int vmx_pi_update_irte(struct kvm *kvm, unsigned int host_irq, 16 15 uint32_t guest_irq, bool set);
+1 -2
arch/x86/kvm/vmx/vmenter.S
··· 59 59 * without the explicit restore, thinks the stack is getting walloped. 60 60 * Using an unwind hint is problematic due to x86-64's dynamic alignment. 61 61 */ 62 - mov %_ASM_BP, %_ASM_SP 63 - pop %_ASM_BP 62 + leave 64 63 RET 65 64 .endm 66 65
+4 -1
arch/x86/kvm/vmx/vmx.c
··· 772 772 return; 773 773 774 774 list_for_each_entry(v, &per_cpu(loaded_vmcss_on_cpu, cpu), 775 - loaded_vmcss_on_cpu_link) 775 + loaded_vmcss_on_cpu_link) { 776 776 vmcs_clear(v->vmcs); 777 + if (v->shadow_vmcs) 778 + vmcs_clear(v->shadow_vmcs); 779 + } 777 780 778 781 kvm_cpu_vmxoff(); 779 782 }
+1 -65
arch/x86/kvm/vmx/x86_ops.h
··· 57 57 void vmx_update_exception_bitmap(struct kvm_vcpu *vcpu); 58 58 int vmx_get_feature_msr(u32 msr, u64 *data); 59 59 int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info); 60 + #define vmx_complete_emulated_msr kvm_complete_insn_gp 60 61 u64 vmx_get_segment_base(struct kvm_vcpu *vcpu, int seg); 61 62 void vmx_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg); 62 63 void vmx_set_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg); ··· 164 163 void tdx_flush_tlb_all(struct kvm_vcpu *vcpu); 165 164 void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level); 166 165 int tdx_gmem_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn); 167 - #else 168 - static inline void tdx_disable_virtualization_cpu(void) {} 169 - static inline int tdx_vm_init(struct kvm *kvm) { return -EOPNOTSUPP; } 170 - static inline void tdx_mmu_release_hkid(struct kvm *kvm) {} 171 - static inline void tdx_vm_destroy(struct kvm *kvm) {} 172 - static inline int tdx_vm_ioctl(struct kvm *kvm, void __user *argp) { return -EOPNOTSUPP; } 173 - 174 - static inline int tdx_vcpu_create(struct kvm_vcpu *vcpu) { return -EOPNOTSUPP; } 175 - static inline void tdx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event) {} 176 - static inline void tdx_vcpu_free(struct kvm_vcpu *vcpu) {} 177 - static inline void tdx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) {} 178 - static inline int tdx_vcpu_pre_run(struct kvm_vcpu *vcpu) { return -EOPNOTSUPP; } 179 - static inline fastpath_t tdx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit) 180 - { 181 - return EXIT_FASTPATH_NONE; 182 - } 183 - static inline void tdx_prepare_switch_to_guest(struct kvm_vcpu *vcpu) {} 184 - static inline void tdx_vcpu_put(struct kvm_vcpu *vcpu) {} 185 - static inline bool tdx_protected_apic_has_interrupt(struct kvm_vcpu *vcpu) { return false; } 186 - static inline int tdx_handle_exit(struct kvm_vcpu *vcpu, 187 - enum exit_fastpath_completion fastpath) { return 0; } 188 - 189 - static inline void tdx_deliver_interrupt(struct kvm_lapic *apic, int delivery_mode, 190 - int trig_mode, int vector) {} 191 - static inline void tdx_inject_nmi(struct kvm_vcpu *vcpu) {} 192 - static inline void tdx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason, u64 *info1, 193 - u64 *info2, u32 *intr_info, u32 *error_code) {} 194 - static inline bool tdx_has_emulated_msr(u32 index) { return false; } 195 - static inline int tdx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) { return 1; } 196 - static inline int tdx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) { return 1; } 197 - 198 - static inline int tdx_vcpu_ioctl(struct kvm_vcpu *vcpu, void __user *argp) { return -EOPNOTSUPP; } 199 - 200 - static inline int tdx_sept_link_private_spt(struct kvm *kvm, gfn_t gfn, 201 - enum pg_level level, 202 - void *private_spt) 203 - { 204 - return -EOPNOTSUPP; 205 - } 206 - 207 - static inline int tdx_sept_free_private_spt(struct kvm *kvm, gfn_t gfn, 208 - enum pg_level level, 209 - void *private_spt) 210 - { 211 - return -EOPNOTSUPP; 212 - } 213 - 214 - static inline int tdx_sept_set_private_spte(struct kvm *kvm, gfn_t gfn, 215 - enum pg_level level, 216 - kvm_pfn_t pfn) 217 - { 218 - return -EOPNOTSUPP; 219 - } 220 - 221 - static inline int tdx_sept_remove_private_spte(struct kvm *kvm, gfn_t gfn, 222 - enum pg_level level, 223 - kvm_pfn_t pfn) 224 - { 225 - return -EOPNOTSUPP; 226 - } 227 - 228 - static inline void tdx_flush_tlb_current(struct kvm_vcpu *vcpu) {} 229 - static inline void tdx_flush_tlb_all(struct kvm_vcpu *vcpu) {} 230 - static inline void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level) {} 231 - static inline int tdx_gmem_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn) { return 0; } 232 166 #endif 233 167 234 168 #endif /* __KVM_X86_VMX_X86_OPS_H */
+5 -2
arch/x86/kvm/x86.c
··· 7344 7344 r = READ_ONCE(kvm->arch.default_tsc_khz); 7345 7345 goto out; 7346 7346 } 7347 - case KVM_MEMORY_ENCRYPT_OP: { 7347 + case KVM_MEMORY_ENCRYPT_OP: 7348 + r = -ENOTTY; 7349 + if (!kvm_x86_ops.mem_enc_ioctl) 7350 + goto out; 7351 + 7348 7352 r = kvm_x86_call(mem_enc_ioctl)(kvm, argp); 7349 7353 break; 7350 - } 7351 7354 case KVM_MEMORY_ENCRYPT_REG_REGION: { 7352 7355 struct kvm_enc_region region; 7353 7356