From: Jens Axboe <axboe@kernel.dk>
To: Ming Lei <tom.leiming@gmail.com>, David Sterba <dsterba@suse.com>
Cc: linux-block <linux-block@vger.kernel.org>,
Liu Bo <bo.li.liu@oracle.com>,
fdmanana@suse.com
Subject: Re: [PATCH] block: note about cloned bios and bio_for_each_segment_all
Date: Fri, 14 Jul 2017 08:22:31 -0600 [thread overview]
Message-ID: <06376146-e4c3-efd6-8893-155052b14034@kernel.dk> (raw)
In-Reply-To: <CACVXFVP_a5kofmW-Wfx1FT_kyqFKdatf57RfKLrh+Jte1J8ZmA@mail.gmail.com>
On 07/14/2017 07:47 AM, Ming Lei wrote:
>> @@ -156,6 +156,9 @@ static inline void *bio_data(struct bio *bio)
>> /*
>> * drivers should _never_ use the all version - the bio may have been split
>> * before it got to the driver and the driver won't own all of it
>> + *
>> + * Note that cloned bios must not use this as their bi_vcnt may be invalid and
>> + * this could lead to silent corruptions.
>> */
>> #define bio_for_each_segment_all(bvl, bio, i) \
>> for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++)
>> --
>> 2.13.0
>>
>
> Maybe we can add a warning here if it is a cloned bio.
I think that's a good idea, it's easy for people to get this wrong, and
the consequences can be dire. How about something like this?
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 7b1cf4ba0902..13b6ac6eae29 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -155,9 +155,12 @@ static inline void *bio_data(struct bio *bio)
/*
* drivers should _never_ use the all version - the bio may have been split
- * before it got to the driver and the driver won't own all of it
+ * before it got to the driver and the driver won't own all of it.
+ *
+ * Don't use this on cloned bio's.
*/
#define bio_for_each_segment_all(bvl, bio, i) \
+ WARN_ON_ONCE(bio_flagged(bio, BIO_CLONED)); \
for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++)
static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,
--
Jens Axboe
next prev parent reply other threads:[~2017-07-14 14:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-14 13:40 [PATCH] block: note about cloned bios and bio_for_each_segment_all David Sterba
2017-07-14 13:47 ` Ming Lei
2017-07-14 14:22 ` Jens Axboe [this message]
2017-07-14 20:54 ` Liu Bo
2017-07-14 22:35 ` Ming Lei
2017-07-14 22:37 ` Jens Axboe
2017-07-14 23:20 ` Liu Bo
2017-07-18 22:19 ` Bart Van Assche
2017-07-24 16:19 ` Peter Zijlstra
2017-07-15 0:28 ` David Sterba
2017-07-14 15:03 ` David Sterba
2017-07-14 17:56 ` Filipe Manana
2017-07-14 18:19 ` Jens Axboe
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=06376146-e4c3-efd6-8893-155052b14034@kernel.dk \
--to=axboe@kernel.dk \
--cc=bo.li.liu@oracle.com \
--cc=dsterba@suse.com \
--cc=fdmanana@suse.com \
--cc=linux-block@vger.kernel.org \
--cc=tom.leiming@gmail.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