Skip to contentSkip to conversation

KVM/nSVM: properly map nested VMCB

PATCH In review Vitaly Kuznetsov 4 participants 5 messages Jun 4, 2019 – Aug 14, 2019

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

PATCH 1/1 KVM/nSVM: properly map nested VMCB

Commit 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory") broke nested SVM completely: kvm_vcpu_map()'s second parameter is GFN so vmcb_gpa needs to be converted with gpa_to_gfn(), not the other way around.

Fixes 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory")
---
 arch/x86/kvm/svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +2 -2
index 735b8c01895e..5beca1030c9a 100644
@@ -3293,7 +3293,7 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
 				       vmcb->control.exit_int_info_err,
 				       KVM_ISA_SVM);
 
-	rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(svm->nested.vmcb), &map);
+	rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb), &map);
 	if (rc) {
 		if (rc == -EINVAL)
 			kvm_inject_gp(&svm->vcpu, 0);
@@ -3583,7 +3583,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
 
 	vmcb_gpa = svm->vmcb->save.rax;
 
-	rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(vmcb_gpa), &map);
+	rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb_gpa), &map);
 	if (rc) {
 		if (rc == -EINVAL)
 			kvm_inject_gp(&svm->vcpu, 0);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Vitaly Kuznetsov

Commit 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory") broke nested SVM completely: kvm_vcpu_map()'s second parameter is GFN so vmcb_gpa needs to be converted with gpa_to_gfn(), not the other way around.

Fixes 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory")
maintainer
#2 lore raw
In reply to Vitaly Kuznetsov
Quoted 26 lines · Vitaly Kuznetsov

Commit 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory") broke nested SVM completely: kvm_vcpu_map()'s second parameter is GFN so vmcb_gpa needs to be converted with gpa_to_gfn(), not the other way around.

Fixes 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory")
---
 arch/x86/kvm/svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +1 -1
index 735b8c01895e..5beca1030c9a 100644
@@ -3293,7 +3293,7 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
 				       vmcb->control.exit_int_info_err,
 				       KVM_ISA_SVM);
 
-	rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(svm->nested.vmcb), &map);
+	rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb), &map);
 	if (rc) {
 		if (rc == -EINVAL)
 			kvm_inject_gp(&svm->vcpu, 0);

arch/x86/kvm/svm.c static bool nested_svm_vmrun(struct vcpu_svm *svm) · line 3589

Quoted 8 lines
arch/x86/kvm/svm.c +1 -1
@@ -3583,7 +3583,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
 
 	vmcb_gpa = svm->vmcb->save.rax;
 
-	rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(vmcb_gpa), &map);
+	rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb_gpa), &map);
 	if (rc) {
 		if (rc == -EINVAL)
 			kvm_inject_gp(&svm->vcpu, 0);

Oops. Queued, thanks.

Paolo

#3 lore raw

Hello,

Quoted 29 lines · Paolo Bonzini
Quoted 28 lines · Vitaly Kuznetsov

Commit 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory") broke nested SVM completely: kvm_vcpu_map()'s second parameter is GFN so vmcb_gpa needs to be converted with gpa_to_gfn(), not the other way around.

Fixes 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest memory")
---
  arch/x86/kvm/svm.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +1 -1
index 735b8c01895e..5beca1030c9a 100644
@@ -3293,7 +3293,7 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
  				       vmcb->control.exit_int_info_err,
  				       KVM_ISA_SVM);
 
-	rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(svm->nested.vmcb), &map);
+	rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb), &map);
  	if (rc) {
  		if (rc == -EINVAL)
  			kvm_inject_gp(&svm->vcpu, 0);
@@ -3583,7 +3583,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
 
  	vmcb_gpa = svm->vmcb->save.rax;
 
Quoted 7 lines

arch/x86/kvm/svm.c static bool nested_svm_vmrun(struct vcpu_svm *svm) · line 3589

Quoted 6 lines
arch/x86/kvm/svm.c +1 -1
-	rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(vmcb_gpa), &map);
+	rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb_gpa), &map);
  	if (rc) {
  		if (rc == -EINVAL)
  			kvm_inject_gp(&svm->vcpu, 0);

Oops. Queued, thanks.

Given that this fix didn't make it to 5.2, and its straightforwardness, could you send it to stable for inclusion?

Regards

    Jiri Palecek

maintainer
#4 lore raw
Quoted 44 lines · Jiri Palecek

Hello,

Quoted 33 lines · Paolo Bonzini
Quoted 32 lines · Vitaly Kuznetsov

Commit 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping guest
memory") broke nested SVM completely: kvm_vcpu_map()'s second parameter is
GFN so vmcb_gpa needs to be converted with gpa_to_gfn(), not the other way
around.

Fixes 8c5fbf1a7231 ("KVM/nSVM: Use the new mapping API for mapping

guest memory")

---
  arch/x86/kvm/svm.c | 4 ++--

  1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/svm.c +1 -1
index 735b8c01895e..5beca1030c9a 100644
@@ -3293,7 +3293,7 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
                          vmcb->control.exit_int_info_err,
                          KVM_ISA_SVM);
 
-    rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(svm->nested.vmcb), &map);
+    rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(svm->nested.vmcb), &map);
       if (rc) {
           if (rc == -EINVAL)
               kvm_inject_gp(&svm->vcpu, 0);
@@ -3583,7 +3583,7 @@ static bool nested_svm_vmrun(struct vcpu_svm *svm)
 
       vmcb_gpa = svm->vmcb->save.rax;
 
Quoted 7 lines

arch/x86/kvm/svm.c static bool nested_svm_vmrun(struct vcpu_svm *svm) · line 3589

Quoted 6 lines
arch/x86/kvm/svm.c +1 -1
-    rc = kvm_vcpu_map(&svm->vcpu, gfn_to_gpa(vmcb_gpa), &map);
+    rc = kvm_vcpu_map(&svm->vcpu, gpa_to_gfn(vmcb_gpa), &map);
       if (rc) {
           if (rc == -EINVAL)
               kvm_inject_gp(&svm->vcpu, 0);

Oops.  Queued, thanks.

Quoted 2 lines

Given that this fix didn't make it to 5.2, and its straightforwardness, could you send it to stable for inclusion?

Done, thanks for the reminder!

Paolo