mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@ti.com>
To: Kent Overstreet <koverstreet@google.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-aio@kvack.org>,
	<akpm@linux-foundation.org>, Zach Brown <zab@redhat.com>,
	Felipe Balbi <balbi@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mark Fasheh <mfasheh@suse.com>, Joel Becker <jlbec@evilplan.org>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Jens Axboe <axboe@kernel.dk>,
	Asai Thambi S P <asamymuthupa@micron.com>,
	Selvan Mani <smani@micron.com>,
	Sam Bradshaw <sbradshaw@micron.com>,
	Jeff Moyer <jmoyer@redhat.com>, Al Viro <viro@zeniv.linux.org.uk>,
	Benjamin LaHaise <bcrl@kvack.org>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Linux USB Mailing List <linux-usb@vger.kernel.org>
Subject: Re: [PATCH 03/33] gadget: remove only user of aio retry
Date: Thu, 21 Mar 2013 18:42:04 +0200	[thread overview]
Message-ID: <20130321164203.GC15740@arwen.pp.htv.fi> (raw)
In-Reply-To: <1363883754-27966-4-git-send-email-koverstreet@google.com>

[-- Attachment #1: Type: text/plain, Size: 5316 bytes --]

Hi,

On Thu, Mar 21, 2013 at 09:35:24AM -0700, Kent Overstreet wrote:
> From: Zach Brown <zab@redhat.com>
> 
> This removes the only in-tree user of aio retry.  This will let us remove
> the retry code from the aio core.
> 
> Removing retry is relatively easy as the USB gadget wasn't using it to
> retry IOs at all.  It always fully submitted the IO in the context of the
> initial io_submit() call.  It only used the AIO retry facility to get the
> submitter's mm context for copying the result of a read back to user
> space.  This is easy to implement with use_mm() and a work struct, much
> like kvm does with async_pf_execute() for get_user_pages().
> 
> Signed-off-by: Zach Brown <zab@redhat.com>
> Signed-off-by: Kent Overstreet <koverstreet@google.com>
> Cc: Felipe Balbi <balbi@ti.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Mark Fasheh <mfasheh@suse.com>
> Cc: Joel Becker <jlbec@evilplan.org>
> Cc: Rusty Russell <rusty@rustcorp.com.au>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Asai Thambi S P <asamymuthupa@micron.com>
> Cc: Selvan Mani <smani@micron.com>
> Cc: Sam Bradshaw <sbradshaw@micron.com>
> Cc: Jeff Moyer <jmoyer@redhat.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Benjamin LaHaise <bcrl@kvack.org>
> Cc: Theodore Ts'o <tytso@mit.edu>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

I don't have any objections with the approach. Let's see if anyone from
linux-usb has anything to say, though

>  drivers/usb/gadget/inode.c | 38 +++++++++++++++++++++++++++++---------
>  1 file changed, 29 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
> index e2b2e9c..a1aad43 100644
> --- a/drivers/usb/gadget/inode.c
> +++ b/drivers/usb/gadget/inode.c
> @@ -24,6 +24,7 @@
>  #include <linux/sched.h>
>  #include <linux/slab.h>
>  #include <linux/poll.h>
> +#include <linux/mmu_context.h>
>  
>  #include <linux/device.h>
>  #include <linux/moduleparam.h>
> @@ -513,6 +514,9 @@ static long ep_ioctl(struct file *fd, unsigned code, unsigned long value)
>  struct kiocb_priv {
>  	struct usb_request	*req;
>  	struct ep_data		*epdata;
> +	struct kiocb 		*iocb;
> +	struct mm_struct 	*mm;
> +	struct work_struct	work;
>  	void			*buf;
>  	const struct iovec	*iv;
>  	unsigned long		nr_segs;
> @@ -540,15 +544,12 @@ static int ep_aio_cancel(struct kiocb *iocb, struct io_event *e)
>  	return value;
>  }
>  
> -static ssize_t ep_aio_read_retry(struct kiocb *iocb)
> +static ssize_t ep_copy_to_user(struct kiocb_priv *priv)
>  {
> -	struct kiocb_priv	*priv = iocb->private;
>  	ssize_t			len, total;
>  	void			*to_copy;
>  	int			i;
>  
> -	/* we "retry" to get the right mm context for this: */
> -
>  	/* copy stuff into user buffers */
>  	total = priv->actual;
>  	len = 0;
> @@ -568,9 +569,26 @@ static ssize_t ep_aio_read_retry(struct kiocb *iocb)
>  		if (total == 0)
>  			break;
>  	}
> +
> +	return len;
> +}
> +
> +static void ep_user_copy_worker(struct work_struct *work)
> +{
> +	struct kiocb_priv *priv = container_of(work, struct kiocb_priv, work);
> +	struct mm_struct *mm = priv->mm;
> +	struct kiocb *iocb = priv->iocb;
> +	size_t ret;
> +
> +	use_mm(mm);
> +	ret = ep_copy_to_user(priv);
> +	unuse_mm(mm);
> +
> +	/* completing the iocb can drop the ctx and mm, don't touch mm after */
> +	aio_complete(iocb, ret, ret);
> +
>  	kfree(priv->buf);
>  	kfree(priv);
> -	return len;
>  }
>  
>  static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
> @@ -596,14 +614,14 @@ static void ep_aio_complete(struct usb_ep *ep, struct usb_request *req)
>  		aio_complete(iocb, req->actual ? req->actual : req->status,
>  				req->status);
>  	} else {
> -		/* retry() won't report both; so we hide some faults */
> +		/* ep_copy_to_user() won't report both; we hide some faults */
>  		if (unlikely(0 != req->status))
>  			DBG(epdata->dev, "%s fault %d len %d\n",
>  				ep->name, req->status, req->actual);
>  
>  		priv->buf = req->buf;
>  		priv->actual = req->actual;
> -		kick_iocb(iocb);
> +		schedule_work(&priv->work);
>  	}
>  	spin_unlock(&epdata->dev->lock);
>  
> @@ -633,8 +651,10 @@ fail:
>  		return value;
>  	}
>  	iocb->private = priv;
> +	priv->iocb = iocb;
>  	priv->iv = iv;
>  	priv->nr_segs = nr_segs;
> +	INIT_WORK(&priv->work, ep_user_copy_worker);
>  
>  	value = get_ready_ep(iocb->ki_filp->f_flags, epdata);
>  	if (unlikely(value < 0)) {
> @@ -646,6 +666,7 @@ fail:
>  	get_ep(epdata);
>  	priv->epdata = epdata;
>  	priv->actual = 0;
> +	priv->mm = current->mm; /* mm teardown waits for iocbs in exit_aio() */
>  
>  	/* each kiocb is coupled to one usb_request, but we can't
>  	 * allocate or submit those if the host disconnected.
> @@ -674,7 +695,7 @@ fail:
>  		kfree(priv);
>  		put_ep(epdata);
>  	} else
> -		value = (iv ? -EIOCBRETRY : -EIOCBQUEUED);
> +		value = -EIOCBQUEUED;
>  	return value;
>  }
>  
> @@ -692,7 +713,6 @@ ep_aio_read(struct kiocb *iocb, const struct iovec *iov,
>  	if (unlikely(!buf))
>  		return -ENOMEM;
>  
> -	iocb->ki_retry = ep_aio_read_retry;
>  	return ep_aio_rwtail(iocb, buf, iocb->ki_left, epdata, iov, nr_segs);
>  }
>  
> -- 
> 1.8.1.3
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  reply	other threads:[~2013-03-21 16:43 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-21 16:35 [PATCH 00/33] AIO cleanups/performance improvements Kent Overstreet
2013-03-21 16:35 ` [PATCH 01/33] mm: remove old aio use_mm() comment Kent Overstreet
2013-03-28 14:13   ` Theodore Ts'o
2013-04-12 15:42   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 02/33] aio: remove dead code from aio.h Kent Overstreet
2013-03-28 14:13   ` Theodore Ts'o
2013-04-12 15:42   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 03/33] gadget: remove only user of aio retry Kent Overstreet
2013-03-21 16:42   ` Felipe Balbi [this message]
2013-04-12 15:42   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 04/33] aio: remove retry-based AIO Kent Overstreet
2013-03-28 14:20   ` Theodore Ts'o
2013-04-12 15:43   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 05/33] char: add aio_{read,write} to /dev/{null,zero} Kent Overstreet
2013-03-28 14:20   ` Theodore Ts'o
2013-04-12 15:43   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 06/33] aio: kill return value of aio_complete() Kent Overstreet
2013-03-28 14:22   ` Theodore Ts'o
2013-04-12 15:44   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 07/33] aio: add kiocb_cancel() Kent Overstreet
2013-03-28 14:54   ` Theodore Ts'o
2013-04-12 15:58   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 08/33] aio: move private stuff out of aio.h Kent Overstreet
2013-03-29 16:07   ` Theodore Ts'o
2013-04-12 15:59   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 09/33] aio: dprintk() -> pr_debug() Kent Overstreet
2013-03-21 17:38   ` Joe Perches
2013-03-29 16:17   ` Theodore Ts'o
2013-04-12 16:01   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 10/33] aio: do fget() after aio_get_req() Kent Overstreet
2013-03-29 16:48   ` Theodore Ts'o
2013-04-12 16:51   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 11/33] aio: make aio_put_req() lockless Kent Overstreet
2013-03-29 17:14   ` Theodore Ts'o
2013-04-12 21:01   ` Jeff Moyer
2013-03-21 16:35 ` [PATCH 12/33] aio: refcounting cleanup Kent Overstreet
2013-04-02  1:32   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 13/33] wait: add wait_event_hrtimeout() Kent Overstreet
2013-04-02  1:43   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 14/33] aio: make aio_read_evt() more efficient, convert to hrtimers Kent Overstreet
2013-04-02  1:58   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 15/33] aio: use flush_dcache_page() Kent Overstreet
2013-04-02  2:12   ` Theodore Ts'o
2013-04-09 21:07     ` Kent Overstreet
2013-03-21 16:35 ` [PATCH 16/33] aio: use cancellation list lazily Kent Overstreet
2013-04-02  2:36   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 17/33] aio: change reqs_active to include unreaped completions Kent Overstreet
2013-04-02  2:53   ` Theodore Ts'o
2013-04-02 15:47     ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 18/33] aio: kill batch allocation Kent Overstreet
2013-04-02  3:03   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 19/33] aio: kill struct aio_ring_info Kent Overstreet
2013-04-02  3:26   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 20/33] aio: give shared kioctx fields their own cachelines Kent Overstreet
2013-04-02  3:27   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 21/33] aio: reqs_active -> reqs_available Kent Overstreet
2013-04-02 15:48   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 22/33] aio: percpu reqs_available Kent Overstreet
2013-04-02 16:03   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 23/33] generic dynamic per cpu refcounting Kent Overstreet
2013-04-02 16:27   ` Theodore Ts'o
2013-04-12 19:36     ` Kent Overstreet
2013-04-16  1:41       ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 24/33] aio: percpu ioctx refcount Kent Overstreet
2013-04-02 16:28   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 25/33] aio: use xchg() instead of completion_lock Kent Overstreet
2013-04-02 16:35   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 26/33] aio: don't include aio.h in sched.h Kent Overstreet
2013-04-02 16:35   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 27/33] aio: kill ki_key Kent Overstreet
2013-04-02 16:36   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 28/33] aio: kill ki_retry Kent Overstreet
2013-04-02 18:46   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 29/33] block: Prep work for batch completion Kent Overstreet
2013-04-02 18:48   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 30/33] block, aio: batch completion for bios/kiocbs Kent Overstreet
2013-04-02 19:48   ` Theodore Ts'o
2013-04-10 21:59     ` Kent Overstreet
2013-04-02 19:53   ` Theodore Ts'o
2013-04-10 22:09     ` Kent Overstreet
2013-03-21 16:35 ` [PATCH 31/33] virtio-blk: convert to batch completion Kent Overstreet
2013-04-02 19:53   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 32/33] mtip32xx: " Kent Overstreet
2013-04-02 19:54   ` Theodore Ts'o
2013-03-21 16:35 ` [PATCH 33/33] aio: fix kioctx not being freed after cancellation at exit time Kent Overstreet
2013-04-02 21:35   ` Theodore Ts'o
2013-04-09 21:15     ` Kent Overstreet

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=20130321164203.GC15740@arwen.pp.htv.fi \
    --to=balbi@ti.com \
    --cc=akpm@linux-foundation.org \
    --cc=asamymuthupa@micron.com \
    --cc=axboe@kernel.dk \
    --cc=bcrl@kvack.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jlbec@evilplan.org \
    --cc=jmoyer@redhat.com \
    --cc=koverstreet@google.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mfasheh@suse.com \
    --cc=rusty@rustcorp.com.au \
    --cc=sbradshaw@micron.com \
    --cc=smani@micron.com \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zab@redhat.com \
    /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

all inboxes | Powered by JetHome®