From: Johannes Thumshirn <jthumshirn@suse.de>
To: Jens Axboe <axboe@fb.com>
Cc: Hannes Reinecke <hare@suse.de>,
Bart Van Assche <bvanassche@acm.org>,
Christoph Hellwig <hch@lst.de>, Jan Kara <jack@suse.cz>,
Linux Block Layer Mailinglist <linux-block@vger.kernel.org>,
Linux FSDEVEL Mailinglist <linux-fsdevel@vger.kernel.org>,
Johannes Thumshirn <jthumshirn@suse.de>
Subject: [PATCH 2/2] bio: introduce BIO_ALLOCED flag and check it in bio_free
Date: Thu, 21 Mar 2019 13:30:45 +0100 [thread overview]
Message-ID: <20190321123045.32396-3-jthumshirn@suse.de> (raw)
In-Reply-To: <20190321123045.32396-1-jthumshirn@suse.de>
When we're submitting a bio from stack and this ends up being split, we
call bio_put(). bio_put() will eventually call bio_free() if the reference
count drops to 0. But freeing the bio is wrong, as it was never allocated
out of the bio's mempool.
Flag each normally allocated bio as 'BIO_ALLOCATED' and skip freeing if the
flag isn't set.
Fixes: 189ce2b9dcc3 ("block: fast-path for small and simple direct I/O requests")
Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
block/bio.c | 4 ++++
include/linux/blk_types.h | 1 +
2 files changed, 5 insertions(+)
diff --git a/block/bio.c b/block/bio.c
index 8c689aed46a0..3282479d511d 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -255,6 +255,9 @@ static void bio_free(struct bio *bio)
bio_uninit(bio);
+ if (!bio_flagged(bio, BIO_ALLOCED))
+ return;
+
if (bs) {
bvec_free(&bs->bvec_pool, bio->bi_io_vec, BVEC_POOL_IDX(bio));
@@ -521,6 +524,7 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
bvl = bio->bi_inline_vecs;
}
+ bio_set_flag(bio, BIO_ALLOCED);
bio->bi_pool = bs;
bio->bi_max_vecs = nr_iovecs;
bio->bi_io_vec = bvl;
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 0273bad71a96..d0c9d6fd6e71 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -216,6 +216,7 @@ struct bio {
* bio flags
*/
enum {
+ BIO_ALLOCED = 0, /* bio allocated by bio_alloc_bioset */
BIO_SEG_VALID = 1, /* bi_phys_segments valid */
BIO_CLONED = 2, /* doesn't own data */
BIO_BOUNCED = 3, /* bio is a bounce bio */
--
2.16.4
prev parent reply other threads:[~2019-03-21 12:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-21 12:30 [PATCH 0/2] add flag for tracking bio allocation Johannes Thumshirn
2019-03-21 12:30 ` [PATCH 1/2] block: bio: ensure newly added bio flags don't override BVEC_POOL_IDX Johannes Thumshirn
2019-03-21 13:18 ` Hannes Reinecke
2019-03-21 13:22 ` Johannes Thumshirn
2019-03-21 14:15 ` Jens Axboe
2019-03-21 14:21 ` Jens Axboe
2019-03-21 14:23 ` Johannes Thumshirn
2019-03-21 14:25 ` Jens Axboe
2019-03-21 15:54 ` Hannes Reinecke
2019-03-22 10:24 ` Johannes Thumshirn
2019-03-21 12:30 ` Johannes Thumshirn [this message]
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=20190321123045.32396-3-jthumshirn@suse.de \
--to=jthumshirn@suse.de \
--cc=axboe@fb.com \
--cc=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@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 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).