From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752785AbdHKGqr (ORCPT ); Fri, 11 Aug 2017 02:46:47 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:37143 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751891AbdHKGqi (ORCPT ); Fri, 11 Aug 2017 02:46:38 -0400 From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li , Brijesh Singh , David Hildenbrand Subject: [PATCH v3] KVM: MMU: Fix guest stuck during boot due to read/write emulation against GVA Date: Thu, 10 Aug 2017 23:46:33 -0700 Message-Id: <1502433993-4326-1-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li 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 setting the gpa_available flag under direct mode. Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Brijesh Singh Cc: David Hildenbrand Signed-off-by: Wanpeng Li --- arch/x86/kvm/mmu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 849312d..4780348 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -3791,8 +3791,11 @@ 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; + /* With shadow page tables, cr2 could contain a GVA, not a GPA */ + if (vcpu->arch.mmu.direct_map) { + 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