linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Minchan Kim <minchan@kernel.org>,
	Brian Geffon <bgeffon@google.com>,
	linux-block@vger.kernel.org, linux-mm@kvack.org,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	gao xu <gaoxu2@honor.com>
Subject: [PATCH v2 1/6] zram: do not permit params change after init
Date: Wed, 11 Mar 2026 17:42:44 +0900	[thread overview]
Message-ID: <20260311084312.1766036-2-senozhatsky@chromium.org> (raw)
In-Reply-To: <20260311084312.1766036-1-senozhatsky@chromium.org>

First, algorithm_params_store(), like any sysfs handler,
should grab device lock.

Second, like any write() sysfs handler, it should grab
device 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.

Another thing to notice is that algorithm_params_store()
accesses device's ->comp_algs for algo priority lookup,
which should be protected by device lock in exclusive
mode in general.

Fixes: 4eac932103a5d ("zram: introduce algorithm_params device attribute")
Acked-by: Brian Geffon <bgeffon@google.com>
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 fa38d26119ec..db862179cf59 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1750,6 +1750,10 @@ static ssize_t algorithm_params_store(struct device *dev,
 		}
 	}
 
+	guard(rwsem_write)(&zram->dev_lock);
+	if (init_done(zram))
+		return -EBUSY;
+
 	/* Lookup priority by algorithm name */
 	if (algo) {
 		s32 p;
-- 
2.53.0.473.g4a7958ca14-goog



  reply	other threads:[~2026-03-11  8:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11  8:42 [PATCH v2 0/6] zram: recompression cleanups and tweaks Sergey Senozhatsky
2026-03-11  8:42 ` Sergey Senozhatsky [this message]
2026-03-11  8:42 ` [PATCH v2 2/6] zram: do not autocorrect bad recompression parameters Sergey Senozhatsky
2026-03-11  8:42 ` [PATCH v2 3/6] zram: drop ->num_active_comps Sergey Senozhatsky
2026-03-11  8:42 ` [PATCH v2 4/6] zram: update recompression documentation Sergey Senozhatsky
2026-03-11  8:42 ` [PATCH v2 5/6] zram: remove chained recompression Sergey Senozhatsky
2026-03-11  8:42 ` [PATCH v2 6/6] zram: unify and harden algo/priority params handling Sergey Senozhatsky

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=20260311084312.1766036-2-senozhatsky@chromium.org \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=bgeffon@google.com \
    --cc=gaoxu2@honor.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox