[PATCH 01/34] mm, gup: introduce concept of "foreign" get_user_pages()

2015-12-03 Thread Dave Hansen

From: Dave Hansen 

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 introduces two new get_user_pages() variants:

get_current_user_pages()
get_foreign_user_pages()

get_current_user_pages() is a drop-in replacement for when
get_user_pages() was called with (current, current->mm, ...) as
arguments.  Using it makes a few of the call sites look a bit
nicer.

get_foreign_user_pages() is a replacement for when
get_user_pages() is called on non-current tsk/mm.

We leave a stub get_user_pages() around with a __deprecated
warning.

Signed-off-by: Dave Hansen 
Cc: Andrew Morton 
Cc: Kirill A. Shutemov 
Cc: Andrea Arcangeli 
Cc: Naoya Horiguchi 
---

 b/arch/mips/mm/gup.c  |3 -
 b/arch/s390/mm/gup.c  |3 -
 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 |4 +-
 b/drivers/gpu/drm/i915/i915_gem_userptr.c |2 -
 b/drivers/gpu/drm/radeon/radeon_ttm.c |4 +-
 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/sgi-gru/grufault.c |3 -
 b/drivers/scsi/st.c   |2 -
 b/drivers/video/fbdev/pvr2fb.c|4 +-
 b/drivers/virt/fsl_hypervisor.c   |5 +-
 b/fs/exec.c   |8 +++-
 b/include/linux/mm.h  |   39 +--
 b/kernel/events/uprobes.c |4 +-
 b/mm/frame_vector.c   |2 -
 b/mm/gup.c|   51 --
 b/mm/memory.c |2 -
 b/mm/mempolicy.c  |6 +--
 b/mm/nommu.c  |   34 ++---
 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 +++---
 36 files changed, 147 insertions(+), 113 deletions(-)

diff -puN arch/mips/mm/gup.c~get_current_user_pages arch/mips/mm/gup.c
--- a/arch/mips/mm/gup.c~get_current_user_pages 2015-12-03 16:21:17.700311841 
-0800
+++ b/arch/mips/mm/gup.c2015-12-03 16:21:17.762314653 -0800
@@ -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 */
diff -puN arch/s390/mm/gup.c~get_current_user_pages arch/s390/mm/gup.c
--- a/arch/s390/mm/gup.c~get_current_user_pages 2015-12-03 16:21:17.701311886 
-0800
+++ b/arch/s390/mm/gup.c2015-12-03 16:21:17.762314653 -0800
@@ -241,8 +241,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;
diff -puN arch/sh/mm/gup.c~get_current_user_pages arch/sh/mm/gup.c
--- a/arch/sh/mm/gup.c~get_current_user_pages   2015-12-03 16:21:17.703311977 
-0800
+++ b/arch/sh/mm/gup.c  2015-12-03 16:21:17.762314653 -0800
@@ -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 */
diff -puN 

[PATCH 01/34] mm, gup: introduce concept of "foreign" get_user_pages()

2015-12-03 Thread Dave Hansen

From: Dave Hansen 

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 introduces two new get_user_pages() variants:

get_current_user_pages()
get_foreign_user_pages()

get_current_user_pages() is a drop-in replacement for when
get_user_pages() was called with (current, current->mm, ...) as
arguments.  Using it makes a few of the call sites look a bit
nicer.

get_foreign_user_pages() is a replacement for when
get_user_pages() is called on non-current tsk/mm.

We leave a stub get_user_pages() around with a __deprecated
warning.

Signed-off-by: Dave Hansen 
Cc: Andrew Morton 
Cc: Kirill A. Shutemov 
Cc: Andrea Arcangeli 
Cc: Naoya Horiguchi 
---

 b/arch/mips/mm/gup.c  |3 -
 b/arch/s390/mm/gup.c  |3 -
 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 |4 +-
 b/drivers/gpu/drm/i915/i915_gem_userptr.c |2 -
 b/drivers/gpu/drm/radeon/radeon_ttm.c |4 +-
 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/sgi-gru/grufault.c |3 -
 b/drivers/scsi/st.c   |2 -
 b/drivers/video/fbdev/pvr2fb.c|4 +-
 b/drivers/virt/fsl_hypervisor.c   |5 +-
 b/fs/exec.c   |8 +++-
 b/include/linux/mm.h  |   39 +--
 b/kernel/events/uprobes.c |4 +-
 b/mm/frame_vector.c   |2 -
 b/mm/gup.c|   51 --
 b/mm/memory.c |2 -
 b/mm/mempolicy.c  |6 +--
 b/mm/nommu.c  |   34 ++---
 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 +++---
 36 files changed, 147 insertions(+), 113 deletions(-)

diff -puN arch/mips/mm/gup.c~get_current_user_pages arch/mips/mm/gup.c
--- a/arch/mips/mm/gup.c~get_current_user_pages 2015-12-03 16:21:17.700311841 
-0800
+++ b/arch/mips/mm/gup.c2015-12-03 16:21:17.762314653 -0800
@@ -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 */
diff -puN arch/s390/mm/gup.c~get_current_user_pages arch/s390/mm/gup.c
--- a/arch/s390/mm/gup.c~get_current_user_pages 2015-12-03 16:21:17.701311886 
-0800
+++ b/arch/s390/mm/gup.c2015-12-03 16:21:17.762314653 -0800
@@ -241,8 +241,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;
diff -puN arch/sh/mm/gup.c~get_current_user_pages arch/sh/mm/gup.c
--- a/arch/sh/mm/gup.c~get_current_user_pages   2015-12-03 16:21:17.703311977 
-0800
+++ b/arch/sh/mm/gup.c  2015-12-03 16:21:17.762314653 -0800
@@ -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,