From patchwork Tue Oct 19 11:05:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 265371 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9JB5b9L017037 for ; Tue, 19 Oct 2010 11:05:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758314Ab0JSLF1 (ORCPT ); Tue, 19 Oct 2010 07:05:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57095 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758334Ab0JSLFY (ORCPT ); Tue, 19 Oct 2010 07:05:24 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9JB5Nvx001014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 19 Oct 2010 07:05:23 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9JB5Mae031413; Tue, 19 Oct 2010 07:05:23 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 5A6F718D46D; Tue, 19 Oct 2010 13:05:22 +0200 (IST) Date: Tue, 19 Oct 2010 13:05:22 +0200 From: Gleb Natapov To: Marcelo Tosatti Cc: kvm Subject: Re: KVM: attempt async pf only if address is contained in vma Message-ID: <20101019110522.GH10207@redhat.com> References: <20101018222402.GA27350@amt.cnet> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20101018222402.GA27350@amt.cnet> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 19 Oct 2010 11:05:37 +0000 (UTC) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 796b06e..29e40e5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -954,6 +954,12 @@ unsigned long gfn_to_hva(struct kvm *kvm, gfn_t gfn) } EXPORT_SYMBOL_GPL(gfn_to_hva); +static pfn_t get_fault_pfn(void) +{ + get_page(fault_page); + return fault_pfn; +} + static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, bool *async) { @@ -983,7 +989,7 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, struct vm_area_struct *vma; if (atomic) - goto return_fault_page; + return get_fault_pfn(); down_read(¤t->mm->mmap_sem); if (is_hwpoison_address(addr)) { @@ -992,22 +998,20 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic, return page_to_pfn(hwpoison_page); } - vma = find_vma(current->mm, addr); + vma = find_vma_intersection(current->mm, addr, addr+1); - if (vma == NULL || addr < vma->vm_start || - !(vma->vm_flags & VM_PFNMAP)) { - if (async && !(vma->vm_flags & VM_PFNMAP) && - (vma->vm_flags & VM_WRITE)) + if (vma == NULL) + return get_fault_pfn(); + if ((vma->vm_flags & VM_PFNMAP)) { + pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) + + vma->vm_pgoff; + BUG_ON(!kvm_is_mmio_pfn(pfn)); + } else { + if (async && (vma->vm_flags & VM_WRITE)) *async = true; - up_read(¤t->mm->mmap_sem); -return_fault_page: - get_page(fault_page); - return page_to_pfn(fault_page); + pfn = get_fault_pfn(); } - - pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; up_read(¤t->mm->mmap_sem); - BUG_ON(!kvm_is_mmio_pfn(pfn)); } else pfn = page_to_pfn(page[0]);