qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 06/17] kvm: Faults which trigger IO release the mmap


From: Andrea Arcangeli
Subject: [Qemu-devel] [PATCH 06/17] kvm: Faults which trigger IO release the mmap_sem
Date: Fri, 3 Oct 2014 19:07:56 +0200

From: Andres Lagar-Cavilla <address@hidden>

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čmář <address@hidden>
Signed-off-by: Andres Lagar-Cavilla <address@hidden>
Signed-off-by: Andrea Arcangeli <address@hidden>
---
 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)
 
        might_sleep();
 
-       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);
 
        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(&current->mm->mmap_sem);
        } else
-               npages = get_user_pages_fast(addr, 1, write_fault,
-                                            page);
+               npages = get_user_pages_unlocked(current, current->mm, addr, 1,
+                                                write_fault, 0, page);
        if (npages != 1)
                return npages;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]