* [PATCH 0/3] dm zoned: fix metadata recovery and a tertiary superblock crash
@ 2026-11-30 16:14 Yingjie Wang
2026-11-30 16:17 ` [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails Yingjie Wang
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Yingjie Wang @ 2026-11-30 16:14 UTC (permalink / raw)
To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski
Cc: dm-devel, linux-kernel, Damien Le Moal, Hannes Reinecke,
Dan Carpenter, Yingjie Wang
Patch 1 fixes an invalid free when the tertiary superblock of a zoned
device cannot be read. Dan Carpenter reported it as a double free after
an allocation failure. A read error also triggers it and results in a
NULL pointer dereference.
Patches 2 and 3 fix the recovery from the secondary superblock. With
some volumes formatted with dmzadm, for example on a 14 TB drive with
256 MiB zones, loading the table fails with -EIO if the primary
superblock is corrupted, although the secondary one is valid. Patch 3
fixes the search for it. Patch 2 is needed first, because the recovery
writes to the metadata zones before they are checked.
Tested with KASAN on null_blk devices, including fault injection and the
recovery of volumes formatted with dmzadm. All of these problems were
reproduced without the series and are gone with it.
Yingjie Wang (3):
dm zoned: fix invalid free when reading a tertiary superblock fails
dm zoned: check the metadata zones before recovering a metadata set
dm zoned: fix the search for the secondary superblock
drivers/md/dm-zoned-metadata.c | 49 +++++++++++++++++++---------------
1 file changed, 28 insertions(+), 21 deletions(-)
base-commit: 5feb56b402e9827d599b4076da9ad71c374b9ef5
^ permalink raw reply [flat|nested] 11+ messages in thread* [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails 2026-11-30 16:14 [PATCH 0/3] dm zoned: fix metadata recovery and a tertiary superblock crash Yingjie Wang @ 2026-11-30 16:17 ` Yingjie Wang 2026-12-02 5:55 ` Damien Le Moal 2026-12-03 7:58 ` Hannes Reinecke 2026-11-30 16:17 ` [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set Yingjie Wang 2026-11-30 16:17 ` [PATCH 3/3] dm zoned: fix the search for the secondary superblock Yingjie Wang 2 siblings, 2 replies; 11+ messages in thread From: Yingjie Wang @ 2026-11-30 16:17 UTC (permalink / raw) To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Damien Le Moal, Hannes Reinecke, Dan Carpenter, Yingjie Wang, stable dmz_get_sb() does not leave a block to free when it fails. If the read fails, it frees the block and sets sb->mblk to NULL. If the allocation fails, it does not touch sb->mblk, which is either NULL or, after the first iteration of the loop, points to the block that was freed by the previous one. dmz_load_sb() nevertheless calls dmz_free_mblock() in this case. A read error on the first block of a zoned device therefore results in a NULL pointer dereference: (zoned1): Read tertiary super block failed KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047] An allocation failure can result in a double free, as reported by Smatch. Remove the bogus dmz_free_mblock() call. Fixes: 5d2c74f3ddc0 ("dm zoned: allocate temporary superblock for tertiary devices") Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/dm-devel/ahrruAVoUpDmh6Cf@stanley.mountain/ Suggested-by: Dan Carpenter <error27@gmail.com> Cc: stable@vger.kernel.org Signed-off-by: Yingjie Wang <x-professor@outlook.com> --- drivers/md/dm-zoned-metadata.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index f7aa04954d2f..1168537bb70d 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -1327,7 +1327,6 @@ static int dmz_load_sb(struct dmz_metadata *zmd) if (ret) { dmz_dev_err(sb->dev, "Read tertiary super block failed"); - dmz_free_mblock(zmd, sb->mblk); goto out_kfree; } ret = dmz_check_sb(zmd, sb, true); ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails 2026-11-30 16:17 ` [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails Yingjie Wang @ 2026-12-02 5:55 ` Damien Le Moal 2026-12-03 7:58 ` Hannes Reinecke 1 sibling, 0 replies; 11+ messages in thread From: Damien Le Moal @ 2026-12-02 5:55 UTC (permalink / raw) To: Yingjie Wang, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Hannes Reinecke, Dan Carpenter, stable On 12/1/26 01:17, Yingjie Wang wrote: > dmz_get_sb() does not leave a block to free when it fails. If the read > fails, it frees the block and sets sb->mblk to NULL. If the allocation > fails, it does not touch sb->mblk, which is either NULL or, after the > first iteration of the loop, points to the block that was freed by the > previous one. > > dmz_load_sb() nevertheless calls dmz_free_mblock() in this case. A > read error on the first block of a zoned device therefore results in a > NULL pointer dereference: > > (zoned1): Read tertiary super block failed > KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047] > > An allocation failure can result in a double free, as reported by > Smatch. > > Remove the bogus dmz_free_mblock() call. > > Fixes: 5d2c74f3ddc0 ("dm zoned: allocate temporary superblock for tertiary devices") > Reported-by: Dan Carpenter <error27@gmail.com> > Closes: https://lore.kernel.org/dm-devel/ahrruAVoUpDmh6Cf@stanley.mountain/ > Suggested-by: Dan Carpenter <error27@gmail.com> > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang <x-professor@outlook.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> -- Damien Le Moal Western Digital Research ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails 2026-11-30 16:17 ` [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails Yingjie Wang 2026-12-02 5:55 ` Damien Le Moal @ 2026-12-03 7:58 ` Hannes Reinecke 1 sibling, 0 replies; 11+ messages in thread From: Hannes Reinecke @ 2026-12-03 7:58 UTC (permalink / raw) To: Yingjie Wang, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Damien Le Moal, Dan Carpenter, stable On 11/30/26 5:17 PM, Yingjie Wang wrote: > dmz_get_sb() does not leave a block to free when it fails. If the read > fails, it frees the block and sets sb->mblk to NULL. If the allocation > fails, it does not touch sb->mblk, which is either NULL or, after the > first iteration of the loop, points to the block that was freed by the > previous one. > > dmz_load_sb() nevertheless calls dmz_free_mblock() in this case. A > read error on the first block of a zoned device therefore results in a > NULL pointer dereference: > > (zoned1): Read tertiary super block failed > KASAN: null-ptr-deref in range [0x0000000000000040-0x0000000000000047] > > An allocation failure can result in a double free, as reported by > Smatch. > > Remove the bogus dmz_free_mblock() call. > > Fixes: 5d2c74f3ddc0 ("dm zoned: allocate temporary superblock for tertiary devices") > Reported-by: Dan Carpenter <error27@gmail.com> > Closes: https://lore.kernel.org/dm-devel/ahrruAVoUpDmh6Cf@stanley.mountain/ > Suggested-by: Dan Carpenter <error27@gmail.com> > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang <x-professor@outlook.com> > --- > drivers/md/dm-zoned-metadata.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c > index f7aa04954d2f..1168537bb70d 100644 > --- a/drivers/md/dm-zoned-metadata.c > +++ b/drivers/md/dm-zoned-metadata.c > @@ -1327,7 +1327,6 @@ static int dmz_load_sb(struct dmz_metadata *zmd) > if (ret) { > dmz_dev_err(sb->dev, > "Read tertiary super block failed"); > - dmz_free_mblock(zmd, sb->mblk); > goto out_kfree; > } > ret = dmz_check_sb(zmd, sb, true); > Reviewed-by: Hannes Reinecke <hare@kernel.org> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set 2026-11-30 16:14 [PATCH 0/3] dm zoned: fix metadata recovery and a tertiary superblock crash Yingjie Wang 2026-11-30 16:17 ` [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails Yingjie Wang @ 2026-11-30 16:17 ` Yingjie Wang 2026-12-02 5:58 ` Damien Le Moal 2026-12-03 8:01 ` Hannes Reinecke 2026-11-30 16:17 ` [PATCH 3/3] dm zoned: fix the search for the secondary superblock Yingjie Wang 2 siblings, 2 replies; 11+ messages in thread From: Yingjie Wang @ 2026-11-30 16:17 UTC (permalink / raw) To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Damien Le Moal, Hannes Reinecke, Dan Carpenter, Yingjie Wang, stable dmz_ctr_metadata() verifies that the zones of both metadata sets exist and are random or cache zones, but only after dmz_load_sb() has returned. By then, dmz_recover_mblocks() may already have written to these zones. The position of the secondary superblock is not checked against the number of metadata zones it describes either. If dmz_lookup_secondary_sb() finds it in the first zone searched and it describes two metadata zones per set, for example, recovering the primary set overwrites the secondary superblock that it is recovering from, and the table is loaded. Move the zone checks to dmz_check_sb(), and also check there that the zones are on the device that holds the metadata and that the secondary superblock is where it is expected to be. Volumes formatted with dmzadm are not affected, because it places the secondary set right after the primary one and requires both to fit on that device. This is needed before fixing dmz_lookup_secondary_sb(). Otherwise, more superblocks would be found and used for recovery without these checks. Fixes: 3b1a94c88b79 ("dm zoned: drive-managed zoned block device target") Cc: stable@vger.kernel.org Signed-off-by: Yingjie Wang <x-professor@outlook.com> --- drivers/md/dm-zoned-metadata.c | 35 +++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 1168537bb70d..91cc8d28e524 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -974,7 +974,7 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb, { struct dmz_super *sb = dsb->sb; struct dmz_dev *dev = dsb->dev; - unsigned int nr_meta_zones, nr_data_zones; + unsigned int nr_meta_zones, nr_data_zones, i; u32 crc, stored_crc; u64 gen, sb_block; @@ -1059,6 +1059,27 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb, return -ENXIO; } + /* The secondary set immediately follows the primary set */ + if (dsb == &zmd->sb[1] && + dsb->zone->id != zmd->sb[0].zone->id + nr_meta_zones) { + dmz_dev_err(dev, "Invalid secondary superblock zone %u", + dsb->zone->id); + return -ENXIO; + } + + for (i = 0; i < nr_meta_zones << 1; i++) { + struct dm_zone *zone = dmz_get(zmd, zmd->sb[0].zone->id + i); + + if (!zone || zone->dev != dev) { + dmz_dev_err(dev, "metadata zone %u not present", i); + return -ENXIO; + } + if (!dmz_is_rnd(zone) && !dmz_is_cache(zone)) { + dmz_dev_err(dev, "metadata zone %u is not random", i); + return -ENXIO; + } + } + if (!le32_to_cpu(sb->nr_reserved_seq) || le32_to_cpu(sb->nr_reserved_seq) >= (zmd->nr_useable_zones - nr_meta_zones)) { dmz_dev_err(dev, "Invalid number of reserved sequential zones"); @@ -2900,18 +2921,6 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, /* Set metadata zones starting from sb_zone */ for (i = 0; i < zmd->nr_meta_zones << 1; i++) { zone = dmz_get(zmd, zmd->sb[0].zone->id + i); - if (!zone) { - dmz_zmd_err(zmd, - "metadata zone %u not present", i); - ret = -ENXIO; - goto err; - } - if (!dmz_is_rnd(zone) && !dmz_is_cache(zone)) { - dmz_zmd_err(zmd, - "metadata zone %d is not random", i); - ret = -ENXIO; - goto err; - } set_bit(DMZ_META, &zone->flags); } /* Load mapping table */ ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set 2026-11-30 16:17 ` [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set Yingjie Wang @ 2026-12-02 5:58 ` Damien Le Moal 2026-12-03 8:01 ` Hannes Reinecke 1 sibling, 0 replies; 11+ messages in thread From: Damien Le Moal @ 2026-12-02 5:58 UTC (permalink / raw) To: Yingjie Wang, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Hannes Reinecke, Dan Carpenter, stable On 12/1/26 01:17, Yingjie Wang wrote: > dmz_ctr_metadata() verifies that the zones of both metadata sets exist > and are random or cache zones, but only after dmz_load_sb() has > returned. By then, dmz_recover_mblocks() may already have written to > these zones. > > The position of the secondary superblock is not checked against the > number of metadata zones it describes either. If > dmz_lookup_secondary_sb() finds it in the first zone searched and it > describes two metadata zones per set, for example, recovering the > primary set overwrites the secondary superblock that it is recovering > from, and the table is loaded. > > Move the zone checks to dmz_check_sb(), and also check there that the > zones are on the device that holds the metadata and that the secondary > superblock is where it is expected to be. Volumes formatted with dmzadm > are not affected, because it places the secondary set right after the > primary one and requires both to fit on that device. > > This is needed before fixing dmz_lookup_secondary_sb(). Otherwise, more > superblocks would be found and used for recovery without these checks. > > Fixes: 3b1a94c88b79 ("dm zoned: drive-managed zoned block device target") > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang <x-professor@outlook.com> Reviewed-by: Damien Le Moal <dlemoal@kernel.org> -- Damien Le Moal Western Digital Research ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set 2026-11-30 16:17 ` [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set Yingjie Wang 2026-12-02 5:58 ` Damien Le Moal @ 2026-12-03 8:01 ` Hannes Reinecke 2026-12-03 9:03 ` Yingjie Wang 1 sibling, 1 reply; 11+ messages in thread From: Hannes Reinecke @ 2026-12-03 8:01 UTC (permalink / raw) To: Yingjie Wang, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Damien Le Moal, Dan Carpenter, stable On 11/30/26 5:17 PM, Yingjie Wang wrote: > dmz_ctr_metadata() verifies that the zones of both metadata sets exist > and are random or cache zones, but only after dmz_load_sb() has > returned. By then, dmz_recover_mblocks() may already have written to > these zones. > > The position of the secondary superblock is not checked against the > number of metadata zones it describes either. If > dmz_lookup_secondary_sb() finds it in the first zone searched and it > describes two metadata zones per set, for example, recovering the > primary set overwrites the secondary superblock that it is recovering > from, and the table is loaded. > > Move the zone checks to dmz_check_sb(), and also check there that the > zones are on the device that holds the metadata and that the secondary > superblock is where it is expected to be. Volumes formatted with dmzadm > are not affected, because it places the secondary set right after the > primary one and requires both to fit on that device. > > This is needed before fixing dmz_lookup_secondary_sb(). Otherwise, more > superblocks would be found and used for recovery without these checks. > > Fixes: 3b1a94c88b79 ("dm zoned: drive-managed zoned block device target") > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang <x-professor@outlook.com> > --- > drivers/md/dm-zoned-metadata.c | 35 +++++++++++++++++++++------------- > 1 file changed, 22 insertions(+), 13 deletions(-) > > diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c > index 1168537bb70d..91cc8d28e524 100644 > --- a/drivers/md/dm-zoned-metadata.c > +++ b/drivers/md/dm-zoned-metadata.c > @@ -974,7 +974,7 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb, > { > struct dmz_super *sb = dsb->sb; > struct dmz_dev *dev = dsb->dev; > - unsigned int nr_meta_zones, nr_data_zones; > + unsigned int nr_meta_zones, nr_data_zones, i; > u32 crc, stored_crc; > u64 gen, sb_block; > > @@ -1059,6 +1059,27 @@ static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb, > return -ENXIO; > } > > + /* The secondary set immediately follows the primary set */ > + if (dsb == &zmd->sb[1] && > + dsb->zone->id != zmd->sb[0].zone->id + nr_meta_zones) { > + dmz_dev_err(dev, "Invalid secondary superblock zone %u", > + dsb->zone->id); > + return -ENXIO; > + } > + > + for (i = 0; i < nr_meta_zones << 1; i++) { > + struct dm_zone *zone = dmz_get(zmd, zmd->sb[0].zone->id + i); > + > + if (!zone || zone->dev != dev) { > + dmz_dev_err(dev, "metadata zone %u not present", i); > + return -ENXIO; > + } > + if (!dmz_is_rnd(zone) && !dmz_is_cache(zone)) { > + dmz_dev_err(dev, "metadata zone %u is not random", i); > + return -ENXIO; > + } > + } > + > if (!le32_to_cpu(sb->nr_reserved_seq) || > le32_to_cpu(sb->nr_reserved_seq) >= (zmd->nr_useable_zones - nr_meta_zones)) { > dmz_dev_err(dev, "Invalid number of reserved sequential zones"); > @@ -2900,18 +2921,6 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, > /* Set metadata zones starting from sb_zone */ > for (i = 0; i < zmd->nr_meta_zones << 1; i++) { > zone = dmz_get(zmd, zmd->sb[0].zone->id + i); > - if (!zone) { > - dmz_zmd_err(zmd, > - "metadata zone %u not present", i); > - ret = -ENXIO; > - goto err; > - } > - if (!dmz_is_rnd(zone) && !dmz_is_cache(zone)) { > - dmz_zmd_err(zmd, > - "metadata zone %d is not random", i); > - ret = -ENXIO; > - goto err; > - } > set_bit(DMZ_META, &zone->flags); > } > /* Load mapping table */ But now the second iteration looks odd. Surely dmz_get() can fail here, no? But can't we move the 'set_bit' call in the first iteration? Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set 2026-12-03 8:01 ` Hannes Reinecke @ 2026-12-03 9:03 ` Yingjie Wang 0 siblings, 0 replies; 11+ messages in thread From: Yingjie Wang @ 2026-12-03 9:03 UTC (permalink / raw) To: Hannes Reinecke, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Damien Le Moal, Dan Carpenter, stable Hi Hannes, On 12/3/26 09:01, Hannes Reinecke wrote: > But now the second iteration looks odd. Surely dmz_get() can fail here, > no? But can't we move the 'set_bit' call in the first iteration? I don't think dmz_get() can fail there: it walks the same zones as the new loop in dmz_check_sb(). zmd->nr_meta_zones is only set at the end of a successful dmz_check_sb() of the primary or secondary superblock, and zmd->sb[0].zone doesn't change after the zones are initialized. dmz_load_sb() fails unless one of these two superblocks passed, and the tertiary superblocks return from dmz_check_sb() before the loop without setting nr_meta_zones. I didn't move set_bit() into dmz_check_sb() because a superblock can still be rejected after that loop, and the two superblocks can describe different numbers of metadata zones. For example, if the primary superblock fails the nr_reserved_seq check and describes more metadata zones than the secondary one, set 0 is recovered from set 1, and the zones that only the primary counted would stay marked as metadata. So the zones are only marked once dmz_load_sb() has succeeded. I can add a comment to the second loop in a follow-up if you like. Thanks, Yingjie ^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/3] dm zoned: fix the search for the secondary superblock 2026-11-30 16:14 [PATCH 0/3] dm zoned: fix metadata recovery and a tertiary superblock crash Yingjie Wang 2026-11-30 16:17 ` [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails Yingjie Wang 2026-11-30 16:17 ` [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set Yingjie Wang @ 2026-11-30 16:17 ` Yingjie Wang 2026-12-02 6:03 ` Damien Le Moal 2026-12-03 8:03 ` Hannes Reinecke 2 siblings, 2 replies; 11+ messages in thread From: Yingjie Wang @ 2026-11-30 16:17 UTC (permalink / raw) To: Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Damien Le Moal, Hannes Reinecke, Dan Carpenter, Yingjie Wang, stable If the primary superblock of a volume formatted with dmzadm is corrupted, dmz_lookup_secondary_sb() fails to find the valid secondary one in two cases: - After the first iteration, sb[1].block is advanced to the next zone, but sb[1].zone is set to the zone that was just examined. Unless the superblock is in the first zone that is searched, dmz_check_sb() then rejects it because it does not appear to be in the right zone. With 256 MiB zones, this affects volumes larger than about 8.8 TB, which need more than one zone per metadata set: Invalid superblock position (is 131072 expected 65536) - The number of random zones is used as the limit. With multiple devices, the metadata is on the cache device instead, and nothing is searched at all if the zoned devices have no random zones. Commit b38c0ad57f8e ("dm zoned: Fix metadata zone size check") fixed the same problem in dmz_check_sb(). Set the block and the zone together at the start of each iteration, and use the number of cache zones if there are multiple devices. This depends on the previous patch, which rejects superblocks that must not be used for recovery. Fixes: a92fbc446d1a ("dm zoned: convert to xarray") Fixes: 34f5affd04c4 ("dm zoned: separate random and cache zones") Cc: stable@vger.kernel.org Signed-off-by: Yingjie Wang <x-professor@outlook.com> --- drivers/md/dm-zoned-metadata.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 91cc8d28e524..687573bbc091 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -1125,10 +1125,11 @@ static int dmz_read_sb(struct dmz_metadata *zmd, struct dmz_sb *sb, int set) */ static int dmz_lookup_secondary_sb(struct dmz_metadata *zmd) { - unsigned int zone_nr_blocks = zmd->zone_nr_blocks; + unsigned int nr_zones = zmd->nr_devs > 1 ? zmd->nr_cache_zones : + zmd->nr_rnd_zones; struct dmz_mblock *mblk; unsigned int zone_id = zmd->sb[0].zone->id; - int i; + unsigned int i; /* Allocate a block */ mblk = dmz_alloc_mblock(zmd, 0); @@ -1139,16 +1140,14 @@ static int dmz_lookup_secondary_sb(struct dmz_metadata *zmd) zmd->sb[1].sb = mblk->data; /* Bad first super block: search for the second one */ - zmd->sb[1].block = zmd->sb[0].block + zone_nr_blocks; - zmd->sb[1].zone = dmz_get(zmd, zone_id + 1); zmd->sb[1].dev = zmd->sb[0].dev; - for (i = 1; i < zmd->nr_rnd_zones; i++) { + for (i = 1; i < nr_zones; i++) { + zmd->sb[1].block = zmd->sb[0].block + i * zmd->zone_nr_blocks; + zmd->sb[1].zone = dmz_get(zmd, zone_id + i); if (dmz_read_sb(zmd, &zmd->sb[1], 1) != 0) break; if (le32_to_cpu(zmd->sb[1].sb->magic) == DMZ_MAGIC) return 0; - zmd->sb[1].block += zone_nr_blocks; - zmd->sb[1].zone = dmz_get(zmd, zone_id + i); } dmz_free_mblock(zmd, mblk); ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3] dm zoned: fix the search for the secondary superblock 2026-11-30 16:17 ` [PATCH 3/3] dm zoned: fix the search for the secondary superblock Yingjie Wang @ 2026-12-02 6:03 ` Damien Le Moal 2026-12-03 8:03 ` Hannes Reinecke 1 sibling, 0 replies; 11+ messages in thread From: Damien Le Moal @ 2026-12-02 6:03 UTC (permalink / raw) To: Yingjie Wang, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Hannes Reinecke, Dan Carpenter, stable On 12/1/26 01:17, Yingjie Wang wrote: > If the primary superblock of a volume formatted with dmzadm is > corrupted, dmz_lookup_secondary_sb() fails to find the valid secondary > one in two cases: > > - After the first iteration, sb[1].block is advanced to the next zone, > but sb[1].zone is set to the zone that was just examined. Unless > the superblock is in the first zone that is searched, dmz_check_sb() > then rejects it because it does not appear to be in the right zone. > With 256 MiB zones, this affects volumes larger than about 8.8 TB, > which need more than one zone per metadata set: > > Invalid superblock position (is 131072 expected 65536) > > - The number of random zones is used as the limit. With multiple > devices, the metadata is on the cache device instead, and nothing is > searched at all if the zoned devices have no random zones. Commit > b38c0ad57f8e ("dm zoned: Fix metadata zone size check") fixed the > same problem in dmz_check_sb(). > > Set the block and the zone together at the start of each iteration, and > use the number of cache zones if there are multiple devices. > > This depends on the previous patch, which rejects superblocks that must > not be used for recovery. > > Fixes: a92fbc446d1a ("dm zoned: convert to xarray") > Fixes: 34f5affd04c4 ("dm zoned: separate random and cache zones") > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang <x-professor@outlook.com> Looks good, with a few nits below. With that addressed, feel free to add: Reviewed-by: Damien Le Moal <dlemoal@kernel.org> > --- > drivers/md/dm-zoned-metadata.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > > diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c > index 91cc8d28e524..687573bbc091 100644 > --- a/drivers/md/dm-zoned-metadata.c > +++ b/drivers/md/dm-zoned-metadata.c > @@ -1125,10 +1125,11 @@ static int dmz_read_sb(struct dmz_metadata *zmd, struct dmz_sb *sb, int set) > */ > static int dmz_lookup_secondary_sb(struct dmz_metadata *zmd) > { > - unsigned int zone_nr_blocks = zmd->zone_nr_blocks; > + unsigned int nr_zones = zmd->nr_devs > 1 ? zmd->nr_cache_zones : > + zmd->nr_rnd_zones; Please spell this initialization out after the declaration so that it looks nicer. > struct dmz_mblock *mblk; > unsigned int zone_id = zmd->sb[0].zone->id; > - int i; > + unsigned int i; Declare this together with nr_zones. And here add: if (zmd->nr_devs > 1) nr_zones = zmd->nr_cache_zones; else nr_zones = zmd->nr_rnd_zones; > > /* Allocate a block */ > mblk = dmz_alloc_mblock(zmd, 0); > @@ -1139,16 +1140,14 @@ static int dmz_lookup_secondary_sb(struct dmz_metadata *zmd) > zmd->sb[1].sb = mblk->data; > > /* Bad first super block: search for the second one */ > - zmd->sb[1].block = zmd->sb[0].block + zone_nr_blocks; > - zmd->sb[1].zone = dmz_get(zmd, zone_id + 1); > zmd->sb[1].dev = zmd->sb[0].dev; > - for (i = 1; i < zmd->nr_rnd_zones; i++) { > + for (i = 1; i < nr_zones; i++) { > + zmd->sb[1].block = zmd->sb[0].block + i * zmd->zone_nr_blocks; > + zmd->sb[1].zone = dmz_get(zmd, zone_id + i); > if (dmz_read_sb(zmd, &zmd->sb[1], 1) != 0) > break; > if (le32_to_cpu(zmd->sb[1].sb->magic) == DMZ_MAGIC) > return 0; > - zmd->sb[1].block += zone_nr_blocks; > - zmd->sb[1].zone = dmz_get(zmd, zone_id + i); > } > > dmz_free_mblock(zmd, mblk); -- Damien Le Moal Western Digital Research ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 3/3] dm zoned: fix the search for the secondary superblock 2026-11-30 16:17 ` [PATCH 3/3] dm zoned: fix the search for the secondary superblock Yingjie Wang 2026-12-02 6:03 ` Damien Le Moal @ 2026-12-03 8:03 ` Hannes Reinecke 1 sibling, 0 replies; 11+ messages in thread From: Hannes Reinecke @ 2026-12-03 8:03 UTC (permalink / raw) To: Yingjie Wang, Alasdair Kergon, Mike Snitzer, Mikulas Patocka, Benjamin Marzinski Cc: dm-devel, linux-kernel, Damien Le Moal, Dan Carpenter, stable On 11/30/26 5:17 PM, Yingjie Wang wrote: > If the primary superblock of a volume formatted with dmzadm is > corrupted, dmz_lookup_secondary_sb() fails to find the valid secondary > one in two cases: > > - After the first iteration, sb[1].block is advanced to the next zone, > but sb[1].zone is set to the zone that was just examined. Unless > the superblock is in the first zone that is searched, dmz_check_sb() > then rejects it because it does not appear to be in the right zone. > With 256 MiB zones, this affects volumes larger than about 8.8 TB, > which need more than one zone per metadata set: > > Invalid superblock position (is 131072 expected 65536) > > - The number of random zones is used as the limit. With multiple > devices, the metadata is on the cache device instead, and nothing is > searched at all if the zoned devices have no random zones. Commit > b38c0ad57f8e ("dm zoned: Fix metadata zone size check") fixed the > same problem in dmz_check_sb(). > > Set the block and the zone together at the start of each iteration, and > use the number of cache zones if there are multiple devices. > > This depends on the previous patch, which rejects superblocks that must > not be used for recovery. > > Fixes: a92fbc446d1a ("dm zoned: convert to xarray") > Fixes: 34f5affd04c4 ("dm zoned: separate random and cache zones") > Cc: stable@vger.kernel.org > Signed-off-by: Yingjie Wang <x-professor@outlook.com> > --- > drivers/md/dm-zoned-metadata.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > Reviewed-by: Hannes Reinecke <hare@kernel.org> Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-12-03 9:03 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-30 16:14 [PATCH 0/3] dm zoned: fix metadata recovery and a tertiary superblock crash Yingjie Wang 2026-11-30 16:17 ` [PATCH 1/3] dm zoned: fix invalid free when reading a tertiary superblock fails Yingjie Wang 2026-12-02 5:55 ` Damien Le Moal 2026-12-03 7:58 ` Hannes Reinecke 2026-11-30 16:17 ` [PATCH 2/3] dm zoned: check the metadata zones before recovering a metadata set Yingjie Wang 2026-12-02 5:58 ` Damien Le Moal 2026-12-03 8:01 ` Hannes Reinecke 2026-12-03 9:03 ` Yingjie Wang 2026-11-30 16:17 ` [PATCH 3/3] dm zoned: fix the search for the secondary superblock Yingjie Wang 2026-12-02 6:03 ` Damien Le Moal 2026-12-03 8:03 ` Hannes Reinecke
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®