All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary. (fwd)
@ 2021-02-22 18:15 ` Mikulas Patocka
  0 siblings, 0 replies; 10+ messages in thread
From: Mikulas Patocka @ 2021-02-22 18:15 UTC (permalink / raw)
  To: Jens Axboe, Marian Csontos; +Cc: linux-block, dm-devel



---------- Forwarded message ----------
Date: Thu, 19 Nov 2020 15:36:51 -0500 (EST)
From: Mikulas Patocka <mpatocka@redhat.com>
To: David Teigland <teigland@redhat.com>, Jens Axboe <axboe@kernel.dk>
Cc: heinzm@redhat.com, Zdenek Kabelac <zkabelac@redhat.com>,
    Marian Csontos <mcsontos@redhat.com>, linux-block@vger.kernel.org,
    dm-devel@redhat.com
Subject: [PATCH] blk-settings: make sure that max_sectors is aligned on
    "logical_block_size" boundary.

We get these I/O errors when we run md-raid1 on the top of dm-integrity on 
the top of ramdisk:
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb

The ramdisk device has logical_block_size 512 and max_sectors 255. The 
dm-integrity device uses logical_block_size 4096 and it doesn't affect the 
"max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have 
a device with max_sectors not aligned on logical_block_size.

The md-raid device sees that the underlying leg has max_sectors 255 and it
will split the bios on 255-sector boundary, making the bios unaligned on
logical_block_size.

In order to fix the bug, we round down max_sectors to logical_block_size.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

---
 block/blk-settings.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Index: linux-2.6/block/blk-settings.c
===================================================================
--- linux-2.6.orig/block/blk-settings.c	2020-10-29 12:20:46.000000000 +0100
+++ linux-2.6/block/blk-settings.c	2020-11-19 21:20:18.000000000 +0100
@@ -591,6 +591,16 @@ int blk_stack_limits(struct queue_limits
 		ret = -1;
 	}
 
+	t->max_sectors = round_down(t->max_sectors, t->logical_block_size / 512);
+	if (t->max_sectors < PAGE_SIZE / 512)
+		t->max_sectors = PAGE_SIZE / 512;
+	t->max_hw_sectors = round_down(t->max_hw_sectors, t->logical_block_size / 512);
+	if (t->max_sectors < PAGE_SIZE / 512)
+		t->max_hw_sectors = PAGE_SIZE / 512;
+	t->max_dev_sectors = round_down(t->max_dev_sectors, t->logical_block_size / 512);
+	if (t->max_sectors < PAGE_SIZE / 512)
+		t->max_dev_sectors = PAGE_SIZE / 512;
+
 	/* Discard alignment and granularity */
 	if (b->discard_granularity) {
 		alignment = queue_limit_discard_alignment(b, start);


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

* [dm-devel] [PATCH] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary. (fwd)
@ 2021-02-22 18:15 ` Mikulas Patocka
  0 siblings, 0 replies; 10+ messages in thread
From: Mikulas Patocka @ 2021-02-22 18:15 UTC (permalink / raw)
  To: Jens Axboe, Marian Csontos; +Cc: linux-block, dm-devel



---------- Forwarded message ----------
Date: Thu, 19 Nov 2020 15:36:51 -0500 (EST)
From: Mikulas Patocka <mpatocka@redhat.com>
To: David Teigland <teigland@redhat.com>, Jens Axboe <axboe@kernel.dk>
Cc: heinzm@redhat.com, Zdenek Kabelac <zkabelac@redhat.com>,
    Marian Csontos <mcsontos@redhat.com>, linux-block@vger.kernel.org,
    dm-devel@redhat.com
Subject: [PATCH] blk-settings: make sure that max_sectors is aligned on
    "logical_block_size" boundary.

We get these I/O errors when we run md-raid1 on the top of dm-integrity on 
the top of ramdisk:
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb

The ramdisk device has logical_block_size 512 and max_sectors 255. The 
dm-integrity device uses logical_block_size 4096 and it doesn't affect the 
"max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have 
a device with max_sectors not aligned on logical_block_size.

