* Re: [f2fs-dev] [PATCH v4 3/4] zram: validate parameters in each backend's setup_params [not found] ` <CAEjiKSkExTnRc77Va-cOSpoNJ4S0i_-r2-iGFyxoSw2mqh1Diw@mail.gmail.com> @ 2026-08-04 4:42 ` Sergey Senozhatsky 2026-08-05 1:26 ` Jaegeuk Kim via Linux-f2fs-devel 0 siblings, 1 reply; 2+ messages in thread From: Sergey Senozhatsky @ 2026-08-04 4:42 UTC (permalink / raw) To: haoqin huang Cc: Jens Axboe, Minchan Kim, linux-kernel, linux-f2fs-devel, linux-block, Sergey Senozhatsky, Nick Terrell, David Sterba, Jaegeuk Kim, Andrew Morton, Rongwei Wang, Haoqin Huang On (26/08/03 20:20), haoqin huang wrote: > On Thu, Jul 30, 2026 at 3:24 PM Sergey Senozhatsky > <senozhatsky@chromium.org> wrote: > > > diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c > > > index f6a336acfe20..5d551d165213 100644 > > > --- a/drivers/block/zram/backend_lz4hc.c > > > +++ b/drivers/block/zram/backend_lz4hc.c > > > @@ -20,6 +20,11 @@ static int lz4hc_setup_params(struct zcomp_params *params) > > > { > > > if (params->level == ZCOMP_PARAM_NOT_SET) > > > params->level = LZ4HC_DEFAULT_CLEVEL; > > > + else if (params->level < LZ4HC_MIN_CLEVEL || > > > + params->level > LZ4HC_MAX_CLEVEL) { > > > + pr_err("lz4hc: invalid compression level %d\n", params->level); > > > + return -EINVAL; > > > + } > > > > So... lib/lz4/lz4hc_compress.c supports levels 1 and 2. However, > > LZ4HC_MIN_CLEVEL is set to 3, but clearly the compression library > > supports levels lower than LZ4HC_MIN_CLEVEL. In fact, LZ4HC_MIN_CLEVEL > > is never used in the lz4 code. Maybe here we need to just hardcode > > "< 1" and put a comment: > > > > My bad, completely missed that LZ4HC_MIN_CLEVEL is advisory and the > library actually accepts 1-2. Will hardcode < 1 in v5. No worries, that LZ4HC_MIN_CLEVEL thing is difficult to spot. > Btw, would it make sense to fix LZ4HC_MIN_CLEVEL to 1 in the lz4 > header as a separate cleanup? It seems misleading as-is. I'm afraid we cannot do that. f2fs uses LZ4HC_MIN_CLEVEL, I assume compression level is stored per-inode? So if we change LZ4HC_MIN_CLEVEL then newer f2fs will start accepting compression levels that older kernels don't support. Cc-ed Jaegeuk and Chao just for visibility. _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [f2fs-dev] [PATCH v4 3/4] zram: validate parameters in each backend's setup_params 2026-08-04 4:42 ` [f2fs-dev] [PATCH v4 3/4] zram: validate parameters in each backend's setup_params Sergey Senozhatsky @ 2026-08-05 1:26 ` Jaegeuk Kim via Linux-f2fs-devel 0 siblings, 0 replies; 2+ messages in thread From: Jaegeuk Kim via Linux-f2fs-devel @ 2026-08-05 1:26 UTC (permalink / raw) To: Sergey Senozhatsky Cc: Jens Axboe, linux-kernel, linux-f2fs-devel, linux-block, Minchan Kim, Nick Terrell, David Sterba, Andrew Morton, Rongwei Wang, Haoqin Huang, haoqin huang On 08/04, Sergey Senozhatsky wrote: > On (26/08/03 20:20), haoqin huang wrote: > > On Thu, Jul 30, 2026 at 3:24 PM Sergey Senozhatsky > > <senozhatsky@chromium.org> wrote: > > > > diff --git a/drivers/block/zram/backend_lz4hc.c b/drivers/block/zram/backend_lz4hc.c > > > > index f6a336acfe20..5d551d165213 100644 > > > > --- a/drivers/block/zram/backend_lz4hc.c > > > > +++ b/drivers/block/zram/backend_lz4hc.c > > > > @@ -20,6 +20,11 @@ static int lz4hc_setup_params(struct zcomp_params *params) > > > > { > > > > if (params->level == ZCOMP_PARAM_NOT_SET) > > > > params->level = LZ4HC_DEFAULT_CLEVEL; > > > > + else if (params->level < LZ4HC_MIN_CLEVEL || > > > > + params->level > LZ4HC_MAX_CLEVEL) { > > > > + pr_err("lz4hc: invalid compression level %d\n", params->level); > > > > + return -EINVAL; > > > > + } > > > > > > So... lib/lz4/lz4hc_compress.c supports levels 1 and 2. However, > > > LZ4HC_MIN_CLEVEL is set to 3, but clearly the compression library > > > supports levels lower than LZ4HC_MIN_CLEVEL. In fact, LZ4HC_MIN_CLEVEL > > > is never used in the lz4 code. Maybe here we need to just hardcode > > > "< 1" and put a comment: > > > > > > > My bad, completely missed that LZ4HC_MIN_CLEVEL is advisory and the > > library actually accepts 1-2. Will hardcode < 1 in v5. > > No worries, that LZ4HC_MIN_CLEVEL thing is difficult to spot. > > > Btw, would it make sense to fix LZ4HC_MIN_CLEVEL to 1 in the lz4 > > header as a separate cleanup? It seems misleading as-is. > > I'm afraid we cannot do that. f2fs uses LZ4HC_MIN_CLEVEL, I assume > compression level is stored per-inode? So if we change LZ4HC_MIN_CLEVEL > then newer f2fs will start accepting compression levels that older kernels > don't support. Cc-ed Jaegeuk and Chao just for visibility. Yeah, since we have 239 clevel = le16_to_cpu(ri->i_compress_flag) >> 240 COMPRESS_LEVEL_OFFSET; 255 #ifdef CONFIG_F2FS_FS_LZ4 256 #ifdef CONFIG_F2FS_FS_LZ4HC 257 if (clevel && 258 (clevel < LZ4HC_MIN_CLEVEL || clevel > LZ4HC_MAX_CLEVEL)) 259 goto err_level; 260 #else 261 if (clevel) 262 goto err_level; 263 #endif 264 #endif _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-05 1:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260730025240.17724-1-haoqinhuang7@gmail.com>
[not found] ` <20260730060133.80233-1-haoqinhuang7@gmail.com>
[not found] ` <20260730060133.80233-4-haoqinhuang7@gmail.com>
[not found] ` <amr3P_4zxX2w7ZNR@google.com>
[not found] ` <CAEjiKSkExTnRc77Va-cOSpoNJ4S0i_-r2-iGFyxoSw2mqh1Diw@mail.gmail.com>
2026-08-04 4:42 ` [f2fs-dev] [PATCH v4 3/4] zram: validate parameters in each backend's setup_params Sergey Senozhatsky
2026-08-05 1:26 ` Jaegeuk Kim via Linux-f2fs-devel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox