linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bio: ensure __bio_clone_fast copies bi_partno
@ 2017-11-17  7:47 Michael Lyle
  2017-11-17 11:04 ` Coly Li
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Michael Lyle @ 2017-11-17  7:47 UTC (permalink / raw)
  To: linux-block, linux-bcache
  Cc: Michael Lyle, Christoph Hellwig, Jens Axboe, stable

A new field was introduced in 74d46992e0d9dee7f1f376de0d56d31614c8a17a,
bi_partno, instead of using bdev->bd_contains and encoding the partition
information in the bi_bdev field.  __bio_clone_fast was changed to copy
the disk information, but not the partition information.  At minimum,
this regressed bcache and caused data corruption.

Signed-off-by: Michael Lyle <mlyle@lyle.org>
Fixes: 74d46992e0d9dee7f1f376de0d56d31614c8a17a
Reported-by: Pavel Goran <via-bcache@pvgoran.name>
Reported-by: Campbell Steven <casteven@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: <stable@vger.kernel.org>
---
 block/bio.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/bio.c b/block/bio.c
index 101c2a9b5481..33fa6b4af312 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -597,6 +597,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
 	 * so we don't set nor calculate new physical/hw segment counts here
 	 */
 	bio->bi_disk = bio_src->bi_disk;
+	bio->bi_partno = bio_src->bi_partno;
 	bio_set_flag(bio, BIO_CLONED);
 	bio->bi_opf = bio_src->bi_opf;
 	bio->bi_write_hint = bio_src->bi_write_hint;
-- 
2.14.1

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17  7:47 [PATCH] bio: ensure __bio_clone_fast copies bi_partno Michael Lyle
@ 2017-11-17 11:04 ` Coly Li
  2017-11-17 11:34 ` Ming Lei
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Coly Li @ 2017-11-17 11:04 UTC (permalink / raw)
  To: Michael Lyle, linux-block, linux-bcache
  Cc: Christoph Hellwig, Jens Axboe, stable

On 17/11/2017 3:47 PM, Michael Lyle wrote:
> A new field was introduced in 74d46992e0d9dee7f1f376de0d56d31614c8a17a,
> bi_partno, instead of using bdev->bd_contains and encoding the partition
> information in the bi_bdev field.  __bio_clone_fast was changed to copy
> the disk information, but not the partition information.  At minimum,
> this regressed bcache and caused data corruption.
> 

Hi Michael,

Thanks for the fix, it looks good to me.

> Signed-off-by: Michael Lyle <mlyle@lyle.org>
> Fixes: 74d46992e0d9dee7f1f376de0d56d31614c8a17a
> Reported-by: Pavel Goran <via-bcache@pvgoran.name>
> Reported-by: Campbell Steven <casteven@gmail.com>

Reviewed-by: Coly Li <colyli@suse.de>

Coly Li

> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: <stable@vger.kernel.org>
> ---
>  block/bio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/block/bio.c b/block/bio.c
> index 101c2a9b5481..33fa6b4af312 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -597,6 +597,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
>  	 * so we don't set nor calculate new physical/hw segment counts here
>  	 */
>  	bio->bi_disk = bio_src->bi_disk;
> +	bio->bi_partno = bio_src->bi_partno;
>  	bio_set_flag(bio, BIO_CLONED);
>  	bio->bi_opf = bio_src->bi_opf;
>  	bio->bi_write_hint = bio_src->bi_write_hint;
> 

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17  7:47 [PATCH] bio: ensure __bio_clone_fast copies bi_partno Michael Lyle
  2017-11-17 11:04 ` Coly Li
@ 2017-11-17 11:34 ` Ming Lei
  2017-11-17 15:08 ` Christoph Hellwig
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Ming Lei @ 2017-11-17 11:34 UTC (permalink / raw)
  To: Michael Lyle
  Cc: linux-block, linux-bcache, Christoph Hellwig, Jens Axboe, stable

