]> git.ipfire.org Git - thirdparty/linux.git/commit
dm-pcache: advance slot index before writing slot
authorDongsheng Yang <dongsheng.yang@linux.dev>
Fri, 5 Dec 2025 05:46:18 +0000 (05:46 +0000)
committerMikulas Patocka <mpatocka@redhat.com>
Wed, 10 Dec 2025 18:28:23 +0000 (19:28 +0100)
commitebbb90344a7da2421e4b54668b94e81828b8b308
tree0e416898b4c80f4a69eb40432d41042ed30223b1
parent7799eaecfeb756664be37c079520af67d5d64f70
dm-pcache: advance slot index before writing slot

In dm-pcache, in order to ensure crash-consistency, a dual-copy scheme
is used to alternately update metadata, and there is a slot index that
records the current slot. However, in the write path the current
implementation writes directly to the current slot indexed by slot
index, and then advances the slot — which ends up overwriting the
existing slot, violating the crash-consistency guarantee.

This patch fixes that behavior, preventing metadata from being
overwritten incorrectly.

In addition, this patch add a missing pmem_wmb() after memcpy_flushcache().

Signed-off-by: Dongsheng Yang <dongsheng.yang@linux.dev>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Zheng Gu <cengku@gmail.com>
Cc: stable@vger.kernel.org # 6.18
drivers/md/dm-pcache/cache.c
drivers/md/dm-pcache/cache_segment.c