public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: note about cloned bios and bio_for_each_segment_all
@ 2017-07-14 13:40 David Sterba
  2017-07-14 13:47 ` Ming Lei
  0 siblings, 1 reply; 13+ messages in thread
From: David Sterba @ 2017-07-14 13:40 UTC (permalink / raw)
  To: linux-block; +Cc: David Sterba, bo.li.liu, fdmanana

We've switched to cloned bios in btrfs and hit a nasty bug leading to
corruptions, when cloned bios are iterated by bio_for_each_segment_all.

Report and fix:
https://patchwork.kernel.org/patch/9838535/

As a matter of precaution, we've added assertions to btrfs code to catch
the bad usage pattern:

https://patchwork.kernel.org/patch/9839267/

The cloned/bi_vcnt behaviour seems tobe implementation dependent and is
not documented, so this patch at least warns about this one particular
case but this might still be insufficient.

CC: linux-block@vger.kernel.org
Signed-off-by: David Sterba <dsterba@suse.com>
---
 include/linux/bio.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/bio.h b/include/linux/bio.h
index 7b1cf4ba0902..f1ac84edcf39 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-07-24 16:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox