mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten
@ 2025-12-26  2:42 linan666
  2025-12-26  2:42 ` [PATCH v3 2/2] md: Fix forward incompatibility from configurable logical block size linan666
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: linan666 @ 2025-12-26  2:42 UTC (permalink / raw)
  To: song, yukuai, linan122, xni
  Cc: linux-raid, linux-kernel, bugreports61, linan666, yangerkun, yi.zhang

From: Li Nan <linan122@huawei.com>

In super_1_validate(), mddev->logical_block_size is directly overwritten
with the value from metadata. This causes the previously configured lbs
to be lost, making the configuration ineffective. Fix it.

Fixes: 62ed1b582246 ("md: allow configuring logical block size")
Signed-off-by: Li Nan <linan122@huawei.com>
Reviewed-by: Yu Kuai <yukuai@fnnas.com>
---
 drivers/md/md.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index e5922a682953..7c0dd94a4d25 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1999,7 +1999,6 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struc
 		mddev->layout = le32_to_cpu(sb->layout);
 		mddev->raid_disks = le32_to_cpu(sb->raid_disks);
 		mddev->dev_sectors = le64_to_cpu(sb->size);
-		mddev->logical_block_size = le32_to_cpu(sb->logical_block_size);
 		mddev->events = ev1;
 		mddev->bitmap_info.offset = 0;
 		mddev->bitmap_info.space = 0;
@@ -2015,6 +2014,9 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struc
 
 		mddev->max_disks =  (4096-256)/2;
 
+		if (!mddev->logical_block_size)
+			mddev->logical_block_size = le32_to_cpu(sb->logical_block_size);
+
 		if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) &&
 		    mddev->bitmap_info.file == NULL) {
 			mddev->bitmap_info.offset =
-- 
2.39.2


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

* [PATCH v3 2/2] md: Fix forward incompatibility from configurable logical block size
  2025-12-26  2:42 [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten linan666
@ 2025-12-26  2:42 ` linan666
  2025-12-27  2:16   ` Yu Kuai
  2025-12-26  7:49 ` [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten Xiao Ni
  2025-12-27  2:15 ` Yu Kuai
  2 siblings, 1 reply; 5+ messages in thread
From: linan666 @ 2025-12-26  2:42 UTC (permalink / raw)
  To: song, yukuai, linan122, xni
  Cc: linux-raid, linux-kernel, bugreports61, linan666, yangerkun, yi.zhang

From: Li Nan <linan122@huawei.com>

Commit 62ed1b582246 ("md: allow configuring logical block size") used
reserved pad to add 'logical_block_size' to metadata. RAID rejects
non-zero reserved pad, so arrays fail when rolling back to old kernels
after booting new ones.

Set 'logical_block_size' only for newly created arrays to support rollback
to old kernels. Importantly new arrays still won't work on old kernels to
prevent data loss issue from LBS changes.

For arrays created on old kernels which confirmed not to rollback,
configure LBS by echo current LBS (queue/logical_block_size) to
md/logical_block_size.

Fixes: 62ed1b582246 ("md: allow configuring logical block size")
Reported-by: BugReports <bugreports61@gmail.com>
Closes: https://lore.kernel.org/linux-raid/825e532d-d1e1-44bb-5581-692b7c091796@huaweicloud.com/T/#t
Signed-off-by: Li Nan <linan122@huawei.com>
---
v3:
  - fix comment: %s/writing 'enable'/writing current LBS/

v2:
  - move warn message to mddev_stack_rdev_limits
  - set current LBS to sysfs to enable feature instead of 'enable'

 drivers/md/md.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 7c0dd94a4d25..d8e69d7f8ccb 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5983,13 +5983,33 @@ lbs_store(struct mddev *mddev, const char *buf, size_t len)
 	if (mddev->major_version == 0)
 		return -EINVAL;
 
-	if (mddev->pers)
-		return -EBUSY;
-
 	err = kstrtouint(buf, 10, &lbs);
 	if (err < 0)
 		return -EINVAL;
 
+	if (mddev->pers) {
+		unsigned int curr_lbs;
+
+		if (mddev->logical_block_size)
+			return -EBUSY;
+		/*
+		 * To fix forward compatibility issues, LBS is not
+		 * configured in old kernels array (<=6.18) by default.
+		 * If the user confirms no rollback to old kernels,
+		 * enable LBS by writing current LBS — to prevent data
+		 * loss from LBS changes.
+		 */
+		curr_lbs = queue_logical_block_size(mddev->gendisk->queue);
+		if (lbs != curr_lbs)
+			return -EINVAL;
+
+		mddev->logical_block_size = curr_lbs;
+		set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
+		pr_info("%s: config logical block size success, array will not be assembled in old kernels (<= 6.18)\n",
+			mdname(mddev));
+		return len;
+	}
+
 	err = mddev_lock(mddev);
 	if (err)
 		goto unlock;
@@ -6165,7 +6185,27 @@ int mddev_stack_rdev_limits(struct mddev *mddev, struct queue_limits *lim,
 			mdname(mddev));
 		return -EINVAL;
 	}
-	mddev->logical_block_size = lim->logical_block_size;
+
+	/* Only 1.x meta needs to set logical block size */
+	if (mddev->major_version == 0)
+		return 0;
+
+	/*
+	 * Fix forward compatibility issue. Only set LBS by default for
+	 * new array, mddev->events == 0 indicates the array was just
+	 * created. When assembling an array, read LBS from the superblock
+	 * instead — LBS is 0 in superblocks created by old kernels.
+	 */
+	if (!mddev->events) {
+		pr_info("%s: array will not be assembled in old kernels that lack configurable lbs support (<= 6.18)\n",
+			mdname(mddev));
+		mddev->logical_block_size = lim->logical_block_size;
+	}
+
+	if (!mddev->logical_block_size)
+		pr_warn("%s: echo current LBS to md/logical_block_size to prevent data loss issue from LBS changes.\n"
+			"\tNote: After setting, array will not be assembled in old kernels (<= 6.18)\n",
+			mdname(mddev));
 
 	return 0;
 }
-- 
2.39.2


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

* Re: [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten
  2025-12-26  2:42 [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten linan666
  2025-12-26  2:42 ` [PATCH v3 2/2] md: Fix forward incompatibility from configurable logical block size linan666
@ 2025-12-26  7:49 ` Xiao Ni
  2025-12-27  2:15 ` Yu Kuai
  2 siblings, 0 replies; 5+ messages in thread
From: Xiao Ni @ 2025-12-26  7:49 UTC (permalink / raw)
  To: linan666
  Cc: song, yukuai, linan122, linux-raid, linux-kernel, bugreports61,
	yangerkun, yi.zhang

On Fri, Dec 26, 2025 at 10:54 AM <linan666@huaweicloud.com> wrote:
>
> From: Li Nan <linan122@huawei.com>
>
> In super_1_validate(), mddev->logical_block_size is directly overwritten
> with the value from metadata. This causes the previously configured lbs
> to be lost, making the configuration ineffective. Fix it.
>
> Fixes: 62ed1b582246 ("md: allow configuring logical block size")
> Signed-off-by: Li Nan <linan122@huawei.com>
> Reviewed-by: Yu Kuai <yukuai@fnnas.com>
> ---
>  drivers/md/md.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index e5922a682953..7c0dd94a4d25 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1999,7 +1999,6 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struc
>                 mddev->layout = le32_to_cpu(sb->layout);
>                 mddev->raid_disks = le32_to_cpu(sb->raid_disks);
>                 mddev->dev_sectors = le64_to_cpu(sb->size);
> -               mddev->logical_block_size = le32_to_cpu(sb->logical_block_size);
>                 mddev->events = ev1;
>                 mddev->bitmap_info.offset = 0;
>                 mddev->bitmap_info.space = 0;
> @@ -2015,6 +2014,9 @@ static int super_1_validate(struct mddev *mddev, struct md_rdev *freshest, struc
>
>                 mddev->max_disks =  (4096-256)/2;
>
> +               if (!mddev->logical_block_size)
> +                       mddev->logical_block_size = le32_to_cpu(sb->logical_block_size);
> +
>                 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) &&
>                     mddev->bitmap_info.file == NULL) {
>                         mddev->bitmap_info.offset =
> --
> 2.39.2
>

Reviewed-by: Xiao Ni <xni@redhat.com>


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

* Re: [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten
  2025-12-26  2:42 [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten linan666
  2025-12-26  2:42 ` [PATCH v3 2/2] md: Fix forward incompatibility from configurable logical block size linan666
  2025-12-26  7:49 ` [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten Xiao Ni
@ 2025-12-27  2:15 ` Yu Kuai
  2 siblings, 0 replies; 5+ messages in thread
From: Yu Kuai @ 2025-12-27  2:15 UTC (permalink / raw)
  To: linan666, song, linan122, xni
  Cc: linux-raid, linux-kernel, bugreports61, yangerkun, yi.zhang, yukuai

在 2025/12/26 10:42, linan666@huaweicloud.com 写道:

> In super_1_validate(), mddev->logical_block_size is directly overwritten
> with the value from metadata. This causes the previously configured lbs
> to be lost, making the configuration ineffective. Fix it.
>
> Fixes: 62ed1b582246 ("md: allow configuring logical block size")
> Signed-off-by: Li Nan<linan122@huawei.com>
> Reviewed-by: Yu Kuai<yukuai@fnnas.com>
> ---
>   drivers/md/md.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)

Applied to md-6.19

-- 
Thansk,
Kuai

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

* Re: [PATCH v3 2/2] md: Fix forward incompatibility from configurable logical block size
  2025-12-26  2:42 ` [PATCH v3 2/2] md: Fix forward incompatibility from configurable logical block size linan666
@ 2025-12-27  2:16   ` Yu Kuai
  0 siblings, 0 replies; 5+ messages in thread
From: Yu Kuai @ 2025-12-27  2:16 UTC (permalink / raw)
  To: linan666, song, linan122, xni
  Cc: linux-raid, linux-kernel, bugreports61, yangerkun, yi.zhang, yukuai

在 2025/12/26 10:42, linan666@huaweicloud.com 写道:

> From: Li Nan<linan122@huawei.com>
>
> Commit 62ed1b582246 ("md: allow configuring logical block size") used
> reserved pad to add 'logical_block_size' to metadata. RAID rejects
> non-zero reserved pad, so arrays fail when rolling back to old kernels
> after booting new ones.
>
> Set 'logical_block_size' only for newly created arrays to support rollback
> to old kernels. Importantly new arrays still won't work on old kernels to
> prevent data loss issue from LBS changes.
>
> For arrays created on old kernels which confirmed not to rollback,
> configure LBS by echo current LBS (queue/logical_block_size) to
> md/logical_block_size.
>
> Fixes: 62ed1b582246 ("md: allow configuring logical block size")
> Reported-by: BugReports<bugreports61@gmail.com>
> Closes:https://lore.kernel.org/linux-raid/825e532d-d1e1-44bb-5581-692b7c091796@huaweicloud.com/T/#t
> Signed-off-by: Li Nan<linan122@huawei.com>
> ---
> v3:
>    - fix comment: %s/writing 'enable'/writing current LBS/
>
> v2:
>    - move warn message to mddev_stack_rdev_limits
>    - set current LBS to sysfs to enable feature instead of 'enable'
>
>   drivers/md/md.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
>   1 file changed, 44 insertions(+), 4 deletions(-)

Applied to md-6.19 with a few wording changes:

   | Location            | Before                            | After                                      |
   |---------------------|-----------------------------------|--------------------------------------------|
   | Line 5994 (comment) | configured in old kernels array   | configured for arrays from old kernels     |
   | Line 6005 (pr_info) | config logical block size success | logical block size configured successfully |
   | Line 6192 (comment) | new array                         | new arrays                                 |
   | Line 6197 (pr_info) | configurable lbs support          | configurable LBS support                   |
   | Line 6203 (pr_warn) | data loss issue                   | data loss issues                           |

-- 
Thansk,
Kuai

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

end of thread, other threads:[~2025-12-27  2:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-26  2:42 [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten linan666
2025-12-26  2:42 ` [PATCH v3 2/2] md: Fix forward incompatibility from configurable logical block size linan666
2025-12-27  2:16   ` Yu Kuai
2025-12-26  7:49 ` [PATCH v3 1/2] md: Fix logical_block_size configuration being overwritten Xiao Ni
2025-12-27  2:15 ` Yu Kuai

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

all inboxes | Powered by JetHome®