Skip to content

Commit dadbb61

Browse files
Souptick Joardertorvalds
authored andcommitted
mm/gup.c: convert to use get_user_{page|pages}_fast_only()
API __get_user_pages_fast() renamed to get_user_pages_fast_only() to align with pin_user_pages_fast_only(). As part of this we will get rid of write parameter. Instead caller will pass FOLL_WRITE to get_user_pages_fast_only(). This will not change any existing functionality of the API. All the callers are changed to pass FOLL_WRITE. Also introduce get_user_page_fast_only(), and use it in a few places that hard-code nr_pages to 1. Updated the documentation of the API. Signed-off-by: Souptick Joarder <jrdr.linux@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Reviewed-by: Paul Mackerras <paulus@ozlabs.org> [arch/powerpc/kvm] Cc: Matthew Wilcox <willy@infradead.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com> Cc: Michal Suchanek <msuchanek@suse.de> Link: http://lkml.kernel.org/r/1590396812-31277-1-git-send-email-jrdr.linux@gmail.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e77132e commit dadbb61

7 files changed

Lines changed: 32 additions & 27 deletions

File tree

‎arch/powerpc/kvm/book3s_64_mmu_hv.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ int kvmppc_book3s_hv_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
581581
* We always ask for write permission since the common case
582582
* is that the page is writable.
583583
*/
584-
if (__get_user_pages_fast(hva, 1, 1, &page) == 1) {
584+
if (get_user_page_fast_only(hva, FOLL_WRITE, &page)) {
585585
write_ok = true;
586586
} else {
587587
/* Call KVM generic code to do the slow-path check */

‎arch/powerpc/kvm/book3s_64_mmu_radix.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu,
795795
* is that the page is writable.
796796
*/
797797
hva = gfn_to_hva_memslot(memslot, gfn);
798-
if (!kvm_ro && __get_user_pages_fast(hva, 1, 1, &page) == 1) {
798+
if (!kvm_ro && get_user_page_fast_only(hva, FOLL_WRITE, &page)) {
799799
upgrade_write = true;
800800
} else {
801801
unsigned long pfn;

‎arch/powerpc/perf/callchain_64.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ int read_user_stack_slow(void __user *ptr, void *buf, int nb)
3030
unsigned long addr = (unsigned long) ptr;
3131
unsigned long offset;
3232
struct page *page;
33-
int nrpages;
3433
void *kaddr;
3534

36-
nrpages = __get_user_pages_fast(addr, 1, 1, &page);
37-
if (nrpages == 1) {
35+
if (get_user_page_fast_only(addr, FOLL_WRITE, &page)) {
3836
kaddr = page_address(page);
3937

4038
/* align address to page boundary */

‎include/linux/mm.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,10 +1824,16 @@ extern int mprotect_fixup(struct vm_area_struct *vma,
18241824
/*
18251825
* doesn't attempt to fault and will return short.
18261826
*/
1827-
int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
1828-
struct page **pages);
1827+
int get_user_pages_fast_only(unsigned long start, int nr_pages,
1828+
unsigned int gup_flags, struct page **pages);
18291829
int pin_user_pages_fast_only(unsigned long start, int nr_pages,
18301830
unsigned int gup_flags, struct page **pages);
1831+
1832+
static inline bool get_user_page_fast_only(unsigned long addr,
1833+
unsigned int gup_flags, struct page **pagep)
1834+
{
1835+
return get_user_pages_fast_only(addr, 1, gup_flags, pagep) == 1;
1836+
}
18311837
/*
18321838
* per-process(per-mm_struct) statistics.
18331839
*/

‎kernel/events/core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6934,12 +6934,12 @@ static u64 perf_virt_to_phys(u64 virt)
69346934
* Walking the pages tables for user address.
69356935
* Interrupts are disabled, so it prevents any tear down
69366936
* of the page tables.
6937-
* Try IRQ-safe __get_user_pages_fast first.
6937+
* Try IRQ-safe get_user_page_fast_only first.
69386938
* If failed, leave phys_addr as 0.
69396939
*/
69406940
if (current->mm != NULL) {
69416941
pagefault_disable();
6942-
if (__get_user_pages_fast(virt, 1, 0, &p) == 1)
6942+
if (get_user_page_fast_only(virt, 0, &p))
69436943
phys_addr = page_to_phys(p) + virt % PAGE_SIZE;
69446944
pagefault_enable();
69456945
}

‎mm/gup.c‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
22942294
* to be special.
22952295
*
22962296
* For a futex to be placed on a THP tail page, get_futex_key requires a
2297-
* __get_user_pages_fast implementation that can pin pages. Thus it's still
2297+
* get_user_pages_fast_only implementation that can pin pages. Thus it's still
22982298
* useful to have gup_huge_pmd even if we can't operate on ptes.
22992299
*/
23002300
static int gup_pte_range(pmd_t pmd, unsigned long addr, unsigned long end,
@@ -2699,7 +2699,7 @@ static inline void gup_pgd_range(unsigned long addr, unsigned long end,
26992699

27002700
#ifndef gup_fast_permitted
27012701
/*
2702-
* Check if it's allowed to use __get_user_pages_fast() for the range, or
2702+
* Check if it's allowed to use get_user_pages_fast_only() for the range, or
27032703
* we need to fall back to the slow version:
27042704
*/
27052705
static bool gup_fast_permitted(unsigned long start, unsigned long end)
@@ -2811,8 +2811,14 @@ static int internal_get_user_pages_fast(unsigned long start, int nr_pages,
28112811

28122812
return ret;
28132813
}
2814-
2815-
/*
2814+
/**
2815+
* get_user_pages_fast_only() - pin user pages in memory
2816+
* @start: starting user address
2817+
* @nr_pages: number of pages from start to pin
2818+
* @gup_flags: flags modifying pin behaviour
2819+
* @pages: array that receives pointers to the pages pinned.
2820+
* Should be at least nr_pages long.
2821+
*
28162822
* Like get_user_pages_fast() except it's IRQ-safe in that it won't fall back to
28172823
* the regular GUP.
28182824
* Note a difference with get_user_pages_fast: this always returns the
@@ -2825,8 +2831,8 @@ static int internal_get_user_pages_fast(unsigned long start, int nr_pages,
28252831
* access can get ambiguous page results. If you call this function without
28262832
* 'write' set, you'd better be sure that you're ok with that ambiguity.
28272833
*/
2828-
int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
2829-
struct page **pages)
2834+
int get_user_pages_fast_only(unsigned long start, int nr_pages,
2835+
unsigned int gup_flags, struct page **pages)
28302836
{
28312837
int nr_pinned;
28322838
/*
@@ -2836,10 +2842,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28362842
* FOLL_FAST_ONLY is required in order to match the API description of
28372843
* this routine: no fall back to regular ("slow") GUP.
28382844
*/
2839-
unsigned int gup_flags = FOLL_GET | FOLL_FAST_ONLY;
2840-
2841-
if (write)
2842-
gup_flags |= FOLL_WRITE;
2845+
gup_flags |= FOLL_GET | FOLL_FAST_ONLY;
28432846

28442847
nr_pinned = internal_get_user_pages_fast(start, nr_pages, gup_flags,
28452848
pages);
@@ -2855,7 +2858,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28552858

28562859
return nr_pinned;
28572860
}
2858-
EXPORT_SYMBOL_GPL(__get_user_pages_fast);
2861+
EXPORT_SYMBOL_GPL(get_user_pages_fast_only);
28592862

28602863
/**
28612864
* get_user_pages_fast() - pin user pages in memory
@@ -2926,8 +2929,8 @@ int pin_user_pages_fast(unsigned long start, int nr_pages,
29262929
EXPORT_SYMBOL_GPL(pin_user_pages_fast);
29272930

29282931
/*
2929-
* This is the FOLL_PIN equivalent of __get_user_pages_fast(). Behavior is the
2930-
* same, except that this one sets FOLL_PIN instead of FOLL_GET.
2932+
* This is the FOLL_PIN equivalent of get_user_pages_fast_only(). Behavior
2933+
* is the same, except that this one sets FOLL_PIN instead of FOLL_GET.
29312934
*
29322935
* The API rules are the same, too: no negative values may be returned.
29332936
*/

‎virt/kvm/kvm_main.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,6 @@ static bool hva_to_pfn_fast(unsigned long addr, bool write_fault,
17401740
bool *writable, kvm_pfn_t *pfn)
17411741
{
17421742
struct page *page[1];
1743-
int npages;
17441743

17451744
/*
17461745
* Fast pin a writable pfn only if it is a write fault request
@@ -1750,8 +1749,7 @@ static bool hva_to_pfn_fast(unsigned long addr, bool write_fault,
17501749
if (!(write_fault || writable))
17511750
return false;
17521751

1753-
npages = __get_user_pages_fast(addr, 1, 1, page);
1754-
if (npages == 1) {
1752+
if (get_user_page_fast_only(addr, FOLL_WRITE, page)) {
17551753
*pfn = page_to_pfn(page[0]);
17561754

17571755
if (writable)
@@ -1791,7 +1789,7 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault,
17911789
if (unlikely(!write_fault) && writable) {
17921790
struct page *wpage;
17931791

1794-
if (__get_user_pages_fast(addr, 1, 1, &wpage) == 1) {
1792+
if (get_user_page_fast_only(addr, FOLL_WRITE, &wpage)) {
17951793
*writable = true;
17961794
put_page(page);
17971795
page = wpage;
@@ -2003,7 +2001,7 @@ int gfn_to_page_many_atomic(struct kvm_memory_slot *slot, gfn_t gfn,
20032001
if (entry < nr_pages)
20042002
return 0;
20052003

2006-
return __get_user_pages_fast(addr, nr_pages, 1, pages);
2004+
return get_user_pages_fast_only(addr, nr_pages, FOLL_WRITE, pages);
20072005
}
20082006
EXPORT_SYMBOL_GPL(gfn_to_page_many_atomic);
20092007

0 commit comments

Comments
 (0)