Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4984797yba; Mon, 13 May 2019 03:23:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPuNozZQUiRvoQ7neLe1R9KFZWCTUqy7jpjRFhjv60TK+xt1YdOaWA+JXp2W6fD52u91AU X-Received: by 2002:a63:6a41:: with SMTP id f62mr29850155pgc.392.1557743015862; Mon, 13 May 2019 03:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557743015; cv=none; d=google.com; s=arc-20160816; b=I2+OeJZejrZBMm32oJr1i66WAU7oYHll4sMWZxkSQWguFtcnCUD80Va8DY3ReFss+p j2sP9MATUcPg244TZQd1pjLU9ZIblXQIWOf2f2puDDfixIs7ImleD7KmHjwEsk7dsfC1 STQr/zruVXdip8fpGF/xqOHzY33ElnOppt4kFIONh/KlypXVtCF1DTPQxhluEFESTqS8 Q3E4BSl6eR/Lnz7HTDJsNV4rvHSmlbv0fp35NSSw7iB8Y2GgA5Isx/tOSzvOj1Qr8XqO EUyg11R4qBDK7UTGbyzpWM/9e1BgodGMf/lTwALxszyAYZ1BXMyFO2WHVYFk2qvhXvD/ k+xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=vsdiDk6Zs+VFH2JCv9rnfu5G+QrChkqRIl4npyicJBc=; b=fum2UhqTSukawgScOmQL/X4kFMvdTf8xXMtijQPn9wZMGcfbk/V7NV9cfnbF+eNuKa 5G5wAtLRFStRy+Dbn2LgbNyEIHcJMNF2jfD8pz4CV2PbD14IZpqEWNX9HZHaGsQNto/7 SG1fRMTR3PcsH+yV2epl8waAeecyhGSSR0UtEBhLq6g0j+h1YD/kfe68Pb8AUejZis7f XmaNVAIxMhQ1IgFwTk1m83IESvS7AayKztnndhjaVas6qNpkmVcvVlT3B66wCSO1Nps0 BfnULR20hgyyeB7oUQICN9eVZBJNa44lcRgs2aeL0lLNDz0G2yHl/De18NOg8qOicw1/ eu9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sJoehUkf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si13701551plz.359.2019.05.13.03.23.20; Mon, 13 May 2019 03:23:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sJoehUkf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728598AbfEMJqp (ORCPT + 99 others); Mon, 13 May 2019 05:46:45 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37618 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727848AbfEMJqp (ORCPT ); Mon, 13 May 2019 05:46:45 -0400 Received: by mail-pl1-f196.google.com with SMTP id p15so6203927pll.4; Mon, 13 May 2019 02:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vsdiDk6Zs+VFH2JCv9rnfu5G+QrChkqRIl4npyicJBc=; b=sJoehUkfTIPBjdwCA842y47ItVU7i0/ozJqcI7HD7rahSFSwiOjxdqnTRMDQd1uexP za3Eg0f9RS6Kzy5IiE2/Nkm1DorV2mAJ8ViCldtmBh7rBAcSnVECvo89Hctg3MLkE0YK eKiayAvWMeIdj8VBlREE32aOwQJ1n87rjCWKH+RT8vLP37vPDoIf7NPl4CYCtHHp94Zc 6L1u26+hHZDbmC/iqjqXTOvQXjL9GbHtHw5KOPNYs4Bz+X3SShCdO/3rWE+WayNACl5o N2x3LRMNlb0/R9jmXBGXUVpFBc26kjYzK8JPXOl6YKcStk5I4KegNc9VstS5vPltVn7v dB/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vsdiDk6Zs+VFH2JCv9rnfu5G+QrChkqRIl4npyicJBc=; b=l7AHoQ2fnTakytdumQI6jTj/yAiu9xj8lUciTAcl5WiMOQHTpt9jsKvB3zhVPaeM91 /t46Hkt8lGX2XllLPXBmClnjFinui6FsfUpg0y4uVXgRKnM1tkRI+dezPjgk87s9jRdN FfTkI67kqfkni6lhc/tUvlxQtvFKsO3dmu5DDNJwNvkW+9BAuY+Eg4BMbVuG4Rs6olbK AW9uPkzSw3zL4Uh3zwzydAfySHz14lRZGGrwdRSnpQzV/YaHMGOqL9yuIQGYVT6KP+Sj SC3/xiGSEDRHpfiZxIdQIYIYqZKWvRug0ulFrXj4KQIYjLn++9d8taFWi8cPXQT3KBvm 463Q== X-Gm-Message-State: APjAAAUq3+BP6aChx+ewkvOLe1RCOFrIu5+jJJVg9fnrDIqE8pH9YZOa FkY416m3yVeEeEKV5ERn99CadRMx X-Received: by 2002:a17:902:f215:: with SMTP id gn21mr29293861plb.194.1557740804275; Mon, 13 May 2019 02:46:44 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id r64sm44584748pfa.25.2019.05.13.02.46.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 May 2019 02:46:43 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Sean Christopherson , Liran Alon Subject: [PATCH] KVM: X86: Enable IA32_MSIC_ENABLE MONITOR bit when exposing mwait/monitor Date: Mon, 13 May 2019 17:46:39 +0800 Message-Id: <1557740799-5792-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li MSR IA32_MSIC_ENABLE bit 18, according to SDM: | When this bit is set to 0, the MONITOR feature flag is not set (CPUID.01H:ECX[bit 3] = 0). | This indicates that MONITOR/MWAIT are not supported. | | Software attempts to execute MONITOR/MWAIT will cause #UD when this bit is 0. | | When this bit is set to 1 (default), MONITOR/MWAIT are supported (CPUID.01H:ECX[bit 3] = 1). This bit should be set to 1, if BIOS enables MONITOR/MWAIT support on host and we intend to expose mwait/monitor to the guest. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Sean Christopherson Cc: Liran Alon Signed-off-by: Wanpeng Li --- arch/x86/kvm/x86.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 1d89cb9..664449e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2723,6 +2723,13 @@ static int get_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host) return 0; } +static inline bool kvm_can_mwait_in_guest(void) +{ + return boot_cpu_has(X86_FEATURE_MWAIT) && + !boot_cpu_has_bug(X86_BUG_MONITOR) && + boot_cpu_has(X86_FEATURE_ARAT); +} + int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) { switch (msr_info->index) { @@ -2801,6 +2808,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) msr_info->data = (u64)vcpu->arch.ia32_tsc_adjust_msr; break; case MSR_IA32_MISC_ENABLE: + if (kvm_can_mwait_in_guest() && kvm_mwait_in_guest(vcpu->kvm)) + vcpu->arch.ia32_misc_enable_msr |= MSR_IA32_MISC_ENABLE_MWAIT; msr_info->data = vcpu->arch.ia32_misc_enable_msr; break; case MSR_IA32_SMBASE: @@ -2984,13 +2993,6 @@ static int msr_io(struct kvm_vcpu *vcpu, struct kvm_msrs __user *user_msrs, return r; } -static inline bool kvm_can_mwait_in_guest(void) -{ - return boot_cpu_has(X86_FEATURE_MWAIT) && - !boot_cpu_has_bug(X86_BUG_MONITOR) && - boot_cpu_has(X86_FEATURE_ARAT); -} - int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) { int r = 0; -- 2.7.4