All of lore.kernel.org
 help / color / mirror / Atom feed
From: Badari Pulavarty <pbadari@us.ibm.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel@vger.kernel.org, hch@lst.de, bcrl@kvack.org,
	cel@citi.umich.edu
Subject: Re: [PATCH 1/4] Vectorize aio_read/aio_write methods
Date: Thu, 11 May 2006 13:45:29 -0700	[thread overview]
Message-ID: <4463A269.2080601@us.ibm.com> (raw)
In-Reply-To: 20060511132136.569d59c1.akpm@osdl.org



Andrew Morton wrote:

>Badari Pulavarty <pbadari@us.ibm.com> wrote:
>
>>On Thu, 2006-05-11 at 11:47 -0700, Andrew Morton wrote:
>>
>>>Badari Pulavarty <pbadari@us.ibm.com> wrote:
>>>
>>>> static ssize_t ep_aio_read_retry(struct kiocb *iocb)
>>>> {
>>>> 	struct kiocb_priv	*priv = iocb->private;
>>>>-	ssize_t			status = priv->actual;
>>>>+	ssize_t			len, total;
>>>> 
>>>> 	/* we "retry" to get the right mm context for this: */
>>>>-	status = copy_to_user(priv->ubuf, priv->buf, priv->actual);
>>>>-	if (unlikely(0 != status))
>>>>-		status = -EFAULT;
>>>>-	else
>>>>-		status = priv->actual;
>>>>+
>>>>+	/* copy stuff into user buffers */
>>>>+	total = priv->actual;
>>>>+	len = 0;
>>>>+	for (i=0; i < priv->count; i++) {
>>>>+		ssize_t this = min(priv->iv[i].iov_len, total);
>>>>+
>>>>+		if (copy_to_user(priv->iv[i].iov_buf, priv->buf, this))
>>>>+			break;
>>>>+
>>>>+		total -= this;
>>>>+		len += this;
>>>>+		if (total <= 0)
>>>>+			break;
>>>>+	}
>>>>+
>>>>+	if (unlikely(len == 0))
>>>>+		len = -EFAULT;
>>>>
>>>This is still wrong, isn't it?  Or am I looking at the same patch?
>>>
>>>There's no way in which `total' can go negative, so it'd be nicer to just
>>>test it for equality with zero.  Because if it goes unexpectedly negative,
>>>we _want_ the kernel to malfunction, rather than mysteriously covering
>>>things up.
>>>
>>>The final test there should be
>>>
>>>	if (unlikely(total != 0))
>>>
>>>yes?
>>>
>>No. The original check is correct - we want to return EFAULT if
>>copy_to_user() failed and we haven't copied anything so far.
>>If we copied anything so far, we should return, that many bytes.
>>(like short-io).
>>
>
>oic.  And we're sure that we cannot call into this code if someone's trying
>a zero-sized read?
>
>Either way, the below (which is faster!) will fix, yes?
>
>--- 25/drivers/usb/gadget/inode.c~vectorize-aio_read-aio_write-methods-fix	Thu May 11 11:53:41 2006
>+++ 25-akpm/drivers/usb/gadget/inode.c	Thu May 11 13:19:45 2006
>@@ -567,18 +567,18 @@ static ssize_t ep_aio_read_retry(struct 
> 	for (i = 0; i < priv->count; i++) {
> 		ssize_t this = min(priv->iv[i].iov_len, total);
> 
>-		if (copy_to_user(priv->iv[i].iov_buf, priv->buf, this))
>+		if (copy_to_user(priv->iv[i].iov_buf, priv->buf, this)) {
>+			if (len == 0)
>+				len = -EFAULT;
> 			break;
>+		}
> 
> 		total -= this;
> 		len += this;
>-		if (total <= 0)
>+		if (total == 0)
> 			break;
> 	}
> 
>-	if (unlikely(len == 0))
>-		len = -EFAULT;
>-
> 	kfree(priv->buf);
> 	kfree(priv);
> 	aio_put_req(iocb);
>_
>
Yes, this is good.

No one should call into this code with size == 0, since we should have 
returned
success without doing any IO in the first place.

Thanks,
Badari



  reply	other threads:[~2006-05-11 20:45 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-02 15:07 [PATCH 0/3] VFS changes to collapse AIO and vectored IO into single (set of) fileops Badari Pulavarty
2006-05-02 15:08 ` [PATCH 1/3] Vectorize aio_read/aio_write methods Badari Pulavarty
2006-05-02 15:20   ` Chuck Lever
2006-05-02 15:35     ` Badari Pulavarty
2006-05-02 15:09 ` [PATCH 2/3] Remove readv/writev methods and use aio_read/aio_write instead Badari Pulavarty
2006-05-02 15:11 ` [PATCH 3/3] Core aio changes to support vectored AIO Badari Pulavarty
2006-05-09 18:03 ` [PATCH 0/3] VFS changes to collapse AIO and vectored IO into single (set of) fileops Badari Pulavarty
2006-05-09 18:07   ` [PATCH 1/3] Vectorize aio_read/aio_write methods Badari Pulavarty
2006-05-09 19:01     ` Andrew Morton
2006-05-09 19:03       ` Christoph Hellwig
2006-05-09 19:13         ` Andrew Morton
2006-05-09 19:20           ` Christoph Hellwig
2006-05-09 23:57             ` Badari Pulavarty
2006-05-10  8:00               ` Christoph Hellwig
2006-05-10 15:01                 ` Badari Pulavarty
2006-05-10 16:01             ` Badari Pulavarty
2006-05-10 20:50           ` Badari Pulavarty
2006-05-09 20:07         ` Badari Pulavarty
2006-05-09 23:53       ` Badari Pulavarty
2006-05-09 18:07   ` [PATCH 2/3] Remove readv/writev methods and use aio_read/aio_write instead Badari Pulavarty
2006-05-09 18:08   ` [PATCH 3/3] Zach's core aio changes to support vectored AIO Badari Pulavarty
2006-05-09 18:55     ` christoph
2006-05-09 20:05       ` Badari Pulavarty
2006-05-09 18:14   ` [PATCH 0/3] VFS changes to collapse AIO and vectored IO into single (set of) fileops Benjamin LaHaise
2006-05-11 15:38   ` [PATCH 0/4] VFS fileop cleanups by collapsing AIO and vector IO Badari Pulavarty
2006-05-11 15:38     ` [PATCH 1/4] Vectorize aio_read/aio_write methods Badari Pulavarty
2006-05-11 18:39       ` Andrew Morton
2006-05-11 19:33         ` Mark Fasheh
2006-05-11 18:47       ` Andrew Morton
2006-05-11 19:07         ` Badari Pulavarty
2006-05-11 20:21           ` Andrew Morton
2006-05-11 20:45             ` Badari Pulavarty [this message]
     [not found]               ` <4463AB55.2010105@citi.umich.edu>
     [not found]                 ` <4463B368.9050602@us.ibm.com>
     [not found]                   ` <4463B7B0.4000102@citi.umich.edu>
2006-05-11 22:50                     ` Badari Pulavarty
2006-05-12  7:38                       ` Christoph Hellwig
2006-05-11 18:52       ` Andrew Morton
2006-05-11 19:12         ` Badari Pulavarty
2006-05-12 10:03       ` Andrew Morton
2006-05-12 10:08         ` Andrew Morton
2006-05-12 13:56           ` Badari Pulavarty
2006-05-11 15:40     ` [PATCH 2/4] Remove readv/writev methods and use aio_read/aio_write instead Badari Pulavarty
2006-05-11 15:42     ` [PATCH 3/4] Core aio changes to support vectored AIO Badari Pulavarty
2006-05-11 15:43     ` [PATCH 4/4] Streamline generic_file_* interfaces and filemap cleanups Badari Pulavarty
2006-05-15 21:19     ` [PATCH 0/4] VFS fileop cleanups by collapsing AIO and vector IO Badari Pulavarty
2006-05-15 21:21       ` [PATCH 1/4] Vectorize aio_read/aio_write methods Badari Pulavarty
2006-05-15 21:22       ` [PATCH 2/4] Remove readv/writev methods and use aio_read/aio_write instead Badari Pulavarty
2006-05-22  1:00         ` Andrew Morton
2006-05-22  4:39           ` Badari Pulavarty
2006-05-22  5:34           ` Christoph Hellwig
2006-05-22  8:16             ` Ian Kent
2006-05-22  8:19             ` Ian Kent
2006-05-22  9:29             ` Andrew Morton
2006-05-22  9:35               ` Andrew Morton
2006-05-22 10:32                 ` Christoph Hellwig
2006-05-22 10:44                   ` Andrew Morton
2006-05-22 10:50                   ` Ian Kent
2006-05-22 15:24             ` Badari Pulavarty
2006-05-22 15:00           ` Badari Pulavarty
2006-05-22 17:06             ` Andrew Morton
2006-05-22 17:24               ` Badari Pulavarty
2006-05-23  8:29                 ` Ian Kent
2006-05-23 14:35                   ` Ian Kent
2006-05-28  0:15                     ` Badari Pulavarty
2006-05-29  7:06                       ` Ian Kent
2006-05-15 21:22       ` [PATCH 3/4] Core aio changes to support vectored AIO Badari Pulavarty
2006-05-15 21:23       ` [PATCH 4/4] Streamline generic_file_* interfaces and filemap cleanups Badari Pulavarty
2006-05-15 22:28         ` Nathan Scott
2006-05-15 22:42           ` Andrew Morton
2006-05-15 22:56             ` Nathan Scott
2006-05-15 22:47           ` Badari Pulavarty
2006-05-16 10:50           ` christoph
  -- strict thread matches above, loose matches on Subject: below --
2006-06-02 19:06 [PATCH 0/4] VFS fileop cleanups by collapsing AIO and vector IO (2.6.17-rc5-mm2) Badari Pulavarty
2006-06-02 19:07 ` [PATCH 1/4] Vectorize aio_read/aio_write methods Badari Pulavarty
2006-06-13 23:32 [PATCH 0/4] VFS fileop cleanups by collapsing AIO and vector IO Badari Pulavarty
2006-06-13 23:32 ` [PATCH 1/4] Vectorize aio_read/aio_write methods Badari Pulavarty

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=4463A269.2080601@us.ibm.com \
    --to=pbadari@us.ibm.com \
    --cc=akpm@osdl.org \
    --cc=bcrl@kvack.org \
    --cc=cel@citi.umich.edu \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.