Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3492896pxf; Mon, 29 Mar 2021 03:55:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGzZwwzYa2HwXepQipZ3SvG2eXjbKb/5xfIJtLyx3gqe9tq/aHMpAviHxYMquLcdHwVCMf X-Received: by 2002:a17:907:ea3:: with SMTP id ho35mr27994371ejc.219.1617015357167; Mon, 29 Mar 2021 03:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617015357; cv=none; d=google.com; s=arc-20160816; b=YjvP5v4Ofm/HUdndK62qk6AGDWzfHtOfiQm9nJMxzpqkxQkIjA+aFQDflVLKmKeVbU Kny3fGkaLQQdF5zWihLb6iBDL74hmJZyJiCvCavLSCiuttz8Wau9QelWyYXx4joyD9zL F/lt5oEqNRkKHZYxa4Uqt2AsJv8mTY1eLybVzCHCQyJI/y3BTi+AKYG+X4FGfXRXcAql AfoxlE78hHuLKptmZGffdcm7ZV3MqPHaMyVq3+otPU5AhBOOI7xXefDiTqPV8LB1UU09 PbN79K28Gawe2fvwDMz5cXTc55AYY0sHrwYNCue2bTi59qPmQe9d/Hos3ZHGxjN10snA Nocg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EHyq6ZaqcaNgT/wjwHm5+IoqqvR9uBwMpWLE/srwOgo=; b=txS6hOQSkjRnMrye7YM6oxM9j0B51z03m5Of/Uc51Hl6tMQmlbszWj1xQJfmrWcRFw b/NoPZLDWo7BXsyhWaurMiluv6WS7OaoAeXoIekCtpK9HZ+FCzcJ+PD66D0Ak2/ZnMH6 wbfgYEiV9WbPCpRjDHYf2Skf1BNjmIzw9/xRxPjkOumSI1/fnYyhSmqIGAxQdHESinpF cT5w3ADFgLWFdR0u8mudt/xcRA6h/v3f7GU1GOS9zw+e/UbxwC8WB405uTpi7AffkRuy 5caMJdeYsBLZiq4qo9BIVrMAyAC02VbxzOMu7n1X+UaQlnG/Fa2lo8dAe93CEOlDsGSt 7bUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="08Q/s/Ty"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u26si13887225ejg.555.2021.03.29.03.55.35; Mon, 29 Mar 2021 03:55:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="08Q/s/Ty"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233742AbhC2InV (ORCPT + 99 others); Mon, 29 Mar 2021 04:43:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:41880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232468AbhC2IZh (ORCPT ); Mon, 29 Mar 2021 04:25:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0119B61864; Mon, 29 Mar 2021 08:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006304; bh=/U9OayEP9seZoWp8frEnEOHONJ43U6EX8rW+mNWSftg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=08Q/s/Ty8Z1EQmpjZ4LhLvArDunLzTyc7TuwTR5iqJRZau6SresPhiS6ZLiAX0+XY 2kzDfuP1TMfFM5erLiOhHQjGSQahXfC02AlcnJ3UjwgtGGxTcsj1tCjFUiFT2TyLZ+ FmclSwRFDtb2vjqj1lk6Lh51erZQ4fxkjZpUe2t8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shinichiro Kawasaki , Damien Le Moal , Mike Snitzer , Sasha Levin Subject: [PATCH 5.10 193/221] dm table: Fix zoned model check and zone sectors check Date: Mon, 29 Mar 2021 09:58:44 +0200 Message-Id: <20210329075635.565181084@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shin'ichiro Kawasaki [ Upstream commit 2d669ceb69c276f7637cf760287ca4187add082e ] Commit 24f6b6036c9e ("dm table: fix zoned iterate_devices based device capability checks") triggered dm table load failure when dm-zoned device is set up for zoned block devices and a regular device for cache. The commit inverted logic of two callback functions for iterate_devices: device_is_zoned_model() and device_matches_zone_sectors(). The logic of device_is_zoned_model() was inverted then all destination devices of all targets in dm table are required to have the expected zoned model. This is fine for dm-linear, dm-flakey and dm-crypt on zoned block devices since each target has only one destination device. However, this results in failure for dm-zoned with regular cache device since that target has both regular block device and zoned block devices. As for device_matches_zone_sectors(), the commit inverted the logic to require all zoned block devices in each target have the specified zone_sectors. This check also fails for regular block device which does not have zones. To avoid the check failures, fix the zone model check and the zone sectors check. For zone model check, introduce the new feature flag DM_TARGET_MIXED_ZONED_MODEL, and set it to dm-zoned target. When the target has this flag, allow it to have destination devices with any zoned model. For zone sectors check, skip the check if the destination device is not a zoned block device. Also add comments and improve an error message to clarify expectations to the two checks. Fixes: 24f6b6036c9e ("dm table: fix zoned iterate_devices based device capability checks") Signed-off-by: Shin'ichiro Kawasaki Signed-off-by: Damien Le Moal Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-table.c | 33 +++++++++++++++++++++++++-------- drivers/md/dm-zoned-target.c | 2 +- include/linux/device-mapper.h | 15 ++++++++++++++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 9b824c21580a..5c590895c14c 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -1387,6 +1387,13 @@ static int device_not_zoned_model(struct dm_target *ti, struct dm_dev *dev, return !q || blk_queue_zoned_model(q) != *zoned_model; } +/* + * Check the device zoned model based on the target feature flag. If the target + * has the DM_TARGET_ZONED_HM feature flag set, host-managed zoned devices are + * also accepted but all devices must have the same zoned model. If the target + * has the DM_TARGET_MIXED_ZONED_MODEL feature set, the devices can have any + * zoned model with all zoned devices having the same zone size. + */ static bool dm_table_supports_zoned_model(struct dm_table *t, enum blk_zoned_model zoned_model) { @@ -1396,13 +1403,15 @@ static bool dm_table_supports_zoned_model(struct dm_table *t, for (i = 0; i < dm_table_get_num_targets(t); i++) { ti = dm_table_get_target(t, i); - if (zoned_model == BLK_ZONED_HM && - !dm_target_supports_zoned_hm(ti->type)) - return false; - - if (!ti->type->iterate_devices || - ti->type->iterate_devices(ti, device_not_zoned_model, &zoned_model)) - return false; + if (dm_target_supports_zoned_hm(ti->type)) { + if (!ti->type->iterate_devices || + ti->type->iterate_devices(ti, device_not_zoned_model, + &zoned_model)) + return false; + } else if (!dm_target_supports_mixed_zoned_model(ti->type)) { + if (zoned_model == BLK_ZONED_HM) + return false; + } } return true; @@ -1414,9 +1423,17 @@ static int device_not_matches_zone_sectors(struct dm_target *ti, struct dm_dev * struct request_queue *q = bdev_get_queue(dev->bdev); unsigned int *zone_sectors = data; + if (!blk_queue_is_zoned(q)) + return 0; + return !q || blk_queue_zone_sectors(q) != *zone_sectors; } +/* + * Check consistency of zoned model and zone sectors across all targets. For + * zone sectors, if the destination device is a zoned block device, it shall + * have the specified zone_sectors. + */ static int validate_hardware_zoned_model(struct dm_table *table, enum blk_zoned_model zoned_model, unsigned int zone_sectors) @@ -1435,7 +1452,7 @@ static int validate_hardware_zoned_model(struct dm_table *table, return -EINVAL; if (dm_table_any_dev_attr(table, device_not_matches_zone_sectors, &zone_sectors)) { - DMERR("%s: zone sectors is not consistent across all devices", + DMERR("%s: zone sectors is not consistent across all zoned devices", dm_device_name(table->md)); return -EINVAL; } diff --git a/drivers/md/dm-zoned-target.c b/drivers/md/dm-zoned-target.c index 697f9de37355..7e88df64d197 100644 --- a/drivers/md/dm-zoned-target.c +++ b/drivers/md/dm-zoned-target.c @@ -1143,7 +1143,7 @@ static int dmz_message(struct dm_target *ti, unsigned int argc, char **argv, static struct target_type dmz_type = { .name = "zoned", .version = {2, 0, 0}, - .features = DM_TARGET_SINGLETON | DM_TARGET_ZONED_HM, + .features = DM_TARGET_SINGLETON | DM_TARGET_MIXED_ZONED_MODEL, .module = THIS_MODULE, .ctr = dmz_ctr, .dtr = dmz_dtr, diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index d2d7f9b6a276..50cc070cb1f7 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -246,7 +246,11 @@ struct target_type { #define dm_target_passes_integrity(type) ((type)->features & DM_TARGET_PASSES_INTEGRITY) /* - * Indicates that a target supports host-managed zoned block devices. + * Indicates support for zoned block devices: + * - DM_TARGET_ZONED_HM: the target also supports host-managed zoned + * block devices but does not support combining different zoned models. + * - DM_TARGET_MIXED_ZONED_MODEL: the target supports combining multiple + * devices with different zoned models. */ #define DM_TARGET_ZONED_HM 0x00000040 #define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM) @@ -257,6 +261,15 @@ struct target_type { #define DM_TARGET_NOWAIT 0x00000080 #define dm_target_supports_nowait(type) ((type)->features & DM_TARGET_NOWAIT) +#ifdef CONFIG_BLK_DEV_ZONED +#define DM_TARGET_MIXED_ZONED_MODEL 0x00000200 +#define dm_target_supports_mixed_zoned_model(type) \ + ((type)->features & DM_TARGET_MIXED_ZONED_MODEL) +#else +#define DM_TARGET_MIXED_ZONED_MODEL 0x00000000 +#define dm_target_supports_mixed_zoned_model(type) (false) +#endif + struct dm_target { struct dm_table *table; struct target_type *type; -- 2.30.1