From: Mikulas Patocka <mpatocka@redhat.com>
To: Dongsheng Yang <dongsheng.yang@linux.dev>
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: Sat, 6 Dec 2025 12:36:18 +0100 (CET) [thread overview]
Message-ID: <d2d28180-417d-ea74-e338-94c2e0736e91@redhat.com> (raw)
In-Reply-To: <6686f762-5bf3-401a-b69d-a2876864b187@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 2379 bytes --]
On Fri, 5 Dec 2025, Dongsheng Yang wrote:
>
> 在 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
OK. I staged all 3 patches and I'll send to Linus soon.
Mikulas
prev parent reply other threads:[~2025-12-06 11:36 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
2025-12-06 11:36 ` Mikulas Patocka [this message]
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=d2d28180-417d-ea74-e338-94c2e0736e91@redhat.com \
--to=mpatocka@redhat.com \
--cc=cengku@gmail.com \
--cc=chenl311@chinatelecom.cn \
--cc=dm-devel@lists.linux.dev \
--cc=dongsheng.yang@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.