diff mbox series

[2/2] iov_iter: fix iov_iter_type

Message ID 20190426104521.30602-3-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series block/iov_iter: fix two issues related with BIO_NO_PAGE_REF | expand

Commit Message

Ming Lei April 26, 2019, 10:45 a.m. UTC
Commit 875f1d0769cd ("iov_iter: add ITER_BVEC_FLAG_NO_REF flag")
introduces one extra flag of ITER_BVEC_FLAG_NO_REF, and this flag
is stored into iter->type.

However, iov_iter_type() doesn't consider the new added flag, fix
it by masking this flag in iov_iter_type().

Fixes: 875f1d0769cd ("iov_iter: add ITER_BVEC_FLAG_NO_REF flag")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 include/linux/uio.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christoph Hellwig April 26, 2019, 12:44 p.m. UTC | #1
On Fri, Apr 26, 2019 at 06:45:21PM +0800, Ming Lei wrote:
>  static inline enum iter_type iov_iter_type(const struct iov_iter *i)
>  {
> -	return i->type & ~(READ | WRITE);
> +	return i->type & ~(READ | WRITE | ITER_BVEC_FLAG_NO_REF);

The way we handle i->type is a complete mess.  I think we need
three different values:

   .rw (can be READ or WRITE)
   .type (ITER_IOVEC, ITER_KVEC, ITER_BVEC, ITER_PIPE, ITER_DISCARD)
   .flags (ITER_BVEC_FLAG_NO_REF)

.type seems to be worth an u8 on its own.  And at least as long
as we have space rw and flags should probably be their own u8 aswell,
although we could use accessors to fold them.
Ming Lei April 26, 2019, 10:13 p.m. UTC | #2
On Fri, Apr 26, 2019 at 05:44:35AM -0700, Christoph Hellwig wrote:
> On Fri, Apr 26, 2019 at 06:45:21PM +0800, Ming Lei wrote:
> >  static inline enum iter_type iov_iter_type(const struct iov_iter *i)
> >  {
> > -	return i->type & ~(READ | WRITE);
> > +	return i->type & ~(READ | WRITE | ITER_BVEC_FLAG_NO_REF);
> 
> The way we handle i->type is a complete mess.  I think we need
> three different values:
> 
>    .rw (can be READ or WRITE)
>    .type (ITER_IOVEC, ITER_KVEC, ITER_BVEC, ITER_PIPE, ITER_DISCARD)
>    .flags (ITER_BVEC_FLAG_NO_REF)
> 
> .type seems to be worth an u8 on its own.  And at least as long
> as we have space rw and flags should probably be their own u8 aswell,
> although we could use accessors to fold them.

I agree we need a cleanup, which might be a bit bigger change. It should
be clean to convert them into bit fields.

This issue is quite serious, system ram can easily be leaked completely,
so could we fix the issue by the easy way first?

Thanks, 
Ming
Christoph Hellwig April 27, 2019, 6:02 a.m. UTC | #3
On Sat, Apr 27, 2019 at 06:13:23AM +0800, Ming Lei wrote:
> I agree we need a cleanup, which might be a bit bigger change. It should
> be clean to convert them into bit fields.
> 
> This issue is quite serious, system ram can easily be leaked completely,
> so could we fix the issue by the easy way first?

I'm fine with this as a quick band-aid for 5.2:

Reviewed-by: Christoph Hellwig <hch@lst.de>

But we really need to fix this properly ASAP.
diff mbox series

Patch

diff --git a/include/linux/uio.h b/include/linux/uio.h
index f184af1999a8..2d0131ad4604 100644
--- a/include/linux/uio.h
+++ b/include/linux/uio.h
@@ -60,7 +60,7 @@  struct iov_iter {
 
 static inline enum iter_type iov_iter_type(const struct iov_iter *i)
 {
-	return i->type & ~(READ | WRITE);
+	return i->type & ~(READ | WRITE | ITER_BVEC_FLAG_NO_REF);
 }
 
 static inline bool iter_is_iovec(const struct iov_iter *i)