public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] SVM: handle MCEs properly
@ 2008-04-09 12:15 Joerg Roedel
  2008-04-09 12:15 ` [PATCH 1/3] SVM: indent svm_set_cr4 with tabs instead of spaces Joerg Roedel
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Joerg Roedel @ 2008-04-09 12:15 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel

This patchset implements proper MCE handling for SVM in the KVM hypervisor.
Currently KVM does not set CR4.MCE when it runs the guest. When a MCE condition
occurs while the guest is running the exception gets lost. This may result in
data corruption or other undefined behaviour. This patchset sets CR4.MCE to the
value in the host and adds the intercept for machine check exceptions to the
SVM implementation. When this intercept occurs, it calls the host MCE exception
handler manually.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>




-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] SVM: indent svm_set_cr4 with tabs instead of spaces
  2008-04-09 12:15 [PATCH 0/3] SVM: handle MCEs properly Joerg Roedel
@ 2008-04-09 12:15 ` Joerg Roedel
  2008-04-09 12:15 ` [PATCH 2/3] SVM: align shadow CR4.MCE with host Joerg Roedel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2008-04-09 12:15 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel

The smv_set_cr4 function is indented with spaces. This patch replaces them with
tabs.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/kvm/svm.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index ad27346..d7439ce 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -878,10 +878,10 @@ set:
 
 static void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 {
-       vcpu->arch.cr4 = cr4;
-       if (!npt_enabled)
-	       cr4 |= X86_CR4_PAE;
-       to_svm(vcpu)->vmcb->save.cr4 = cr4;
+	vcpu->arch.cr4 = cr4;
+	if (!npt_enabled)
+		cr4 |= X86_CR4_PAE;
+	to_svm(vcpu)->vmcb->save.cr4 = cr4;
 }
 
 static void svm_set_segment(struct kvm_vcpu *vcpu,
-- 
1.5.3.7



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] SVM: align shadow CR4.MCE with host
  2008-04-09 12:15 [PATCH 0/3] SVM: handle MCEs properly Joerg Roedel
  2008-04-09 12:15 ` [PATCH 1/3] SVM: indent svm_set_cr4 with tabs instead of spaces Joerg Roedel
