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

KVM: VMX: Use the kernel's version of VMXOFF

Drop kvm_cpu_vmxoff() in favor of the kernel's cpu_vmxoff(). Modify the
latter to return -EIO on fault so that KVM can invoke
kvm_spurious_fault() when appropriate. In addition to the obvious code
reuse, dropping kvm_cpu_vmxoff() also eliminates VMX's last usage of the
__ex()/__kvm_handle_fault_on_reboot() macros, thus helping pave the way
toward dropping them entirely.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20201231002702.2223707-7-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Sean Christopherson and committed by
Paolo Bonzini
6a289139 5ef940bd

+9 -13
+6 -1
arch/x86/include/asm/virtext.h
··· 41 41 * faults are guaranteed to be due to the !post-VMXON check unless the CPU is 42 42 * magically in RM, VM86, compat mode, or at CPL>0. 43 43 */ 44 - static inline void cpu_vmxoff(void) 44 + static inline int cpu_vmxoff(void) 45 45 { 46 46 asm_volatile_goto("1: vmxoff\n\t" 47 47 _ASM_EXTABLE(1b, %l[fault]) 48 48 ::: "cc", "memory" : fault); 49 + 50 + cr4_clear_bits(X86_CR4_VMXE); 51 + return 0; 52 + 49 53 fault: 50 54 cr4_clear_bits(X86_CR4_VMXE); 55 + return -EIO; 51 56 } 52 57 53 58 static inline int cpu_vmx_enabled(void)
+3 -12
arch/x86/kvm/vmx/vmx.c
··· 2369 2369 __loaded_vmcs_clear(v); 2370 2370 } 2371 2371 2372 - 2373 - /* Just like cpu_vmxoff(), but with the __kvm_handle_fault_on_reboot() 2374 - * tricks. 2375 - */ 2376 - static void kvm_cpu_vmxoff(void) 2377 - { 2378 - asm volatile (__ex("vmxoff")); 2379 - 2380 - cr4_clear_bits(X86_CR4_VMXE); 2381 - } 2382 - 2383 2372 static void hardware_disable(void) 2384 2373 { 2385 2374 vmclear_local_loaded_vmcss(); 2386 - kvm_cpu_vmxoff(); 2375 + 2376 + if (cpu_vmxoff()) 2377 + kvm_spurious_fault(); 2387 2378 2388 2379 intel_pt_handle_vmx(0); 2389 2380 }