block/iov_iter: fix two issues related with BIO_NO_PAGE_REF
Subsystems (3)
cover block/iov_iter: fix two issues related with BIO_NO_PAGE_REF
Hi,
Fix two issues related with BIO_NO_PAGE_REF, both are introduced recently in for-5.2/block.
Ming Lei (2):
block: fix handling for BIO_NO_PAGE_REF
iov_iter: fix iov_iter_type
fs/block_dev.c | 3 ++- include/linux/uio.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.9.5
PATCH 1/2 block: fix handling for BIO_NO_PAGE_REF
Commit 399254aaf489211 ("block: add BIO_NO_PAGE_REF flag") introduces BIO_NO_PAGE_REF, and once this flag is set for one bio, all pages in the bio won't be get/put during IO.
However, if one bio is submitted via __blkdev_direct_IO_simple(), even though BIO_NO_PAGE_REF is set, pages still may be put.
Fixes this issue by avoiding to put pages if BIO_NO_PAGE_REF is set.
--- fs/block_dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/block_dev.c +2 -1
@@ -264,7 +264,8 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter,bio_for_each_segment_all (bvec, &bio, i, iter_all) {if (should_dirty && !PageCompound (bvec->bv_page))set_page_dirty_lock (bvec->bv_page); -put_page (bvec->bv_page); +if (!bio_flagged (&bio,BIO_NO_PAGE_REF )) +put_page (bvec->bv_page); }if (unlikely (bio.bi_status))
Signature · 1 line
2.9.5
Re: [PATCH 1/2] block: fix handling for BIO_NO_PAGE_REF
Quoted 4 lines · Ming Lei
Commit
399254aaf489211("block: addBIO_NO_PAGE_REFflag") introducesBIO_NO_PAGE_REF, and once this flag is set for one bio, all pages in the bio won't be get/put during IO.
Quoted 8 lines
However, if one bio is submitted via
__blkdev_direct_IO_simple(), even thoughBIO_NO_PAGE_REFis set, pages still may be put.Fixes this issue by avoiding to put pages if
BIO_NO_PAGE_REFis set.Fixes 399254aaf489211 ("block: add BIO_NO_PAGE_REF flag")Signed-off-by Ming Lei <[email protected]>
Looks good,
PATCH 2/2 iov_iter: fix iov_iter_type
In reply to Ming LeiCommit 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().
--- include/linux/uio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/uio.h +1 -1
@@ -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)
Signature · 1 line
2.9.5
Re: [PATCH 2/2] iov_iter: fix iov_iter_type
include/linux/uio.h struct iov_iter { · line 63
Quoted 4 lines · Ming Lei
static inline enum
iter_typeiov_iter_type(const struct iov_iter *i){include/linux/uio.h +1
-1-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.
Re: [PATCH 2/2] iov_iter: fix iov_iter_type
Quoted 9 lines · Christoph Hellwig
include/linux/uio.h struct iov_iter { · line 63
Quoted 4 lines · Ming Lei
static inline enum
iter_typeiov_iter_type(const struct iov_iter *i){include/linux/uio.h +1
-1-return i->type & ~(READ |WRITE ); +return i->type & ~(READ |WRITE |ITER_BVEC_FLAG_NO_REF );The way we handle
i->typeis a complete mess. I think we need three different values:
Quoted 7 lines
.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
Reviewed-byRe: [PATCH 2/2] iov_iter: fix iov_iter_type
Quoted 5 lines · Ming Lei
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:
But we really need to fix this properly ASAP.
Quoted 5 lines · Ming Lei
Hi,
Fix two issues related with
BIO_NO_PAGE_REF, both are introduced recently in for-5.2/block.
Quoted 11 lines
Ming Lei (2):
block: fix handling forBIO_NO_PAGE_REF
iov_iter: fixiov_iter_typefs/block_dev.c | 3 ++- include/linux/uio.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)Signature · 1 line
2.9.5
Hi Jens,
The two page leak issues are quite serious, given whole system memory can be consumed up easily in some dio tests.
Could you consider to merge them if you are fine?
Thanks,
Ming
Quoted 4 lines · Ming Lei
Hi,
Fix two issues related with
BIO_NO_PAGE_REF, both are introduced recently in for-5.2/block.
Applied, thanks.
Signature · 1 line
Jens Axboe