Skip to content

Commit 0664e57

Browse files
aarcange-rhtorvalds
authored andcommitted
mm: gup: kvm use get_user_pages_unlocked
Use the more generic get_user_pages_unlocked which has the additional benefit of passing FAULT_FLAG_ALLOW_RETRY at the very first page fault (which allows the first page fault in an unmapped area to be always able to block indefinitely by being allowed to release the mmap_sem). Signed-off-by: Andrea Arcangeli <aarcange@redhat.com> Reviewed-by: Andres Lagar-Cavilla <andreslc@google.com> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Peter Feiner <pfeiner@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7e33912 commit 0664e57

3 files changed

Lines changed: 5 additions & 58 deletions

File tree

‎include/linux/kvm_host.h‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,6 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, unsigned long hva,
200200
int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
201201
#endif
202202

203-
/*
204-
* Carry out a gup that requires IO. Allow the mm to relinquish the mmap
205-
* semaphore if the filemap/swap has to wait on a page lock. pagep == NULL
206-
* controls whether we retry the gup one more time to completion in that case.
207-
* Typically this is called after a FAULT_FLAG_RETRY_NOWAIT in the main tdp
208-
* handler.
209-
*/
210-
int kvm_get_user_page_io(struct task_struct *tsk, struct mm_struct *mm,
211-
unsigned long addr, bool write_fault,
212-
struct page **pagep);
213-
214203
enum {
215204
OUTSIDE_GUEST_MODE,
216205
IN_GUEST_MODE,

‎virt/kvm/async_pf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static void async_pf_execute(struct work_struct *work)
8080

8181
might_sleep();
8282

83-
kvm_get_user_page_io(NULL, mm, addr, 1, NULL);
83+
get_user_pages_unlocked(NULL, mm, addr, 1, 1, 0, NULL);
8484
kvm_async_page_present_sync(vcpu, apf);
8585

8686
spin_lock(&vcpu->async_pf.lock);

‎virt/kvm/kvm_main.c‎

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,43 +1128,6 @@ static int get_user_page_nowait(struct task_struct *tsk, struct mm_struct *mm,
11281128
return __get_user_pages(tsk, mm, start, 1, flags, page, NULL, NULL);
11291129
}
11301130

1131-
int kvm_get_user_page_io(struct task_struct *tsk, struct mm_struct *mm,
1132-
unsigned long addr, bool write_fault,
1133-
struct page **pagep)
1134-
{
1135-
int npages;
1136-
int locked = 1;
1137-
int flags = FOLL_TOUCH | FOLL_HWPOISON |
1138-
(pagep ? FOLL_GET : 0) |
1139-
(write_fault ? FOLL_WRITE : 0);
1140-
1141-
/*
1142-
* If retrying the fault, we get here *not* having allowed the filemap
1143-
* to wait on the page lock. We should now allow waiting on the IO with
1144-
* the mmap semaphore released.
1145-
*/
1146-
down_read(&mm->mmap_sem);
1147-
npages = __get_user_pages(tsk, mm, addr, 1, flags, pagep, NULL,
1148-
&locked);
1149-
if (!locked) {
1150-
VM_BUG_ON(npages);
1151-
1152-
if (!pagep)
1153-
return 0;
1154-
1155-
/*
1156-
* The previous call has now waited on the IO. Now we can
1157-
* retry and complete. Pass TRIED to ensure we do not re
1158-
* schedule async IO (see e.g. filemap_fault).
1159-
*/
1160-
down_read(&mm->mmap_sem);
1161-
npages = __get_user_pages(tsk, mm, addr, 1, flags | FOLL_TRIED,
1162-
pagep, NULL, NULL);
1163-
}
1164-
up_read(&mm->mmap_sem);
1165-
return npages;
1166-
}
1167-
11681131
static inline int check_user_page_hwpoison(unsigned long addr)
11691132
{
11701133
int rc, flags = FOLL_TOUCH | FOLL_HWPOISON | FOLL_WRITE;
@@ -1227,15 +1190,10 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault,
12271190
npages = get_user_page_nowait(current, current->mm,
12281191
addr, write_fault, page);
12291192
up_read(&current->mm->mmap_sem);
1230-
} else {
1231-
/*
1232-
* By now we have tried gup_fast, and possibly async_pf, and we
1233-
* are certainly not atomic. Time to retry the gup, allowing
1234-
* mmap semaphore to be relinquished in the case of IO.
1235-
*/
1236-
npages = kvm_get_user_page_io(current, current->mm, addr,
1237-
write_fault, page);
1238-
}
1193+
} else
1194+
npages = __get_user_pages_unlocked(current, current->mm, addr, 1,
1195+
write_fault, 0, page,
1196+
FOLL_TOUCH|FOLL_HWPOISON);
12391197
if (npages != 1)
12401198
return npages;
12411199

0 commit comments

Comments
 (0)