Skip to contentSkip to conversation

kvm/svm: fix DR interception handling on upcoming AMD CPUs

PATCH In review Andre Przywara 3 participants 5 messages Feb 9, 2011

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

PATCH 1/1 kvm/svm: fix DR interception handling on upcoming AMD CPUs

Somehow the code line advancing the RIP and checking for exceptions got dropped between the post on the ML and the commit. Add it again to let guests boot on upcoming AMD CPUs again.

---
 arch/x86/kvm/svm.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +1 -0
index 25bd1bc..be06e58 100644
@@ -2776,6 +2776,7 @@ static int dr_interception(struct vcpu_svm *svm)
 		if (!err)
 			kvm_register_write(&svm->vcpu, reg, val);
 	}
+	kvm_complete_insn_gp(&svm->vcpu, err);
 
 	return 1;
 }
Signature · 1 line
1.6.4
#1 lore raw
Quoted 15 lines · Andre Przywara

Somehow the code line advancing the RIP and checking for exceptions got dropped between the post on the ML and the commit. Add it again to let guests boot on upcoming AMD CPUs again.

---
 arch/x86/kvm/svm.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +0 -0
index 25bd1bc..be06e58 100644

arch/x86/kvm/svm.c static int dr_interception(struct vcpu_svm *svm) · line 2779

Quoted 4 lines
arch/x86/kvm/svm.c +1 -0
@@ -2776,6 +2776,7 @@ static int dr_interception(struct vcpu_svm *svm)
 		if (!err)
 			kvm_register_write(&svm->vcpu, reg, val);
 	}
+	kvm_complete_insn_gp(&svm->vcpu, err);

Any exception check takes presedence over the intercept. So a call to skip_emulated_instruction should be sufficient here.

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
#2 lore raw
Quoted 11 lines · Joerg
Quoted 10 lines · Andre Przywara

Somehow the code line advancing the RIP and checking for exceptions got dropped between the post on the ML and the commit. Add it again to let guests boot on upcoming AMD CPUs again.

---
 arch/x86/kvm/svm.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 12 lines

arch/x86/kvm/svm.c static int dr_interception(struct vcpu_svm *svm) · line 2779

Quoted 9 lines
arch/x86/kvm/svm.c +1 -0
index 25bd1bc..be06e58 100644
@@ -2776,6 +2776,7 @@ static int dr_interception(struct vcpu_svm *svm)
 		if (!err)
 			kvm_register_write(&svm->vcpu, reg, val);
 	}
+	kvm_complete_insn_gp(&svm->vcpu, err);

Any exception check takes presedence over the intercept. So a call to skip_emulated_instruction should be sufficient here.

You are right, but I think this way the implementation is cleaner and more generic. If there is no exception condition detected (err==0), then the call will just do skip_emulated_instruction anyway. But as I write this, I see that err is not initialized, so I'd propose this corrected version of the patch instead.

Regards,
Andre.

--

From 8c1dced7b4f80e4968b03656aee2452535b2ef2f Mon Sep 17 00:00:00 2001
From: Andre Przywara <[email protected]>
Date: Wed, 9 Feb 2011 01:10:45 +0100
Subject: [PATCH] kvm/svm: fix DR interception handling on upcoming AMD CPUs

Somehow the code line advancing the RIP and checking for exceptions got dropped between the mail on the ML and the commit.
Add it again to let guests boot on upcoming AMD CPUs again. While at it, properly initialize the err variable to fix the write DR case.

---
 arch/x86/kvm/svm.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
arch/x86/kvm/svm.c +2 -1
index 25bd1bc..d558121 100644
@@ -2760,7 +2760,7 @@ static int dr_interception(struct vcpu_svm *svm)
 {
 	int reg, dr;
 	unsigned long val;
-	int err;
+	int err = 0;
 
 	if (!boot_cpu_has(X86_FEATURE_DECODEASSISTS))
 		return emulate_on_interception(svm);
@@ -2776,6 +2776,7 @@ static int dr_interception(struct vcpu_svm *svm)
 		if (!err)
 			kvm_register_write(&svm->vcpu, reg, val);
 	}
+	kvm_complete_insn_gp(&svm->vcpu, err);
 
 	return 1;
 }
Signature · 1 line
1.6.4
#3 lore raw
Quoted 25 lines · Andre Przywara
Quoted 11 lines · Joerg
Quoted 10 lines · Andre Przywara

Somehow the code line advancing the RIP and checking for exceptions got dropped between the post on the ML and the commit. Add it again to let guests boot on upcoming AMD CPUs again.

---
 arch/x86/kvm/svm.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Quoted 12 lines

arch/x86/kvm/svm.c static int dr_interception(struct vcpu_svm *svm) · line 2779

Quoted 9 lines
arch/x86/kvm/svm.c +1 -0
index 25bd1bc..be06e58 100644
@@ -2776,6 +2776,7 @@ static int dr_interception(struct vcpu_svm *svm)
 		if (!err)
 			kvm_register_write(&svm->vcpu, reg, val);
 	}
+	kvm_complete_insn_gp(&svm->vcpu, err);

Any exception check takes presedence over the intercept. So a call to skip_emulated_instruction should be sufficient here.

Quoted 5 lines

You are right, but I think this way the implementation is cleaner and more generic. If there is no exception condition detected (err==0), then the call will just do skip_emulated_instruction anyway.
But as I write this, I see that err is not initialized, so I'd propose this corrected version of the patch instead.

One function call is not less clean than another and this function call has more overhead.
Beside that, looking at kvm_set_dr this function only returns 1 if one tries to set dr4 or dr5 while CR4.DE is not set. In this case the function you call here would inject a #GP but architecturally a #UD is required.
This problem doesn't matter too much because the exceptions take precedence over the intercept anyway so it is sufficient to call skip_emulated_instruction here.

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
#4 lore raw
Quoted 32 lines · Joerg
Quoted 22 lines · Andre Przywara
Quoted 21 lines · Joerg
Quoted 19 lines · Andre Przywara

Somehow the code line advancing the RIP and checking for exceptions got dropped between the post on the ML and the commit. Add it again to let guests boot on upcoming AMD CPUs again.

---

  arch/x86/kvm/svm.c |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 25bd1bc..be06e58 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2776,6 +2776,7 @@ static int dr_interception(struct vcpu_svm *svm)
if (!err)
kvm_register_write(&svm->vcpu, reg, val);
}
+ kvm_complete_insn_gp(&svm->vcpu, err);

Quoted 8 lines
Quoted 2 lines

Any exception check takes presedence over the intercept. So a call to skip_emulated_instruction should be sufficient here.

You are right, but I think this way the implementation is cleaner and more generic. If there is no exception condition detected (err==0), then the call will just do skip_emulated_instruction anyway.
But as I write this, I see that err is not initialized, so I'd propose this corrected version of the patch instead.

Quoted 9 lines

One function call is not less clean than another and this function call has more overhead.
Beside that, looking at kvm_set_dr this function only returns 1 if one tries to set dr4 or dr5 while CR4.DE is not set. In this case the function you call here would inject a #GP but architecturally a #UD is required.
This problem doesn't matter too much because the exceptions take precedence over the intercept anyway so it is sufficient to call skip_emulated_instruction here.

Given that the exception is incorrect I agree skip_emulated_instruction() is a better choice here.

Signature · 1 line
error compiling committee.c: too many arguments to function