From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6DA81E521E; Mon, 23 Jun 2025 21:25:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713908; cv=none; b=H2+AhQzE55xmJpgizyRvSonY34ZU8QGtO3yAgeWGsju16YTPI7jOYd/5WAuNsNjQbLbiJPdnG+9SGerv2jv6MeDm+6za3qHYIIwUlwbhgbN5kx51incyiSy+r84UIs/KlKi97shLgOXNZHAYUNJEAhFcFqUDWLmVt9LP7BhPSBU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750713908; c=relaxed/simple; bh=LCkZz2V/8gm1Sj/0NYaH1TpKREffNt33LOykeZPLBBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZkxsIvO/1AMQ1nZGfPBgtUWr9Qx1ElTAs+vI+TgNyOFSCbuho513hURYwLWqdIdmXwHOejW/k97/XIwZLRMqGXECJYj4ilGrpttc6D72dvEXBsUGMHzbvkMByoUiRjX0yA84Oj3G7uITCKL99xzSgyYk+qSMeJckwgi4Y2TiXAk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Z5OUimZb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Z5OUimZb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BCF4C4CEEA; Mon, 23 Jun 2025 21:25:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750713908; bh=LCkZz2V/8gm1Sj/0NYaH1TpKREffNt33LOykeZPLBBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z5OUimZb2y75zP8hYWsPRjsf+WHH3X8ItOd/zOQmqqOdi4oR9WtNC6zlPKy6KaIWJ S8l0cdKPI190v5xSlXqDK6sH94J70OpbQxQ4u15DJ4A4h4+Mqlp0MHuq4rjzv9GH+R jp+QE/M1Ah8vV2b6LZfbot8aRFQmUCbOQ2uZim30= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Damien Le Moal , Benjamin Marzinski , Mikulas Patocka , Sasha Levin Subject: [PATCH 6.1 134/508] dm: dont change md if dm_table_set_restrictions() fails Date: Mon, 23 Jun 2025 15:02:59 +0200 Message-ID: <20250623130648.586219826@linuxfoundation.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: <20250623130645.255320792@linuxfoundation.org> References: <20250623130645.255320792@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Marzinski [ Upstream commit 9eb7109a5bfc5b8226e9517e9f3cc6d414391884 ] __bind was changing the disk capacity, geometry and mempools of the mapped device before calling dm_table_set_restrictions() which could fail, forcing dm to drop the new table. Failing here would leave the device using the old table but with the wrong capacity and mempools. Move dm_table_set_restrictions() earlier in __bind(). Since it needs the capacity to be set, save the old version and restore it on failure. Fixes: bb37d77239af2 ("dm: introduce zone append emulation") Reviewed-by: Damien Le Moal Tested-by: Damien Le Moal Signed-off-by: Benjamin Marzinski Signed-off-by: Mikulas Patocka Signed-off-by: Sasha Levin --- drivers/md/dm.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 4767265793de7..2b8fe98c515ed 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -2165,21 +2165,29 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, struct queue_limits *limits) { struct dm_table *old_map; - sector_t size; + sector_t size, old_size; int ret; lockdep_assert_held(&md->suspend_lock); size = dm_table_get_size(t); + old_size = dm_get_size(md); + set_capacity(md->disk, size); + + ret = dm_table_set_restrictions(t, md->queue, limits); + if (ret) { + set_capacity(md->disk, old_size); + old_map = ERR_PTR(ret); + goto out; + } + /* * Wipe any geometry if the size of the table changed. */ - if (size != dm_get_size(md)) + if (size != old_size) memset(&md->geometry, 0, sizeof(md->geometry)); - set_capacity(md->disk, size); - dm_table_event_callback(t, event_callback, md); if (dm_table_request_based(t)) { @@ -2212,12 +2220,6 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, t->mempools = NULL; } - ret = dm_table_set_restrictions(t, md->queue, limits); - if (ret) { - old_map = ERR_PTR(ret); - goto out; - } - old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); rcu_assign_pointer(md->map, (void *)t); md->immutable_target_type = dm_table_get_immutable_target_type(t); -- 2.39.5