* [PATCH 0/2] AMD Erratum 383 workaround for KVM
@ 2010-05-17 12:43 Joerg Roedel
2010-05-17 12:43 ` [PATCH 1/2] KVM: SVM: Handle MCEs early in the vmexit process Joerg Roedel
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-05-17 12:43 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Elsie Wahlig, Bhavna Sarathy, Boris Ostrovsky
Hi,
these two patches implement the workaround for AMD Erratum 383 into KVM.
This is necessary to prevent the host to crash if a guest triggers the
erratum.
For details on the erratum please see page 96 of
http://support.amd.com/us/Processor_TechDocs/41322.pdf
The workaround implemented in these patches will be documented in the
next update of the revision guide.
Joerg
Diffstat:
arch/x86/include/asm/msr-index.h | 1 +
arch/x86/kvm/svm.c | 98 +++++++++++++++++++++++++++++++++++++-
2 files changed, 98 insertions(+), 1 deletions(-)
Shortlog:
Joerg Roedel (2):
KVM: SVM: Handle MCEs early in the vmexit process
KVM: SVM: Implement workaround for Erratum 383
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] KVM: SVM: Handle MCEs early in the vmexit process
2010-05-17 12:43 [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
@ 2010-05-17 12:43 ` Joerg Roedel
2010-05-17 12:43 ` [PATCH 2/2] KVM: SVM: Implement workaround for Erratum 383 Joerg Roedel
2010-05-19 12:03 ` [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
2 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-05-17 12:43 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Elsie Wahlig, Bhavna Sarathy, Boris Ostrovsky, Joerg Roedel,
stable
This patch moves handling of the MC vmexits to an earlier
point in the vmexit. The handle_exit function is too late
because the vcpu might alreadry have changed its physical
cpu.
Cc: stable@kernel.org
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm.c | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index cea916f..f92d191 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1410,7 +1410,7 @@ static int nm_interception(struct vcpu_svm *svm)
return 1;
}
-static int mc_interception(struct vcpu_svm *svm)
+static void svm_handle_mce(struct vcpu_svm *svm)
{
/*
* On an #MC intercept the MCE handler is not called automatically in
@@ -1420,6 +1420,11 @@ static int mc_interception(struct vcpu_svm *svm)
"int $0x12\n");
/* not sure if we ever come back to this point */
+ return;
+}
+
+static int mc_interception(struct vcpu_svm *svm)
+{
return 1;
}
@@ -3183,6 +3188,14 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
vcpu->arch.regs_avail &= ~(1 << VCPU_EXREG_PDPTR);
vcpu->arch.regs_dirty &= ~(1 << VCPU_EXREG_PDPTR);
}
+
+ /*
+ * We need to handle MC intercepts here before the vcpu has a chance to
+ * change the physical cpu
+ */
+ if (unlikely(svm->vmcb->control.exit_code ==
+ SVM_EXIT_EXCP_BASE + MC_VECTOR))
+ svm_handle_mce(svm);
}
#undef R
--
1.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] KVM: SVM: Implement workaround for Erratum 383
2010-05-17 12:43 [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
2010-05-17 12:43 ` [PATCH 1/2] KVM: SVM: Handle MCEs early in the vmexit process Joerg Roedel
@ 2010-05-17 12:43 ` Joerg Roedel
2010-05-19 12:03 ` [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
2 siblings, 0 replies; 5+ messages in thread
From: Joerg Roedel @ 2010-05-17 12:43 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: kvm, Elsie Wahlig, Bhavna Sarathy, Boris Ostrovsky, Joerg Roedel,
stable
This patch implements a workaround for AMD erratum 383 into
KVM. Without this erratum fix it is possible for a guest to
kill the host machine. This patch implements the suggested
workaround for hypervisors which will be published by the
next revision guide update.
Cc: stable@kernel.org
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/include/asm/msr-index.h | 1 +
arch/x86/kvm/svm.c | 83 ++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 4eb2f72..fdb6af2 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -112,6 +112,7 @@
#define MSR_AMD64_PATCH_LOADER 0xc0010020
#define MSR_AMD64_OSVW_ID_LENGTH 0xc0010140
#define MSR_AMD64_OSVW_STATUS 0xc0010141
+#define MSR_AMD64_DC_CFG 0xc0011022
#define MSR_AMD64_IBSFETCHCTL 0xc0011030
#define MSR_AMD64_IBSFETCHLINAD 0xc0011031
#define MSR_AMD64_IBSFETCHPHYSAD 0xc0011032
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index f92d191..8a42a0d 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -28,6 +28,7 @@
#include <linux/ftrace_event.h>
#include <linux/slab.h>
+#include <asm/tlbflush.h>
#include <asm/desc.h>
#include <asm/virtext.h>
@@ -56,6 +57,8 @@ MODULE_LICENSE("GPL");
#define DEBUGCTL_RESERVED_BITS (~(0x3fULL))
+static bool erratum_383_found __read_mostly;
+
static const u32 host_save_user_msrs[] = {
#ifdef CONFIG_X86_64
MSR_STAR, MSR_LSTAR, MSR_CSTAR, MSR_SYSCALL_MASK, MSR_KERNEL_GS_BASE,
@@ -374,6 +377,31 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
svm->vmcb->control.event_inj_err = error_code;
}
+static void svm_init_erratum_383(void)
+{
+ u32 low, high;
+ int err;
+ u64 val;
+
+ /* Only Fam10h is affected */
+ if (boot_cpu_data.x86 != 0x10)
+ return;
+
+ /* Use _safe variants to not break nested virtualization */
+ val = native_read_msr_safe(MSR_AMD64_DC_CFG, &err);
+ if (err)
+ return;
+
+ val |= (1ULL << 47);
+
+ low = lower_32_bits(val);
+ high = upper_32_bits(val);
+
+ native_write_msr_safe(MSR_AMD64_DC_CFG, low, high);
+
+ erratum_383_found = true;
+}
+
static int has_svm(void)
{
const char *msg;
@@ -429,6 +457,8 @@ static int svm_hardware_enable(void *garbage)
wrmsrl(MSR_VM_HSAVE_PA, page_to_pfn(sd->save_area) << PAGE_SHIFT);
+ svm_init_erratum_383();
+
return 0;
}
@@ -1410,8 +1440,61 @@ static int nm_interception(struct vcpu_svm *svm)
return 1;
}
+static bool is_erratum_383(void)
+{
+ int err, i;
+ u64 value;
+
+ if (!erratum_383_found)
+ return false;
+
+ value = native_read_msr_safe(MSR_IA32_MC0_STATUS, &err);
+ if (err)
+ return false;
+
+ /* Bit 62 may or may not be set for this mce */
+ value &= ~(1ULL << 62);
+
+ if (value != 0xb600000000010015)
+ return false;
+
+ /* Clear MCi_STATUS registers */
+ for (i = 0; i < 6; ++i)
+ native_write_msr_safe(MSR_IA32_MCx_STATUS(i), 0, 0);
+
+ value = native_read_msr_safe(MSR_IA32_MCG_STATUS, &err);
+ if (!err) {
+ u32 low, high;
+
+ value &= ~(1ULL << 2);
+ low = lower_32_bits(value);
+ high = upper_32_bits(value);
+
+ native_write_msr_safe(MSR_IA32_MCG_STATUS, low, high);
+ }
+
+ /* Flush tlb to evict multi-match entries */
+ __flush_tlb_all();
+
+ return true;
+}
+
static void svm_handle_mce(struct vcpu_svm *svm)
{
+ if (is_erratum_383()) {
+ /*
+ * Erratum 383 triggered. Guest state is corrupt so kill the
+ * guest.
+ */
+ struct kvm_run *kvm_run = svm->vcpu.run;
+
+ pr_err("KVM: Guest triggered AMD Erratum 383\n");
+
+ set_bit(KVM_REQ_TRIPLE_FAULT, &svm->vcpu.requests);
+
+ return;
+ }
+
/*
* On an #MC intercept the MCE handler is not called automatically in
* the host. So do it by hand here.
--
1.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] AMD Erratum 383 workaround for KVM
2010-05-17 12:43 [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
2010-05-17 12:43 ` [PATCH 1/2] KVM: SVM: Handle MCEs early in the vmexit process Joerg Roedel
2010-05-17 12:43 ` [PATCH 2/2] KVM: SVM: Implement workaround for Erratum 383 Joerg Roedel
@ 2010-05-19 12:03 ` Joerg Roedel
2010-05-19 16:13 ` Avi Kivity
2 siblings, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2010-05-19 12:03 UTC (permalink / raw)
To: Avi Kivity, Marcelo Tosatti
Cc: Ostrovsky, Boris, Wahlig, Elsie, kvm@vger.kernel.org,
Sarathy, Bhavna
On Mon, May 17, 2010 at 08:43:33AM -0400, Joerg Roedel wrote:
> these two patches implement the workaround for AMD Erratum 383 into KVM.
> This is necessary to prevent the host to crash if a guest triggers the
> erratum.
> For details on the erratum please see page 96 of
>
> http://support.amd.com/us/Processor_TechDocs/41322.pdf
>
> The workaround implemented in these patches will be documented in the
> next update of the revision guide.
Hey Marcelo, Avi,
have you had a chance to look at this? Any opinions?
Thanks,
Joerg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] AMD Erratum 383 workaround for KVM
2010-05-19 12:03 ` [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
@ 2010-05-19 16:13 ` Avi Kivity
0 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2010-05-19 16:13 UTC (permalink / raw)
To: Joerg Roedel
Cc: Marcelo Tosatti, Ostrovsky, Boris, Wahlig, Elsie,
kvm@vger.kernel.org, Sarathy, Bhavna
On 05/19/2010 03:03 PM, Joerg Roedel wrote:
> On Mon, May 17, 2010 at 08:43:33AM -0400, Joerg Roedel wrote:
>
>> these two patches implement the workaround for AMD Erratum 383 into KVM.
>> This is necessary to prevent the host to crash if a guest triggers the
>> erratum.
>> For details on the erratum please see page 96 of
>>
>> http://support.amd.com/us/Processor_TechDocs/41322.pdf
>>
>> The workaround implemented in these patches will be documented in the
>> next update of the revision guide.
>>
> Hey Marcelo, Avi,
>
> have you had a chance to look at this? Any opinions?
>
>
Sorry, holiday here. Patches applied, thanks.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-05-19 16:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-17 12:43 [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
2010-05-17 12:43 ` [PATCH 1/2] KVM: SVM: Handle MCEs early in the vmexit process Joerg Roedel
2010-05-17 12:43 ` [PATCH 2/2] KVM: SVM: Implement workaround for Erratum 383 Joerg Roedel
2010-05-19 12:03 ` [PATCH 0/2] AMD Erratum 383 workaround for KVM Joerg Roedel
2010-05-19 16:13 ` Avi Kivity
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).