Skip to content

Commit d4edcf0

Browse files
hansendcIngo Molnar
authored andcommitted
mm/gup: Switch all callers of get_user_pages() to not pass tsk/mm
We will soon modify the vanilla get_user_pages() so it can no longer be used on mm/tasks other than 'current/current->mm', which is by far the most common way it is called. For now, we allow the old-style calls, but warn when they are used. (implemented in previous patch) This patch switches all callers of: get_user_pages() get_user_pages_unlocked() get_user_pages_locked() to stop passing tsk/mm so they will no longer see the warnings. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Dave Hansen <dave@sr71.net> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: jack@suse.cz Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/20160212210156.113E9407@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent cde7014 commit d4edcf0

File tree

29 files changed

+44
-64
lines changed

29 files changed

+44
-64
lines changed

arch/cris/arch-v32/drivers/cryptocop.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,9 +2719,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
27192719
/* Acquire the mm page semaphore. */
27202720
down_read(&current->mm->mmap_sem);
27212721

2722-
err = get_user_pages(current,
2723-
current->mm,
2724-
(unsigned long int)(oper.indata + prev_ix),
2722+
err = get_user_pages((unsigned long int)(oper.indata + prev_ix),
27252723
noinpages,
27262724
0, /* read access only for in data */
27272725
0, /* no force */
@@ -2736,9 +2734,7 @@ static int cryptocop_ioctl_process(struct inode *inode, struct file *filp, unsig
27362734
}
27372735
noinpages = err;
27382736
if (oper.do_cipher){
2739-
err = get_user_pages(current,
2740-
current->mm,
2741-
(unsigned long int)oper.cipher_outdata,
2737+
err = get_user_pages((unsigned long int)oper.cipher_outdata,
27422738
nooutpages,
27432739
1, /* write access for out data */
27442740
0, /* no force */

arch/ia64/kernel/err_inject.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ store_virtual_to_phys(struct device *dev, struct device_attribute *attr,
142142
u64 virt_addr=simple_strtoull(buf, NULL, 16);
143143
int ret;
144144

145-
ret = get_user_pages(current, current->mm, virt_addr,
146-
1, VM_READ, 0, NULL, NULL);
145+
ret = get_user_pages(virt_addr, 1, VM_READ, 0, NULL, NULL);
147146
if (ret<=0) {
148147
#ifdef ERR_INJ_DEBUG
149148
printk("Virtual address %lx is not existing.\n",virt_addr);

arch/mips/mm/gup.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
286286
start += nr << PAGE_SHIFT;
287287
pages += nr;
288288

289-
ret = get_user_pages_unlocked(current, mm, start,
290-
(end - start) >> PAGE_SHIFT,
289+
ret = get_user_pages_unlocked(start, (end - start) >> PAGE_SHIFT,
291290
write, 0, pages);
292291

293292
/* Have to be a bit careful with return values */

arch/s390/mm/gup.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
210210
int get_user_pages_fast(unsigned long start, int nr_pages, int write,
211211
struct page **pages)
212212
{
213-
struct mm_struct *mm = current->mm;
214213
int nr, ret;
215214

216215
might_sleep();
@@ -222,8 +221,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
222221
/* Try to get the remaining pages with get_user_pages */
223222
start += nr << PAGE_SHIFT;
224223
pages += nr;
225-
ret = get_user_pages_unlocked(current, mm, start,
226-
nr_pages - nr, write, 0, pages);
224+
ret = get_user_pages_unlocked(start, nr_pages - nr, write, 0, pages);
227225
/* Have to be a bit careful with return values */
228226
if (nr > 0)
229227
ret = (ret < 0) ? nr : ret + nr;

arch/sh/mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
257257
start += nr << PAGE_SHIFT;
258258
pages += nr;
259259

260-
ret = get_user_pages_unlocked(current, mm, start,
260+
ret = get_user_pages_unlocked(start,
261261
(end - start) >> PAGE_SHIFT, write, 0, pages);
262262

263263
/* Have to be a bit careful with return values */

arch/sparc/mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
237237
start += nr << PAGE_SHIFT;
238238
pages += nr;
239239

240-
ret = get_user_pages_unlocked(current, mm, start,
240+
ret = get_user_pages_unlocked(start,
241241
(end - start) >> PAGE_SHIFT, write, 0, pages);
242242

243243
/* Have to be a bit careful with return values */

arch/x86/mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
422422
start += nr << PAGE_SHIFT;
423423
pages += nr;
424424

425-
ret = get_user_pages_unlocked(current, mm, start,
425+
ret = get_user_pages_unlocked(start,
426426
(end - start) >> PAGE_SHIFT,
427427
write, 0, pages);
428428

arch/x86/mm/mpx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ static int mpx_resolve_fault(long __user *addr, int write)
546546
int nr_pages = 1;
547547
int force = 0;
548548

549-
gup_ret = get_user_pages(current, current->mm, (unsigned long)addr,
550-
nr_pages, write, force, NULL, NULL);
549+
gup_ret = get_user_pages((unsigned long)addr, nr_pages, write,
550+
force, NULL, NULL);
551551
/*
552552
* get_user_pages() returns number of pages gotten.
553553
* 0 means we failed to fault in and get anything,

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_tt *ttm)
518518
uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
519519
struct page **pages = ttm->pages + pinned;
520520

521-
r = get_user_pages(current, current->mm, userptr, num_pages,
522-
write, 0, pages, NULL);
521+
r = get_user_pages(userptr, num_pages, write, 0, pages, NULL);
523522
if (r < 0)
524523
goto release_pages;
525524

drivers/gpu/drm/radeon/radeon_ttm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,7 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm)
554554
uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
555555
struct page **pages = ttm->pages + pinned;
556556

557-
r = get_user_pages(current, current->mm, userptr, num_pages,
558-
write, 0, pages, NULL);
557+
r = get_user_pages(userptr, num_pages, write, 0, pages, NULL);
559558
if (r < 0)
560559
goto release_pages;
561560

drivers/gpu/drm/via/via_dmablit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ via_lock_all_dma_pages(drm_via_sg_info_t *vsg, drm_via_dmablit_t *xfer)
239239
if (NULL == vsg->pages)
240240
return -ENOMEM;
241241
down_read(&current->mm->mmap_sem);
242-
ret = get_user_pages(current, current->mm,
243-
(unsigned long)xfer->mem_addr,
242+
ret = get_user_pages((unsigned long)xfer->mem_addr,
244243
vsg->num_pages,
245244
(vsg->direction == DMA_FROM_DEVICE),
246245
0, vsg->pages, NULL);

drivers/infiniband/core/umem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
188188
sg_list_start = umem->sg_head.sgl;
189189

190190
while (npages) {
191-
ret = get_user_pages(current, current->mm, cur_base,
191+
ret = get_user_pages(cur_base,
192192
min_t(unsigned long, npages,
193193
PAGE_SIZE / sizeof (struct page *)),
194194
1, !umem->writable, page_list, vma_list);

drivers/infiniband/hw/mthca/mthca_memfree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
472472
goto out;
473473
}
474474

475-
ret = get_user_pages(current, current->mm, uaddr & PAGE_MASK, 1, 1, 0,
476-
pages, NULL);
475+
ret = get_user_pages(uaddr & PAGE_MASK, 1, 1, 0, pages, NULL);
477476
if (ret < 0)
478477
goto out;
479478

drivers/infiniband/hw/qib/qib_user_pages.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ static int __qib_get_user_pages(unsigned long start_page, size_t num_pages,
6666
}
6767

6868
for (got = 0; got < num_pages; got += ret) {
69-
ret = get_user_pages(current, current->mm,
70-
start_page + got * PAGE_SIZE,
69+
ret = get_user_pages(start_page + got * PAGE_SIZE,
7170
num_pages - got, 1, 1,
7271
p + got, NULL);
7372
if (ret < 0)

drivers/infiniband/hw/usnic/usnic_uiom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static int usnic_uiom_get_pages(unsigned long addr, size_t size, int writable,
144144
ret = 0;
145145

146146
while (npages) {
147-
ret = get_user_pages(current, current->mm, cur_base,
147+
ret = get_user_pages(cur_base,
148148
min_t(unsigned long, npages,
149149
PAGE_SIZE / sizeof(struct page *)),
150150
1, !writable, page_list, NULL);

drivers/media/pci/ivtv/ivtv-udma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr,
124124
}
125125

126126
/* Get user pages for DMA Xfer */
127-
err = get_user_pages_unlocked(current, current->mm,
128-
user_dma.uaddr, user_dma.page_count, 0, 1, dma->map);
127+
err = get_user_pages_unlocked(user_dma.uaddr, user_dma.page_count, 0,
128+
1, dma->map);
129129

130130
if (user_dma.page_count != err) {
131131
IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n",

drivers/media/pci/ivtv/ivtv-yuv.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,12 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
7575
ivtv_udma_get_page_info (&uv_dma, (unsigned long)args->uv_source, 360 * uv_decode_height);
7676

7777
/* Get user pages for DMA Xfer */
78-
y_pages = get_user_pages_unlocked(current, current->mm,
79-
y_dma.uaddr, y_dma.page_count, 0, 1,
80-
&dma->map[0]);
78+
y_pages = get_user_pages_unlocked(y_dma.uaddr,
79+
y_dma.page_count, 0, 1, &dma->map[0]);
8180
uv_pages = 0; /* silence gcc. value is set and consumed only if: */
8281
if (y_pages == y_dma.page_count) {
83-
uv_pages = get_user_pages_unlocked(current, current->mm,
84-
uv_dma.uaddr, uv_dma.page_count, 0, 1,
85-
&dma->map[y_pages]);
82+
uv_pages = get_user_pages_unlocked(uv_dma.uaddr,
83+
uv_dma.page_count, 0, 1, &dma->map[y_pages]);
8684
}
8785

8886
if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) {

drivers/media/v4l2-core/videobuf-dma-sg.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
181181
dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
182182
data, size, dma->nr_pages);
183183

184-
err = get_user_pages(current, current->mm,
185-
data & PAGE_MASK, dma->nr_pages,
184+
err = get_user_pages(data & PAGE_MASK, dma->nr_pages,
186185
rw == READ, 1, /* force */
187186
dma->pages, NULL);
188187

drivers/misc/mic/scif/scif_rma.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,6 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot,
13941394
}
13951395

13961396
pinned_pages->nr_pages = get_user_pages(
1397-
current,
1398-
mm,
13991397
(u64)addr,
14001398
nr_pages,
14011399
!!(prot & SCIF_PROT_WRITE),

drivers/misc/sgi-gru/grufault.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma,
198198
#else
199199
*pageshift = PAGE_SHIFT;
200200
#endif
201-
if (get_user_pages
202-
(current, current->mm, vaddr, 1, write, 0, &page, NULL) <= 0)
201+
if (get_user_pages(vaddr, 1, write, 0, &page, NULL) <= 0)
203202
return -EFAULT;
204203
*paddr = page_to_phys(page);
205204
put_page(page);

drivers/scsi/st.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4817,8 +4817,6 @@ static int sgl_map_user_pages(struct st_buffer *STbp,
48174817
/* Try to fault in all of the necessary pages */
48184818
/* rw==READ means read from drive, write into memory area */
48194819
res = get_user_pages_unlocked(
4820-
current,
4821-
current->mm,
48224820
uaddr,
48234821
nr_pages,
48244822
rw == READ,

drivers/video/fbdev/pvr2fb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
686686
if (!pages)
687687
return -ENOMEM;
688688

689-
ret = get_user_pages_unlocked(current, current->mm, (unsigned long)buf,
690-
nr_pages, WRITE, 0, pages);
689+
ret = get_user_pages_unlocked((unsigned long)buf, nr_pages, WRITE,
690+
0, pages);
691691

692692
if (ret < nr_pages) {
693693
nr_pages = ret;

drivers/virt/fsl_hypervisor.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,8 @@ static long ioctl_memcpy(struct fsl_hv_ioctl_memcpy __user *p)
244244

245245
/* Get the physical addresses of the source buffer */
246246
down_read(&current->mm->mmap_sem);
247-
num_pinned = get_user_pages(current, current->mm,
248-
param.local_vaddr - lb_offset, num_pages,
249-
(param.source == -1) ? READ : WRITE,
247+
num_pinned = get_user_pages(param.local_vaddr - lb_offset,
248+
num_pages, (param.source == -1) ? READ : WRITE,
250249
0, pages, NULL);
251250
up_read(&current->mm->mmap_sem);
252251

mm/frame_vector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int get_vaddr_frames(unsigned long start, unsigned int nr_frames,
5858
if (!(vma->vm_flags & (VM_IO | VM_PFNMAP))) {
5959
vec->got_ref = true;
6060
vec->is_pfns = false;
61-
ret = get_user_pages_locked(current, mm, start, nr_frames,
61+
ret = get_user_pages_locked(start, nr_frames,
6262
write, force, (struct page **)(vec->ptrs), &locked);
6363
goto out;
6464
}

mm/gup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,8 +936,10 @@ long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
936936
EXPORT_SYMBOL(get_user_pages_remote);
937937

938938
/*
939-
* This is the same as get_user_pages_remote() for the time
940-
* being.
939+
* This is the same as get_user_pages_remote(), just with a
940+
* less-flexible calling convention where we assume that the task
941+
* and mm being operated on are the current task's. We also
942+
* obviously don't pass FOLL_REMOTE in here.
941943
*/
942944
long get_user_pages6(unsigned long start, unsigned long nr_pages,
943945
int write, int force, struct page **pages,

mm/ksm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static inline bool ksm_test_exit(struct mm_struct *mm)
352352
/*
353353
* We use break_ksm to break COW on a ksm page: it's a stripped down
354354
*
355-
* if (get_user_pages(current, mm, addr, 1, 1, 1, &page, NULL) == 1)
355+
* if (get_user_pages(addr, 1, 1, 1, &page, NULL) == 1)
356356
* put_page(page);
357357
*
358358
* but taking great care only to touch a ksm page, in a VM_MERGEABLE vma,

mm/mempolicy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,12 +844,12 @@ static void get_policy_nodemask(struct mempolicy *p, nodemask_t *nodes)
844844
}
845845
}
846846

847-
static int lookup_node(struct mm_struct *mm, unsigned long addr)
847+
static int lookup_node(unsigned long addr)
848848
{
849849
struct page *p;
850850
int err;
851851

852-
err = get_user_pages(current, mm, addr & PAGE_MASK, 1, 0, 0, &p, NULL);
852+
err = get_user_pages(addr & PAGE_MASK, 1, 0, 0, &p, NULL);
853853
if (err >= 0) {
854854
err = page_to_nid(p);
855855
put_page(p);
@@ -904,7 +904,7 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask,
904904

905905
if (flags & MPOL_F_NODE) {
906906
if (flags & MPOL_F_ADDR) {
907-
err = lookup_node(mm, addr);
907+
err = lookup_node(addr);
908908
if (err < 0)
909909
goto out;
910910
*policy = err;

net/ceph/pagevec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct page **ceph_get_direct_page_vector(const void __user *data,
2424
return ERR_PTR(-ENOMEM);
2525

2626
while (got < num_pages) {
27-
rc = get_user_pages_unlocked(current, current->mm,
27+
rc = get_user_pages_unlocked(
2828
(unsigned long)data + ((unsigned long)got * PAGE_SIZE),
2929
num_pages - got, write_page, 0, pages + got);
3030
if (rc < 0)

virt/kvm/kvm_main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,15 +1264,16 @@ unsigned long kvm_vcpu_gfn_to_hva_prot(struct kvm_vcpu *vcpu, gfn_t gfn, bool *w
12641264
return gfn_to_hva_memslot_prot(slot, gfn, writable);
12651265
}
12661266

1267-
static int get_user_page_nowait(struct task_struct *tsk, struct mm_struct *mm,
1268-
unsigned long start, int write, struct page **page)
1267+
static int get_user_page_nowait(unsigned long start, int write,
1268+
struct page **page)
12691269
{
12701270
int flags = FOLL_TOUCH | FOLL_NOWAIT | FOLL_HWPOISON | FOLL_GET;
12711271

12721272
if (write)
12731273
flags |= FOLL_WRITE;
12741274

1275-
return __get_user_pages(tsk, mm, start, 1, flags, page, NULL, NULL);
1275+
return __get_user_pages(current, current->mm, start, 1, flags, page,
1276+
NULL, NULL);
12761277
}
12771278

12781279
static inline int check_user_page_hwpoison(unsigned long addr)
@@ -1334,8 +1335,7 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault,
13341335

13351336
if (async) {
13361337
down_read(&current->mm->mmap_sem);
1337-
npages = get_user_page_nowait(current, current->mm,
1338-
addr, write_fault, page);
1338+
npages = get_user_page_nowait(addr, write_fault, page);
13391339
up_read(&current->mm->mmap_sem);
13401340
} else
13411341
npages = __get_user_pages_unlocked(current, current->mm, addr, 1,

0 commit comments

Comments
 (0)