From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa6Le-0001OE-F3 for qemu-devel@nongnu.org; Fri, 03 Oct 2014 13:09:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xa6LU-0005lO-VO for qemu-devel@nongnu.org; Fri, 03 Oct 2014 13:08:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63210) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xa6LU-0005kv-OT for qemu-devel@nongnu.org; Fri, 03 Oct 2014 13:08:44 -0400 From: Andrea Arcangeli Date: Fri, 3 Oct 2014 19:07:56 +0200 Message-Id: <1412356087-16115-7-git-send-email-aarcange@redhat.com> In-Reply-To: <1412356087-16115-1-git-send-email-aarcange@redhat.com> References: <1412356087-16115-1-git-send-email-aarcange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 06/17] kvm: Faults which trigger IO release the mmap_sem List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org Cc: Robert Love , Dave Hansen , Jan Kara , Neil Brown , Stefan Hajnoczi , Andrew Jones , KOSAKI Motohiro , Michel Lespinasse , Taras Glek , Juan Quintela , Hugh Dickins , Isaku Yamahata , Mel Gorman , Sasha Levin , Android Kernel Team , "\\\"Dr. David Alan Gilbert\\\"" , "Huangpeng (Peter)" , Andres Lagar-Cavilla , Christopher Covington , Anthony Liguori , Paolo Bonzini , Keith Packard , Wenchao Xia , Andy Lutomirski , Minchan Kim , Dmitry Adamushko , Johannes Weiner , Mike Hommey , Andrew Morton , Linus Torvalds , Peter Feiner From: Andres Lagar-Cavilla When KVM handles a tdp fault it uses FOLL_NOWAIT. If the guest memory has been swapped out or is behind a filemap, this will trigger async readahead and return immediately. The rationale is that KVM will kick back the guest with an "async page fault" and allow for some other guest process to take over. If async PFs are enabled the fault is retried asap from an async workqueue. If not, it's retried immediately in the same code path. In either case the retry will not relinquish the mmap semaphore and will block on the IO. This is a bad thing, as other mmap semaphore users now stall as a function of swap or filemap latency. This patch ensures both the regular and async PF path re-enter the fault allowing for the mmap semaphore to be relinquished in the case of IO wait. Reviewed-by: Radim Kr=C4=8Dm=C3=A1=C5=99 Signed-off-by: Andres Lagar-Cavilla Signed-off-by: Andrea Arcangeli --- virt/kvm/async_pf.c | 4 +--- virt/kvm/kvm_main.c | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c index d6a3d09..44660ae 100644 --- a/virt/kvm/async_pf.c +++ b/virt/kvm/async_pf.c @@ -80,9 +80,7 @@ static void async_pf_execute(struct work_struct *work) =20 might_sleep(); =20 - down_read(&mm->mmap_sem); - get_user_pages(NULL, mm, addr, 1, 1, 0, NULL, NULL); - up_read(&mm->mmap_sem); + get_user_pages_unlocked(NULL, mm, addr, 1, 1, 0, NULL); kvm_async_page_present_sync(vcpu, apf); =20 spin_lock(&vcpu->async_pf.lock); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 95519bc..921bce7 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1170,8 +1170,8 @@ static int hva_to_pfn_slow(unsigned long addr, bool= *async, bool write_fault, addr, write_fault, page); up_read(¤t->mm->mmap_sem); } else - npages =3D get_user_pages_fast(addr, 1, write_fault, - page); + npages =3D get_user_pages_unlocked(current, current->mm, addr, 1, + write_fault, 0, page); if (npages !=3D 1) return npages; =20