* [PATCH] zram: do not permit params change after init
@ 2026-03-10 6:01 Sergey Senozhatsky
2026-03-10 14:01 ` Brian Geffon
2026-03-11 8:27 ` Sergey Senozhatsky
0 siblings, 2 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2026-03-10 6:01 UTC (permalink / raw)
To: Andrew Morton
Cc: Minchan Kim, Brian Geffon, linux-block, linux-mm,
Sergey Senozhatsky, gao xu
First, algorithm_params_store(), like any sysfs handler,
should grab device init lock.
Second, like any write() sysfs handler, it should grab
device init lock in exclusive mode.
Third, it should not permit change of algos' parameters
after device init, as this doesn't make sense - we cannot
compress with one C/D dict and then just change C/D dict
to a different one, for example.
Fixes: 4eac932103a5d ("zram: introduce algorithm_params device attribute")
Cc: gao xu <gaoxu2@honor.com>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
drivers/block/zram/zram_drv.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index c41e1257243f..7551c5e664a9 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1769,6 +1769,10 @@ static ssize_t algorithm_params_store(struct device *dev,
if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
return -EINVAL;
+ guard(rwsem_write)(&zram->dev_lock);
+ if (init_done(zram))
+ return -EBUSY;
+
ret = comp_params_store(zram, prio, level, dict_path, &deflate_params);
return ret ? ret : len;
}
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: do not permit params change after init
2026-03-10 6:01 [PATCH] zram: do not permit params change after init Sergey Senozhatsky
@ 2026-03-10 14:01 ` Brian Geffon
2026-03-10 14:02 ` Brian Geffon
2026-03-11 8:27 ` Sergey Senozhatsky
1 sibling, 1 reply; 4+ messages in thread
From: Brian Geffon @ 2026-03-10 14:01 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Andrew Morton, Minchan Kim, linux-block, linux-mm, gao xu
On Tue, Mar 10, 2026 at 2:04 AM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> First, algorithm_params_store(), like any sysfs handler,
> should grab device init lock.
>
> Second, like any write() sysfs handler, it should grab
> device init lock in exclusive mode.
comp_algorithm_store() and recomp_algorithm_store()?
>
> Third, it should not permit change of algos' parameters
> after device init, as this doesn't make sense - we cannot
> compress with one C/D dict and then just change C/D dict
> to a different one, for example.
>
> Fixes: 4eac932103a5d ("zram: introduce algorithm_params device attribute")
> Cc: gao xu <gaoxu2@honor.com>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Acked-by: Brian Geffon <bgeffon@google.com>
> ---
> drivers/block/zram/zram_drv.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index c41e1257243f..7551c5e664a9 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -1769,6 +1769,10 @@ static ssize_t algorithm_params_store(struct device *dev,
> if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
> return -EINVAL;
>
> + guard(rwsem_write)(&zram->dev_lock);
> + if (init_done(zram))
> + return -EBUSY;
> +
> ret = comp_params_store(zram, prio, level, dict_path, &deflate_params);
> return ret ? ret : len;
> }
> --
> 2.53.0.473.g4a7958ca14-goog
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: do not permit params change after init
2026-03-10 14:01 ` Brian Geffon
@ 2026-03-10 14:02 ` Brian Geffon
0 siblings, 0 replies; 4+ messages in thread
From: Brian Geffon @ 2026-03-10 14:02 UTC (permalink / raw)
To: Sergey Senozhatsky
Cc: Andrew Morton, Minchan Kim, linux-block, linux-mm, gao xu
On Tue, Mar 10, 2026 at 10:01 AM Brian Geffon <bgeffon@google.com> wrote:
>
> On Tue, Mar 10, 2026 at 2:04 AM Sergey Senozhatsky
> <senozhatsky@chromium.org> wrote:
> >
> > First, algorithm_params_store(), like any sysfs handler,
> > should grab device init lock.
> >
> > Second, like any write() sysfs handler, it should grab
> > device init lock in exclusive mode.
>
> comp_algorithm_store() and recomp_algorithm_store()?
disregard, that happens in __comp_algorithm_store().
>
> >
> > Third, it should not permit change of algos' parameters
> > after device init, as this doesn't make sense - we cannot
> > compress with one C/D dict and then just change C/D dict
> > to a different one, for example.
> >
> > Fixes: 4eac932103a5d ("zram: introduce algorithm_params device attribute")
> > Cc: gao xu <gaoxu2@honor.com>
> > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
>
> Acked-by: Brian Geffon <bgeffon@google.com>
>
> > ---
> > drivers/block/zram/zram_drv.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > index c41e1257243f..7551c5e664a9 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -1769,6 +1769,10 @@ static ssize_t algorithm_params_store(struct device *dev,
> > if (prio < ZRAM_PRIMARY_COMP || prio >= ZRAM_MAX_COMPS)
> > return -EINVAL;
> >
> > + guard(rwsem_write)(&zram->dev_lock);
> > + if (init_done(zram))
> > + return -EBUSY;
> > +
> > ret = comp_params_store(zram, prio, level, dict_path, &deflate_params);
> > return ret ? ret : len;
> > }
> > --
> > 2.53.0.473.g4a7958ca14-goog
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zram: do not permit params change after init
2026-03-10 6:01 [PATCH] zram: do not permit params change after init Sergey Senozhatsky
2026-03-10 14:01 ` Brian Geffon
@ 2026-03-11 8:27 ` Sergey Senozhatsky
1 sibling, 0 replies; 4+ messages in thread
From: Sergey Senozhatsky @ 2026-03-11 8:27 UTC (permalink / raw)
To: Andrew Morton
Cc: Minchan Kim, Brian Geffon, linux-block, linux-mm, gao xu,
Sergey Senozhatsky
On (26/03/10 15:01), Sergey Senozhatsky wrote:
> First, algorithm_params_store(), like any sysfs handler,
> should grab device init lock.
>
> Second, like any write() sysfs handler, it should grab
> device init lock in exclusive mode.
>
> Third, it should not permit change of algos' parameters
> after device init, as this doesn't make sense - we cannot
> compress with one C/D dict and then just change C/D dict
> to a different one, for example.
>
> Fixes: 4eac932103a5d ("zram: introduce algorithm_params device attribute")
> Cc: gao xu <gaoxu2@honor.com>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Andrew, I will include this patch into v2 of the zram fixups,
can you please drop it for now?
We need to protect algo lookup path as well, which accesses
->comp_algs. I'll fix that in v2.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-11 8:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 6:01 [PATCH] zram: do not permit params change after init Sergey Senozhatsky
2026-03-10 14:01 ` Brian Geffon
2026-03-10 14:02 ` Brian Geffon
2026-03-11 8:27 ` Sergey Senozhatsky
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox