public inbox for linux-bcache@vger.kernel.org
 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
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ 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] 10+ 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
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ 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] 10+ 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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ 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] 10+ 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
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ 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] 10+ 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
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ 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] 10+ 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
  2017-11-21 15:38 ` Pavel Goran
  6 siblings, 2 replies; 10+ 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.org, axboe@kernel.dk

On Thu, 2017-11-16 at 23:47 -0800, Michael Lyle wrote:
> 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;

Have you considered to use bio_copy_dev() instead of open-coding it?

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?

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?

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?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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
  2017-11-21 15:38 ` Pavel Goran
  6 siblings, 0 replies; 10+ 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] 10+ 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
                   ` (5 preceding siblings ...)
  2017-11-17 20:25 ` Campbell Steven
@ 2017-11-21 15:38 ` Pavel Goran
  6 siblings, 0 replies; 10+ messages in thread
From: Pavel Goran @ 2017-11-21 15:38 UTC (permalink / raw)
  To: Michael Lyle; +Cc: linux-bcache

Hello Michael,

Friday, November 17, 2017, 2:47:25 PM, you 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 for the patch. It resolved the issue for me, I'm now running 4.14
without apparent problems.

> 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;

Pavel Goran
  

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

end of thread, other threads:[~2017-11-21 15:38 UTC | newest]

Thread overview: 10+ 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
2017-11-21 15:38 ` Pavel Goran

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