diff mbox series

KVM/nSVM: properly map nested VMCB

Message ID 20190604160939.17031-1-vkuznets@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM/nSVM: properly map nested VMCB | expand

Commit Message

Vitaly Kuznetsov June 4, 2019, 4:09 p.m. UTC
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")
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/svm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Sean Christopherson June 4, 2019, 4:48 p.m. UTC | #1
On Tue, Jun 04, 2019 at 06:09:39PM +0200, Vitaly Kuznetsov wrote:
> 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")
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Reviewed-by: Sean Christopherson <sean.j.christopherson@intel.com>
Paolo Bonzini June 4, 2019, 5:27 p.m. UTC | #2
On 04/06/19 18:09, Vitaly Kuznetsov wrote:
> 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")
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 735b8c01895e..5beca1030c9a 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -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);
> 

Oops.  Queued, thanks.

Paolo
Jiri Palecek Aug. 10, 2019, 6:35 p.m. UTC | #3
Hello,

On 04. 06. 19 19:27, Paolo Bonzini wrote:
> On 04/06/19 18:09, Vitaly Kuznetsov wrote:
>> 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")
>> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> ---
>>   arch/x86/kvm/svm.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>> index 735b8c01895e..5beca1030c9a 100644
>> --- a/arch/x86/kvm/svm.c
>> +++ b/arch/x86/kvm/svm.c
>> @@ -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);
>>
> 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
Paolo Bonzini Aug. 14, 2019, 12:43 p.m. UTC | #4
On 10/08/19 20:35, Jiri Palecek wrote:
> Hello,
> 
> On 04. 06. 19 19:27, Paolo Bonzini wrote:
>> On 04/06/19 18:09, Vitaly Kuznetsov wrote:
>>> 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")
>>> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>>> ---
>>>   arch/x86/kvm/svm.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
>>> index 735b8c01895e..5beca1030c9a 100644
>>> --- a/arch/x86/kvm/svm.c
>>> +++ b/arch/x86/kvm/svm.c
>>> @@ -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);
>>>
>> 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?

Done, thanks for the reminder!

Paolo
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 735b8c01895e..5beca1030c9a 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -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);