Skip to content

Commit 422eeb5

Browse files
committed
KVM: Put mm immediately after async #PF worker completes remote gup()
Put the async #PF worker's reference to the VM's address space as soon as the worker is done with the mm. This will allow deferring getting a reference to the worker itself without having to track whether or not getting a reference succeeded. Note, if the vCPU is still alive, there is no danger of the worker getting stuck with tearing down the host page tables, as userspace also holds a reference (obviously), i.e. there is no risk of delaying the page-present notification due to triggering the slow path in mmput(). Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com> Reviewed-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20240110011533.503302-3-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 3d75b8a commit 422eeb5

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

virt/kvm/async_pf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static void async_pf_execute(struct work_struct *work)
6464
get_user_pages_remote(mm, addr, 1, FOLL_WRITE, NULL, &locked);
6565
if (locked)
6666
mmap_read_unlock(mm);
67+
mmput(mm);
6768

6869
if (IS_ENABLED(CONFIG_KVM_ASYNC_PF_SYNC))
6970
kvm_arch_async_page_present(vcpu, apf);
@@ -85,8 +86,6 @@ static void async_pf_execute(struct work_struct *work)
8586
trace_kvm_async_pf_completed(addr, cr2_or_gpa);
8687

8788
__kvm_vcpu_wake_up(vcpu);
88-
89-
mmput(mm);
9089
}
9190

9291
static void kvm_flush_and_free_async_pf_work(struct kvm_async_pf *work)

0 commit comments

Comments
 (0)