mm, gup: introduce concept of "foreign" get_user_pages()
Subsystems (35)
PATCH 1/1 mm, gup: introduce concept of "foreign" get_user_pages()
Just sending an update to this one patch instead of resending the entire series.
Jan Kara suggested that we just change get_user_pages()'s prototype to remove tsk/mm instead of introducing a separate get_user_pages_current(). Also, we moved the "_foreign" in get_user_pages_foreign() to the end to be more consistent with the "_unlocked" version.
This approach will break any new users of get_user_pages() which try to pass a tsk/mm, but Jan doesn't think these are frequent enough to be a concern. This passes an allyesconfig on 4.4, at least.
As always, any acks on this approach would be much appreciated. This is the largest swath of non-x86 code that protection keys touches, and I'm sure the x86 maintainers would appreciate seeing some acks from folks on it.
---
From: Dave Hansen <[email protected]>
For protection keys, we need to understand whether protections should be enforced in software or not. In general, we enforce protections when working on our own task, but not when on others. We call these "current" and "foreign" operations.
This patch introduces a new get_user_pages() variant:
get_user_pages_foreign()
The plain get_user_pages() can no longer be used on mm/tasks other than 'current/current->mm', which is by far the most common way it is called. Using it makes a few of the call sites look a bit nicer.
get_user_pages_foreign() is a replacement for when get_user_pages() is called on non-current tsk/mm.
This also switches get_user_pages_unlocked() over to be like get_user_pages() and not take a tsk/mm. If someone wants the get_user_pages_unlocked() behavior with a non-current tsk/mm, they just have to use __get_user_pages_unlocked() directly.
---
b/arch/cris/arch-v32/drivers/cryptocop.c | 8 --- b/arch/ia64/kernel/err_inject.c | 3 - b/arch/mips/mm/gup.c | 3 - b/arch/s390/mm/gup.c | 4 - b/arch/sh/mm/gup.c | 2 b/arch/sparc/mm/gup.c | 2 b/arch/x86/mm/gup.c | 2 b/arch/x86/mm/mpx.c | 4 - b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 - b/drivers/gpu/drm/i915/i915_gem_userptr.c | 2 b/drivers/gpu/drm/radeon/radeon_ttm.c | 3 - b/drivers/gpu/drm/via/via_dmablit.c | 3 - b/drivers/infiniband/core/umem.c | 2 b/drivers/infiniband/core/umem_odp.c | 8 +-- b/drivers/infiniband/hw/mthca/mthca_memfree.c | 3 - b/drivers/infiniband/hw/qib/qib_user_pages.c | 3 - b/drivers/infiniband/hw/usnic/usnic_uiom.c | 2 b/drivers/media/pci/ivtv/ivtv-udma.c | 4 - b/drivers/media/pci/ivtv/ivtv-yuv.c | 10 +--- b/drivers/media/v4l2-core/videobuf-dma-sg.c | 3 - b/drivers/misc/mic/scif/scif_rma.c | 2 b/drivers/misc/sgi-gru/grufault.c | 3 - b/drivers/scsi/st.c | 2 b/drivers/staging/rdma/hfi1/user_pages.c | 3 - b/drivers/staging/rdma/ipath/ipath_user_pages.c | 3 - b/drivers/video/fbdev/pvr2fb.c | 4 - b/drivers/virt/fsl_hypervisor.c | 5 -- b/fs/exec.c | 8 ++- b/include/linux/mm.h | 23 +++++----- b/kernel/events/uprobes.c | 4 - b/mm/frame_vector.c | 2 b/mm/gup.c | 51 +++++++++++++++--------- b/mm/ksm.c | 2 b/mm/memory.c | 2 b/mm/mempolicy.c | 6 +- b/mm/nommu.c | 35 +++++++++------- b/mm/process_vm_access.c | 6 +- b/mm/util.c | 4 - b/net/ceph/pagevec.c | 2 b/security/tomoyo/domain.c | 9 +++- b/virt/kvm/async_pf.c | 2 b/virt/kvm/kvm_main.c | 13 ++---- 42 files changed, 135 insertions(+), 130 deletions(-)
arch/mips/mm/gup.c renamed from arch/mips/mm/gup.c~get_current_user_pages +1 -2
@@ -301,8 +301,7 @@ slow_irqon: start += nr <<PAGE_SHIFT ; pages += nr; - ret =get_user_pages_unlocked (current, mm, start, - (end - start) >>PAGE_SHIFT , + ret =get_user_pages_unlocked (start, (end - start) >>PAGE_SHIFT , write,0 , pages);/* Have to be a bit careful with return values */
arch/s390/mm/gup.c renamed from arch/s390/mm/gup.c~get_current_user_pages +1 -3
@@ -230,7 +230,6 @@ int __get_user_pages_fast(unsigned longint get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages) { -struct mm_struct *mm = current->mm;int nr, ret; start &=PAGE_MASK ;
@@ -241,8 +240,7 @@ int get_user_pages_fast(unsigned long st/* Try to get the remaining pages with get_user_pages */ start += nr <<PAGE_SHIFT ; pages += nr; - ret =get_user_pages_unlocked (current, mm, start, - nr_pages - nr, write,0 , pages); + ret =get_user_pages_unlocked (start, nr_pages - nr, write,0 , pages);/* Have to be a bit careful with return values */ if (nr >0 ) ret = (ret <0 ) ? nr : ret + nr;
arch/sh/mm/gup.c renamed from arch/sh/mm/gup.c~get_current_user_pages +1 -1
@@ -257,7 +257,7 @@ slow_irqon: start += nr <<PAGE_SHIFT ; pages += nr; - ret =get_user_pages_unlocked (current, mm, start, + ret =get_user_pages_unlocked (start, (end - start) >>PAGE_SHIFT , write,0 , pages);/* Have to be a bit careful with return values */
arch/sparc/mm/gup.c renamed from arch/sparc/mm/gup.c~get_current_user_pages +1 -1
@@ -249,7 +249,7 @@ slow: start += nr <<PAGE_SHIFT ; pages += nr; - ret =get_user_pages_unlocked (current, mm, start, + ret =get_user_pages_unlocked (start, (end - start) >>PAGE_SHIFT , write,0 , pages);/* Have to be a bit careful with return values */
arch/x86/mm/gup.c renamed from arch/x86/mm/gup.c~get_current_user_pages +1 -1
@@ -386,7 +386,7 @@ slow_irqon: start += nr <<PAGE_SHIFT ; pages += nr; - ret =get_user_pages_unlocked (current, mm, start, + ret =get_user_pages_unlocked (start, (end - start) >>PAGE_SHIFT , write,0 , pages);
arch/x86/mm/mpx.c renamed from arch/x86/mm/mpx.c~get_current_user_pages +2 -2
@@ -546,8 +546,8 @@ static int mpx_resolve_fault(long __userint nr_pages =1 ;int force =0 ; - gup_ret =get_user_pages (current, current->mm, (unsigned long )addr, - nr_pages, write, force,NULL ,NULL ); + gup_ret =get_user_pages ((unsigned long )addr, nr_pages, write, + force,NULL ,NULL );/* * get_user_pages() returns number of pages gotten. * 0 means we failed to fault in and get anything,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c renamed from drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c~get_current_user_pages +1 -2
@@ -518,8 +518,7 @@ static int amdgpu_ttm_tt_pin_userptr(struint64_t userptr = gtt->userptr + pinned *PAGE_SIZE ;struct page **pages = ttm->pages + pinned; - r =get_user_pages (current, current->mm, userptr, num_pages, - write,0 , pages,NULL ); + r =get_user_pages (userptr, num_pages, write,0 , pages,NULL );if (r <0 ) goto release_pages;
drivers/gpu/drm/i915/i915_gem_userptr.c renamed from drivers/gpu/drm/i915/i915_gem_userptr.c~get_current_user_pages +1 -1
@@ -584,7 +584,7 @@ __i915_gem_userptr_get_pages_worker(strudown_read (&mm->mmap_sem);while (pinned < npages) { - ret = get_user_pages(work->task, mm, + ret = get_user_pages_foreign(work->task, mm, obj->userptr.ptr + pinned * PAGE_SIZE, npages - pinned, !obj->userptr.read_only, 0,
drivers/gpu/drm/radeon/radeon_ttm.c renamed from drivers/gpu/drm/radeon/radeon_ttm.c~get_current_user_pages +1 -2
@@ -554,8 +554,7 @@ static int radeon_ttm_tt_pin_userptr(struint64_t userptr = gtt->userptr + pinned *PAGE_SIZE ;struct page **pages = ttm->pages + pinned; - r =get_user_pages (current, current->mm, userptr, num_pages, - write,0 , pages,NULL ); + r =get_user_pages (userptr, num_pages, write,0 , pages,NULL );if (r <0 ) goto release_pages;
drivers/gpu/drm/via/via_dmablit.c renamed from drivers/gpu/drm/via/via_dmablit.c~get_current_user_pages +1 -2
@@ -239,8 +239,7 @@ via_lock_all_dma_pages(drm_via_sg_info_tif (NULL == vsg->pages)return -ENOMEM ;down_read (¤t->mm->mmap_sem); - ret =get_user_pages (current, current->mm, - (unsigned long )xfer->mem_addr, + ret =get_user_pages ((unsigned long )xfer->mem_addr, vsg->num_pages, (vsg->direction ==DMA_FROM_DEVICE ),0 , vsg->pages,NULL );
drivers/infiniband/core/umem.c renamed from drivers/infiniband/core/umem.c~get_current_user_pages +1 -1
@@ -188,7 +188,7 @@ struct ib_umem *ib_umem_get(struct ib_uc sg_list_start = umem->sg_head.sgl;while (npages) { - ret =get_user_pages (current, current->mm, cur_base, + ret =get_user_pages (cur_base, min_t(unsigned long, npages,PAGE_SIZE /sizeof (struct page *)),1 , !umem->writable, page_list, vma_list);
drivers/infiniband/core/umem_odp.c renamed from drivers/infiniband/core/umem_odp.c~get_current_user_pages +4 -4
@@ -572,10 +572,10 @@ int ib_umem_odp_map_dma_pages(struct ib_* complex (and doesn't gain us much performance in most use * cases). */ - npages =get_user_pages (owning_process, owning_mm, user_virt, - gup_num_pages, - access_mask &ODP_WRITE_ALLOWED_BIT ,0 , - local_page_list,NULL ); + npages =get_user_pages_foreign (owning_process, owning_mm, + user_virt, gup_num_pages, + access_mask &ODP_WRITE_ALLOWED_BIT , +0 , local_page_list,NULL );up_read (&owning_mm->mmap_sem);if (npages <0 )
drivers/infiniband/hw/mthca/mthca_memfree.c renamed from drivers/infiniband/hw/mthca/mthca_memfree.c~get_current_user_pages +1 -2
@@ -472,8 +472,7 @@ int mthca_map_user_db(struct mthca_dev * goto out; } - ret =get_user_pages (current, current->mm, uaddr &PAGE_MASK ,1 ,1 ,0 , - pages,NULL ); + ret =get_user_pages (uaddr &PAGE_MASK ,1 ,1 ,0 , pages,NULL );if (ret <0 ) goto out;
drivers/infiniband/hw/qib/qib_user_pages.c renamed from drivers/infiniband/hw/qib/qib_user_pages.c~get_current_user_pages +1 -2
@@ -66,8 +66,7 @@ static int __qib_get_user_pages(unsigned }for (got =0 ; got < num_pages; got += ret) { - ret =get_user_pages (current, current->mm, - start_page + got *PAGE_SIZE , + ret =get_user_pages (start_page + got *PAGE_SIZE , num_pages - got,1 ,1 , p + got,NULL );if (ret <0 )
drivers/infiniband/hw/usnic/usnic_uiom.c renamed from drivers/infiniband/hw/usnic/usnic_uiom.c~get_current_user_pages +1 -1
@@ -144,7 +144,7 @@ static int usnic_uiom_get_pages(unsigned ret =0 ;while (npages) { - ret =get_user_pages (current, current->mm, cur_base, + ret =get_user_pages (cur_base, min_t(unsigned long, npages,PAGE_SIZE /sizeof (struct page *)),1 , !writable, page_list,NULL );
drivers/media/pci/ivtv/ivtv-udma.c renamed from drivers/media/pci/ivtv/ivtv-udma.c~get_current_user_pages +2 -2
@@ -124,8 +124,8 @@ int ivtv_udma_setup(struct ivtv *itv, un }/* Get user pages for DMA Xfer */ - err =get_user_pages_unlocked (current, current->mm, - user_dma.uaddr, user_dma.page_count,0 ,1 , dma->map); + err =get_user_pages_unlocked (user_dma.uaddr, user_dma.page_count,0 , +1 , dma->map);if (user_dma.page_count != err) { IVTV_DEBUG_WARN("failed to map user pages, returned %d instead of %d\n",
drivers/media/pci/ivtv/ivtv-yuv.c renamed from drivers/media/pci/ivtv/ivtv-yuv.c~get_current_user_pages +4 -6
@@ -75,14 +75,12 @@ static int ivtv_yuv_prep_user_dma(structivtv_udma_get_page_info (&uv_dma, (unsigned long )args->uv_source,360 * uv_decode_height);/* Get user pages for DMA Xfer */ - y_pages =get_user_pages_unlocked (current, current->mm, - y_dma.uaddr, y_dma.page_count,0 ,1 , - &dma->map[0 ]); + y_pages =get_user_pages_unlocked (y_dma.uaddr, + y_dma.page_count,0 ,1 , &dma->map[0 ]); uv_pages =0 ;/* silence gcc. value is set and consumed only if: */ if (y_pages == y_dma.page_count) { - uv_pages =get_user_pages_unlocked (current, current->mm, - uv_dma.uaddr, uv_dma.page_count,0 ,1 , - &dma->map[y_pages]); + uv_pages =get_user_pages_unlocked (uv_dma.uaddr, + uv_dma.page_count,0 ,1 , &dma->map[y_pages]); }if (y_pages != y_dma.page_count || uv_pages != uv_dma.page_count) {
drivers/media/v4l2-core/videobuf-dma-sg.c renamed from drivers/media/v4l2-core/videobuf-dma-sg.c~get_current_user_pages +1 -2
@@ -181,8 +181,7 @@ static int videobuf_dma_init_user_lockeddprintk (1 ,"init user [0x%lx+0x%lx => %d pages]\n" , data, size, dma->nr_pages); - err =get_user_pages (current, current->mm, - data &PAGE_MASK , dma->nr_pages, + err =get_user_pages (data &PAGE_MASK , dma->nr_pages, rw ==READ ,1 ,/* force */ dma->pages,NULL );
drivers/misc/sgi-gru/grufault.c renamed from drivers/misc/sgi-gru/grufault.c~get_current_user_pages +1 -2
@@ -198,8 +198,7 @@ static int non_atomic_pte_lookup(struct#else *pageshift =PAGE_SHIFT ;#endif -if (get_user_pages - (current, current->mm, vaddr,1 , write,0 , &page,NULL ) <=0 ) +if (get_user_pages (vaddr,1 , write,0 , &page,NULL ) <=0 )return -EFAULT ; *paddr =page_to_phys (page);put_page (page);
drivers/scsi/st.c renamed from drivers/scsi/st.c~get_current_user_pages +0 -2
@@ -4817,8 +4817,6 @@ static int sgl_map_user_pages(struct st_/* Try to fault in all of the necessary pages */ /* rw==READ means read from drive, write into memory area */ res = get_user_pages_unlocked( - current, - current->mm, uaddr, nr_pages, rw == READ,
drivers/video/fbdev/pvr2fb.c renamed from drivers/video/fbdev/pvr2fb.c~get_current_user_pages +2 -2
@@ -686,8 +686,8 @@ static ssize_t pvr2fb_write(struct fb_inif (!pages)return -ENOMEM ; - ret =get_user_pages_unlocked (current, current->mm, (unsigned long )buf, - nr_pages,WRITE ,0 , pages); + ret =get_user_pages_unlocked ((unsigned long )buf, nr_pages,WRITE , +0 , pages);if (ret < nr_pages) { nr_pages = ret;
drivers/virt/fsl_hypervisor.c renamed from drivers/virt/fsl_hypervisor.c~get_current_user_pages +2 -3
@@ -244,9 +244,8 @@ static long ioctl_memcpy(struct fsl_hv_i/* Get the physical addresses of the source buffer */ down_read (¤t->mm->mmap_sem); - num_pinned =get_user_pages (current, current->mm, - param.local_vaddr - lb_offset, num_pages, - (param.source ==-1 ) ?READ :WRITE , + num_pinned =get_user_pages (param.local_vaddr - lb_offset, + num_pages, (param.source ==-1 ) ?READ :WRITE ,0 , pages,NULL );up_read (¤t->mm->mmap_sem);
fs/exec.c renamed from fs/exec.c~get_current_user_pages +6 -2
@@ -198,8 +198,12 @@ static struct page *get_arg_page(struct return NULL; }#endif - ret =get_user_pages (current, bprm->mm, pos, -1 , write,1 , &page,NULL ); +/* +* We are doing an exec(). 'current' is the process +* doing the exec and bprm->mm is the new process's mm. +*/ + ret =get_user_pages_foreign (current, bprm->mm, pos,1 , write, +1 , &page,NULL );if (ret <=0 )return NULL ;
include/linux/mm.h renamed from include/linux/mm.h~get_current_user_pages +11 -12
@@ -1191,20 +1191,19 @@ long __get_user_pages(struct task_struct unsigned long start, unsigned long nr_pages, unsigned int foll_flags, struct page **pages, struct vm_area_struct **vmas, int *nonblocking); -long get_user_pages (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -int write,int force,struct page **pages, -struct vm_area_struct **vmas); -long get_user_pages_locked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, -int write,int force,struct page **pages, -int *locked); -long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, +long get_user_pages_foreign (struct task_struct *tsk,struct mm_struct *mm, +unsigned long start,unsigned long nr_pages, +int write,int force,struct page **pages, +struct vm_area_struct **vmas); +long get_user_pages (unsigned long start,unsigned long nr_pages, +int write,int force,struct page **pages, +struct vm_area_struct **vmas); +long get_user_pages_locked (unsigned long start,unsigned long nr_pages, +int write,int force,struct page **pages,int *locked); +long __get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages,unsigned int gup_flags); -long get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, +long get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages);int get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages);
kernel/events/uprobes.c renamed from kernel/events/uprobes.c~get_current_user_pages +2 -2
@@ -298,7 +298,7 @@ int uprobe_write_opcode(struct mm_struct retry:/* Read the page with vaddr into memory */ - ret =get_user_pages (NULL , mm, vaddr,1 ,0 ,1 , &old_page, &vma); + ret =get_user_pages_foreign (NULL , mm, vaddr,1 ,0 ,1 , &old_page, &vma);if (ret <=0 )return ret;
@@ -1699,7 +1699,7 @@ static int is_trap_at_addr(struct mm_strif (likely (result ==0 )) goto out; - result =get_user_pages (NULL , mm, vaddr,1 ,0 ,1 , &page,NULL ); + result =get_user_pages (vaddr,1 ,0 ,1 , &page,NULL );if (result <0 )return result;
mm/frame_vector.c renamed from mm/frame_vector.c~get_current_user_pages +1 -1
@@ -58,7 +58,7 @@ int get_vaddr_frames(unsigned long startif (!(vma->vm_flags & (VM_IO |VM_PFNMAP ))) { vec->got_ref = true; vec->is_pfns = false; - ret =get_user_pages_locked (current, mm, start, nr_frames, + ret =get_user_pages_locked (start, nr_frames, write, force, (struct page **)(vec->ptrs), &locked); goto out; }
mm/gup.c renamed from mm/gup.c~get_current_user_pages +33 -18
116 lines not on this page · raw message
mm/memory.c renamed from mm/memory.c~get_current_user_pages +1 -1
@@ -3659,7 +3659,7 @@ static int __access_remote_vm(struct tasvoid *maddr;struct page *page =NULL ; - ret =get_user_pages (tsk, mm, addr,1 , + ret =get_user_pages_foreign (tsk, mm, addr,1 , write,1 , &page, &vma);if (ret <=0 ) {#ifndef CONFIG_HAVE_IOREMAP_PROT
mm/mempolicy.c renamed from mm/mempolicy.c~get_current_user_pages +3 -3
@@ -813,12 +813,12 @@ static void get_policy_nodemask(struct m } } -static int lookup_node (struct mm_struct *mm,unsigned long addr) +static int lookup_node (unsigned long addr) {struct page *p;int err; - err =get_user_pages (current, mm, addr &PAGE_MASK ,1 ,0 ,0 , &p,NULL ); + err =get_user_pages (addr &PAGE_MASK ,1 ,0 ,0 , &p,NULL );if (err >=0 ) { err =page_to_nid (p);put_page (p);
@@ -873,7 +873,7 @@ static long do_get_mempolicy(int *policyif (flags &MPOL_F_NODE ) {if (flags &MPOL_F_ADDR ) { - err =lookup_node (mm, addr); + err =lookup_node (addr);if (err <0 ) goto out; *policy = err;
mm/nommu.c renamed from mm/nommu.c~get_current_user_pages +20 -15
@@ -182,7 +182,7 @@ finish_or_fault:* slab page or a secondary page from a compound page * - don't permit access to VMAs that don't support it, such as I/O mappings */ -long get_user_pages (struct task_struct *tsk,struct mm_struct *mm, +long get_user_pages_foreign (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages,struct vm_area_struct **vmas)
@@ -197,37 +197,42 @@ long get_user_pages(struct task_struct *return __get_user_pages (tsk, mm, start, nr_pages, flags, pages, vmas,NULL ); } -EXPORT_SYMBOL (get_user_pages); +EXPORT_SYMBOL (get_user_pages_foreign); -long get_user_pages_locked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, +long get_user_pages_locked (unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages,int *locked) { -return get_user_pages (tsk, mm, start, nr_pages, write, force, - pages,NULL ); +return get_user_pages (start, nr_pages, write, + force, pages,NULL ); }EXPORT_SYMBOL (get_user_pages_locked); -long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, +long get_user_pages (unsigned long start,unsigned long nr_pages, +int write,int force,struct page **pages, +struct vm_area_struct **vmas) +{ +return get_user_pages_foreign (current, current->mm, start, nr_pages, + write, force, pages, vmas); +} +EXPORT_SYMBOL (get_user_pages); + +long __get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages,unsigned int gup_flags) {long ret; -down_read (&mm->mmap_sem); - ret =get_user_pages (tsk, mm, start, nr_pages, write, force, - pages,NULL ); -up_read (&mm->mmap_sem); +down_read (¤t->mm->mmap_sem); + ret =get_user_pages (start, nr_pages, write, force, pages,NULL ); +up_read (¤t->mm->mmap_sem);return ret; }EXPORT_SYMBOL (__get_user_pages_unlocked); -long get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, +long get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages) { -return __get_user_pages_unlocked (tsk, mm, start, nr_pages, write, +return __get_user_pages_unlocked (start, nr_pages, write, force, pages,0 ); }EXPORT_SYMBOL (get_user_pages_unlocked);
mm/process_vm_access.c renamed from mm/process_vm_access.c~get_current_user_pages +4 -2
@@ -99,8 +99,10 @@ static int process_vm_rw_single_vec(unsisize_t bytes;/* Get the pages we're interested in */ - pages =get_user_pages_unlocked (task, mm, pa, pages, - vm_write,0 , process_pages); +down_read (&mm->mmap_sem); + pages =get_user_pages_foreign (task, mm, pa, pages, vm_write, +0 , process_pages,NULL ); +up_read (&mm->mmap_sem);if (pages <=0 )return -EFAULT ;
mm/util.c renamed from mm/util.c~get_current_user_pages +1 -3
@@ -277,9 +277,7 @@ EXPORT_SYMBOL_GPL(__get_user_pages_fast)int __weak get_user_pages_fast (unsigned long start,int nr_pages,int write,struct page **pages) { -struct mm_struct *mm = current->mm; -return get_user_pages_unlocked (current, mm, start, nr_pages, - write,0 , pages); +return get_user_pages_unlocked (start, nr_pages, write,0 , pages); }EXPORT_SYMBOL_GPL (get_user_pages_fast);
net/ceph/pagevec.c renamed from net/ceph/pagevec.c~get_current_user_pages +1 -1
@@ -24,7 +24,7 @@ struct page **ceph_get_direct_page_vectoreturn ERR_PTR (-ENOMEM );while (got < num_pages) { - rc =get_user_pages_unlocked (current, current->mm, + rc =get_user_pages_unlocked ( (unsigned long )data + ((unsigned long )got *PAGE_SIZE ), num_pages - got, write_page,0 , pages + got);if (rc <0 )
security/tomoyo/domain.c renamed from security/tomoyo/domain.c~get_current_user_pages +8 -1
@@ -874,7 +874,14 @@ bool tomoyo_dump_page(struct linux_binpr }/* Same with get_arg_page(bprm, pos, 0) in fs/exec.c */ #ifdef CONFIG_MMU -if (get_user_pages (current, bprm->mm, pos,1 ,0 ,1 , &page,NULL ) <=0 ) +/* +* This is called at execve() time in order to dig around +* in the argv/environment of the new proceess +* (represented by bprm). 'current' is the process doing +* the execve(). +*/ +if (get_user_pages_foreign (current, bprm->mm, pos,1 , +0 ,1 , &page,NULL ) <=0 )return false;#else page = bprm->page[pos /PAGE_SIZE ];
virt/kvm/async_pf.c renamed from virt/kvm/async_pf.c~get_current_user_pages +1 -1
@@ -80,7 +80,7 @@ static void async_pf_execute(struct workmight_sleep (); -get_user_pages_unlocked (NULL , mm, addr,1 ,1 ,0 ,NULL ); +get_user_pages_unlocked (addr,1 ,1 ,0 ,NULL );kvm_async_page_present_sync (vcpu, apf);spin_lock (&vcpu->async_pf.lock);
virt/kvm/kvm_main.c renamed from virt/kvm/kvm_main.c~get_current_user_pages +6 -7
@@ -1274,15 +1274,16 @@ unsigned long kvm_vcpu_gfn_to_hva_prot(sreturn gfn_to_hva_memslot_prot (slot, gfn, writable); } -static int get_user_page_nowait (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,int write,struct page **page) +static int get_user_page_nowait (unsigned long start,int write, +struct page **page) {int flags =FOLL_TOUCH |FOLL_NOWAIT |FOLL_HWPOISON |FOLL_GET ;if (write) flags |=FOLL_WRITE ; -return __get_user_pages (tsk, mm, start,1 , flags, page,NULL ,NULL ); +return __get_user_pages (current, current->mm, start,1 , flags, page, +NULL ,NULL ); }static inline int check_user_page_hwpoison (unsigned long addr)
@@ -1344,12 +1345,10 @@ static int hva_to_pfn_slow(unsigned longif (async) {down_read (¤t->mm->mmap_sem); - npages =get_user_page_nowait (current, current->mm, - addr, write_fault, page); + npages =get_user_page_nowait (addr, write_fault, page);up_read (¤t->mm->mmap_sem); }else - npages =__get_user_pages_unlocked (current, current->mm, addr,1 , - write_fault,0 , page, + npages =__get_user_pages_unlocked (addr,1 , write_fault,0 , page,FOLL_TOUCH |FOLL_HWPOISON );if (npages !=1 )return npages;
arch/cris/arch-v32/drivers/cryptocop.c renamed from arch/cris/arch-v32/drivers/cryptocop.c~get_current_user_pages +2 -6
@@ -2719,9 +2719,7 @@ static int cryptocop_ioctl_process(struc/* Acquire the mm page semaphore. */ down_read (¤t->mm->mmap_sem); - err = get_user_pages(current, - current->mm, - (unsigned long int)(oper.indata + prev_ix), + err = get_user_pages((unsigned long int)(oper.indata + prev_ix), noinpages, 0, /* read access only for in data */ 0, /* no force */
@@ -2736,9 +2734,7 @@ static int cryptocop_ioctl_process(struc } noinpages = err;if (oper.do_cipher){ - err = get_user_pages(current, - current->mm, - (unsigned long int)oper.cipher_outdata, + err = get_user_pages((unsigned long int)oper.cipher_outdata, nooutpages, 1, /* write access for out data */ 0, /* no force */
arch/ia64/kernel/err_inject.c renamed from arch/ia64/kernel/err_inject.c~get_current_user_pages +1 -2
@@ -142,8 +142,7 @@ store_virtual_to_phys(struct device *devu64 virt_addr=simple_strtoull (buf,NULL ,16 );int ret; - ret =get_user_pages (current, current->mm, virt_addr, -1 ,VM_READ ,0 ,NULL ,NULL ); + ret =get_user_pages (virt_addr,1 ,VM_READ ,0 ,NULL ,NULL );if (ret<=0 ) {#ifdef ERR_INJ_DEBUG printk ("Virtual address %lx is not existing.\n" ,virt_addr);
drivers/staging/rdma/hfi1/user_pages.c renamed from drivers/staging/rdma/hfi1/user_pages.c~get_current_user_pages +1 -2
@@ -83,8 +83,7 @@ static int __hfi1_get_user_pages(unsigne }for (got =0 ; got < num_pages; got += ret) { - ret =get_user_pages (current, current->mm, - start_page + got *PAGE_SIZE , + ret =get_user_pages (start_page + got *PAGE_SIZE , num_pages - got,1 ,1 , p + got,NULL );if (ret <0 )
drivers/staging/rdma/ipath/ipath_user_pages.c renamed from drivers/staging/rdma/ipath/ipath_user_pages.c~get_current_user_pages +1 -2
@@ -70,8 +70,7 @@ static int __ipath_get_user_pages(unsign (unsigned long) num_pages, start_page);for (got =0 ; got < num_pages; got += ret) { - ret =get_user_pages (current, current->mm, - start_page + got *PAGE_SIZE , + ret =get_user_pages (start_page + got *PAGE_SIZE , num_pages - got,1 ,1 , p + got,NULL );if (ret <0 )
mm/ksm.c renamed from mm/ksm.c~get_current_user_pages +1 -1
@@ -352,7 +352,7 @@ static inline bool ksm_test_exit(struct/* * We use break_ksm to break COW on a ksm page: it's a stripped down * -* if (get_user_pages(current, mm, addr, 1, 1, 1, &page, NULL) == 1) +* if (get_user_pages(addr, 1, 1, 1, &page, NULL) == 1) * put_page(page); * * but taking great care only to touch a ksm page, in a VM_MERGEABLE vma,
drivers/misc/mic/scif/scif_rma.c renamed from drivers/misc/mic/scif/scif_rma.c~get_current_user_pages +0 -2
@@ -1394,8 +1394,6 @@ retry: } pinned_pages->nr_pages = get_user_pages( - current, - mm, (u64)addr, nr_pages, !!(prot & SCIF_PROT_WRITE),
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Dave Hansen
Just sending an update to this one patch instead of resending the entire series.
Jan Kara suggested that we just change get_user_pages()'s prototype to remove tsk/mm instead of introducing a separate
get_user_pages_current(). Also, we moved the "_foreign" inget_user_pages_foreign()to the end to be more consistent with the "_unlocked" version.
Thanks, and you could have blamed me too, not just Jan ;)
Quoted 9 lines
This approach will break any new users of
get_user_pages()which try to pass a tsk/mm, but Jan doesn't think these are frequent enough to be a concern. This passes an allyesconfig on 4.4, at least.As always, any acks on this approach would be much appreciated. This is the largest swath of non-x86 code that protection keys touches, and I'm sure the x86 maintainers would appreciate seeing some acks from folks on it.
This is finally a thorough review attempt, sorry I didn't catch some of the stuff below earlier.
Quoted 18 lines
---
From: Dave Hansen <[email protected]>
For protection keys, we need to understand whether protections should be enforced in software or not. In general, we enforce protections when working on our own task, but not when on others. We call these "current" and "foreign" operations.
This patch introduces a new
get_user_pages()variant:
get_user_pages_foreign()The plain
get_user_pages()can no longer be used on mm/tasks other than 'current/current->mm', which is by far the most common way it is called. Using it makes a few of the call sites look a bit nicer.
Quoted 7 lines
get_user_pages_foreign()is a replacement for whenget_user_pages()is called on non-current tsk/mm.This also switches
get_user_pages_unlocked()over to be likeget_user_pages()and not take a tsk/mm. If someone wants theget_user_pages_unlocked()behavior with a non-current tsk/mm, they just have to use__get_user_pages_unlocked()directly.
Hmm, but your patch actually changes __get_user_pages_unlocked() to also not include the task and mm params and assume current and current->mm? Wouldn't it be more consistent if __get_user_unlocked() stayed as it is? What you say above is true for {__}get_user_pages_locked.
Quoted 52 lines
Signed-off-by Dave Hansen <[email protected]>Cc Andrew Morton <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Andrea Arcangeli <[email protected]>Cc Naoya Horiguchi <[email protected]>---
b/arch/cris/arch-v32/drivers/cryptocop.c | 8 --- b/arch/ia64/kernel/err_inject.c | 3 - b/arch/mips/mm/gup.c | 3 - b/arch/s390/mm/gup.c | 4 - b/arch/sh/mm/gup.c | 2 b/arch/sparc/mm/gup.c | 2 b/arch/x86/mm/gup.c | 2 b/arch/x86/mm/mpx.c | 4 - b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 3 - b/drivers/gpu/drm/i915/i915_gem_userptr.c | 2 b/drivers/gpu/drm/radeon/radeon_ttm.c | 3 - b/drivers/gpu/drm/via/via_dmablit.c | 3 - b/drivers/infiniband/core/umem.c | 2 b/drivers/infiniband/core/umem_odp.c | 8 +-- b/drivers/infiniband/hw/mthca/mthca_memfree.c | 3 - b/drivers/infiniband/hw/qib/qib_user_pages.c | 3 - b/drivers/infiniband/hw/usnic/usnic_uiom.c | 2 b/drivers/media/pci/ivtv/ivtv-udma.c | 4 - b/drivers/media/pci/ivtv/ivtv-yuv.c | 10 +--- b/drivers/media/v4l2-core/videobuf-dma-sg.c | 3 - b/drivers/misc/mic/scif/scif_rma.c | 2 b/drivers/misc/sgi-gru/grufault.c | 3 - b/drivers/scsi/st.c | 2 b/drivers/staging/rdma/hfi1/user_pages.c | 3 - b/drivers/staging/rdma/ipath/ipath_user_pages.c | 3 - b/drivers/video/fbdev/pvr2fb.c | 4 - b/drivers/virt/fsl_hypervisor.c | 5 -- b/fs/exec.c | 8 ++- b/include/linux/mm.h | 23 +++++----- b/kernel/events/uprobes.c | 4 - b/mm/frame_vector.c | 2 b/mm/gup.c | 51 +++++++++++++++--------- b/mm/ksm.c | 2 b/mm/memory.c | 2 b/mm/mempolicy.c | 6 +- b/mm/nommu.c | 35 +++++++++------- b/mm/process_vm_access.c | 6 +- b/mm/util.c | 4 - b/net/ceph/pagevec.c | 2 b/security/tomoyo/domain.c | 9 +++- b/virt/kvm/async_pf.c | 2 b/virt/kvm/kvm_main.c | 13 ++---- 42 files changed, 135 insertions(+), 130 deletions(-)
[...]
Quoted 12 lines
kernel/events/uprobes.c renamed from kernel/events/uprobes.c~get_current_user_pages +1
-1@@ -298,7 +298,7 @@ int uprobe_write_opcode(struct mm_struct retry:/* Read the page with vaddr into memory */ - ret =get_user_pages (NULL , mm, vaddr,1 ,0 ,1 , &old_page, &vma); + ret =get_user_pages_foreign (NULL , mm, vaddr,1 ,0 ,1 , &old_page, &vma);if (ret <=0 )return ret;
kernel/events/uprobes.c static int is_trap_at_addr(struct mm_str · line 1702
Quoted 5 lines
kernel/events/uprobes.c renamed from kernel/events/uprobes.c~get_current_user_pages +1
-1@@ -1699,7 +1699,7 @@ static int is_trap_at_addr(struct mm_strif (likely (result ==0 )) goto out; - result =get_user_pages (NULL , mm, vaddr,1 ,0 ,1 , &page,NULL ); + result =get_user_pages (vaddr,1 ,0 ,1 , &page,NULL );
Yeah it seems that mm here is current->mm, and using current task instead of NULL affects AFAICS just the min/maj fault counting, but isn't it still a subtle and unintended functional change?
[...]
kernel/events/uprobes.c static int is_trap_at_addr(struct mm_str
Quoted 5 lines
kernel/events/uprobes.c renamed from kernel/events/uprobes.c~get_current_user_pages +1
-2-__always_inline long __get_user_pages_unlocked (struct task_struct *tsk,struct mm_struct *mm, -unsigned long start,unsigned long nr_pages, +__always_inline long __get_user_pages_unlocked (unsigned long start,unsigned long nr_pages,int write,int force,struct page **pages,unsigned int gup_flags)
This is the IMHO unneeded inconsistency what I mentioned above...
mm/process_vm_access.c static int process_vm_rw_single_vec(unsi · line 105
Quoted 13 lines
diff -puN
mm/process_vm_access.c~get_current_user_pagesmm/process_vm_access.cmm/process_vm_access.c renamed from mm/process_vm_access.c~get_current_user_pages +4
-2@@ -99,8 +99,10 @@ static int process_vm_rw_single_vec(unsisize_t bytes;/* Get the pages we're interested in */ - pages =get_user_pages_unlocked (task, mm, pa, pages, - vm_write,0 , process_pages); +down_read (&mm->mmap_sem); + pages =get_user_pages_foreign (task, mm, pa, pages, vm_write, +0 , process_pages,NULL ); +up_read (&mm->mmap_sem);
You could have simply used __get_user_pages_unlocked() if it wasn't changed.
mm/process_vm_access.c static void async_pf_execute(struct work · line 83
Quoted 6 lines
mm/process_vm_access.c renamed from mm/process_vm_access.c~get_current_user_pages +1
-1@@ -80,7 +80,7 @@ static void async_pf_execute(struct workmight_sleep (); -get_user_pages_unlocked (NULL , mm, addr,1 ,1 ,0 ,NULL ); +get_user_pages_unlocked (addr,1 ,1 ,0 ,NULL );
This seems to get mm from some structure where struct work is embedded, are you sure it's current->mm? I think it's another place for __get_user_pages_unlocked().
Quoted 6 lines
mm/process_vm_access.c renamed from mm/process_vm_access.c~get_current_user_pages +0
-1static inline int check_user_page_hwpoison (unsigned long addr)@@ -1344,12 +1345,10 @@ static int hva_to_pfn_slow(unsigned longif (async) {down_read (¤t->mm->mmap_sem); - npages = get_user_page_nowait(current, current->mm,
mm/process_vm_access.c static int hva_to_pfn_slow(unsigned long · line 1354
Quoted 10 lines
mm/process_vm_access.c renamed from mm/process_vm_access.c~get_current_user_pages +2
-3- addr, write_fault, page); + npages =get_user_page_nowait (addr, write_fault, page);up_read (¤t->mm->mmap_sem); }else - npages =__get_user_pages_unlocked (current, current->mm, addr,1 , - write_fault,0 , page, + npages =__get_user_pages_unlocked (addr,1 , write_fault,0 , page,FOLL_TOUCH |FOLL_HWPOISON );if (npages !=1 )return npages;
If you change __get_user_pages_unlocked() as I suggested, you could use get_user_pages_unlocked() here?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>