On Thu, Nov 16, 2017 at 11:47:25PM -0800, Michael Lyle wrote:
> A new field was introduced in 74d46992e0d9dee7f1f376de0d56d31614c8a17a,
> bi_partno, instead of using bdev->bd_contains and encoding the partition
> information in the bi_bdev field.  __bio_clone_fast was changed to copy
> the disk information, but not the partition information.  At minimum,
> this regressed bcache and caused data corruption.
> 
> Signed-off-by: Michael Lyle <mlyle@lyle.org>
> Fixes: 74d46992e0d9dee7f1f376de0d56d31614c8a17a
> Reported-by: Pavel Goran <via-bcache@pvgoran.name>
> Reported-by: Campbell Steven <casteven@gmail.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: <stable@vger.kernel.org>
> ---
>  block/bio.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/block/bio.c b/block/bio.c
> index 101c2a9b5481..33fa6b4af312 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -597,6 +597,7 @@ void __bio_clone_fast(struct bio *bio, struct bio *bio_src)
>  	 * so we don't set nor calculate new physical/hw segment counts here
>  	 */
>  	bio->bi_disk = bio_src->bi_disk;
> +	bio->bi_partno = bio_src->bi_partno;
>  	bio_set_flag(bio, BIO_CLONED);
>  	bio->bi_opf = bio_src->bi_opf;
>  	bio->bi_write_hint = bio_src->bi_write_hint;

Reviewed-by: Ming Lei <ming.lei@redhat.com>

-- 
Ming

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17  7:47 [PATCH] bio: ensure __bio_clone_fast copies bi_partno Michael Lyle
  2017-11-17 11:04 ` Coly Li
  2017-11-17 11:34 ` Ming Lei
@ 2017-11-17 15:08 ` Christoph Hellwig
  2017-11-17 15:27 ` Jens Axboe
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2017-11-17 15:08 UTC (permalink / raw)
  To: Michael Lyle
  Cc: linux-block, linux-bcache, Christoph Hellwig, Jens Axboe, stable

Looks good,

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

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17  7:47 [PATCH] bio: ensure __bio_clone_fast copies bi_partno Michael Lyle
                   ` (2 preceding siblings ...)
  2017-11-17 15:08 ` Christoph Hellwig
@ 2017-11-17 15:27 ` Jens Axboe
  2017-11-17 16:50 ` Bart Van Assche
  2017-11-17 20:25 ` Campbell Steven
  5 siblings, 0 replies; 9+ messages in thread
From: Jens Axboe @ 2017-11-17 15:27 UTC (permalink / raw)
  To: Michael Lyle, linux-block, linux-bcache; +Cc: Christoph Hellwig, stable

On 11/17/2017 12:47 AM, Michael Lyle wrote:
> A new field was introduced in 74d46992e0d9dee7f1f376de0d56d31614c8a17a,
> bi_partno, instead of using bdev->bd_contains and encoding the partition
> information in the bi_bdev field.  __bio_clone_fast was changed to copy
> the disk information, but not the partition information.  At minimum,
> this regressed bcache and caused data corruption.

That's not good... Fix looks good to me, I'll queue this up for a pull
today. Thanks for bisecting this, Michael.

-- 
Jens Axboe

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17  7:47 [PATCH] bio: ensure __bio_clone_fast copies bi_partno Michael Lyle
                   ` (3 preceding siblings ...)
  2017-11-17 15:27 ` Jens Axboe
@ 2017-11-17 16:50 ` Bart Van Assche
  2017-11-17 17:02   ` Michael Lyle
  2017-11-17 17:18   ` hch
  2017-11-17 20:25 ` Campbell Steven
  5 siblings, 2 replies; 9+ messages in thread
From: Bart Van Assche @ 2017-11-17 16:50 UTC (permalink / raw)
  To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org,
	mlyle@lyle.org
  Cc: hch@lst.de, stable@vger.kernel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CBhbHNvIGNvcGllcw0KYmlfcGFydG5vPw0KDQpIb3cg
YWJvdXQgdGhlIGZvbGxvd2luZyBjbGFzcyBvZiBhc3NpZ25tZW50cyBpbiBkcml2ZXJzL21kL3Jh
aWQxLmM6DQoNCgkJbWJpby0+YmlfZGlzayA9ICh2b2lkICopY29uZi0+bWlycm9yc1tpXS5yZGV2
Ow0KDQpTaG91bGQgdGhlc2UgYXNzaWdubWVudHMgcGVyaGFwcyBiZSBmb2xsb3dlZCBieSBhIG1i
aW8tPmJpX3BhcnRubyBhc3NpZ25tZW50Pw0KDQpIb3cgYWJvdXQgdGhlIGZvbGxvd2luZyBjbGFz
cyBvZiBhc3NpZ25tZW50cyBpbiB0aGUgTlZNZSBjb2RlOg0KDQogICAgICAgICAgICAgICBiaW8t
PmJpX2Rpc2sgPSBkaXNrOw0KDQpTaG91bGQgdGhlc2UgYXNzaWdubWVudHMgcGVyaGFwcyBiZSBm
b2xsb3dlZCBieSBhIGJpby0+YmlfcGFydG5vIGFzc2lnbm1lbnQ/DQoNClRoYW5rcywNCg0KQmFy
dC4=

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17 16:50 ` Bart Van Assche
@ 2017-11-17 17:02   ` Michael Lyle
  2017-11-17 17:18   ` hch
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Lyle @ 2017-11-17 17:02 UTC (permalink / raw)
  To: Bart Van Assche, linux-bcache@vger.kernel.org,
	linux-block@vger.kernel.org
  Cc: hch@lst.de, stable@vger.kernel.org, axboe@kernel.dk

