From: Ashok Raj <ashok.raj@intel.com>
To: kvm@vger.kernel.org
Cc: Tony Luck <tony.luck@intel.com>, Ashok Raj <ashok.raj@intel.com>,
Gleb Natapov <gleb@kernel.org>,
linux-kernel@vger.kernel.org, qemu-devel@nongnu.org,
Andi Kleen <andi.kleen@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>, Boris Petkov <bp@suse.de>
Subject: [Qemu-devel] [Patch V0] This patch adds some support required for KVM in order to support LMCE.
Date: Wed, 9 Dec 2015 14:57:08 -0500 [thread overview]
Message-ID: <1449691029-15525-1-git-send-email-ashok.raj@intel.com> (raw)
- Add support for MSR_IA32_MCG_EXT_CTL
- Add MCG_LMCE_P to KVM_MCE_CAP_SUPPORTED
- Changes to IA32_FEATURE_CONTROL, allow this MSR to be defined just not for
nested VMM, but now its required for Local MCE.
Reviewed-by: Andi Kleen <andi.kleen@intel.com>
Reviewed-by: Tony Luck <tony.luck@intel.com>
Tested-by: Gong Chen <gong.chen@intel.com>
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/vmx.c | 26 +++++++++++++++++++++-----
arch/x86/kvm/x86.c | 17 ++++++++++++++++-
3 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 30cfd64..6940141 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -525,6 +525,7 @@ struct kvm_vcpu_arch {
u64 mcg_cap;
u64 mcg_status;
u64 mcg_ctl;
+ u64 mcg_ext_ctl;
u64 *mce_banks;
/* Cache MMIO info */
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 87acc52..c2ce9f4 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2747,6 +2747,20 @@ static int vmx_get_vmx_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
return 0;
}
+bool can_feature_control_exist(struct kvm_vcpu *vcpu)
+{
+ /*
+ * There are some features that require BIOS enabling.
+ * In such cases BIOS is supposed to set this bit and indicate
+ * the feature is enabled and available to the OS.
+ * Local Machine Check Exception (LMCE) is one such feature.
+ */
+ if (vcpu->arch.mcg_cap & MCG_LMCE_P)
+ return true;
+
+ return (nested_vmx_allowed(vcpu));
+}
+
/*
* Reads an msr value (of 'msr_index') into 'pdata'.
* Returns 0 on success, non-0 otherwise.
@@ -2789,9 +2803,11 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
msr_info->data = vmcs_read64(GUEST_BNDCFGS);
break;
case MSR_IA32_FEATURE_CONTROL:
- if (!nested_vmx_allowed(vcpu))
+ if (can_feature_control_exist(vcpu))
+ msr_info->data =
+ to_vmx(vcpu)->nested.msr_ia32_feature_control;
+ else
return 1;
- msr_info->data = to_vmx(vcpu)->nested.msr_ia32_feature_control;
break;
case MSR_IA32_VMX_BASIC ... MSR_IA32_VMX_VMFUNC:
if (!nested_vmx_allowed(vcpu))
@@ -2882,9 +2898,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
ret = kvm_set_msr_common(vcpu, msr_info);
break;
case MSR_IA32_FEATURE_CONTROL:
- if (!nested_vmx_allowed(vcpu) ||
- (to_vmx(vcpu)->nested.msr_ia32_feature_control &
- FEATURE_CONTROL_LOCKED && !msr_info->host_initiated))
+ if ((can_feature_control_exist(vcpu) == false) ||
+ ((to_vmx(vcpu)->nested.msr_ia32_feature_control &
+ FEATURE_CONTROL_LOCKED) && !msr_info->host_initiated))
return 1;
vmx->nested.msr_ia32_feature_control = data;
if (msr_info->host_initiated && data == 0)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 00462bd..0da3871 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -70,7 +70,7 @@
#define MAX_IO_MSRS 256
#define KVM_MAX_MCE_BANKS 32
-#define KVM_MCE_CAP_SUPPORTED (MCG_CTL_P | MCG_SER_P)
+#define KVM_MCE_CAP_SUPPORTED (MCG_CTL_P | MCG_SER_P | MCG_LMCE_P)
#define emul_to_vcpu(ctxt) \
container_of(ctxt, struct kvm_vcpu, arch.emulate_ctxt)
@@ -974,6 +974,7 @@ static u32 emulated_msrs[] = {
MSR_IA32_MISC_ENABLE,
MSR_IA32_MCG_STATUS,
MSR_IA32_MCG_CTL,
+ MSR_IA32_MCG_EXT_CTL,
MSR_IA32_SMBASE,
};
@@ -1913,6 +1914,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 data)
return -1;
vcpu->arch.mcg_ctl = data;
break;
+ case MSR_IA32_MCG_EXT_CTL:
+ if (!(mcg_cap & MCG_LMCE_P))
+ return 1;
+ if (data != 0 && data != 0x1)
+ return -1;
+ vcpu->arch.mcg_ext_ctl = data;
+ break;
default:
if (msr >= MSR_IA32_MC0_CTL &&
msr < MSR_IA32_MCx_CTL(bank_num)) {
@@ -2170,6 +2178,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
case MSR_IA32_MCG_CTL:
case MSR_IA32_MCG_STATUS:
+ case MSR_IA32_MCG_EXT_CTL:
case MSR_IA32_MC0_CTL ... MSR_IA32_MCx_CTL(KVM_MAX_MCE_BANKS) - 1:
return set_msr_mce(vcpu, msr, data);
@@ -2266,6 +2275,11 @@ static int get_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
return 1;
data = vcpu->arch.mcg_ctl;
break;
+ case MSR_IA32_MCG_EXT_CTL:
+ if (!(mcg_cap & MCG_LMCE_P))
+ return 1;
+ data = vcpu->arch.mcg_ext_ctl;
+ break;
case MSR_IA32_MCG_STATUS:
data = vcpu->arch.mcg_status;
break;
@@ -2384,6 +2398,7 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
case MSR_IA32_P5_MC_TYPE:
case MSR_IA32_MCG_CAP:
case MSR_IA32_MCG_CTL:
+ case MSR_IA32_MCG_EXT_CTL:
case MSR_IA32_MCG_STATUS:
case MSR_IA32_MC0_CTL ... MSR_IA32_MCx_CTL(KVM_MAX_MCE_BANKS) - 1:
return get_msr_mce(vcpu, msr_info->index, &msr_info->data);
--
2.4.3
next reply other threads:[~2015-12-09 18:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-09 19:57 Ashok Raj [this message]
2015-12-09 19:57 ` [Qemu-devel] [Patch V0] x86, mce: Basic support to add LMCE support to QEMU Ashok Raj
2015-12-09 21:07 ` Paolo Bonzini
2015-12-09 23:05 ` Raj, Ashok
2015-12-09 22:23 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1449691029-15525-1-git-send-email-ashok.raj@intel.com \
--to=ashok.raj@intel.com \
--cc=andi.kleen@intel.com \
--cc=bp@suse.de \
--cc=gleb@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).