FAILED: patch "[PATCH] zram: set default primary compressor in zram_destroy_comps()" failed to apply to 6.6-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x dde75313eed0b014c437f48dd75c0308b592cbf9
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090323-gumminess-earthy-c60d@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From dde75313eed0b014c437f48dd75c0308b592cbf9 Mon Sep 17 00:00:00 2001
From: Sergey Senozhatsky <[email protected]>
Date: Wed, 29 Jul 2026 13:57:35 +0900
Subject: [PATCH] zram: set default primary compressor in zram_destroy_comps()
Patch series "zram: fix zram issues reported by sashiko".
Sashiko drove by and reported [1] a couple of zram issues:
a possible BUG_ON() in zlib code due to missing winbits range validation and one possible NULL-ptr dereference in zcomp. Both are low risk yet still worth fixing.
This patch (of 2):
zram_destroy_comps() resets all compressors and leaves them set to NULL, including the primary one, which is invalid device state, as now comp_algorithm_show()->strcmp() can be called on a NULL compressor. Set default primary compressor in zram_destroy_comps().
drivers/block/zram/zram_drv.c +1 -2
@@ -2828,6 +2828,7 @@ static void zram_destroy_comps(struct zram *zram) zram->comp_algs[prio] =NULL ;zram_comp_params_reset (zram); +comp_algorithm_set (zram,ZRAM_PRIMARY_COMP , default_compressor); }static void zram_reset_device (struct zram *zram)
@@ -2845,8 +2846,6 @@ static void zram_reset_device(struct zram *zram)zram_destroy_comps (zram);memset (&zram->stats,0 ,sizeof (zram->stats));reset_bdev (zram); - -comp_algorithm_set (zram,ZRAM_PRIMARY_COMP , default_compressor); } static ssize_t disksize_store(struct device *dev, struct device_attribute *attr,
Sasha Levin
maintainerPATCH 1/4 zram: take write lock in wb limit store handlers
From: Sergey Senozhatsky <[email protected]>
[ Upstream commit 7c929664fddfdaaa4afe5ae833d0f3044709d95c ]
Write device attrs handlers should take write zram init_lock. While at it, fixup coding styles.
Stable-dep-of: dde75313eed0 ("zram: set default primary compressor in zram_destroy_comps()")
--- drivers/block/zram/zram_drv.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/block/zram/zram_drv.c +10 -7
@@ -365,7 +365,8 @@ static ssize_t idle_store(struct device *dev,#ifdef CONFIG_ZRAM_WRITEBACK static ssize_t writeback_limit_enable_store (struct device *dev, -struct device_attribute *attr,const char *buf,size_t len) +struct device_attribute *attr, +const char *buf,size_t len) {struct zram *zram =dev_to_zram (dev);u64 val;
@@ -374,18 +375,19 @@ static ssize_t writeback_limit_enable_store(struct device *dev,if (kstrtoull (buf,10 , &val))return ret; -down_read (&zram->init_lock); +down_write (&zram->init_lock);spin_lock (&zram->wb_limit_lock); zram->wb_limit_enable = val;spin_unlock (&zram->wb_limit_lock); -up_read (&zram->init_lock); +up_write (&zram->init_lock); ret = len;return ret; }static ssize_t writeback_limit_enable_show (struct device *dev, -struct device_attribute *attr,char *buf) +struct device_attribute *attr, +char *buf) {bool val;struct zram *zram =dev_to_zram (dev);
@@ -400,7 +402,8 @@ static ssize_t writeback_limit_enable_show(struct device *dev, }static ssize_t writeback_limit_store (struct device *dev, -struct device_attribute *attr,const char *buf,size_t len) +struct device_attribute *attr, +const char *buf,size_t len) {struct zram *zram =dev_to_zram (dev);u64 val;
@@ -409,11 +412,11 @@ static ssize_t writeback_limit_store(struct device *dev,if (kstrtoull (buf,10 , &val))return ret; -down_read (&zram->init_lock); +down_write (&zram->init_lock);spin_lock (&zram->wb_limit_lock); zram->bd_wb_limit = val;spin_unlock (&zram->wb_limit_lock); -up_read (&zram->init_lock); +up_write (&zram->init_lock); ret = len;return ret;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/4 zram: fix the issue that the write - back limits might overflow
From: Yuwen Chen <[email protected]>
[ Upstream commit 04d31610a7221cca624646241b1f6b3edd6c99fd ]
When the page size exceeds 4KB, if bd_wb_limit is set to a value that is not aligned with the page size, it will cause a numerical wrap-around issue for bd_wb_limit. For example, when the page size is set to 16KB and bd_wb_limit is set to 3, after one write-back operation, the value of bd_wb_limit will become -1. More seriously, since bd_wb_limit is an unsigned number, its value may become as large as 2^64 - 1.
The core reason for this problem is that the unit of bd_wb_limit is 4KB. For example, when a write-back occurs on a system with a page size of 16KB, 4 needs to be subtracted from bd_wb_limit. This operation takes place in the zram_account_writeback_submit function.
This patch fixes the issue by limiting bd_wb_limit to be an integer multiple of PAGE_SIZE / 4096.
Stable-dep-of: dde75313eed0 ("zram: set default primary compressor in zram_destroy_comps()")
--- drivers/block/zram/zram_drv.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/block/zram/zram_drv.c +10 -0
@@ -412,6 +412,16 @@ static ssize_t writeback_limit_store(struct device *dev,if (kstrtoull (buf,10 , &val))return ret; +/* +* When the page size is greater than 4KB, if bd_wb_limit is set to +* a value that is not page - size aligned, it will cause value +* wrapping. For example, when the page size is set to 16KB and +* bd_wb_limit is set to 3, a single write - back operation will +* cause bd_wb_limit to become -1. Even more terrifying is that +* bd_wb_limit is an unsigned number. +*/ + val =rounddown (val,PAGE_SIZE /4096 ); +down_write (&zram->init_lock);spin_lock (&zram->wb_limit_lock); zram->bd_wb_limit = val;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/4 zram: move bd_stat to writeback section
In reply to Sasha LevinFrom: Sergey Senozhatsky <[email protected]>
[ Upstream commit 910bbb441c004050e188dd8da5071054099e592c ]
Move bd_stat function and attribute declaration to existing CONFIG_WRITEBACK ifdef-sections.
Stable-dep-of: dde75313eed0 ("zram: set default primary compressor in zram_destroy_comps()")
--- drivers/block/zram/zram_drv.c | 54 ++++++++++++++++------------------- 1 file changed, 25 insertions(+), 29 deletions(-)
drivers/block/zram/zram_drv.c +25 -29
@@ -364,6 +364,24 @@ static ssize_t idle_store(struct device *dev, }#ifdef CONFIG_ZRAM_WRITEBACK +#define FOUR_K (x) ((x) * (1 << (PAGE_SHIFT - 12))) +static ssize_t bd_stat_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct zram *zram =dev_to_zram (dev); +ssize_t ret; + +down_read (&zram->init_lock); + ret =scnprintf (buf,PAGE_SIZE , +"%8llu %8llu %8llu\n" , +FOUR_K ((u64 )atomic64_read (&zram->stats.bd_count)), +FOUR_K ((u64 )atomic64_read (&zram->stats.bd_reads)), +FOUR_K ((u64 )atomic64_read (&zram->stats.bd_writes))); +up_read (&zram->init_lock); + +return ret; +} +static ssize_t writeback_limit_enable_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t len)
@@ -1200,27 +1218,6 @@ static ssize_t mm_stat_show(struct device *dev,return ret; } - -#ifdef CONFIG_ZRAM_WRITEBACK -#define FOUR_K (x) ((x) * (1 << (PAGE_SHIFT - 12))) -static ssize_t bd_stat_show (struct device *dev, -struct device_attribute *attr,char *buf) -{ -struct zram *zram =dev_to_zram (dev); -ssize_t ret; - -down_read (&zram->init_lock); - ret =scnprintf (buf,PAGE_SIZE , -"%8llu %8llu %8llu\n" , -FOUR_K ((u64 )atomic64_read (&zram->stats.bd_count)), -FOUR_K ((u64 )atomic64_read (&zram->stats.bd_reads)), -FOUR_K ((u64 )atomic64_read (&zram->stats.bd_writes))); -up_read (&zram->init_lock); - -return ret; -} -#endif -static ssize_t debug_stat_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -1241,9 +1238,6 @@ static ssize_t debug_stat_show(struct device *dev,static DEVICE_ATTR_RO (io_stat);static DEVICE_ATTR_RO (mm_stat); -#ifdef CONFIG_ZRAM_WRITEBACK -static DEVICE_ATTR_RO (bd_stat); -#endif static DEVICE_ATTR_RO (debug_stat);static void zram_meta_free (struct zram *zram,u64 disksize)
@@ -2014,6 +2008,7 @@ static void zram_slot_free_notify(struct block_device *bdev,zram_slot_unlock (zram, index); } +#define zram_comp_params_reset (_zram) ((void)(_zram))static void zram_destroy_comps (struct zram *zram) {u32 prio;
@@ -2034,11 +2029,14 @@ static void zram_destroy_comps(struct zram *zram)kfree (zram->comp_algs[prio]); zram->comp_algs[prio] =NULL ; } + +zram_comp_params_reset (zram); } +#undef zram_comp_params_resetstatic void zram_reset_device (struct zram *zram) { -down_write (&zram->init_lock); +guard (rwsem_write)(&zram->init_lock); zram->limit_pages =0 ;
@@ -2053,7 +2051,6 @@ static void zram_reset_device(struct zram *zram)reset_bdev (zram);comp_algorithm_set (zram,ZRAM_PRIMARY_COMP , default_compressor); -up_write (&zram->init_lock); } static ssize_t disksize_store(struct device *dev,
@@ -2180,6 +2177,7 @@ static DEVICE_ATTR_WO(idle);static DEVICE_ATTR_RW (max_comp_streams);static DEVICE_ATTR_RW (comp_algorithm);#ifdef CONFIG_ZRAM_WRITEBACK +static DEVICE_ATTR_RO (bd_stat);static DEVICE_ATTR_RW (backing_dev);static DEVICE_ATTR_WO (writeback);static DEVICE_ATTR_RW (writeback_limit);
@@ -2201,6 +2199,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_max_comp_streams.attr, &dev_attr_comp_algorithm.attr, #ifdef CONFIG_ZRAM_WRITEBACK + &dev_attr_bd_stat.attr, &dev_attr_backing_dev.attr, &dev_attr_writeback.attr, &dev_attr_writeback_limit.attr,
@@ -2208,9 +2207,6 @@ static struct attribute *zram_disk_attrs[] = {#endif &dev_attr_io_stat.attr, &dev_attr_mm_stat.attr, -#ifdef CONFIG_ZRAM_WRITEBACK - &dev_attr_bd_stat.attr, -#endif &dev_attr_debug_stat.attr, #ifdef CONFIG_ZRAM_MULTI_COMP &dev_attr_recomp_algorithm.attr,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/4 zram: set default primary compressor in zram_destroy_comps()
In reply to Sasha LevinFrom: Sergey Senozhatsky <[email protected]>
[ Upstream commit dde75313eed0b014c437f48dd75c0308b592cbf9 ]
Patch series "zram: fix zram issues reported by sashiko".
Sashiko drove by and reported [1] a couple of zram issues:
a possible BUG_ON() in zlib code due to missing winbits range validation and one possible NULL-ptr dereference in zcomp. Both are low risk yet still worth fixing.
This patch (of 2):
zram_destroy_comps() resets all compressors and leaves them set to NULL, including the primary one, which is invalid device state, as now comp_algorithm_show()->strcmp() can be called on a NULL compressor. Set default primary compressor in zram_destroy_comps().
--- drivers/block/zram/zram_drv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/block/zram/zram_drv.c +1 -2
@@ -2031,6 +2031,7 @@ static void zram_destroy_comps(struct zram *zram) }zram_comp_params_reset (zram); +comp_algorithm_set (zram,ZRAM_PRIMARY_COMP , default_compressor); }#undef zram_comp_params_reset
@@ -2049,8 +2050,6 @@ static void zram_reset_device(struct zram *zram)zram_destroy_comps (zram);memset (&zram->stats,0 ,sizeof (zram->stats));reset_bdev (zram); - -comp_algorithm_set (zram,ZRAM_PRIMARY_COMP , default_compressor); } static ssize_t disksize_store(struct device *dev,
Signature · 1 line
2.53.0