* [PATCH 1/2] pstore: Consolidate compression handling in both init paths
2026-09-22 21:19 [PATCH 0/2] Small improvements on pstore user experience Guilherme G. Piccoli
@ 2026-09-22 21:19 ` Guilherme G. Piccoli
2026-09-22 21:19 ` [PATCH 2/2] pstore: Allow kmsg_bytes parameter to be written at runtime Guilherme G. Piccoli
2026-09-23 7:20 ` [PATCH 0/2] Small improvements on pstore user experience Kees Cook
2 siblings, 0 replies; 6+ messages in thread
From: Guilherme G. Piccoli @ 2026-09-22 21:19 UTC (permalink / raw)
To: kees; +Cc: tony.luck, gpiccoli, linux-hardening, kernel-dev, kernel
The pstore infrastructure can be initialized in two ways: either through
the filesystem registration at pstore_init(), or via backend registration
that calls pstore_register(). At the same time, we have a peculiarity
regarding pstore compression: multiple algorithms were once supported,
but they were phased out, and only "deflate" is now supported, along
with the backward-compatible "none" value.
These two apparently unrelated topics have one (lacking) point of
convergence: the compression parameter handling is done only in the
pstore registration phase, at allocate_buf_for_compression(). Now, if
the pstore fs gets registered prior to any backend registration, which
is common in practice, some funny scenarios are possible, for example:
users can set any string for compression and it is held in the
compression parameter up to the backend registration (if any). Another
one (maybe even more odd): it's possible to set any value to this
parameter even if CONFIG_PSTORE_COMPRESS is disabled, and such a value
is kept until backend registration, which is counter-intuitive.
Bring both initialization points of pstore in sync regarding the
compression set-up, by funneling the parameter handling through a
single function called in both paths. The __always_inline attribute
usage is deliberate and necessary: the pstore code relies on the
compiler's Dead Code Elimination (DCE) to drop references to zlib
symbols that may not be built. The code checks for CONFIG_PSTORE_COMPRESS
and bails early in some functions, which leads to zlib calls becoming
dead code that is gone with DCE. So, inlining is required here to
avoid undefined references to zlib symbols not built at link time.
On top of that, also improve the compression parameter module info.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---
fs/pstore/platform.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 1d76c9d92056..f3a900cf2cfb 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -89,7 +89,7 @@ MODULE_PARM_DESC(backend, "specific backend to use");
*/
static char *compress = "deflate";
module_param(compress, charp, 0444);
-MODULE_PARM_DESC(compress, "compression to use");
+MODULE_PARM_DESC(compress, "compression to use (deflate/none)");
/* How much of the kernel log to snapshot */
unsigned int kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES;
@@ -201,16 +201,12 @@ static int pstore_compress(const void *in, void *out,
return zstream.total_out;
}
-static void allocate_buf_for_compression(void)
+static __always_inline bool compress_param_adjust(void)
{
- size_t compressed_size;
- char *buf;
-
- /* Skip if not built-in or compression disabled. */
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !compress ||
!strcmp(compress, "none")) {
compress = NULL;
- return;
+ return false;
}
if (strcmp(compress, "deflate")) {
@@ -219,6 +215,16 @@ static void allocate_buf_for_compression(void)
compress = "deflate";
}
+ return true;
+}
+
+static void allocate_buf_for_compression(void)
+{
+ size_t compressed_size;
+ char *buf;
+
+ if (!compress_param_adjust())
+ return;
/*
* The compression buffer only needs to be as large as the maximum
* uncompressed record size, since any record that would be expanded by
@@ -747,6 +753,8 @@ static int __init pstore_init(void)
{
int ret;
+ compress_param_adjust();
+
ret = pstore_init_fs();
if (ret)
free_buf_for_compression();
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] pstore: Allow kmsg_bytes parameter to be written at runtime
2026-09-22 21:19 [PATCH 0/2] Small improvements on pstore user experience Guilherme G. Piccoli
2026-09-22 21:19 ` [PATCH 1/2] pstore: Consolidate compression handling in both init paths Guilherme G. Piccoli
@ 2026-09-22 21:19 ` Guilherme G. Piccoli
2026-09-23 7:20 ` [PATCH 0/2] Small improvements on pstore user experience Kees Cook
2 siblings, 0 replies; 6+ messages in thread
From: Guilherme G. Piccoli @ 2026-09-22 21:19 UTC (permalink / raw)
To: kees; +Cc: tony.luck, gpiccoli, linux-hardening, kernel-dev, kernel
Currently the kmsg_bytes parameter is read-only in sysfs, though
it can be changed both via command-line at boot-time, and through
the pstore filesystem mount option, at runtime.
Add a module parameter callback in order for users to change kmsg_bytes
via the runtime sysfs interface, the same way they can do it using
the mount option.
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
---
fs/pstore/platform.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index f3a900cf2cfb..185afc3db1a4 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -93,7 +93,25 @@ MODULE_PARM_DESC(compress, "compression to use (deflate/none)");
/* How much of the kernel log to snapshot */
unsigned int kmsg_bytes = CONFIG_PSTORE_DEFAULT_KMSG_BYTES;
-module_param(kmsg_bytes, uint, 0444);
+static int param_set_kmsg_bytes(const char *val, const struct kernel_param *kp)
+{
+ unsigned int num;
+
+ if (kstrtouint(val, 0, &num))
+ return -EINVAL;
+
+ WRITE_ONCE(kmsg_bytes, num);
+
+ return 0;
+}
+
+static const struct kernel_param_ops kmsg_bytes_ops = {
+ .set = param_set_kmsg_bytes,
+ .get = param_get_uint,
+};
+
+module_param_cb(kmsg_bytes, &kmsg_bytes_ops, &kmsg_bytes, 0644);
+__MODULE_PARM_TYPE(kmsg_bytes, "uint");
MODULE_PARM_DESC(kmsg_bytes, "amount of kernel log to snapshot (in bytes)");
static void *compress_workspace;
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/2] Small improvements on pstore user experience
2026-09-22 21:19 [PATCH 0/2] Small improvements on pstore user experience Guilherme G. Piccoli
2026-09-22 21:19 ` [PATCH 1/2] pstore: Consolidate compression handling in both init paths Guilherme G. Piccoli
2026-09-22 21:19 ` [PATCH 2/2] pstore: Allow kmsg_bytes parameter to be written at runtime Guilherme G. Piccoli
@ 2026-09-23 7:20 ` Kees Cook
2026-09-23 14:30 ` Guilherme G. Piccoli
2 siblings, 1 reply; 6+ messages in thread
From: Kees Cook @ 2026-09-23 7:20 UTC (permalink / raw)
To: Guilherme G. Piccoli; +Cc: tony.luck, linux-hardening, kernel-dev, kernel
On Tue, Sep 22, 2026 at 06:19:00PM -0300, Guilherme G. Piccoli wrote:
> Hi Kees, Tony,
>
> Here are some small things I've noticed in pstore usage that annoyed
> me a bit, so it's not they must be fixed - no bugs here that I can't see.
>
> But the fact kmsg_bytes can be changed via mount option but I can't
> write on its sysfs parameter, or that I can set compression to like
> "zstd" even when PSTORE_COMPRESS is unset, is a bit confusing to the
> point I tried to improve them with these patches heh
Thanks for poking at it! Yeah, that PSTORE_COMPRESS=n seems like it
needs to get fixed. :P
> Thanks for reviews and comments, and feel free to reject them if in
> your opinion, they make things worse.
Sashiko has some notes:
https://sashiko.dev/#/patchset/20260922212532.98571-1-gpiccoli%40igalia.com
I fear it is uncovered some other (small) preexisting issues, but I do
agree the kmsg_bytes concurrency race is troublesome.
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 6+ messages in thread