Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795026277; b=kQ5l1cBRLfC94eCSHvf8t8MuPiNCPIg7v8sFPv+VTdeyAXh1R4YUyE/OXfT6apL3vcHK csvdaNfFHkK9/VOp4Jvbz9VP/MEwCgU0vRNNH/p2kTquYEWcBIJDBLXC6wV/Djl3fZYkz +yxRZLVQ9TtPc4Y67lAb/uV9r150ya8WLPx/mt58moALevo3yMdpKerZ4GZ8aSkcyKH22 hZ7cknqdZDyClbhBEdBMC737JaHac/CMPjLuoWvHZXWkyziT27TOokXDvQMytyQu7BoAg UfDBg+SsXPFrbiM9wtey7FDTRfVgMxh7lfP8DiCuInrXrBlZCXx6u0M+TL0IGXqbHeQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795026277; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=W27sfFXXOfX39/N9MclYKTx98GPc8NoswOsIQ6AfyaI=; b=fxb5zChzHSz7LVruQlLoAWk+zYDD+w1mtoA1TxBbHkQ63FNSJRKAlx90Wio3sS4anUhn 3dDmvcck6P3z7tZUh/KTVPwXQE/Bq9zor4M7yyas66WD0r+VcIxIvGZhoO1cWEeRyvdO3 pPNhWeffbq6t8W/XzYD5iKDhfvnzPFX01MKAHNtyQ98zAwXV4+jYgGAldHhSuYaxQ1C6K Sg9Uaq+xpznlXG0U32JClnMsXRsyClUnBxYqvJ6pzXCHo7LdoyrWZzyTqRK8g75rwOXNZ 51yyoq11KVobSls1nQXm0r9mSFhk/jjYJpIcazuupGy67VXiAJWNH5r1qbV2H6v9aCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gQD0ZFRB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F34A606A320; Wed, 18 Nov 2026 18:24:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=gQD0ZFRB Received: by smtp.kernel.org (Postfix) with ESMTPSA id E11E51F000C4; Wed, 18 Nov 2026 18:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795026277; bh=W27sfFXXOfX39/N9MclYKTx98GPc8NoswOsIQ6AfyaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gQD0ZFRBSkKycv0u6mlR5VFMHxVjao0hwK9y/+1wX+Exb8A0mKc9D2wgr+Qsd8GTb 6bnj5ffkxV+TGWQqrL8yIXeYLLZ96bd9Jlo0jFXGVDR/eRKYLlZs3rOCdZtsd3ctvS iHn5SF8U/OxoTf3CZLRt6+4wVeJoM4nnL3q/8PMA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mikulas Patocka , Sasha Levin Subject: [PATCH 6.18 1336/2151] dm-snapshot: make the chunk list sorted by the chunk number Date: Wed, 18 Nov 2026 15:51:11 +0100 Message-ID: <20261118150210.726041989@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150121.603863898@linuxfoundation.org> References: <20261118150121.603863898@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka [ Upstream commit bbd6f974d0386036e560af332b6b8cdd17010a72 ] Commit 8581b19eb2c5 ("dm-snapshot: fix 'scheduling while atomic' on real-time kernels") replaced hlist_bl_for_each_entry with hlist_for_each_entry, but the two iteration macros differ after the loop ends: hlist_bl_for_each_entry leaves "e" pointing at the last element, while hlist_for_each_entry() sets it to NULL. The result is that the list is no longer sorted by chunk number as it was intended to be. This bug doesn't cause data corruption because dm_lookup_exception walks the full list. Restore the invariant by tracking the list tail in the "prev" variable and appending after it with hlist_add_behind. Signed-off-by: Mikulas Patocka Fixes: 8581b19eb2c5 ("dm-snapshot: fix 'scheduling while atomic' on real-time kernels") Assisted-by: Claude:claude-opus-5 Signed-off-by: Sasha Levin --- drivers/md/dm-snap.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index 4a3a6cf772f77..c04e570756ef2 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -770,7 +770,7 @@ static void dm_insert_exception(struct dm_exception_table *eh, struct dm_exception *new_e) { struct hlist_head *l; - struct dm_exception *e = NULL; + struct dm_exception *e = NULL, *prev = NULL; l = &eh->table[exception_hash(eh, new_e->old_chunk)].head; @@ -802,21 +802,23 @@ static void dm_insert_exception(struct dm_exception_table *eh, if (new_e->old_chunk < e->old_chunk) break; + + prev = e; } out: - if (!e) { + if (e && new_e->old_chunk < e->old_chunk) { + /* Add before an existing exception */ + hlist_add_before(&new_e->hash_list, &e->hash_list); + } else if (prev) { + /* Add to l's tail: prev is the last exception in this slot */ + hlist_add_behind(&new_e->hash_list, &prev->hash_list); + } else { /* * Either the table doesn't support consecutive chunks or slot * l is empty. */ hlist_add_head(&new_e->hash_list, l); - } else if (new_e->old_chunk < e->old_chunk) { - /* Add before an existing exception */ - hlist_add_before(&new_e->hash_list, &e->hash_list); - } else { - /* Add to l's tail: e is the last exception in this slot */ - hlist_add_behind(&new_e->hash_list, &e->hash_list); } } -- 2.53.0