From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: unit tests and get_user_pages_ptes_fast() Date: Tue, 5 Oct 2010 06:22:17 -0300 Message-ID: <20101005092217.GA15663@amt.cnet> References: <4CA99FE0.7070709@redhat.com> <20101004134052.GQ26357@random.random> <20101004235953.GA1474@amt.cnet> <4CAAD59B.5020003@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Andrea Arcangeli , KVM list To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:51561 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752286Ab0JEMRh (ORCPT ); Tue, 5 Oct 2010 08:17:37 -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 o95CHbJj002907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Oct 2010 08:17:37 -0400 Content-Disposition: inline In-Reply-To: <4CAAD59B.5020003@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Oct 05, 2010 at 09:36:59AM +0200, Avi Kivity wrote: > On 10/05/2010 01:59 AM, Marcelo Tosatti wrote: > >Yep, the drawback is the unnecessary write fault. What i have here is: > > > >--- kvm.orig/virt/kvm/kvm_main.c > >+++ kvm/virt/kvm/kvm_main.c > >@@ -827,7 +827,7 @@ unsigned long gfn_to_hva(struct kvm *kvm > > } > > EXPORT_SYMBOL_GPL(gfn_to_hva); > > > >-pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn) > >+pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t gfn, int *writable) > > { > > struct page *page[1]; > > unsigned long addr; > >@@ -842,8 +842,16 @@ pfn_t gfn_to_pfn(struct kvm *kvm, gfn_t > > return page_to_pfn(bad_page); > > } > > > >+ *writable = 1; > > npages = get_user_pages_fast(addr, 1, 1, page); > > > >+ /* attempt to map read-only */ > >+ if (unlikely(npages != 1)) { > >+ npages = get_user_pages_fast(addr, 1, 0, page); > >+ if (npages == 1) > >+ *writable = 0; > >+ } > >+ > > if (unlikely(npages != 1)) { > > struct vm_area_struct *vma; > > > >Can rebase and resend, if you'd like. > > > > That will work for me but not for ksm. I guess it's good to get > things going, so please to post it. It'll not be so advantageous for ksm because there should be read-faults very rarely on that case. Will post.