mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Yingjie Wang <x-professor@outlook.com>,
	Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Benjamin Marzinski <bmarzins@redhat.com>
Cc: "dm-devel@lists.linux.dev" <dm-devel@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Hannes Reinecke <hare@suse.de>, Dan Carpenter <error27@gmail.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Subject: Re: [PATCH 3/3] dm zoned: fix the search for the secondary superblock
Date: Wed, 2 Dec 2026 15:03:16 +0900	[thread overview]
Message-ID: <17f0e9c6-856b-4814-81c0-388743e0fd58@kernel.org> (raw)
In-Reply-To: <20261130161714.3536812-1-x-professor@outlook.com>

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

      reply	other threads:[~2026-12-02  6:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-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-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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=17f0e9c6-856b-4814-81c0-388743e0fd58@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=error27@gmail.com \
    --cc=hare@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=snitzer@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=x-professor@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®