Skip to contentSkip to conversation

x86: svm: use cr_interception for SVM_EXIT_CR0_SEL_WRITE

PATCH Applied Joel Schopp 3 participants 3 messages Mar 6, 2015 – Mar 13, 2015

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

PATCH v2 1/1 x86: svm: use cr_interception for SVM_EXIT_CR0_SEL_WRITE

From: David Kaplan <[email protected]>

Another patch in my war on emulate_on_interception() use as a svm exit handler.

These were pulled out of a larger patch at the suggestion of Radim Krcmar, see
https://lkml.org/lkml/2015/2/25/559

Changes since v1:
* fixed typo introduced after test, retested

[separated out just cr_interception part from larger removal of INTERCEPT_CR0_WRITE, forward ported, tested]

---
 arch/x86/kvm/svm.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +5 -2
index d319e0c..16ad05b 100644
@@ -2940,7 +2940,10 @@ static int cr_interception(struct vcpu_svm *svm)
 		return emulate_on_interception(svm);
 
 	reg = svm->vmcb->control.exit_info_1 & SVM_EXITINFO_REG_MASK;
-	cr = svm->vmcb->control.exit_code - SVM_EXIT_READ_CR0;
+	if (svm->vmcb->control.exit_code == SVM_EXIT_CR0_SEL_WRITE)
+		cr = SVM_EXIT_WRITE_CR0 - SVM_EXIT_READ_CR0;
+	else
+		cr = svm->vmcb->control.exit_code - SVM_EXIT_READ_CR0;
 
 	err = 0;
 	if (cr >= 16) { /* mov to cr */
@@ -3325,7 +3328,7 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = {
 	[SVM_EXIT_READ_CR3]			= cr_interception,
 	[SVM_EXIT_READ_CR4]			= cr_interception,
 	[SVM_EXIT_READ_CR8]			= cr_interception,
-	[SVM_EXIT_CR0_SEL_WRITE]		= emulate_on_interception,
+	[SVM_EXIT_CR0_SEL_WRITE]		= cr_interception,
 	[SVM_EXIT_WRITE_CR0]			= cr_interception,
 	[SVM_EXIT_WRITE_CR3]			= cr_interception,
 	[SVM_EXIT_WRITE_CR4]			= cr_interception,
Reviewed-by on v2 1/1
#1 lore raw

2015-03-06 14:44-0600, Joel Schopp:

Quoted 7 lines

From: David Kaplan <[email protected]>

Another patch in my war on emulate_on_interception() use as a svm exit handler.

These were pulled out of a larger patch at the suggestion of Radim Krcmar, see
https://lkml.org/lkml/2015/2/25/559

Quoted 8 lines

Changes since v1:
* fixed typo introduced after test, retested

[separated out just cr_interception part from larger removal of INTERCEPT_CR0_WRITE, forward ported, tested]

---

(Existing nested handling is tangled, but looks like everything works,)

Thanks.

#2 lore raw
In reply to Joel Schopp
Quoted 7 lines · Joel Schopp

From: David Kaplan <[email protected]>

Another patch in my war on emulate_on_interception() use as a svm exit handler.

These were pulled out of a larger patch at the suggestion of Radim Krcmar, see
https://lkml.org/lkml/2015/2/25/559

Quoted 7 lines

Changes since v1:
* fixed typo introduced after test, retested

[separated out just cr_interception part from larger removal of INTERCEPT_CR0_WRITE, forward ported, tested]

Applied, thanks.