Skip to contentSkip to conversation

perf-kvm support for SVM

PATCH Applied Joerg Roedel 3 participants 7 messages Jan 14, 2011 – Jan 17, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover perf-kvm support for SVM

Hi,

here is the reworked version of the patch-set. Only patch 1/2 has changed and now contains the real fix for the crashes that were seen and has an updated log message.

Regards,

Joerg

#1 lore raw

PATCH v2 1/2 KVM: SVM: Make sure KERNEL_GS_BASE is valid when loading gs_index

The gs_index loading code uses the swapgs instruction to switch to the user gs_base temporarily. This is unsave in an lightweight exit-path in KVM on AMD because the KERNEL_GS_BASE MSR is switches lazily. An NMI happening in the critical path of load_gs_index may use the wrong GS_BASE value then leading to unpredictable behavior, e.g. a triple-fault.
This patch fixes the issue by making sure that load_gs_index is called only with a valid KERNEL_GS_BASE value loaded in KVM.

---
 arch/x86/kvm/svm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/svm.c +1 -1
index 25bd1bc..54ce246 100644
@@ -1150,8 +1150,8 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
 	kvm_load_ldt(svm->host.ldt);
 #ifdef CONFIG_X86_64
 	loadsegment(fs, svm->host.fs);
-	load_gs_index(svm->host.gs);
 	wrmsrl(MSR_KERNEL_GS_BASE, current->thread.gs);
+	load_gs_index(svm->host.gs);
 #else
 	loadsegment(gs, svm->host.gs);
 #endif
Signature · 1 line
1.7.1
#2 lore raw

PATCH v2 2/2 KVM: SVM: Add support for perf-kvm

In reply to Joerg Roedel

This patch adds the necessary code to run perf-kvm on AMD machines.

---
 arch/x86/kvm/svm.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +10 -2
index 54ce246..73a8f1d 100644
@@ -3645,13 +3645,21 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
 
 	local_irq_disable();
 
-	stgi();
-
 	vcpu->arch.cr2 = svm->vmcb->save.cr2;
 	vcpu->arch.regs[VCPU_REGS_RAX] = svm->vmcb->save.rax;
 	vcpu->arch.regs[VCPU_REGS_RSP] = svm->vmcb->save.rsp;
 	vcpu->arch.regs[VCPU_REGS_RIP] = svm->vmcb->save.rip;
 
+	if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI))
+		kvm_before_handle_nmi(&svm->vcpu);
+
+	stgi();
+
+	/* Any pending NMI will happen here */
+
+	if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI))
+		kvm_after_handle_nmi(&svm->vcpu);
+
 	sync_cr8_to_lapic(vcpu);
 
 	svm->next_rip = 0;
Signature · 1 line
1.7.1
Applied
#3 lore raw
In reply to Joerg Roedel
Quoted 6 lines · Joerg Roedel

Hi,

here is the reworked version of the patch-set. Only patch 1/2 has changed and now contains the real fix for the crashes that were seen and has an updated log message.

Thanks, applied. 2.6.37 and earlier aren't affected, yes? So I'm queuing it for 2.6.38 only.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 9 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel

here is the reworked version of the patch-set. Only patch 1/2 has changed and now contains the real fix for the crashes that were seen and has an updated log message.

Thanks, applied. 2.6.37 and earlier aren't affected, yes? So I'm queuing it for 2.6.38 only.

I think the problem is there since KVM has lazy state switching. So the fix in patch 1 should make it in all currently maintained stable-trees.

Joerg

#5 lore raw
Quoted 8 lines · Joerg Roedel
Quoted 7 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel

here is the reworked version of the patch-set. Only patch 1/2 has changed and now contains the real fix for the crashes that were seen and has an updated log message.

Quoted 6 lines
Quoted 2 lines

Thanks, applied. 2.6.37 and earlier aren't affected, yes? So I'm queuing it for 2.6.38 only.

I think the problem is there since KVM has lazy state switching. So the fix in patch 1 should make it in all currently maintained stable-trees.

The problem is with load_gs_index(), yes? In 2.6.37 this is called before stgi(), so it's protected from nmi.

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw
Quoted 12 lines · Avi Kivity
Quoted 11 lines · Joerg Roedel
Quoted 9 lines · Avi Kivity
Quoted 4 lines · Joerg Roedel

here is the reworked version of the patch-set. Only patch 1/2 has changed and now contains the real fix for the crashes that were seen and has an updated log message.

Thanks, applied. 2.6.37 and earlier aren't affected, yes? So I'm queuing it for 2.6.38 only.

Quoted 6 lines
Quoted 3 lines

I think the problem is there since KVM has lazy state switching. So the fix in patch 1 should make it in all currently maintained stable-trees.

The problem is with load_gs_index(), yes? In 2.6.37 this is called before stgi(), so it's protected from nmi.

Ok, you are right :) So the fix is only necessary for 2.6.38.

Joerg

Signature · 5 lines
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632