linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: "Marciniszyn, Mike" <mike.marciniszyn@intel.com>
Cc: Jan Kara <jack@suse.cz>, LKML <linux-kernel@vger.kernel.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	infinipath <infinipath@intel.com>,
	Roland Dreier <roland@kernel.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>
Subject: Re: [PATCH 23/26] ib: Convert qib_get_user_pages() to get_user_pages_unlocked()
Date: Wed, 2 Oct 2013 17:28:11 +0200	[thread overview]
Message-ID: <20131002152811.GC32181@quack.suse.cz> (raw)
In-Reply-To: <32E1700B9017364D9B60AED9960492BC211AEF75@FMSMSX107.amr.corp.intel.com>

On Wed 02-10-13 14:54:59, Marciniszyn, Mike wrote:
> Thanks!!
> 
> I would like to test these two patches and also do the stable work for
> the deadlock as well.  Do you have these patches in a repo somewhere to
> save me a bit of work?
  I've pushed the patches to:
git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git
into the branch 'get_user_pages'.

> We had been working on an internal version of the deadlock portion of
> this patch that uses get_user_pages_fast() vs. the new
> get_user_pages_unlocked().
> 
> The risk of GUP fast is the loss of the "force" arg on GUP fast, which I
> don't see as significant give our use case.
  Yes. I was discussing with Roland some time ago whether the force
argument is needed and he said it is. So I kept the arguments of
get_user_pages() intact and just simplified the locking...

BTW: Infiniband still needs mmap_sem for modification of mm->pinned_vm. It
might be worthwhile to actually change that to atomic_long_t (only
kernel/events/core.c would need update besides infiniband) and avoid taking
mmap_sem in infiniband code altogether.

> Some nits on the subject and commit message:
> 1. use IB/qib, IB/ipath vs. ib
> 2. use the correct ipath vs. qib in the commit message text
  Sure will do. Thanks the quick reply and for comments.

								Honza