Jens & everyone-- thanks for the speedy review and handling.  I've
updated my test cases to ensure that volumes from old releases work,
even when I "don't think" there's been a disk format change.

Bart--

On 11/17/2017 08:50 AM, Bart Van Assche wrote:
> Have you considered to use bio_copy_dev() instead of open-coding it?

One could... Right now almost all the uses of bio_copy_dev are in bcache
and they need to change for other reasons.  (e.g. macro uses parameter
more than once, function is passed in as parameter).  There's a whole
lot of places to change if it's desired to make bio_copy_dev universally
used to copy device information.

> Additionally, there is more code that copies these fields, e.g. the code in
> bio_clone_bioset(). Shouldn't that code be modified such that it also copies
> bi_partno?

Yes, when I was grepping around there were other things that looked
possibly unsafe.  I don't have test environments for all of these other
subsystems.

I wanted to get the minimal fix for this in, though, because people are
actively losing data to the problem it triggers with bcache.

Mike

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17 16:50 ` Bart Van Assche
  2017-11-17 17:02   ` Michael Lyle
@ 2017-11-17 17:18   ` hch
  1 sibling, 0 replies; 9+ messages in thread
From: hch @ 2017-11-17 17:18 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org,
	mlyle@lyle.org, hch@lst.de, stable@vger.kernel.org,
	axboe@kernel.dk

On Fri, Nov 17, 2017 at 04:50:39PM +0000, Bart Van Assche wrote:
> 
> How about the following class of assignments in drivers/md/raid1.c:
> 
> 		mbio->bi_disk = (void *)conf->mirrors[i].rdev;
> 
> Should these assignments perhaps be followed by a mbio->bi_partno assignment?

No.  They assign a struct md_rdev to the bi_disk pointer, abusing it
for internal storage.  They should not assign mbio->bi_partno.
Instead we should figure out a way to get rid of this.

> 
> How about the following class of assignments in the NVMe code:
> 
>                bio->bi_disk = disk;
> 
> Should these assignments perhaps be followed by a bio->bi_partno assignment?

No, the multipath code always works on whole namespaces, not partitions.

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

* Re: [PATCH] bio: ensure __bio_clone_fast copies bi_partno
  2017-11-17  7:47 [PATCH] bio: ensure __bio_clone_fast copies bi_partno Michael Lyle
                   ` (4 preceding siblings ...)
  2017-11-17 16:50 ` Bart Van Assche
@ 2017-11-17 20:25 ` Campbell Steven
  5 siblings, 0 replies; 9+ messages in thread
From: Campbell Steven @ 2017-11-17 20:25 UTC (permalink / raw)
  To: Michael Lyle
  Cc: linux-block, linux-bcache, Christoph Hellwig, Jens Axboe, stable

On 17 November 2017 at 20:47, Michael Lyle <mlyle@lyle.org> wrote:
> A new field was introduced in 74d46992e0d9dee7f1f376de0d56d31614c8a17a,
> bi_partno, instead of using bdev->bd_contains and encoding the partition
> information in the bi_bdev field.  __bio_clone_fast was changed to copy
> the disk information, but not the partition information.  At minimum,
> this regressed bcache and caused data corruption.

Thanks alot for this Michael, I will run it up on our test servers today.

Campbell

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

end of thread, other threads:[~2017-11-17 20:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-17  7:47 [PATCH] bio: ensure __bio_clone_fast copies bi_partno Michael Lyle
2017-11-17 11:04 ` Coly Li
2017-11-17 11:34 ` Ming Lei
2017-11-17 15:08 ` Christoph Hellwig
2017-11-17 15:27 ` Jens Axboe
2017-11-17 16:50 ` Bart Van Assche
2017-11-17 17:02   ` Michael Lyle
2017-11-17 17:18   ` hch
2017-11-17 20:25 ` Campbell Steven

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).