Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1709279 > unrolled thread

[PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA

Started byWanpeng Li <kernellwp@gmail.com>
First post2017-08-11 08:10 +0200
Last post2017-08-11 08:50 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA Wanpeng Li <kernellwp@gmail.com> - 2017-08-11 08:10 +0200
    Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write  emulation against GVA Paolo Bonzini <pbonzini@redhat.com> - 2017-08-11 08:20 +0200
      Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write  emulation against GVA Wanpeng Li <kernellwp@gmail.com> - 2017-08-11 08:20 +0200
      Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write  emulation against GVA Wanpeng Li <kernellwp@gmail.com> - 2017-08-11 08:50 +0200
      Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write  emulation against GVA David Hildenbrand <david@redhat.com> - 2017-08-11 08:50 +0200

#1709279 — [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA

FromWanpeng Li <kernellwp@gmail.com>
Date2017-08-11 08:10 +0200
Subject[PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA
Message-ID<udbiV-8i7-3@gated-at.bofh.it>
From: Wanpeng Li <wanpeng.li@hotmail.com>

Commit c016004494b0 (KVM: x86: Avoid guest page table walk when gpa_available 
is set) avoids the page table walk when cr2 has already contained a valid GPA. 
However, that is not the truth if ept == 0 and shadow page table is used. In 
this scenario cr2 can just contains a valid GVA. The commit results in guest 
stuck during boot due to read/write emulation against GVA instead of GPA of 
the guest.

This patch fixes it by not setting the gpa_available flag if the shadow page table 
is used.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
 arch/x86/kvm/mmu.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 849312d..e4ce20b 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -3791,8 +3791,6 @@ int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
 
 		if (need_unprotect && kvm_event_needs_reinjection(vcpu))
 			kvm_mmu_unprotect_page_virt(vcpu, fault_address);
-		vcpu->arch.gpa_available = true;
-		vcpu->arch.gpa_val = fault_address;
 		r = kvm_mmu_page_fault(vcpu, fault_address, error_code, insn,
 				insn_len);
 		break;
-- 
2.7.4

[toc] | [next] | [standalone]


#1709283 — Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA

FromPaolo Bonzini <pbonzini@redhat.com>
Date2017-08-11 08:20 +0200
SubjectRe: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA
Message-ID<udbsC-8lW-3@gated-at.bofh.it>
In reply to#1709279
On 11/08/2017 07:59, Wanpeng Li wrote:
> From: Wanpeng Li <wanpeng.li@hotmail.com>
> 
> Commit c016004494b0 (KVM: x86: Avoid guest page table walk when gpa_available 
> is set) avoids the page table walk when cr2 has already contained a valid GPA. 
> However, that is not the truth if ept == 0 and shadow page table is used. In 
> this scenario cr2 can just contains a valid GVA. The commit results in guest 
> stuck during boot due to read/write emulation against GVA instead of GPA of 
> the guest.
> 
> This patch fixes it by not setting the gpa_available flag if the shadow page table 
> is used.

Yup, I got these on my overnight tests too.  A better fix that I was
going to commit today is:

                if (vcpu->arch.mmu.direct_map) {
                        vcpu->arch.gpa_available = true;
                        vcpu->arch.gpa_val = fault_address;
                }

because AMD gets here even if npt=1.

Paolo

> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: Brijesh Singh <brijesh.singh@amd.com>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
>  arch/x86/kvm/mmu.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 849312d..e4ce20b 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -3791,8 +3791,6 @@ int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
>  
>  		if (need_unprotect && kvm_event_needs_reinjection(vcpu))
>  			kvm_mmu_unprotect_page_virt(vcpu, fault_address);
> -		vcpu->arch.gpa_available = true;
> -		vcpu->arch.gpa_val = fault_address;
>  		r = kvm_mmu_page_fault(vcpu, fault_address, error_code, insn,
>  				insn_len);
>  		break;
> 

[toc] | [prev] | [next] | [standalone]


#1709284 — Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA

FromWanpeng Li <kernellwp@gmail.com>
Date2017-08-11 08:20 +0200
SubjectRe: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA
Message-ID<udbsC-8lW-9@gated-at.bofh.it>
In reply to#1709283
2017-08-11 14:13 GMT+08:00 Paolo Bonzini <pbonzini@redhat.com>:
> On 11/08/2017 07:59, Wanpeng Li wrote:
>> From: Wanpeng Li <wanpeng.li@hotmail.com>
>>
>> Commit c016004494b0 (KVM: x86: Avoid guest page table walk when gpa_available
>> is set) avoids the page table walk when cr2 has already contained a valid GPA.
>> However, that is not the truth if ept == 0 and shadow page table is used. In
>> this scenario cr2 can just contains a valid GVA. The commit results in guest
>> stuck during boot due to read/write emulation against GVA instead of GPA of
>> the guest.
>>
>> This patch fixes it by not setting the gpa_available flag if the shadow page table
>> is used.
>
> Yup, I got these on my overnight tests too.  A better fix that I was
> going to commit today is:
>
>                 if (vcpu->arch.mmu.direct_map) {
>                         vcpu->arch.gpa_available = true;
>                         vcpu->arch.gpa_val = fault_address;
>                 }
>
> because AMD gets here even if npt=1.

Good point, could I post a patch for this?

Regards,
Wanpeng Li

>
> Paolo
>
>> Cc: Paolo Bonzini <pbonzini@redhat.com>
>> Cc: Radim Krčmář <rkrcmar@redhat.com>
>> Cc: Brijesh Singh <brijesh.singh@amd.com>
>> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
>> ---
>>  arch/x86/kvm/mmu.c | 2 --
>>  1 file changed, 2 deletions(-)
>>
>> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
>> index 849312d..e4ce20b 100644
>> --- a/arch/x86/kvm/mmu.c
>> +++ b/arch/x86/kvm/mmu.c
>> @@ -3791,8 +3791,6 @@ int kvm_handle_page_fault(struct kvm_vcpu *vcpu, u64 error_code,
>>
>>               if (need_unprotect && kvm_event_needs_reinjection(vcpu))
>>                       kvm_mmu_unprotect_page_virt(vcpu, fault_address);
>> -             vcpu->arch.gpa_available = true;
>> -             vcpu->arch.gpa_val = fault_address;
>>               r = kvm_mmu_page_fault(vcpu, fault_address, error_code, insn,
>>                               insn_len);
>>               break;
>>
>

[toc] | [prev] | [next] | [standalone]


#1709304 — Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA

FromWanpeng Li <kernellwp@gmail.com>
Date2017-08-11 08:50 +0200
SubjectRe: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA
Message-ID<udbVE-7y-5@gated-at.bofh.it>
In reply to#1709283
2017-08-11 14:40 GMT+08:00 David Hildenbrand <david@redhat.com>:
> On 11.08.2017 08:13, Paolo Bonzini wrote:
>> On 11/08/2017 07:59, Wanpeng Li wrote:
>>> From: Wanpeng Li <wanpeng.li@hotmail.com>
>>>
>>> Commit c016004494b0 (KVM: x86: Avoid guest page table walk when gpa_available
>>> is set) avoids the page table walk when cr2 has already contained a valid GPA.
>>> However, that is not the truth if ept == 0 and shadow page table is used. In
>>> this scenario cr2 can just contains a valid GVA. The commit results in guest
>>> stuck during boot due to read/write emulation against GVA instead of GPA of
>>> the guest.
>>>
>>> This patch fixes it by not setting the gpa_available flag if the shadow page table
>>> is used.
>>
>> Yup, I got these on my overnight tests too.  A better fix that I was
>> going to commit today is:
>>
>>                 if (vcpu->arch.mmu.direct_map) {
>>                         vcpu->arch.gpa_available = true;
>>                         vcpu->arch.gpa_val = fault_address;
>>                 }
>>
>
> Makes sense to me. Can we add a comment?
>
> /* with shadow page tables, cr2 could contain a GVA, not a GPA */

Yeah, thanks for the review.

Regards,
Wanpeng Li

[toc] | [prev] | [next] | [standalone]


#1709311 — Re: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA

FromDavid Hildenbrand <david@redhat.com>
Date2017-08-11 08:50 +0200
SubjectRe: [PATCH] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA
Message-ID<udbVE-7y-7@gated-at.bofh.it>
In reply to#1709283
On 11.08.2017 08:13, Paolo Bonzini wrote:
> On 11/08/2017 07:59, Wanpeng Li wrote:
>> From: Wanpeng Li <wanpeng.li@hotmail.com>
>>
>> Commit c016004494b0 (KVM: x86: Avoid guest page table walk when gpa_available 
>> is set) avoids the page table walk when cr2 has already contained a valid GPA. 
>> However, that is not the truth if ept == 0 and shadow page table is used. In 
>> this scenario cr2 can just contains a valid GVA. The commit results in guest 
>> stuck during boot due to read/write emulation against GVA instead of GPA of 
>> the guest.
>>
>> This patch fixes it by not setting the gpa_available flag if the shadow page table 
>> is used.
> 
> Yup, I got these on my overnight tests too.  A better fix that I was
> going to commit today is:
> 
>                 if (vcpu->arch.mmu.direct_map) {
>                         vcpu->arch.gpa_available = true;
>                         vcpu->arch.gpa_val = fault_address;
>                 }
> 

Makes sense to me. Can we add a comment?

/* with shadow page tables, cr2 could contain a GVA, not a GPA */

> because AMD gets here even if npt=1.
> 
> Paolo

-- 

Thanks,

David

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web