* [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin
@ 2025-11-06 4:51 Mario Limonciello (AMD)
2025-11-06 4:51 ` [PATCH 1/3] PM: hibernate: Emit an error when image writing fails Mario Limonciello (AMD)
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Mario Limonciello (AMD) @ 2025-11-06 4:51 UTC (permalink / raw)
To: mario.limonciello, lenb, pavel, rafael
Cc: Mario Limonciello (AMD), Askar Safin, linux-pm
Askar Safin reported some usability issues with hibernate messageing in
some failure cases. This series fixes those issues as well as some style
issues I noticed while touching the function.
Cc: Askar Safin <safinaskar@gmail.com>
Mario Limonciello (AMD) (3):
PM: hibernate: Emit an error when image writing fails
PM: hibernate: Use atomic64_t for compressed_size variable
PM: hibernate: Fix style issues in save_compressed_image()
kernel/power/swap.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] PM: hibernate: Emit an error when image writing fails
2025-11-06 4:51 [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Mario Limonciello (AMD)
@ 2025-11-06 4:51 ` Mario Limonciello (AMD)
2025-11-06 19:54 ` Askar Safin
2025-11-06 4:51 ` [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable Mario Limonciello (AMD)
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Mario Limonciello (AMD) @ 2025-11-06 4:51 UTC (permalink / raw)
To: mario.limonciello, lenb, pavel, rafael
Cc: Mario Limonciello (AMD), Askar Safin, linux-pm
If image writing fails a return code is passed up to the caller but
none of the callers log anything to the log and so the only record
of it is the return code that userspace gets.
Adjust the logging so that the image size and speed of writing is
only emitted on success and if there is an error it's saved the logs.
Reported-by: Askar Safin <safinaskar@gmail.com>
Closes: https://lore.kernel.org/linux-pm/20251105180506.137448-1-safinaskar@gmail.com/
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
kernel/power/swap.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 0beff7eeaabaf..f9bf01f355189 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -877,11 +877,13 @@ static int save_compressed_image(struct swap_map_handle *handle,
stop = ktime_get();
if (!ret)
ret = err2;
- if (!ret)
+ if (!ret) {
+ swsusp_show_speed(start, stop, nr_to_write, "Wrote");
+ pr_info("Image size after compression: %d kbytes\n",
+ (atomic_read(&compressed_size) / 1024));
pr_info("Image saving done\n");
- swsusp_show_speed(start, stop, nr_to_write, "Wrote");
- pr_info("Image size after compression: %d kbytes\n",
- (atomic_read(&compressed_size) / 1024));
+ } else
+ pr_err("Image saving failed: %d\n", ret);
out_clean:
hib_finish_batch(&hb);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable
2025-11-06 4:51 [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Mario Limonciello (AMD)
2025-11-06 4:51 ` [PATCH 1/3] PM: hibernate: Emit an error when image writing fails Mario Limonciello (AMD)
@ 2025-11-06 4:51 ` Mario Limonciello (AMD)
2025-11-06 20:01 ` Askar Safin
2025-11-07 15:56 ` Rafael J. Wysocki
2025-11-06 4:51 ` [PATCH 3/3] PM: hibernate: Fix style issues in save_compressed_image() Mario Limonciello (AMD)
2025-11-06 20:03 ` [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Askar Safin
3 siblings, 2 replies; 9+ messages in thread
From: Mario Limonciello (AMD) @ 2025-11-06 4:51 UTC (permalink / raw)
To: mario.limonciello, lenb, pavel, rafael
Cc: Mario Limonciello (AMD), Askar Safin, linux-pm
`compressed_size` can overflow, showing nonsensical values.
Change from `atomic_t` to `atomic64_t` to prevent overflow.
Reported-by: Askar Safin <safinaskar@gmail.com>
Closes: https://lore.kernel.org/linux-pm/20251105180506.137448-1-safinaskar@gmail.com/
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
kernel/power/swap.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index f9bf01f355189..37270fa5ea600 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -635,7 +635,7 @@ struct cmp_data {
};
/* Indicates the image size after compression */
-static atomic_t compressed_size = ATOMIC_INIT(0);
+static atomic64_t compressed_size = ATOMIC_INIT(0);
/*
* Compression function that runs in its own thread.
@@ -664,7 +664,7 @@ static int compress_threadfn(void *data)
d->ret = crypto_acomp_compress(d->cr);
d->cmp_len = d->cr->dlen;
- atomic_set(&compressed_size, atomic_read(&compressed_size) + d->cmp_len);
+ atomic64_add(d->cmp_len, &compressed_size);
atomic_set_release(&d->stop, 1);
wake_up(&d->done);
}
@@ -696,7 +696,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
hib_init_batch(&hb);
- atomic_set(&compressed_size, 0);
+ atomic64_set(&compressed_size, 0);
/*
* We'll limit the number of threads for compression to limit memory
@@ -879,8 +879,8 @@ static int save_compressed_image(struct swap_map_handle *handle,
ret = err2;
if (!ret) {
swsusp_show_speed(start, stop, nr_to_write, "Wrote");
- pr_info("Image size after compression: %d kbytes\n",
- (atomic_read(&compressed_size) / 1024));
+ pr_info("Image size after compression: %lld kbytes\n",
+ (atomic64_read(&compressed_size) / 1024));
pr_info("Image saving done\n");
} else
pr_err("Image saving failed: %d\n", ret);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] PM: hibernate: Fix style issues in save_compressed_image()
2025-11-06 4:51 [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Mario Limonciello (AMD)
2025-11-06 4:51 ` [PATCH 1/3] PM: hibernate: Emit an error when image writing fails Mario Limonciello (AMD)
2025-11-06 4:51 ` [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable Mario Limonciello (AMD)
@ 2025-11-06 4:51 ` Mario Limonciello (AMD)
2025-11-06 20:03 ` [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Askar Safin
3 siblings, 0 replies; 9+ messages in thread
From: Mario Limonciello (AMD) @ 2025-11-06 4:51 UTC (permalink / raw)
To: mario.limonciello, lenb, pavel, rafael; +Cc: Mario Limonciello (AMD), linux-pm
Fix the two issues caught by checkpatch:
Trailing statements should be on next line.
Prefer 'unsigned int' to bare use of 'unsigned'
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
---
kernel/power/swap.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 37270fa5ea600..488a74d2a56b8 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -689,7 +689,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
ktime_t start;
ktime_t stop;
size_t off;
- unsigned thr, run_threads, nr_threads;
+ unsigned int thr, run_threads, nr_threads;
unsigned char *page = NULL;
struct cmp_data *data = NULL;
struct crc_data *crc = NULL;
@@ -901,7 +901,8 @@ static int save_compressed_image(struct swap_map_handle *handle,
}
vfree(data);
}
- if (page) free_page((unsigned long)page);
+ if (page)
+ free_page((unsigned long)page);
return ret;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] PM: hibernate: Emit an error when image writing fails
2025-11-06 4:51 ` [PATCH 1/3] PM: hibernate: Emit an error when image writing fails Mario Limonciello (AMD)
@ 2025-11-06 19:54 ` Askar Safin
0 siblings, 0 replies; 9+ messages in thread
From: Askar Safin @ 2025-11-06 19:54 UTC (permalink / raw)
To: superm1; +Cc: lenb, linux-pm, mario.limonciello, pavel, rafael, safinaskar
"Mario Limonciello (AMD)" <superm1@kernel.org>:
> If image writing fails a return code is passed up to the caller but
> none of the callers log anything to the log and so the only record
> of it is the return code that userspace gets.
Thank you! This is bug fix, so, please, add to this particular commit:
> Cc: <stable@vger.kernel.org>
> Fixes: a06c6f5d3cc9 ("PM: hibernate: Move to crypto APIs for LZO compression")
a06c6f5d3cc9 introduced that pr_info("Image size after compression...")
--
Askar Safin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable
2025-11-06 4:51 ` [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable Mario Limonciello (AMD)
@ 2025-11-06 20:01 ` Askar Safin
2025-11-07 15:56 ` Rafael J. Wysocki
1 sibling, 0 replies; 9+ messages in thread
From: Askar Safin @ 2025-11-06 20:01 UTC (permalink / raw)
To: superm1; +Cc: lenb, linux-pm, mario.limonciello, pavel, rafael, safinaskar
"Mario Limonciello (AMD)" <superm1@kernel.org>:
> `compressed_size` can overflow, showing nonsensical values.
> Change from `atomic_t` to `atomic64_t` to prevent overflow.
This is bug fix, too. Please, add:
> Cc: <stable@vger.kernel.org>
> Fixes: a06c6f5d3cc9 ("PM: hibernate: Move to crypto APIs for LZO compression")
a06c6f5d3cc9 introduced variable "compressed_size".
(Yes, this commit responsible for both bugs.)
> - atomic_set(&compressed_size, atomic_read(&compressed_size) + d->cmp_len);
So, we read atomic variable, then add something to it, and then write?
This looks like textbook parallel programming error. Very strange.
Anyway, you fixed this, Mario! Thank you!
--
Askar Safin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin
2025-11-06 4:51 [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Mario Limonciello (AMD)
` (2 preceding siblings ...)
2025-11-06 4:51 ` [PATCH 3/3] PM: hibernate: Fix style issues in save_compressed_image() Mario Limonciello (AMD)
@ 2025-11-06 20:03 ` Askar Safin
2025-11-06 20:56 ` Mario Limonciello
3 siblings, 1 reply; 9+ messages in thread
From: Askar Safin @ 2025-11-06 20:03 UTC (permalink / raw)
To: superm1; +Cc: lenb, linux-pm, mario.limonciello, pavel, rafael, safinaskar
"Mario Limonciello (AMD)" <superm1@kernel.org>:
> Askar Safin reported some usability issues with hibernate messageing in
> some failure cases. This series fixes those issues as well as some style
> issues I noticed while touching the function.
I tested in Qemu. Now everything works. Thank you!
Tested-By: <safinaskar@gmail.com>
--
Askar Safin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin
2025-11-06 20:03 ` [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Askar Safin
@ 2025-11-06 20:56 ` Mario Limonciello
0 siblings, 0 replies; 9+ messages in thread
From: Mario Limonciello @ 2025-11-06 20:56 UTC (permalink / raw)
To: Askar Safin; +Cc: lenb, linux-pm, mario.limonciello, pavel, rafael
On 11/6/25 2:03 PM, Askar Safin wrote:
> "Mario Limonciello (AMD)" <superm1@kernel.org>:
>> Askar Safin reported some usability issues with hibernate messageing in
>> some failure cases. This series fixes those issues as well as some style
>> issues I noticed while touching the function.
>
> I tested in Qemu. Now everything works. Thank you!
>
> Tested-By: <safinaskar@gmail.com>
>
Thanks! I'll let Rafael pick up the extra tags you had for the patches
if he agrees with them.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable
2025-11-06 4:51 ` [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable Mario Limonciello (AMD)
2025-11-06 20:01 ` Askar Safin
@ 2025-11-07 15:56 ` Rafael J. Wysocki
1 sibling, 0 replies; 9+ messages in thread
From: Rafael J. Wysocki @ 2025-11-07 15:56 UTC (permalink / raw)
To: Mario Limonciello (AMD)
Cc: mario.limonciello, lenb, pavel, rafael, Askar Safin, linux-pm
On Thu, Nov 6, 2025 at 5:52 AM Mario Limonciello (AMD)
<superm1@kernel.org> wrote:
>
> `compressed_size` can overflow, showing nonsensical values.
> Change from `atomic_t` to `atomic64_t` to prevent overflow.
>
> Reported-by: Askar Safin <safinaskar@gmail.com>
> Closes: https://lore.kernel.org/linux-pm/20251105180506.137448-1-safinaskar@gmail.com/
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> kernel/power/swap.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index f9bf01f355189..37270fa5ea600 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -635,7 +635,7 @@ struct cmp_data {
> };
>
> /* Indicates the image size after compression */
> -static atomic_t compressed_size = ATOMIC_INIT(0);
> +static atomic64_t compressed_size = ATOMIC_INIT(0);
>
> /*
> * Compression function that runs in its own thread.
> @@ -664,7 +664,7 @@ static int compress_threadfn(void *data)
> d->ret = crypto_acomp_compress(d->cr);
> d->cmp_len = d->cr->dlen;
>
> - atomic_set(&compressed_size, atomic_read(&compressed_size) + d->cmp_len);
Hmm, how did I miss this?
> + atomic64_add(d->cmp_len, &compressed_size);
> atomic_set_release(&d->stop, 1);
> wake_up(&d->done);
> }
> @@ -696,7 +696,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
>
> hib_init_batch(&hb);
>
> - atomic_set(&compressed_size, 0);
> + atomic64_set(&compressed_size, 0);
>
> /*
> * We'll limit the number of threads for compression to limit memory
> @@ -879,8 +879,8 @@ static int save_compressed_image(struct swap_map_handle *handle,
> ret = err2;
> if (!ret) {
> swsusp_show_speed(start, stop, nr_to_write, "Wrote");
> - pr_info("Image size after compression: %d kbytes\n",
> - (atomic_read(&compressed_size) / 1024));
> + pr_info("Image size after compression: %lld kbytes\n",
> + (atomic64_read(&compressed_size) / 1024));
> pr_info("Image saving done\n");
> } else
> pr_err("Image saving failed: %d\n", ret);
> --
Applied as 6.18-rc material along with the other patches in the
series, with some changelog adjustments, added tags etc.
Thanks!
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-11-07 15:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-06 4:51 [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Mario Limonciello (AMD)
2025-11-06 4:51 ` [PATCH 1/3] PM: hibernate: Emit an error when image writing fails Mario Limonciello (AMD)
2025-11-06 19:54 ` Askar Safin
2025-11-06 4:51 ` [PATCH 2/3] PM: hibernate: Use atomic64_t for compressed_size variable Mario Limonciello (AMD)
2025-11-06 20:01 ` Askar Safin
2025-11-07 15:56 ` Rafael J. Wysocki
2025-11-06 4:51 ` [PATCH 3/3] PM: hibernate: Fix style issues in save_compressed_image() Mario Limonciello (AMD)
2025-11-06 20:03 ` [PATCH 0/3] Fixups for hibernate issues reported by Askar Safin Askar Safin
2025-11-06 20:56 ` Mario Limonciello
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).