@ 2008-04-09 12:15 ` Joerg Roedel
  2008-04-09 12:15 ` [PATCH 3/3] SVM: add intercept for machine check exception Joerg Roedel
  2008-04-10 23:31 ` [PATCH 0/3] SVM: handle MCEs properly Avi Kivity
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2008-04-09 12:15 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel

This patch aligns the host version of the CR4.MCE bit with the CR4 active in
the guest. This is necessary to get MCE exceptions when the guest is running.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/kvm/svm.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index d7439ce..8af463b 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -878,9 +878,12 @@ set:
 
 static void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 {
+	unsigned long host_cr4_mce = read_cr4() & X86_CR4_MCE;
+
 	vcpu->arch.cr4 = cr4;
 	if (!npt_enabled)
 		cr4 |= X86_CR4_PAE;
+	cr4 |= host_cr4_mce;
 	to_svm(vcpu)->vmcb->save.cr4 = cr4;
 }
 
-- 
1.5.3.7



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] SVM: add intercept for machine check exception
  2008-04-09 12:15 [PATCH 0/3] SVM: handle MCEs properly Joerg Roedel
  2008-04-09 12:15 ` [PATCH 1/3] SVM: indent svm_set_cr4 with tabs instead of spaces Joerg Roedel
  2008-04-09 12:15 ` [PATCH 2/3] SVM: align shadow CR4.MCE with host Joerg Roedel
@ 2008-04-09 12:15 ` Joerg Roedel
  2008-04-10 23:31 ` [PATCH 0/3] SVM: handle MCEs properly Avi Kivity
  3 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2008-04-09 12:15 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm-devel, Joerg Roedel

To properly forward a MCE occured while the guest is running to the host, we
have to intercept this exception and call the host handler by hand. This is
implemented by this patch.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/kvm/svm.c         |   17 ++++++++++++++++-
 include/asm-x86/kvm_host.h |    1 +
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 8af463b..da3ddef 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -507,7 +507,8 @@ static void init_vmcb(struct vcpu_svm *svm)
 					INTERCEPT_DR7_MASK;
 
 	control->intercept_exceptions = (1 << PF_VECTOR) |
-					(1 << UD_VECTOR);
+					(1 << UD_VECTOR) |
+					(1 << MC_VECTOR);
 
 
 	control->intercept = 	(1ULL << INTERCEPT_INTR) |
@@ -1044,6 +1045,19 @@ static int nm_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 	return 1;
 }
 
+static int mc_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
+{
+	/*
+	 * On an #MC intercept the MCE handler is not called automatically in
+	 * the host. So do it by hand here.
+	 */
+	asm volatile (
+		"int $0x12\n");
+	/* not sure if we ever come back to this point */
+
+	return 1;
+}
+
 static int shutdown_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
 {
 	/*
@@ -1367,6 +1381,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm,
 	[SVM_EXIT_EXCP_BASE + UD_VECTOR]	= ud_interception,
 	[SVM_EXIT_EXCP_BASE + PF_VECTOR] 	= pf_interception,
 	[SVM_EXIT_EXCP_BASE + NM_VECTOR] 	= nm_interception,
+	[SVM_EXIT_EXCP_BASE + MC_VECTOR] 	= mc_interception,
 	[SVM_EXIT_INTR] 			= nop_on_interception,
 	[SVM_EXIT_NMI]				= nop_on_interception,
 	[SVM_EXIT_SMI]				= nop_on_interception,
diff --git a/include/asm-x86/kvm_host.h b/include/asm-x86/kvm_host.h
index 781fc87..551ff1d 100644
--- a/include/asm-x86/kvm_host.h
+++ b/include/asm-x86/kvm_host.h
@@ -61,6 +61,7 @@
 #define SS_VECTOR 12
 #define GP_VECTOR 13
 #define PF_VECTOR 14
+#define MC_VECTOR 18
 
 #define SELECTOR_TI_MASK (1 << 2)
 #define SELECTOR_RPL_MASK 0x03
-- 
1.5.3.7



-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] SVM: handle MCEs properly
  2008-04-09 12:15 [PATCH 0/3] SVM: handle MCEs properly Joerg Roedel
                   ` (2 preceding siblings ...)
  2008-04-09 12:15 ` [PATCH 3/3] SVM: add intercept for machine check exception Joerg Roedel
@ 2008-04-10 23:31 ` Avi Kivity
  3 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2008-04-10 23:31 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: kvm-devel

Joerg Roedel wrote:
> This patchset implements proper MCE handling for SVM in the KVM hypervisor.
> Currently KVM does not set CR4.MCE when it runs the guest. When a MCE condition
> occurs while the guest is running the exception gets lost. This may result in
> data corruption or other undefined behaviour. This patchset sets CR4.MCE to the
> value in the host and adds the intercept for machine check exceptions to the
> SVM implementation. When this intercept occurs, it calls the host MCE exception
> handler manually.
>
>   

Applied all, thanks.

-- 
Any sufficiently difficult bug is indistinguishable from a feature.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-04-10 23:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-09 12:15 [PATCH 0/3] SVM: handle MCEs properly Joerg Roedel
2008-04-09 12:15 ` [PATCH 1/3] SVM: indent svm_set_cr4 with tabs instead of spaces Joerg Roedel
2008-04-09 12:15 ` [PATCH 2/3] SVM: align shadow CR4.MCE with host Joerg Roedel
2008-04-09 12:15 ` [PATCH 3/3] SVM: add intercept for machine check exception Joerg Roedel
2008-04-10 23:31 ` [PATCH 0/3] SVM: handle MCEs properly Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox