Skip to content

Commit ce53053

Browse files
author
Al Viro
committed
kvm: switch get_user_page_nowait() to get_user_pages_unlocked()
... and fold into the sole caller, unifying async and non-async cases Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent e716712 commit ce53053

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

virt/kvm/kvm_main.c

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,17 +1314,6 @@ unsigned long kvm_vcpu_gfn_to_hva_prot(struct kvm_vcpu *vcpu, gfn_t gfn, bool *w
13141314
return gfn_to_hva_memslot_prot(slot, gfn, writable);
13151315
}
13161316

1317-
static int get_user_page_nowait(unsigned long start, int write,
1318-
struct page **page)
1319-
{
1320-
int flags = FOLL_NOWAIT | FOLL_HWPOISON;
1321-
1322-
if (write)
1323-
flags |= FOLL_WRITE;
1324-
1325-
return get_user_pages(start, 1, flags, page, NULL);
1326-
}
1327-
13281317
static inline int check_user_page_hwpoison(unsigned long addr)
13291318
{
13301319
int rc, flags = FOLL_HWPOISON | FOLL_WRITE;
@@ -1373,43 +1362,35 @@ static bool hva_to_pfn_fast(unsigned long addr, bool atomic, bool *async,
13731362
static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault,
13741363
bool *writable, kvm_pfn_t *pfn)
13751364
{
1376-
struct page *page[1];
1365+
unsigned int flags = FOLL_HWPOISON;
1366+
struct page *page;
13771367
int npages = 0;
13781368

13791369
might_sleep();
13801370

13811371
if (writable)
13821372
*writable = write_fault;
13831373

1384-
if (async) {
1385-
down_read(&current->mm->mmap_sem);
1386-
npages = get_user_page_nowait(addr, write_fault, page);
1387-
up_read(&current->mm->mmap_sem);
1388-
} else {
1389-
unsigned int flags = FOLL_HWPOISON;
1390-
1391-
if (write_fault)
1392-
flags |= FOLL_WRITE;
1374+
if (write_fault)
1375+
flags |= FOLL_WRITE;
1376+
if (async)
1377+
flags |= FOLL_NOWAIT;
13931378

1394-
npages = get_user_pages_unlocked(addr, 1, page, flags);
1395-
}
1379+
npages = get_user_pages_unlocked(addr, 1, &page, flags);
13961380
if (npages != 1)
13971381
return npages;
13981382

13991383
/* map read fault as writable if possible */
14001384
if (unlikely(!write_fault) && writable) {
1401-
struct page *wpage[1];
1385+
struct page *wpage;
14021386

1403-
npages = __get_user_pages_fast(addr, 1, 1, wpage);
1404-
if (npages == 1) {
1387+
if (__get_user_pages_fast(addr, 1, 1, &wpage) == 1) {
14051388
*writable = true;
1406-
put_page(page[0]);
1407-
page[0] = wpage[0];
1389+
put_page(page);
1390+
page = wpage;
14081391
}
1409-
1410-
npages = 1;
14111392
}
1412-
*pfn = page_to_pfn(page[0]);
1393+
*pfn = page_to_pfn(page);
14131394
return npages;
14141395
}
14151396

0 commit comments

Comments
 (0)