KVM: x86: drop bogus MWAIT check

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/346f48fa311ceee7478b5b810ba050a4a22e0b2e
Commit:     346f48fa311ceee7478b5b810ba050a4a22e0b2e
Parent:     2a140f3b6e23a309453b6f68709a50ece543f0f4
Refname:    refs/heads/master
Author:     Radim Krčmář <[email protected]>
AuthorDate: Wed Nov 29 22:23:42 2017 +0100
Committer:  Paolo Bonzini <[email protected]>
CommitDate: Thu Dec 14 09:26:43 2017 +0100

    KVM: x86: drop bogus MWAIT check
    
    The check was added in some iteration while trying to fix a reported OS
    X on Core 2 bug, but that bug is elsewhere.
    
    The comment is misleading because the guest can call MWAIT with ECX = 0
    even if we enforce CPUID5_ECX_INTERRUPT_BREAK;  the call would have the
    exactly the same effect as if the host didn't have the feature.
    
    A problem is that a QEMU feature exposes CPUID5_ECX_INTERRUPT_BREAK on
    CPUs that do not support it.  Removing the check changes behavior on
    last Pentium 4 lines (Presler, Dempsey, and Tulsa, which had VMX and
    MONITOR while missing INTERRUPT_BREAK) when running a guest OS that uses
    MWAIT without checking for its presence (QEMU doesn't expose MONITOR).
    
    The only known OS that ignores the MONITOR flag is old Mac OS X and we
    allowed it to bug on Core 2 (MWAIT used to throw #UD and only that OS
    noticed), so we can save another 20 lines letting it bug on even older
    CPUs.  Alternatively, we can return MWAIT exiting by default and let
    userspace toggle it.
    
    Reviewed-by: Alexander Graf <[email protected]>
    Acked-by: Borislav Petkov <[email protected]>
    Acked-by: Michael S. Tsirkin <[email protected]>
    Signed-off-by: Radim Krčmář <[email protected]>
    Signed-off-by: Paolo Bonzini <[email protected]>
---
 arch/x86/kvm/x86.h | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)

diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 81f5f50794f6..d15859ec5e92 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -265,8 +265,6 @@ static inline u64 nsec_to_cycles(struct kvm_vcpu *vcpu, u64 nsec)
 
 static inline bool kvm_mwait_in_guest(void)
 {
-	unsigned int eax, ebx, ecx, edx;
-
 	if (!cpu_has(&boot_cpu_data, X86_FEATURE_MWAIT))
 		return false;
 
@@ -275,29 +273,10 @@ static inline bool kvm_mwait_in_guest(void)
 		/* All AMD CPUs have a working MWAIT implementation */
 		return true;
 	case X86_VENDOR_INTEL:
-		/* Handle Intel below */
-		break;
+		return !boot_cpu_has_bug(X86_BUG_MONITOR);
 	default:
 		return false;
 	}
-
-	if (boot_cpu_has_bug(X86_BUG_MONITOR))
-		return false;
-
-	/*
-	 * Intel CPUs without CPUID5_ECX_INTERRUPT_BREAK are problematic as
-	 * they would allow guest to stop the CPU completely by disabling
-	 * interrupts then invoking MWAIT.
-	 */
-	if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
-		return false;
-
-	cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
-
-	if (!(ecx & CPUID5_ECX_INTERRUPT_BREAK))
-		return false;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.