> > -----Original Message-----
> > From: Jan Kara [mailto:jack@suse.cz]
> > Sent: Wednesday, October 02, 2013 10:28 AM
> > To: LKML
> > Cc: linux-mm@kvack.org; Jan Kara; infinipath; Roland Dreier; linux-
> > rdma@vger.kernel.org
> > Subject: [PATCH 23/26] ib: Convert qib_get_user_pages() to
> > get_user_pages_unlocked()
> > 
> > Convert qib_get_user_pages() to use get_user_pages_unlocked().  This
> > shortens the section where we hold mmap_sem for writing and also removes
> > the knowledge about get_user_pages() locking from ipath driver. We also fix
> > a bug in testing pinned number of pages when changing the code.
> > 
> > CC: Mike Marciniszyn <infinipath@intel.com>
> > CC: Roland Dreier <roland@kernel.org>
> > CC: linux-rdma@vger.kernel.org
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> >  drivers/infiniband/hw/qib/qib_user_pages.c | 62 +++++++++++++----------------
> > -
> >  1 file changed, 26 insertions(+), 36 deletions(-)
> > 
> > diff --git a/drivers/infiniband/hw/qib/qib_user_pages.c
> > b/drivers/infiniband/hw/qib/qib_user_pages.c
> > index 2bc1d2b96298..57ce83c2d1d9 100644
> > --- a/drivers/infiniband/hw/qib/qib_user_pages.c
> > +++ b/drivers/infiniband/hw/qib/qib_user_pages.c
> > @@ -48,39 +48,55 @@ static void __qib_release_user_pages(struct page
> > **p, size_t num_pages,
> >  	}
> >  }
> > 
> > -/*
> > - * Call with current->mm->mmap_sem held.
> > +/**
> > + * qib_get_user_pages - lock user pages into memory
> > + * @start_page: the start page
> > + * @num_pages: the number of pages
> > + * @p: the output page structures
> > + *
> > + * This function takes a given start page (page aligned user virtual
> > + * address) and pins it and the following specified number of pages.
> > +For
> > + * now, num_pages is always 1, but that will probably change at some
> > +point
> > + * (because caller is doing expected sends on a single virtually
> > +contiguous
> > + * buffer, so we can do all pages at once).
> >   */
> > -static int __qib_get_user_pages(unsigned long start_page, size_t
> > num_pages,
> > -				struct page **p, struct vm_area_struct
> > **vma)
> > +int qib_get_user_pages(unsigned long start_page, size_t num_pages,
> > +		       struct page **p)
> >  {
> >  	unsigned long lock_limit;
> >  	size_t got;
> >  	int ret;
> > +	struct mm_struct *mm = current->mm;
> > 
> > +	down_write(&mm->mmap_sem);
> >  	lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
> > 
> > -	if (num_pages > lock_limit && !capable(CAP_IPC_LOCK)) {
> > +	if (mm->pinned_vm + num_pages > lock_limit &&
> > !capable(CAP_IPC_LOCK)) {
> > +		up_write(&mm->mmap_sem);
> >  		ret = -ENOMEM;
> >  		goto bail;
> >  	}
> > +	mm->pinned_vm += num_pages;
> > +	up_write(&mm->mmap_sem);
> > 
> >  	for (got = 0; got < num_pages; got += ret) {
> > -		ret = get_user_pages(current, current->mm,
> > -				     start_page + got * PAGE_SIZE,
> > -				     num_pages - got, 1, 1,
> > -				     p + got, vma);
> > +		ret = get_user_pages_unlocked(current, mm,
> > +					      start_page + got * PAGE_SIZE,
> > +					      num_pages - got, 1, 1,
> > +					      p + got);
> >  		if (ret < 0)
> >  			goto bail_release;
> >  	}
> > 
> > -	current->mm->pinned_vm += num_pages;
> > 
> >  	ret = 0;
> >  	goto bail;
> > 
> >  bail_release:
> >  	__qib_release_user_pages(p, got, 0);
> > +	down_write(&mm->mmap_sem);
> > +	mm->pinned_vm -= num_pages;
> > +	up_write(&mm->mmap_sem);
> >  bail:
> >  	return ret;
> >  }
> > @@ -117,32 +133,6 @@ dma_addr_t qib_map_page(struct pci_dev *hwdev,
> > struct page *page,
> >  	return phys;
> >  }
> > 
> > -/**
> > - * qib_get_user_pages - lock user pages into memory
> > - * @start_page: the start page
> > - * @num_pages: the number of pages
> > - * @p: the output page structures
> > - *
> > - * This function takes a given start page (page aligned user virtual
> > - * address) and pins it and the following specified number of pages.  For
> > - * now, num_pages is always 1, but that will probably change at some point
> > - * (because caller is doing expected sends on a single virtually contiguous
> > - * buffer, so we can do all pages at once).
> > - */
> > -int qib_get_user_pages(unsigned long start_page, size_t num_pages,
> > -		       struct page **p)
> > -{
> > -	int ret;
> > -
> > -	down_write(&current->mm->mmap_sem);
> > -
> > -	ret = __qib_get_user_pages(start_page, num_pages, p, NULL);
> > -
> > -	up_write(&current->mm->mmap_sem);
> > -
> > -	return ret;
> > -}
> > -
> >  void qib_release_user_pages(struct page **p, size_t num_pages)  {
> >  	if (current->mm) /* during close after signal, mm can be NULL */
> > --
> > 1.8.1.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2013-10-02 15:28 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-02 14:27 [PATCH 0/26] get_user_pages() cleanup Jan Kara
2013-10-02 14:27 ` [PATCH 01/26] cris: Convert cryptocop to use get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 02/26] ia64: Use get_user_pages_fast() in err_inject.c Jan Kara
2013-10-02 14:27 ` [PATCH 03/26] dma: Use get_user_pages_fast() in dma_pin_iovec_pages() Jan Kara
2013-10-02 14:27 ` [PATCH 04/26] drm: Convert via driver to use get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 05/26] omap3isp: Make isp_video_buffer_prepare_user() " Jan Kara
2013-10-02 19:41   ` Laurent Pinchart
2013-10-02 20:18     ` Jan Kara
2013-10-02 14:27 ` [PATCH 06/26] vmw_vmci: Convert driver to " Jan Kara
2013-10-02 14:27 ` [PATCH 07/26] st: Convert sgl_map_user_pages() " Jan Kara
2013-10-02 14:27 ` [PATCH 08/26] ced1401: Convert driver " Jan Kara
2013-10-02 14:27 ` [PATCH 09/26] crystalhd: Convert crystalhd_map_dio() " Jan Kara
2013-10-02 14:27 ` [PATCH 10/26] lustre: Convert ll_get_user_pages() " Jan Kara
2013-10-05  6:27   ` Dilger, Andreas
2013-10-02 14:27 ` [PATCH 11/26] sep: Convert sep_lock_user_pages() to get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 12/26] pvr2fb: Convert pvr2fb_write() to use get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 13/26] fsl_hypervisor: Convert ioctl_memcpy() " Jan Kara
2013-10-04  2:38   ` Timur Tabi
2013-10-02 14:27 ` [PATCH 14/26] nfs: Convert direct IO " Jan Kara
2013-10-02 14:27 ` [PATCH 15/26] ceph: Convert ceph_get_direct_page_vector() to get_user_pages_fast() Jan Kara
2013-10-02 14:27 ` [PATCH 16/26] mm: Provide get_user_pages_unlocked() Jan Kara
2013-10-02 16:25   ` Christoph Hellwig
2013-10-02 16:28   ` KOSAKI Motohiro
2013-10-02 19:39     ` Jan Kara
2013-10-02 14:27 ` [PATCH 17/26] kvm: Use get_user_pages_unlocked() in async_pf_execute() Jan Kara
2013-10-02 14:59   ` Gleb Natapov
2013-10-02 14:27 ` [PATCH 18/26] mm: Convert process_vm_rw_pages() to use get_user_pages_unlocked() Jan Kara
2013-10-02 16:32   ` KOSAKI Motohiro
2013-10-02 19:36     ` Jan Kara
2013-10-03 22:40       ` KOSAKI Motohiro
2013-10-07 20:55         ` Jan Kara
2013-10-08  0:10           ` KOSAKI Motohiro
2013-10-02 14:28 ` [PATCH 19/26] ivtv: Convert driver " Jan Kara
2013-10-05 12:02   ` Andy Walls
2013-10-07 17:22     ` Jan Kara
2013-10-02 14:28 ` [PATCH 20/26] ib: Convert ib_umem_get() to get_user_pages_unlocked() Jan Kara
2013-10-02 14:28 ` [PATCH 21/26] ib: Convert ipath_get_user_pages() " Jan Kara
2013-10-02 14:28 ` [PATCH 22/26] ib: Convert ipath_user_sdma_pin_pages() to use get_user_pages_unlocked() Jan Kara
2013-10-02 14:28 ` [PATCH 23/26] ib: Convert qib_get_user_pages() to get_user_pages_unlocked() Jan Kara
2013-10-02 14:54   ` Marciniszyn, Mike
2013-10-02 15:28     ` Jan Kara [this message]
2013-10-02 15:32       ` Marciniszyn, Mike
2013-10-02 15:38         ` Jan Kara
2013-10-04 13:39           ` Marciniszyn, Mike
2013-10-04 13:46             ` Marciniszyn, Mike
2013-10-04 13:44         ` Marciniszyn, Mike
2013-10-04 13:52   ` Marciniszyn, Mike
2013-10-04 18:33     ` Jan Kara
2013-10-07 15:20       ` Marciniszyn, Mike
2013-10-07 15:38       ` Marciniszyn, Mike
2013-10-07 17:26         ` Jan Kara
2013-10-08 19:06           ` Jan Kara
2013-10-16 21:39             ` Jan Kara
2013-10-02 14:28 ` [PATCH 24/26] ib: Convert qib_user_sdma_pin_pages() to use get_user_pages_unlocked() Jan Kara
2013-10-02 14:28 ` [PATCH 25/26] ib: Convert mthca_map_user_db() to use get_user_pages_fast() Jan Kara
2013-10-02 14:28 ` [PATCH 26/26] aio: Remove useless get_user_pages() call Jan Kara
2013-10-02 16:20 ` [PATCH 0/26] get_user_pages() cleanup Christoph Hellwig
2013-10-02 20:29   ` Jan Kara
2013-10-04 20:31     ` KOSAKI Motohiro
2013-10-04 20:42       ` KOSAKI Motohiro
2013-10-07 21:18         ` Jan Kara
2013-10-08  0:27           ` KOSAKI Motohiro
2013-10-08  6:06             ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131002152811.GC32181@quack.suse.cz \
    --to=jack@suse.cz \
    --cc=infinipath@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=mike.marciniszyn@intel.com \
    --cc=roland@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).