The md-raid device sees that the underlying leg has max_sectors 255 and it
will split the bios on 255-sector boundary, making the bios unaligned on
logical_block_size.

In order to fix the bug, we round down max_sectors to logical_block_size.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

---
 block/blk-settings.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Index: linux-2.6/block/blk-settings.c
===================================================================
--- linux-2.6.orig/block/blk-settings.c	2020-10-29 12:20:46.000000000 +0100
+++ linux-2.6/block/blk-settings.c	2020-11-19 21:20:18.000000000 +0100
@@ -591,6 +591,16 @@ int blk_stack_limits(struct queue_limits
 		ret = -1;
 	}
 
+	t->max_sectors = round_down(t->max_sectors, t->logical_block_size / 512);
+	if (t->max_sectors < PAGE_SIZE / 512)
+		t->max_sectors = PAGE_SIZE / 512;
+	t->max_hw_sectors = round_down(t->max_hw_sectors, t->logical_block_size / 512);
+	if (t->max_sectors < PAGE_SIZE / 512)
+		t->max_hw_sectors = PAGE_SIZE / 512;
+	t->max_dev_sectors = round_down(t->max_dev_sectors, t->logical_block_size / 512);
+	if (t->max_sectors < PAGE_SIZE / 512)
+		t->max_dev_sectors = PAGE_SIZE / 512;
+
 	/* Discard alignment and granularity */
 	if (b->discard_granularity) {
 		alignment = queue_limit_discard_alignment(b, start);

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


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

* Re: [PATCH] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary. (fwd)
  2021-02-22 18:15 ` [dm-devel] " Mikulas Patocka
@ 2021-02-23  7:37   ` Ming Lei
  -1 siblings, 0 replies; 10+ messages in thread
From: Ming Lei @ 2021-02-23  7:37 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: Jens Axboe, Marian Csontos, linux-block, dm-devel

On Mon, Feb 22, 2021 at 01:15:32PM -0500, Mikulas Patocka wrote:
> 
> 
> ---------- Forwarded message ----------
> Date: Thu, 19 Nov 2020 15:36:51 -0500 (EST)
> From: Mikulas Patocka <mpatocka@redhat.com>
> To: David Teigland <teigland@redhat.com>, Jens Axboe <axboe@kernel.dk>
> Cc: heinzm@redhat.com, Zdenek Kabelac <zkabelac@redhat.com>,
>     Marian Csontos <mcsontos@redhat.com>, linux-block@vger.kernel.org,
>     dm-devel@redhat.com
> Subject: [PATCH] blk-settings: make sure that max_sectors is aligned on
>     "logical_block_size" boundary.
> 
> We get these I/O errors when we run md-raid1 on the top of dm-integrity on 
> the top of ramdisk:
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb
> 
> The ramdisk device has logical_block_size 512 and max_sectors 255. The 
> dm-integrity device uses logical_block_size 4096 and it doesn't affect the 
> "max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have 
> a device with max_sectors not aligned on logical_block_size.
> 
> The md-raid device sees that the underlying leg has max_sectors 255 and it
> will split the bios on 255-sector boundary, making the bios unaligned on
> logical_block_size.
> 
> In order to fix the bug, we round down max_sectors to logical_block_size.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org
> 
> ---
>  block/blk-settings.c |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> Index: linux-2.6/block/blk-settings.c
> ===================================================================
> --- linux-2.6.orig/block/blk-settings.c	2020-10-29 12:20:46.000000000 +0100
> +++ linux-2.6/block/blk-settings.c	2020-11-19 21:20:18.000000000 +0100
> @@ -591,6 +591,16 @@ int blk_stack_limits(struct queue_limits
>  		ret = -1;
>  	}
>  
> +	t->max_sectors = round_down(t->max_sectors, t->logical_block_size / 512);
> +	if (t->max_sectors < PAGE_SIZE / 512)
> +		t->max_sectors = PAGE_SIZE / 512;
> +	t->max_hw_sectors = round_down(t->max_hw_sectors, t->logical_block_size / 512);
> +	if (t->max_sectors < PAGE_SIZE / 512)

	if (t->max_hw_sectors < PAGE_SIZE / 512)

> +		t->max_hw_sectors = PAGE_SIZE / 512;
> +	t->max_dev_sectors = round_down(t->max_dev_sectors, t->logical_block_size / 512);
> +	if (t->max_sectors < PAGE_SIZE / 512)

	if (t->max_dev_sectors < PAGE_SIZE / 512)

> +		t->max_dev_sectors = PAGE_SIZE / 512;

I'd suggest to add a helper(such as, blk_round_down_sectors()) to round_down each
one.

-- 
Ming


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

* Re: [dm-devel] [PATCH] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary. (fwd)
@ 2021-02-23  7:37   ` Ming Lei
  0 siblings, 0 replies; 10+ messages in thread
From: Ming Lei @ 2021-02-23  7:37 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: Jens Axboe, linux-block, dm-devel, Marian Csontos

On Mon, Feb 22, 2021 at 01:15:32PM -0500, Mikulas Patocka wrote:
> 
> 
> ---------- Forwarded message ----------
> Date: Thu, 19 Nov 2020 15:36:51 -0500 (EST)
> From: Mikulas Patocka <mpatocka@redhat.com>
> To: David Teigland <teigland@redhat.com>, Jens Axboe <axboe@kernel.dk>
> Cc: heinzm@redhat.com, Zdenek Kabelac <zkabelac@redhat.com>,
>     Marian Csontos <mcsontos@redhat.com>, linux-block@vger.kernel.org,
>     dm-devel@redhat.com
> Subject: [PATCH] blk-settings: make sure that max_sectors is aligned on
>     "logical_block_size" boundary.
> 
> We get these I/O errors when we run md-raid1 on the top of dm-integrity on 
> the top of ramdisk:
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb
> 
> The ramdisk device has logical_block_size 512 and max_sectors 255. The 
> dm-integrity device uses logical_block_size 4096 and it doesn't affect the 
> "max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have 
> a device with max_sectors not aligned on logical_block_size.
> 
> The md-raid device sees that the underlying leg has max_sectors 255 and it
> will split the bios on 255-sector boundary, making the bios unaligned on
> logical_block_size.
> 
> In order to fix the bug, we round down max_sectors to logical_block_size.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org
> 
> ---
>  block/blk-settings.c |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> Index: linux-2.6/block/blk-settings.c
> ===================================================================
> --- linux-2.6.orig/block/blk-settings.c	2020-10-29 12:20:46.000000000 +0100
> +++ linux-2.6/block/blk-settings.c	2020-11-19 21:20:18.000000000 +0100
> @@ -591,6 +591,16 @@ int blk_stack_limits(struct queue_limits
>  		ret = -1;
>  	}
>  
> +	t->max_sectors = round_down(t->max_sectors, t->logical_block_size / 512);
> +	if (t->max_sectors < PAGE_SIZE / 512)
> +		t->max_sectors = PAGE_SIZE / 512;
> +	t->max_hw_sectors = round_down(t->max_hw_sectors, t->logical_block_size / 512);
> +	if (t->max_sectors < PAGE_SIZE / 512)

	if (t->max_hw_sectors < PAGE_SIZE / 512)

> +		t->max_hw_sectors = PAGE_SIZE / 512;
> +	t->max_dev_sectors = round_down(t->max_dev_sectors, t->logical_block_size / 512);
> +	if (t->max_sectors < PAGE_SIZE / 512)

	if (t->max_dev_sectors < PAGE_SIZE / 512)

> +		t->max_dev_sectors = PAGE_SIZE / 512;

I'd suggest to add a helper(such as, blk_round_down_sectors()) to round_down each
one.

-- 
Ming

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


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

* [PATCH v2] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary
  2021-02-23  7:37   ` [dm-devel] " Ming Lei
@ 2021-02-23 16:28     ` Mikulas Patocka
  -1 siblings, 0 replies; 10+ messages in thread
From: Mikulas Patocka @ 2021-02-23 16:28 UTC (permalink / raw)
  To: Jens Axboe, Ming Lei; +Cc: Mike Snitzer, Marian Csontos, linux-block, dm-devel



On Tue, 23 Feb 2021, Ming Lei wrote:

> I'd suggest to add a helper(such as, blk_round_down_sectors()) to round_down each
> one.

Yes - Here I'm sending the updated patch.

> -- 
> Ming

From: Mikulas Patocka <mpatocka@redhat.com>

We get I/O errors when we run md-raid1 on the top of dm-integrity on the
top of ramdisk.
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb

The ramdisk device has logical_block_size 512 and max_sectors 255. The
dm-integrity device uses logical_block_size 4096 and it doesn't affect the
"max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have
a device with max_sectors not aligned on logical_block_size.

The md-raid device sees that the underlying leg has max_sectors 255 and it
will split the bios on 255-sector boundary, making the bios unaligned on
logical_block_size.

In order to fix the bug, we round down max_sectors to logical_block_size.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

---
 block/blk-settings.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Index: linux-2.6/block/blk-settings.c
===================================================================
--- linux-2.6.orig/block/blk-settings.c	2021-02-23 17:18:59.000000000 +0100
+++ linux-2.6/block/blk-settings.c	2021-02-23 17:23:58.000000000 +0100
@@ -481,6 +481,14 @@ void blk_queue_io_opt(struct request_que
 }
 EXPORT_SYMBOL(blk_queue_io_opt);
 
+static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs)
+{
+	sectors = round_down(sectors, lbs >> SECTOR_SHIFT);
+	if (sectors < PAGE_SIZE >> SECTOR_SHIFT)
+		sectors = PAGE_SIZE >> SECTOR_SHIFT;
+	return sectors;
+}
+
 /**
  * blk_stack_limits - adjust queue_limits for stacked devices
  * @t:	the stacking driver limits (top device)
@@ -607,6 +615,10 @@ int blk_stack_limits(struct queue_limits
 		ret = -1;
 	}
 
+	t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size);
+	t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size);
+	t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size);
+
 	/* Discard alignment and granularity */
 	if (b->discard_granularity) {
 		alignment = queue_limit_discard_alignment(b, start);


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

* [dm-devel] [PATCH v2] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary
@ 2021-02-23 16:28     ` Mikulas Patocka
  0 siblings, 0 replies; 10+ messages in thread
From: Mikulas Patocka @ 2021-02-23 16:28 UTC (permalink / raw)
  To: Jens Axboe, Ming Lei; +Cc: linux-block, Mike Snitzer, Marian Csontos, dm-devel



On Tue, 23 Feb 2021, Ming Lei wrote:

> I'd suggest to add a helper(such as, blk_round_down_sectors()) to round_down each
> one.

Yes - Here I'm sending the updated patch.

> -- 
> Ming

From: Mikulas Patocka <mpatocka@redhat.com>

We get I/O errors when we run md-raid1 on the top of dm-integrity on the
top of ramdisk.
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb

The ramdisk device has logical_block_size 512 and max_sectors 255. The
dm-integrity device uses logical_block_size 4096 and it doesn't affect the
"max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have
a device with max_sectors not aligned on logical_block_size.

The md-raid device sees that the underlying leg has max_sectors 255 and it
will split the bios on 255-sector boundary, making the bios unaligned on
logical_block_size.

In order to fix the bug, we round down max_sectors to logical_block_size.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Cc: stable@vger.kernel.org

---
 block/blk-settings.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Index: linux-2.6/block/blk-settings.c
===================================================================
--- linux-2.6.orig/block/blk-settings.c	2021-02-23 17:18:59.000000000 +0100
+++ linux-2.6/block/blk-settings.c	2021-02-23 17:23:58.000000000 +0100
@@ -481,6 +481,14 @@ void blk_queue_io_opt(struct request_que
 }
 EXPORT_SYMBOL(blk_queue_io_opt);
 
+static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs)
+{
+	sectors = round_down(sectors, lbs >> SECTOR_SHIFT);
+	if (sectors < PAGE_SIZE >> SECTOR_SHIFT)
+		sectors = PAGE_SIZE >> SECTOR_SHIFT;
+	return sectors;
+}
+
 /**
  * blk_stack_limits - adjust queue_limits for stacked devices
  * @t:	the stacking driver limits (top device)
@@ -607,6 +615,10 @@ int blk_stack_limits(struct queue_limits
 		ret = -1;
 	}
 
+	t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size);
+	t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size);
+	t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size);
+
 	/* Discard alignment and granularity */
 	if (b->discard_granularity) {
 		alignment = queue_limit_discard_alignment(b, start);

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


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

* Re: [PATCH v2] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary
  2021-02-23 16:28     ` [dm-devel] " Mikulas Patocka
@ 2021-02-24  0:39       ` Ming Lei
  -1 siblings, 0 replies; 10+ messages in thread
From: Ming Lei @ 2021-02-24  0:39 UTC (permalink / raw)
  To: Mikulas Patocka
  Cc: Jens Axboe, Mike Snitzer, Marian Csontos, linux-block, dm-devel

On Tue, Feb 23, 2021 at 11:28:27AM -0500, Mikulas Patocka wrote:
> 
> 
> On Tue, 23 Feb 2021, Ming Lei wrote:
> 
> > I'd suggest to add a helper(such as, blk_round_down_sectors()) to round_down each
> > one.
> 
> Yes - Here I'm sending the updated patch.
> 
> > -- 
> > Ming
> 
> From: Mikulas Patocka <mpatocka@redhat.com>
> 
> We get I/O errors when we run md-raid1 on the top of dm-integrity on the
> top of ramdisk.
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb
> 
> The ramdisk device has logical_block_size 512 and max_sectors 255. The
> dm-integrity device uses logical_block_size 4096 and it doesn't affect the
> "max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have
> a device with max_sectors not aligned on logical_block_size.
> 
> The md-raid device sees that the underlying leg has max_sectors 255 and it
> will split the bios on 255-sector boundary, making the bios unaligned on
> logical_block_size.
> 
> In order to fix the bug, we round down max_sectors to logical_block_size.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org
> 
> ---
>  block/blk-settings.c |   12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> Index: linux-2.6/block/blk-settings.c
> ===================================================================
> --- linux-2.6.orig/block/blk-settings.c	2021-02-23 17:18:59.000000000 +0100
> +++ linux-2.6/block/blk-settings.c	2021-02-23 17:23:58.000000000 +0100
> @@ -481,6 +481,14 @@ void blk_queue_io_opt(struct request_que
>  }
>  EXPORT_SYMBOL(blk_queue_io_opt);
>  
> +static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs)
> +{
> +	sectors = round_down(sectors, lbs >> SECTOR_SHIFT);
> +	if (sectors < PAGE_SIZE >> SECTOR_SHIFT)
> +		sectors = PAGE_SIZE >> SECTOR_SHIFT;
> +	return sectors;
> +}
> +
>  /**
>   * blk_stack_limits - adjust queue_limits for stacked devices
>   * @t:	the stacking driver limits (top device)
> @@ -607,6 +615,10 @@ int blk_stack_limits(struct queue_limits
>  		ret = -1;
>  	}
>  
> +	t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size);
> +	t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size);
> +	t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size);
> +
>  	/* Discard alignment and granularity */
>  	if (b->discard_granularity) {
>  		alignment = queue_limit_discard_alignment(b, start);

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

-- 
Ming


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

* Re: [dm-devel] [PATCH v2] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary
@ 2021-02-24  0:39       ` Ming Lei
  0 siblings, 0 replies; 10+ messages in thread
From: Ming Lei @ 2021-02-24  0:39 UTC (permalink / raw)
  To: Mikulas Patocka
  Cc: Jens Axboe, linux-block, Mike Snitzer, Marian Csontos, dm-devel

On Tue, Feb 23, 2021 at 11:28:27AM -0500, Mikulas Patocka wrote:
> 
> 
> On Tue, 23 Feb 2021, Ming Lei wrote:
> 
> > I'd suggest to add a helper(such as, blk_round_down_sectors()) to round_down each
> > one.
> 
> Yes - Here I'm sending the updated patch.
> 
> > -- 
> > Ming
> 
> From: Mikulas Patocka <mpatocka@redhat.com>
> 
> We get I/O errors when we run md-raid1 on the top of dm-integrity on the
> top of ramdisk.
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xff00, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0xffff, 0x1
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8048, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8147, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8246, 0xff
> device-mapper: integrity: Bio not aligned on 8 sectors: 0x8345, 0xbb
> 
> The ramdisk device has logical_block_size 512 and max_sectors 255. The
> dm-integrity device uses logical_block_size 4096 and it doesn't affect the
> "max_sectors" value - thus, it inherits 255 from the ramdisk. So, we have
> a device with max_sectors not aligned on logical_block_size.
> 
> The md-raid device sees that the underlying leg has max_sectors 255 and it
> will split the bios on 255-sector boundary, making the bios unaligned on
> logical_block_size.
> 
> In order to fix the bug, we round down max_sectors to logical_block_size.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Cc: stable@vger.kernel.org
> 
> ---
>  block/blk-settings.c |   12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> Index: linux-2.6/block/blk-settings.c
> ===================================================================
> --- linux-2.6.orig/block/blk-settings.c	2021-02-23 17:18:59.000000000 +0100
> +++ linux-2.6/block/blk-settings.c	2021-02-23 17:23:58.000000000 +0100
> @@ -481,6 +481,14 @@ void blk_queue_io_opt(struct request_que
>  }
>  EXPORT_SYMBOL(blk_queue_io_opt);
>  
> +static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs)
> +{
> +	sectors = round_down(sectors, lbs >> SECTOR_SHIFT);
> +	if (sectors < PAGE_SIZE >> SECTOR_SHIFT)
> +		sectors = PAGE_SIZE >> SECTOR_SHIFT;
> +	return sectors;
> +}
> +
>  /**
>   * blk_stack_limits - adjust queue_limits for stacked devices
>   * @t:	the stacking driver limits (top device)
> @@ -607,6 +615,10 @@ int blk_stack_limits(struct queue_limits
>  		ret = -1;
>  	}
>  
> +	t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size);
> +	t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size);
> +	t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size);
> +
>  	/* Discard alignment and granularity */
>  	if (b->discard_granularity) {
>  		alignment = queue_limit_discard_alignment(b, start);

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

-- 
Ming

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


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

* Re: [PATCH v2] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary
  2021-02-23 16:28     ` [dm-devel] " Mikulas Patocka
@ 2021-02-24  2:26       ` Jens Axboe
  -1 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2021-02-24  2:26 UTC (permalink / raw)
  To: Mikulas Patocka, Ming Lei
  Cc: Mike Snitzer, Marian Csontos, linux-block, dm-devel

Applied, thanks.

-- 
Jens Axboe


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

* Re: [dm-devel] [PATCH v2] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary
@ 2021-02-24  2:26       ` Jens Axboe
  0 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2021-02-24  2:26 UTC (permalink / raw)
  To: Mikulas Patocka, Ming Lei
  Cc: linux-block, Mike Snitzer, Marian Csontos, dm-devel

Applied, thanks.

-- 
Jens Axboe

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel


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

end of thread, other threads:[~2021-02-24  2:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 18:15 [PATCH] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary. (fwd) Mikulas Patocka
2021-02-22 18:15 ` [dm-devel] " Mikulas Patocka
2021-02-23  7:37 ` Ming Lei
2021-02-23  7:37   ` [dm-devel] " Ming Lei
2021-02-23 16:28   ` [PATCH v2] blk-settings: make sure that max_sectors is aligned on "logical_block_size" boundary Mikulas Patocka
2021-02-23 16:28     ` [dm-devel] " Mikulas Patocka
2021-02-24  0:39     ` Ming Lei
2021-02-24  0:39       ` [dm-devel] " Ming Lei
2021-02-24  2:26     ` Jens Axboe
2021-02-24  2:26       ` [dm-devel] " Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.