dm-pcache: built-in support and metadata hardening
Subsystems (2)
v2 cover dm-pcache: built-in support and metadata hardening
From: Li Chen <[email protected]>
This three-patch series tidies dm-pcache’s build glue and tightens the metadata scan.
Patch 1 allow dm-pcache to be linked into vmlinux and avoids clashing with the sunrpc cache_flush() by using obj-$(CONFIG_DM_PCACHE) and renaming the helper across the tree.
Patch 2 drops a redundant recomputation of the metadata slot pointer while walking headers.
Patch 3 Ensure dm-pcache initializes cache_info from a zeroed state so metadata CRC failures can’t leak stale flags into the new-cache path.
Thanks for your review.
Li Chen (3):
dm-pcache: allow built-in build and rename flush helper
dm-pcache: reuse meta_addr in pcache_meta_find_latest
dm-pcache: zero cache_info before default init
drivers/md/dm-pcache/Makefile | 2 +- drivers/md/dm-pcache/cache.c | 4 ++-- drivers/md/dm-pcache/cache.h | 2 +- drivers/md/dm-pcache/cache_req.c | 6 +++--- drivers/md/dm-pcache/pcache_internal.h | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-)
Signature · 1 line
2.51.0
PATCH v2 1/3 dm-pcache: allow built-in build and rename flush helper
From: Li Chen <[email protected]>
CONFIG_BCACHE is tristate, so dm-pcache can also be built-in. Switch the Makefile to use obj-$(CONFIG_DM_PCACHE) so the target can be linked into vmlinux instead of always being a loadable module.
Also rename cache_flush() to pcache_cache_flush() to avoid a global symbol clash with sunrpc/cache.c's cache_flush().
--- drivers/md/dm-pcache/Makefile | 2 +- drivers/md/dm-pcache/cache.c | 2 +- drivers/md/dm-pcache/cache.h | 2 +- drivers/md/dm-pcache/cache_req.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-)
drivers/md/dm-pcache/Makefile +1 -1
@@ -1,3 +1,3 @@ dm-pcache-y := dm_pcache.o cache_dev.o segment.o backing_dev.o cache.o cache_gc.o cache_writeback.o cache_segment.o cache_key.o cache_req.o -obj-m += dm-pcache.o +obj-$(CONFIG_DM_PCACHE) += dm-pcache.o
drivers/md/dm-pcache/cache.c +1 -1
@@ -411,7 +411,7 @@ void pcache_cache_stop(struct dm_pcache *pcache) {struct pcache_cache *cache = &pcache->cache; -cache_flush (cache); +pcache_cache_flush (cache);cancel_delayed_work_sync (&cache->gc_work);flush_work (&cache->clean_work);
drivers/md/dm-pcache/cache.h +1 -1
@@ -339,7 +339,7 @@ void cache_seg_put(struct pcache_cache_segment *cache_seg);void cache_seg_set_next_seg (struct pcache_cache_segment *cache_seg,u32 seg_id);/* cache request*/ -int cache_flush (struct pcache_cache *cache); +int pcache_cache_flush (struct pcache_cache *cache);void miss_read_end_work_fn (struct work_struct *work);int pcache_cache_handle_req (struct pcache_cache *cache,struct pcache_request *pcache_req);
drivers/md/dm-pcache/cache_req.c +3 -3
@@ -790,7 +790,7 @@ static int cache_write(struct pcache_cache *cache, struct pcache_request *pcache }/** -* cache_flush - Flush all ksets to persist any pending cache data +* pcache_cache_flush - Flush all ksets to persist any pending cache data * @cache: Pointer to the cache structure * * This function iterates through all ksets associated with the provided `cache`
@@ -802,7 +802,7 @@ static int cache_write(struct pcache_cache *cache, struct pcache_request *pcache* the respective error code, preventing the flush operation from proceeding to * subsequent ksets. */ -int cache_flush (struct pcache_cache *cache) +int pcache_cache_flush (struct pcache_cache *cache) {struct pcache_cache_kset *kset;int ret;
@@ -827,7 +827,7 @@ int pcache_cache_handle_req(struct pcache_cache *cache, struct pcache_request *pstruct bio *bio = pcache_req->bio;if (unlikely (bio->bi_opf &REQ_PREFLUSH )) -return cache_flush (cache); +return pcache_cache_flush (cache);if (bio_data_dir (bio) ==READ )return cache_read (cache, pcache_req);
Signature · 1 line
2.51.0
Dongsheng Yang
maintainerRe: [PATCH v2 1/3] dm-pcache: allow built-in build and rename flush helper
Quoted 10 lines · Li Chen
From: Li Chen <[email protected]>
CONFIG_BCACHEis tristate, so dm-pcache can also be built-in. Switch theMakefileto use obj-$(CONFIG_DM_PCACHE) so the target can be linked into vmlinux instead of always being a loadable module.Also rename
cache_flush()topcache_cache_flush()to avoid a global symbol clash with sunrpc/cache.c'scache_flush().Signed-off-by Li Chen <[email protected]>
Reviewed-by: Dongsheng Yang <[email protected]>
Quoted 73 lines
--- drivers/md/dm-pcache/Makefile | 2 +- drivers/md/dm-pcache/cache.c | 2 +- drivers/md/dm-pcache/cache.h | 2 +- drivers/md/dm-pcache/cache_req.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-)drivers/md/dm-pcache/Makefile +1
-1@@ -1,3 +1,3 @@ dm-pcache-y := dm_pcache.o cache_dev.o segment.o backing_dev.o cache.o cache_gc.o cache_writeback.o cache_segment.o cache_key.o cache_req.o -obj-m += dm-pcache.o +obj-$(CONFIG_DM_PCACHE) += dm-pcache.odrivers/md/dm-pcache/cache.c +1
-1@@ -411,7 +411,7 @@ void pcache_cache_stop(struct dm_pcache *pcache) {struct pcache_cache *cache = &pcache->cache; -cache_flush (cache); +pcache_cache_flush (cache);cancel_delayed_work_sync (&cache->gc_work);flush_work (&cache->clean_work);drivers/md/dm-pcache/cache.h +1
-1@@ -339,7 +339,7 @@ void cache_seg_put(struct pcache_cache_segment *cache_seg);void cache_seg_set_next_seg (struct pcache_cache_segment *cache_seg,u32 seg_id);/* cache request*/ -int cache_flush (struct pcache_cache *cache); +int pcache_cache_flush (struct pcache_cache *cache);void miss_read_end_work_fn (struct work_struct *work);int pcache_cache_handle_req (struct pcache_cache *cache,struct pcache_request *pcache_req);drivers/md/dm-pcache/cache_req.c +3
-3@@ -790,7 +790,7 @@ static int cache_write(struct pcache_cache *cache, struct pcache_request *pcache }/** -* cache_flush - Flush all ksets to persist any pending cache data +* pcache_cache_flush - Flush all ksets to persist any pending cache data * @cache: Pointer to the cache structure * * This function iterates through all ksets associated with the provided `cache` @@ -802,7 +802,7 @@ static int cache_write(struct pcache_cache *cache, struct pcache_request *pcache* the respective error code, preventing the flush operation from proceeding to * subsequent ksets. */ -int cache_flush (struct pcache_cache *cache) +int pcache_cache_flush (struct pcache_cache *cache) {struct pcache_cache_kset *kset;int ret;@@ -827,7 +827,7 @@ int pcache_cache_handle_req(struct pcache_cache *cache, struct pcache_request *pstruct bio *bio = pcache_req->bio;if (unlikely (bio->bi_opf &REQ_PREFLUSH )) -return cache_flush (cache); +return pcache_cache_flush (cache);if (bio_data_dir (bio) ==READ )return cache_read (cache, pcache_req);
PATCH v2 2/3 dm-pcache: reuse meta_addr in pcache_meta_find_latest
In reply to Li ChenFrom: Li Chen <[email protected]>
pcache_meta_find_latest() already computes the metadata address as meta_addr. Reuse that instead of recomputing.
--- drivers/md/dm-pcache/pcache_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-pcache/pcache_internal.h +1 -1
@@ -99,7 +99,7 @@ static inline void __must_check *pcache_meta_find_latest(struct pcache_meta_head/* Update latest if a more recent sequence is found */ if (!latest ||pcache_meta_seq_after (meta->seq, seq_latest)) { seq_latest = meta->seq; - latest = (void *)header + (i * meta_max_size); + latest = meta_addr; } }
Signature · 1 line
2.51.0
Dongsheng Yang
maintainerRe: [PATCH v2 2/3] dm-pcache: reuse meta_addr in pcache_meta_find_latest
Quoted 6 lines · Li Chen
From: Li Chen <[email protected]>
pcache_meta_find_latest()already computes the metadata address asmeta_addr. Reuse that instead of recomputing.Signed-off-by Li Chen <[email protected]>
Reviewed-by: Dongsheng Yang <[email protected]
Quoted 17 lines
--- drivers/md/dm-pcache/pcache_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-pcache/pcache_internal.h +1
-1@@ -99,7 +99,7 @@ static inline void __must_check *pcache_meta_find_latest(struct pcache_meta_head/* Update latest if a more recent sequence is found */ if (!latest ||pcache_meta_seq_after (meta->seq, seq_latest)) { seq_latest = meta->seq; - latest = (void *)header + (i * meta_max_size); + latest = meta_addr; } }
PATCH v2 3/3 dm-pcache: zero cache_info before default init
In reply to Li ChenFrom: Li Chen <[email protected]>
pcache_meta_find_latest() leaves whatever it last copied into the caller’s buffer even when it returns NULL. For cache_info_init(), that meant cache->cache_info could still contain CRC-bad garbage when no valid metadata exists, leading later initialization paths to read bogus flags.
Explicitly memset cache->cache_info in cache_info_init_default() so new-cache paths start from a clean slate. The default sequence number assignment becomes redundant with this reset, so it drops out.
--- drivers/md/dm-pcache/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-pcache/cache.c +1 -1
@@ -181,7 +181,7 @@ static void cache_info_init_default(struct pcache_cache *cache) {struct pcache_cache_info *cache_info = &cache->cache_info; - cache_info->header.seq =0 ; +memset (cache_info,0 ,sizeof (*cache_info)); cache_info->n_segs = cache->cache_dev->seg_num;cache_info_set_gc_percent (cache_info,PCACHE_CACHE_GC_PERCENT_DEFAULT ); }
Signature · 1 line
2.51.0
Re: [PATCH v2 3/3] dm-pcache: zero cache_info before default init
Quoted 32 lines · Li Chen
From: Li Chen <[email protected]>
pcache_meta_find_latest()leaves whatever it last copied into the caller’s buffer even when it returns NULL. Forcache_info_init(), that meantcache->cache_infocould still contain CRC-bad garbage when no valid metadata exists, leading later initialization paths to read bogus flags.Explicitly memset
cache->cache_infoincache_info_init_default()so new-cache paths start from a clean slate. The default sequence number assignment becomes redundant with this reset, so it drops out.Signed-off-by Li Chen <[email protected]>--- drivers/md/dm-pcache/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-pcache/cache.c +1
-2@@ -181,7 +181,7 @@ static void cache_info_init_default(struct pcache_cache *cache) {struct pcache_cache_info *cache_info = &cache->cache_info; - cache_info->header.seq =0 ; +memset (cache_info,0 ,sizeof (*cache_info)); cache_info->n_segs = cache->cache_dev->seg_num;cache_info_set_gc_percent (cache_info,PCACHE_CACHE_GC_PERCENT_DEFAULT ); } --
Quoted 2 lines
2.51.0
It looks good to me.
Dongsheng Yang
maintainerRe: [PATCH v2 3/3] dm-pcache: zero cache_info before default init
In reply to Li ChenQuoted 8 lines · Li Chen
From: Li Chen <[email protected]>
pcache_meta_find_latest()leaves whatever it last copied into the caller’s buffer even when it returns NULL. Forcache_info_init(), that meantcache->cache_infocould still contain CRC-bad garbage when no valid metadata exists, leading later initialization paths to read bogus flags.
Quoted 5 lines
Explicitly memset
cache->cache_infoincache_info_init_default()so new-cache paths start from a clean slate. The default sequence number assignment becomes redundant with this reset, so it drops out.Signed-off-by Li Chen <[email protected]>
Reviewed-by: Dongsheng Yang <[email protected]>
Quoted 17 lines
--- drivers/md/dm-pcache/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/md/dm-pcache/cache.c +1
-1@@ -181,7 +181,7 @@ static void cache_info_init_default(struct pcache_cache *cache) {struct pcache_cache_info *cache_info = &cache->cache_info; - cache_info->header.seq =0 ; +memset (cache_info,0 ,sizeof (*cache_info)); cache_info->n_segs = cache->cache_dev->seg_num;cache_info_set_gc_percent (cache_info,PCACHE_CACHE_GC_PERCENT_DEFAULT ); }
Dongsheng Yang
maintainerHi Mikulas,
Please consider taking these three patches.
Thanx
Dongsheng
Quoted 26 lines · Li Chen
From: Li Chen <[email protected]>
This three-patch series tidies dm-pcache’s build glue and tightens the metadata scan.
Patch 1 allow dm-pcache to be linked into vmlinux and avoids clashing with the sunrpc
cache_flush()by using obj-$(CONFIG_DM_PCACHE) and renaming the helper across the tree.Patch 2 drops a redundant recomputation of the metadata slot pointer while walking headers.
Patch 3 Ensure dm-pcache initializes
cache_infofrom a zeroed state so metadata CRC failures can’t leak stale flags into the new-cache path.Thanks for your review.
Li Chen (3):
dm-pcache: allow built-in build and rename flush helper
dm-pcache: reusemeta_addrinpcache_meta_find_latest
dm-pcache: zerocache_infobefore default initdrivers/md/dm-pcache/Makefile | 2 +- drivers/md/dm-pcache/cache.c | 4 ++-- drivers/md/dm-pcache/cache.h | 2 +- drivers/md/dm-pcache/cache_req.c | 6 +++--- drivers/md/dm-pcache/pcache_internal.h | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-)
Mikulas Patocka
maintainerQuoted 7 lines · Dongsheng Yang
Hi Mikulas,
Please consider taking these three patches.
Thanx
Dongsheng
OK, thanks. I accepted the patches and I staged them for the kernel 6.18.
Mikulas
Quoted 33 lines · Li Chen
Quoted 31 lines
From: Li Chen <[email protected]>
This three-patch series tidies dm-pcache’s build glue and tightens the metadata scan.
Patch 1 allow dm-pcache to be linked into vmlinux and avoids clashing with the sunrpc
cache_flush()by using obj-$(CONFIG_DM_PCACHE) and renaming the helper across the tree.Patch 2 drops a redundant recomputation of the metadata slot pointer while walking headers.
Patch 3 Ensure dm-pcache initializes
cache_infofrom a zeroed state so metadata CRC
failures can’t leak stale flags into the new-cache path.Thanks for your review.
Li Chen (3):
dm-pcache: allow built-in build and rename flush helper
dm-pcache: reusemeta_addrinpcache_meta_find_latest
dm-pcache: zerocache_infobefore default initdrivers/md/dm-pcache/Makefile | 2 +- drivers/md/dm-pcache/cache.c | 4 ++-- drivers/md/dm-pcache/cache.h | 2 +- drivers/md/dm-pcache/cache_req.c | 6 +++--- drivers/md/dm-pcache/pcache_internal.h | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-)