From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: unit tests and get_user_pages_ptes_fast() Date: Tue, 05 Oct 2010 09:36:59 +0200 Message-ID: <4CAAD59B.5020003@redhat.com> References: <4CA99FE0.7070709@redhat.com> <20101004134052.GQ26357@random.random> <20101004235953.GA1474@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Andrea Arcangeli , KVM list To: Marcelo Tosatti Return-path: Received: from mx1.redhat.com ([209.132.183.28]:28834 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755195Ab0JEHhE (ORCPT ); Tue, 5 Oct 2010 03:37:04 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o957b3Jt023514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Oct 2010 03:37:03 -0400 In-Reply-To: <20101004235953.GA1474@amt.cnet> Sender: kvm-owner@vger.kernel.org List-ID: 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. -- I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.