Re: [PATCH v7 09/16] block: serialize zone revalidation
flat view
From: Hannes Reinecke <hare@suse.de>
Date: 2026-09-09 09:20:26
On 9/8/26 10:57 AM, Damien Le Moal wrote:
The zone related fields of struct gendisk can be modified by blk_revalidate_disk_zones() either on the first scan of the disk, or during user triggered scans or device revalidation, if some characteristics of the disk has changed (e.g. the disk capacity). Changes to these fields are always done with the disk request queue frozen so that BIO processing does not see any inconsistent state of the zones. This implies a contract that reading these zone related fields must always be done while holding a usage count on the request queue of the disk. However, increasing the usage count of the disk request queue cannot be done from the context of blk_revalidate_disk_zones() itself, as that would prevent freezing the disk queue and result in a deadlock. This prevents blk_revalidate_disk_zones() from consulting the zone related fields of struct gendisk to detect, for instance, a change in the number of zones of the disk. For such case, we want to detect the change, take appropriate measures and revalidate exclusively revalidate the zones to avoid concurrent revalidation calls to see the same change while corrections are already on-going. A simple solution to avoid this issue is to introduce a mutex to serialize calls to blk_revalidate_disk_zones() and ensure only a single context at a time can modify the zone related fields of a gendisk. In preparation for handling disk capacity revalidation in blk_revalidate_disk_zones(), do so with the mutex zone_revalidate_mutex. This mutex is initialized in disk_init_zone_resources(), destroyed in disk_release_zone_resources() and taken and released only in blk_revalidate_disk_zones() to serialize the execution of this function. Signed-off-by: Damien Le Moal <dlemoal@kernel.org> --- block/blk-zoned.c | 17 +++++++++++++++-- include/linux/blkdev.h | 9 ++++++--- 2 files changed, 21 insertions(+), 5 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