From: Dongsheng Yang <dongsheng.yang@linux.dev>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: cengku@gmail.com, dm-devel@lists.linux.dev, chenl311@chinatelecom.cn
Subject: Re: [PATCH 1/3] dm-pcache: advance slot index before writing slot
Date: Fri, 5 Dec 2025 11:01:42 +0800 [thread overview]
Message-ID: <6686f762-5bf3-401a-b69d-a2876864b187@linux.dev> (raw)
In-Reply-To: <bea8250d-fc7f-6bda-df57-2814e96fd05f@redhat.com>
在 12/5/2025 12:13 AM, Mikulas Patocka 写道:
>
> On Thu, 4 Dec 2025, Dongsheng Yang wrote:
>
>> 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.
>>
>> Signed-off-by: Dongsheng Yang <dongsheng.yang@linux.dev>
>> ---
>> drivers/md/dm-pcache/cache.c | 8 ++++----
>> drivers/md/dm-pcache/cache_segment.c | 8 ++++----
>> 2 files changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/md/dm-pcache/cache.c b/drivers/md/dm-pcache/cache.c
>> index 698697a7a73c..9289c016b7c9 100644
>> --- a/drivers/md/dm-pcache/cache.c
>> +++ b/drivers/md/dm-pcache/cache.c
>> @@ -21,10 +21,10 @@ static void cache_info_write(struct pcache_cache *cache)
>> cache_info->header.crc = pcache_meta_crc(&cache_info->header,
>> sizeof(struct pcache_cache_info));
>>
>> + cache->info_index = (cache->info_index + 1) % PCACHE_META_INDEX_MAX;
>> +
>> memcpy_flushcache(get_cache_info_addr(cache), cache_info,
>> sizeof(struct pcache_cache_info));
>> -
>> - cache->info_index = (cache->info_index + 1) % PCACHE_META_INDEX_MAX;
>> }
>>
>> static void cache_info_init_default(struct pcache_cache *cache);
> I'm not sure whether this is bug or not
It's a bug, if in-place updating for slot happen, there is a potential
metadata corruption while powercut happening at the same time.
so I will add
Cc: stable@vger.kernel.org # 6.18
in V2.
> - but memcpy_flushcache doesn't
> guarantee that the cache will be flushed (despite it's name) or that
> writes would be ordered.
>
> You need pmem_wmb(). I see that you are using it at other places.
Good catch, I will send v2 to add the missing pmem_wmb().
Thanx
>
> Mikulas
next prev parent reply other threads:[~2025-12-05 3:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-04 2:53 [PATCH 1/3] dm-pcache: advance slot index before writing slot Dongsheng Yang
2025-12-04 2:53 ` [PATCH 2/3] dm pcache: fix cache info indexing Dongsheng Yang
2025-12-04 3:09 ` Zheng Gu
2025-12-04 16:01 ` Mikulas Patocka
2025-12-05 3:05 ` Dongsheng Yang
2025-12-04 2:53 ` [PATCH 3/3] dm pcache: fix segment " Dongsheng Yang
2025-12-04 3:10 ` Zheng Gu
2025-12-04 15:59 ` Mikulas Patocka
2025-12-05 3:05 ` Dongsheng Yang
2025-12-04 3:08 ` [PATCH 1/3] dm-pcache: advance slot index before writing slot Zheng Gu
2025-12-04 16:13 ` Mikulas Patocka
2025-12-05 3:01 ` Dongsheng Yang [this message]
2025-12-06 11:36 ` Mikulas Patocka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6686f762-5bf3-401a-b69d-a2876864b187@linux.dev \
--to=dongsheng.yang@linux.dev \
--cc=cengku@gmail.com \
--cc=chenl311@chinatelecom.cn \
--cc=dm-devel@lists.linux.dev \
--cc=mpatocka@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox