• Damien Le Moal's avatar
    block: Fix reference counting for zone write plugs in error state · 19aad274
    Damien Le Moal authored
    When zone is reset or finished, disk_zone_wplug_set_wp_offset() is
    called to update the zone write plug write pointer offset and to clear
    the zone error state (BLK_ZONE_WPLUG_ERROR flag) if it is set.
    However, this processing is missing dropping the reference to the zone
    write plug that was taken in disk_zone_wplug_set_error() when the error
    flag was first set. Furthermore, the error state handling must release
    the zone write plug lock to first execute a report zones command. When
    the report zone races with a reset or finish operation that clears the
    error, we can end up decrementing the zone write plug reference count
    twice: once in disk_zone_wplug_set_wp_offset() for the reset/finish
    operation and one more time in disk_zone_wplugs_work() once
    disk_zone_wplug_handle_error() completes.
    
    Fix this by introducing disk_zone_wplug_clear_error() as the symmetric
    function of disk_zone_wplug_set_error(). disk_zone_wplug_clear_error()
    decrements the zone write plug reference count obtained in
    disk_zone_wplug_set_error() only if the error handling has not started
    yet, that is, only if disk_zone_wplugs_work() has not yet taken the zone
    write plug off the error list. This ensure that either
    disk_zone_wplug_clear_error() or disk_zone_wplugs_work() drop the zone
    write plug reference count.
    
    Fixes: dd291d77
    
     ("block: Introduce zone write plugging")
    Signed-off-by: default avatarDamien Le Moal <dlemoal@kernel.org>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
    Link: https://lore.kernel.org/r/20240501110907.96950-5-dlemoal@kernel.org
    
    Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
    19aad274
blk-zoned.c 52 KB