put_user_pages(): miscellaneous call sites
Subsystems (18)
cover put_user_pages(): miscellaneous call sites
From: John Hubbard <[email protected]>
Hi,
These are best characterized as miscellaneous conversions: many (not all) call sites that don't involve biovec or iov_iter, nor mm/. It also leaves out a few call sites that require some more work. These are mostly pretty simple ones.
It's probably best to send all of these via Andrew's -mm tree, assuming that there are no significant merge conflicts with ongoing work in other trees (which I doubt, given that these are small changes).
These patches apply to the latest linux.git. Patch #1 is also already in Andrew's tree, but given the broad non-linux-mm Cc list, I thought it would be more convenient to just include that patch here, so that people can use linux.git as the base--even though these are probably destined for linux-mm.
This is part a tree-wide conversion, as described in commit fc1d8e7cca2d ("mm: introduce put_user_page*(), placeholder versions"). That commit has an extensive description of the problem and the planned steps to solve it, but the highlites are:
1) Provide put_user_page*() routines, intended to be used for releasing pages that were pinned via get_user_pages*().
2) Convert all of the call sites for get_user_pages*(), to invoke put_user_page*(), instead of put_page(). This involves dozens of call sites, and will take some time.
3) After (2) is complete, use get_user_pages*() and put_user_page*() to implement tracking of these pages. This tracking will be separate from the existing struct page refcounting.
4) Use the tracking and identification of these pages, to implement special handling (especially in writeback paths) when the pages are backed by a filesystem.
And a few references, also from that commit:
[1] https://lwn.net/Articles/774411/ : "DMA and get_user_pages()"
[2] https://lwn.net/Articles/753027/ : "The Trouble with get_user_pages()"
Ira Weiny (1):
fs/binfmt_elf: convert put_page() to put_user_page*()
John Hubbard (33):
mm/gup: add make_dirty arg to put_user_pages_dirty_lock() net/rds: convert put_page() to put_user_page*() net/ceph: convert put_page() to put_user_page*() x86/kvm: convert put_page() to put_user_page*() drm/etnaviv: convert release_pages() to put_user_pages() drm/i915: convert put_page() to put_user_page*() drm/radeon: convert put_page() to put_user_page*() media/ivtv: convert put_page() to put_user_page*() media/v4l2-core/mm: convert put_page() to put_user_page*()
genwqe: convert put_page() to put_user_page*()
scif: convert put_page() to put_user_page*()
vmci: convert put_page() to put_user_page*()
rapidio: convert put_page() to put_user_page*()
oradax: convert put_page() to put_user_page*() staging/vc04_services: convert put_page() to put_user_page*() drivers/tee: convert put_page() to put_user_page*()
vfio: convert put_page() to put_user_page*() fbdev/pvr2fb: convert put_page() to put_user_page*()
fsl_hypervisor: convert put_page() to put_user_page*()
xen: convert put_page() to put_user_page*() fs/exec.c: convert put_page() to put_user_page*()
orangefs: convert put_page() to put_user_page*()
uprobes: convert put_page() to put_user_page*()
futex: convert put_page() to put_user_page*() mm/frame_vector.c: convert put_page() to put_user_page*() mm/gup_benchmark.c: convert put_page() to put_user_page*() mm/memory.c: convert put_page() to put_user_page*() mm/madvise.c: convert put_page() to put_user_page*() mm/process_vm_access.c: convert put_page() to put_user_page*()
crypt: convert put_page() to put_user_page*()
nfs: convert put_page() to put_user_page*()
goldfish_pipe: convert put_page() to put_user_page*() kernel/events/core.c: convert put_page() to put_user_page*()
arch/x86/kvm/svm.c | 4 +- crypto/af_alg.c | 7 +- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 4 +- drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 9 +- drivers/gpu/drm/radeon/radeon_ttm.c | 2 +- drivers/infiniband/core/umem.c | 5 +- drivers/infiniband/hw/hfi1/user_pages.c | 5 +- drivers/infiniband/hw/qib/qib_user_pages.c | 5 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 10 +- drivers/media/pci/ivtv/ivtv-udma.c | 14 +-- drivers/media/pci/ivtv/ivtv-yuv.c | 10 +- drivers/media/v4l2-core/videobuf-dma-sg.c | 3 +- drivers/misc/genwqe/card_utils.c | 17 +-- drivers/misc/mic/scif/scif_rma.c | 17 ++- drivers/misc/vmw_vmci/vmci_context.c | 2 +- drivers/misc/vmw_vmci/vmci_queue_pair.c | 11 +- drivers/platform/goldfish/goldfish_pipe.c | 9 +- drivers/rapidio/devices/rio_mport_cdev.c | 9 +- drivers/sbus/char/oradax.c | 2 +- .../interface/vchiq_arm/vchiq_2835_arm.c | 10 +- drivers/tee/tee_shm.c | 10 +- drivers/vfio/vfio_iommu_type1.c | 8 +- drivers/video/fbdev/pvr2fb.c | 3 +- drivers/virt/fsl_hypervisor.c | 7 +- drivers/xen/gntdev.c | 5 +- drivers/xen/privcmd.c | 7 +- fs/binfmt_elf.c | 2 +- fs/binfmt_elf_fdpic.c | 2 +- fs/exec.c | 2 +- fs/nfs/direct.c | 4 +- fs/orangefs/orangefs-bufmap.c | 7 +- include/linux/mm.h | 5 +- kernel/events/core.c | 2 +- kernel/events/uprobes.c | 6 +- kernel/futex.c | 10 +- mm/frame_vector.c | 4 +- mm/gup.c | 115 ++++++++---------- mm/gup_benchmark.c | 2 +- mm/madvise.c | 2 +- mm/memory.c | 2 +- mm/process_vm_access.c | 18 +-- net/ceph/pagevec.c | 8 +- net/rds/info.c | 5 +- net/rds/message.c | 2 +- net/rds/rdma.c | 15 ++- virt/kvm/kvm_main.c | 4 +- 47 files changed, 151 insertions(+), 266 deletions(-)
Signature · 1 line
2.22.0
PATCH 1/34 mm/gup: add make_dirty arg to put_user_pages_dirty_lock()
From: John Hubbard <[email protected]>
Provide more capable variation of put_user_pages_dirty_lock(), and delete put_user_pages_dirty(). This is based on the following:
1. Lots of call sites become simpler if a bool is passed into put_user_page*(), instead of making the call site choose which put_user_page*() variant to call.
2. Christoph Hellwig's observation that set_page_dirty_lock() is usually correct, and set_page_dirty() is usually a bug, or at least questionable, within a put_user_page*() calling chain.
This leads to the following API choices:
* put_user_pages_dirty_lock(page, npages, make_dirty)
* There is no put_user_pages_dirty(). You have to hand code that, in the rare case that it's required.
--- drivers/infiniband/core/umem.c | 5 +- drivers/infiniband/hw/hfi1/user_pages.c | 5 +- drivers/infiniband/hw/qib/qib_user_pages.c | 5 +- drivers/infiniband/hw/usnic/usnic_uiom.c | 5 +- drivers/infiniband/sw/siw/siw_mem.c | 10 +- include/linux/mm.h | 5 +- mm/gup.c | 115 +++++++++------------ 7 files changed, 58 insertions(+), 92 deletions(-)
drivers/infiniband/core/umem.c +1 -4
@@ -54,10 +54,7 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dfor_each_sg_page (umem->sg_head.sgl, &sg_iter, umem->sg_nents,0 ) { page =sg_page_iter_page (&sg_iter); -if (umem->writable && dirty) -put_user_pages_dirty_lock (&page,1 ); -else -put_user_page (page); +put_user_pages_dirty_lock (&page,1 , umem->writable && dirty); }sg_free_table (&umem->sg_head);
drivers/infiniband/hw/hfi1/user_pages.c +1 -4
@@ -118,10 +118,7 @@ int hfi1_acquire_user_pages(struct mm_struct *mm, unsigned long vaddr, size_t npvoid hfi1_release_user_pages (struct mm_struct *mm,struct page **p,size_t npages,bool dirty) { -if (dirty) -put_user_pages_dirty_lock (p, npages); -else -put_user_pages (p, npages); +put_user_pages_dirty_lock (p, npages, dirty);if (mm) {/* during close after signal, mm can be NULL */ atomic64_sub (npages, &mm->pinned_vm);
drivers/infiniband/hw/qib/qib_user_pages.c +1 -4
@@ -40,10 +40,7 @@static void __qib_release_user_pages (struct page **p,size_t num_pages,int dirty) { -if (dirty) -put_user_pages_dirty_lock (p, num_pages); -else -put_user_pages (p, num_pages); +put_user_pages_dirty_lock (p, num_pages, dirty); }/**
drivers/infiniband/hw/usnic/usnic_uiom.c +1 -4
@@ -75,10 +75,7 @@ static void usnic_uiom_put_pages(struct list_head *chunk_list, int dirty)for_each_sg (chunk->page_list, sg, chunk->nents, i) { page =sg_page (sg); pa =sg_phys (sg); -if (dirty) -put_user_pages_dirty_lock (&page,1 ); -else -put_user_page (page); +put_user_pages_dirty_lock (&page,1 , dirty);usnic_dbg ("pa: %pa\n" , &pa); }kfree (chunk);
drivers/infiniband/sw/siw/siw_mem.c +1 -9
@@ -63,15 +63,7 @@ struct siw_mem *siw_mem_id2obj(struct siw_device *sdev, int stag_index)static void siw_free_plist (struct siw_page_chunk *chunk,int num_pages,bool dirty) { -struct page **p = chunk->plist; - -while (num_pages--) { -if (!PageDirty (*p) && dirty) -put_user_pages_dirty_lock (p,1 ); -else -put_user_page (*p); - p++; - } +put_user_pages_dirty_lock (chunk->plist, num_pages, dirty); }void siw_umem_release (struct siw_umem *umem,bool dirty)
include/linux/mm.h +3 -2
@@ -1057,8 +1057,9 @@ static inline void put_user_page(struct page *page)put_page (page); } -void put_user_pages_dirty (struct page **pages,unsigned long npages); -void put_user_pages_dirty_lock (struct page **pages,unsigned long npages); +void put_user_pages_dirty_lock (struct page **pages,unsigned long npages, +bool make_dirty); +void put_user_pages (struct page **pages,unsigned long npages);#if defined(CONFIG_SPARSEMEM ) && !defined(CONFIG_SPARSEMEM_VMEMMAP )
mm/gup.c +50 -65
135 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH 2/34 net/rds: convert put_page() to put_user_page*()
In reply to [email protected]From: John Hubbard <[email protected]>
For pages that were retained via get_user_pages*(), release those pages via the new put_user_page*() routines, instead of via put_page() or release_pages().
This is part a tree-wide conversion, as described in commit fc1d8e7cca2d ("mm: introduce put_user_page*(), placeholder versions").
--- net/rds/info.c | 5 ++--- net/rds/message.c | 2 +- net/rds/rdma.c | 15 +++++++-------- 3 files changed, 10 insertions(+), 12 deletions(-)
net/rds/info.c +2 -3
@@ -162,7 +162,6 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval,struct rds_info_lengths lens;unsigned long nr_pages =0 ;unsigned long start; -unsigned long i;rds_info_func func;struct page **pages =NULL ;int ret;
@@ -235,8 +234,8 @@ int rds_info_getsockopt(struct socket *sock, int optname, char __user *optval, ret = -EFAULT ; out: -for (i =0 ; pages && i < nr_pages; i++) -put_page (pages[i]); +if (pages) +put_user_pages (pages, nr_pages);kfree (pages);return ret;
net/rds/message.c +1 -1
@@ -404,7 +404,7 @@ static int rds_message_zcopy_from_user(struct rds_message *rm, struct iov_iter *int i;for (i =0 ; i < rm->data.op_nents; i++) -put_page (sg_page (&rm->data.op_sg[i])); +put_user_page (sg_page (&rm->data.op_sg[i])); mmp = &rm->data.op_mmp_znotifier->z_mmp;mm_unaccount_pinned_pages (mmp); ret = -EFAULT ;
net/rds/rdma.c +7 -8
@@ -162,8 +162,7 @@ static int rds_pin_pages(unsigned long user_addr, unsigned int nr_pages, pages);if (ret >=0 && ret < nr_pages) { -while (ret--) -put_page (pages[ret]); +put_user_pages (pages, ret); ret = -EFAULT ; }
@@ -276,7 +275,7 @@ static int __rds_rdma_map(struct rds_sock *rs, struct rds_get_mr_args *args,if (IS_ERR (trans_private)) {for (i =0 ; i < nents; i++) -put_page (sg_page (&sg[i])); +put_user_page (sg_page (&sg[i]));kfree (sg); ret =PTR_ERR (trans_private); goto out;
@@ -464,9 +463,10 @@ void rds_rdma_free_op(struct rm_rdma_op *ro)* to local memory */ if (!ro->op_write) {WARN_ON (!page->mapping &&irqs_disabled ()); -set_page_dirty (page); +put_user_pages_dirty_lock (&page,1 , true); + }else { +put_user_page (page); } -put_page (page); }kfree (ro->op_notifier);
@@ -481,8 +481,7 @@ void rds_atomic_free_op(struct rm_atomic_op *ao)/* Mark page dirty if it was possibly modified, which * is the case for a RDMA_READ which copies from remote * to local memory */ -set_page_dirty (page); -put_page (page); +put_user_pages_dirty_lock (&page,1 , true);kfree (ao->op_notifier); ao->op_notifier =NULL ;
@@ -867,7 +866,7 @@ int rds_cmsg_atomic(struct rds_sock *rs, struct rds_message *rm,return ret; err:if (page) -put_page (page); +put_user_page (page); rm->atomic.op_active =0 ;kfree (rm->atomic.op_notifier);
Signature · 1 line
2.22.0
John Hubbard
reviewerQuoted 4 lines · On 8/1/19 7:16 PM, [email protected] wrote:
From: John Hubbard <[email protected]>
Hi,
Quoted 9 lines
These are best characterized as miscellaneous conversions: many (not all) call sites that don't involve biovec or
iov_iter, normm/. It also leaves out a few call sites that require some more work. These are mostly pretty simple ones.It's probably best to send all of these via Andrew's -mm tree, assuming that there are no significant merge conflicts with ongoing work in other trees (which I doubt, given that these are small changes).
In case anyone is wondering, this truncated series is due to a script failure:
git-send-email chokes when it hits email addresses whose names have a comma in them, as happened here with patch 0003.
Please disregard this set and reply to the other thread.
thanks,
Signature · 2 lines
John Hubbard NVIDIA
Quoted 4 lines · On Thu, Aug 01, 2019 at 07:16:19PM -0700, [email protected] wrote:
This is part a tree-wide conversion, as described in commit
fc1d8e7cca2d("mm: introduce put_user_page*(), placeholder versions"). That commit has an extensive description of the problem and the planned steps to solve it, but the highlites are:
That is one horridly mangled Changelog there :-/ It looks like it's partially duplicated.
Anyway; no objections to any of that, but I just wanted to mention that there are other problems with long term pinning that haven't been mentioned, notably they inhibit compaction.
A long time ago I proposed an interface to mark pages as pinned, such that we could run compaction before we actually did the pinning.
John Hubbard
reviewerQuoted 9 lines · Peter Zijlstra
Quoted 4 lines · On Thu, Aug 01, 2019 at 07:16:19PM -0700, [email protected] wrote:
This is part a tree-wide conversion, as described in commit
fc1d8e7cca2d("mm: introduce put_user_page*(), placeholder versions"). That commit has an extensive description of the problem and the planned steps to solve it, but the highlites are:That is one horridly mangled Changelog there :-/ It looks like it's partially duplicated.
Yeah. It took so long to merge that I think I was no longer able to actually see the commit description, after N readings. sigh
Quoted 8 lines
Anyway; no objections to any of that, but I just wanted to mention that there are other problems with long term pinning that haven't been mentioned, notably they inhibit compaction.
A long time ago I proposed an interface to mark pages as pinned, such that we could run compaction before we actually did the pinning.
This is all heading toward marking pages as pinned, so we should finally get there. I'll post the RFC for tracking pinned pages shortly.
thanks,
Signature · 2 lines
John Hubbard NVIDIA