FAILED: patch "[PATCH] PM: sleep: Allow pm_restrict_gfp_mask() stacking" failed to apply to 6.17-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.17-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.17.y
git checkout FETCH_HEAD
git cherry-pick -x 35e4a69b2003f20a69e7d19ae96ab1eef1aa8e8d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2025110200-aflame-kisser-6334@gregkh' --subject-prefix 'PATCH 6.17.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 35e4a69b2003f20a69e7d19ae96ab1eef1aa8e8d Mon Sep 17 00:00:00 2001
From: "Rafael J. Wysocki" <[email protected]>
Date: Tue, 28 Oct 2025 21:52:31 +0100
Subject: [PATCH] PM: sleep: Allow pm_restrict_gfp_mask() stacking
Allow pm_restrict_gfp_mask() to be called many times in a row to avoid issues with calling dpm_suspend_start() when the GFP mask has been already restricted.
Only the first invocation of pm_restrict_gfp_mask() will actually restrict the GFP mask and the subsequent calls will warn if there is a mismatch between the expected allowed GFP mask and the actual one.
Moreover, if pm_restrict_gfp_mask() is called many times in a row, pm_restore_gfp_mask() needs to be called matching number of times in a row to actually restore the GFP mask. Calling it when the GFP mask has not been restricted will cause it to warn.
This is necessary for the GFP mask restriction starting in hibernation_snapshot() to continue throughout the entire hibernation flow until it completes or it is aborted (either by a wakeup event or by an error).
kernel/power/hibernate.c +0 -4
@@ -706,7 +706,6 @@ static void power_down(void)#ifdef CONFIG_SUSPEND if (hibernation_mode ==HIBERNATION_SUSPEND ) { -pm_restore_gfp_mask (); error =suspend_devices_and_enter (mem_sleep_current);if (!error) goto exit;
@@ -746,9 +745,6 @@ static void power_down(void)cpu_relax (); exit: -/* Match the pm_restore_gfp_mask() call in hibernate(). */ -pm_restrict_gfp_mask (); -/* Restore swap signature. */ error =swsusp_unmark ();if (error)
kernel/power/main.c +17 -5
@@ -31,23 +31,35 @@* held, unless the suspend/hibernate code is guaranteed not to run in parallel * with that modification). */ +static unsigned int saved_gfp_count;static gfp_t saved_gfp_mask;void pm_restore_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&system_transition_mutex)); -if (saved_gfp_mask) { - gfp_allowed_mask = saved_gfp_mask; - saved_gfp_mask =0 ; - } + +if (WARN_ON (!saved_gfp_count) || --saved_gfp_count) +return ; + + gfp_allowed_mask = saved_gfp_mask; + saved_gfp_mask =0 ; + +pm_pr_dbg ("GFP mask restored\n" ); }void pm_restrict_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&system_transition_mutex)); -WARN_ON (saved_gfp_mask); + +if (saved_gfp_count++) { +WARN_ON ((saved_gfp_mask & ~(__GFP_IO | __GFP_FS)) != gfp_allowed_mask); +return ; + } + saved_gfp_mask = gfp_allowed_mask; gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS); + +pm_pr_dbg ("GFP mask restricted\n" ); }unsigned int lock_system_sleep (void )
Sasha Levin
maintainerPATCH 1/2 PM: hibernate: Combine return paths in power_down()
From: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 1f5bcfe91ffce71bdd1022648b9d501d46d20c09 ]
To avoid code duplication and improve clarity, combine the code paths in power_down() leading to a return from that function.
No intentional functional impact.
Stable-dep-of: 35e4a69b2003 ("PM: sleep: Allow pm_restrict_gfp_mask() stacking")
--- kernel/power/hibernate.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
kernel/power/hibernate.c +14 -18
@@ -708,21 +708,11 @@ static void power_down(void)if (hibernation_mode ==HIBERNATION_SUSPEND ) {pm_restore_gfp_mask (); error =suspend_devices_and_enter (mem_sleep_current); -if (error) { - hibernation_mode = hibernation_ops ? -HIBERNATION_PLATFORM : -HIBERNATION_SHUTDOWN ; - }else { -/* Match pm_restore_gfp_mask() call in hibernate() */ -pm_restrict_gfp_mask (); - -/* Restore swap signature. */ - error =swsusp_unmark (); -if (error) -pr_err ("Swap will be unusable! Try swapon -a.\n" ); +if (!error) + goto exit; -return ; - } + hibernation_mode = hibernation_ops ?HIBERNATION_PLATFORM : +HIBERNATION_SHUTDOWN ; }#endif
@@ -733,12 +723,9 @@ static void power_down(void)case HIBERNATION_PLATFORM : error =hibernation_platform_enter ();if (error == -EAGAIN || error == -EBUSY ) { -/* Match pm_restore_gfp_mask() in hibernate(). */ -pm_restrict_gfp_mask (); -swsusp_unmark (); events_check_enabled = false;pr_info ("Wakeup event detected during hibernation, rolling back.\n" ); -return ; + goto exit; } fallthrough;case HIBERNATION_SHUTDOWN :
@@ -757,6 +744,15 @@ static void power_down(void)pr_crit ("Power down manually\n" );while (1 )cpu_relax (); + +exit: +/* Match the pm_restore_gfp_mask() call in hibernate(). */ +pm_restrict_gfp_mask (); + +/* Restore swap signature. */ + error =swsusp_unmark (); +if (error) +pr_err ("Swap will be unusable! Try swapon -a.\n" ); }static int load_image_and_restore (void )
Signature · 1 line
2.51.0
Sasha Levin
maintainerPATCH 2/2 PM: sleep: Allow pm_restrict_gfp_mask() stacking
From: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 35e4a69b2003f20a69e7d19ae96ab1eef1aa8e8d ]
Allow pm_restrict_gfp_mask() to be called many times in a row to avoid issues with calling dpm_suspend_start() when the GFP mask has been already restricted.
Only the first invocation of pm_restrict_gfp_mask() will actually restrict the GFP mask and the subsequent calls will warn if there is a mismatch between the expected allowed GFP mask and the actual one.
Moreover, if pm_restrict_gfp_mask() is called many times in a row, pm_restore_gfp_mask() needs to be called matching number of times in a row to actually restore the GFP mask. Calling it when the GFP mask has not been restricted will cause it to warn.
This is necessary for the GFP mask restriction starting in hibernation_snapshot() to continue throughout the entire hibernation flow until it completes or it is aborted (either by a wakeup event or by an error).
--- kernel/power/hibernate.c | 4 ---- kernel/power/main.c | 22 +++++++++++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-)
kernel/power/hibernate.c +0 -4
@@ -706,7 +706,6 @@ static void power_down(void)#ifdef CONFIG_SUSPEND if (hibernation_mode ==HIBERNATION_SUSPEND ) { -pm_restore_gfp_mask (); error =suspend_devices_and_enter (mem_sleep_current);if (!error) goto exit;
@@ -746,9 +745,6 @@ static void power_down(void)cpu_relax (); exit: -/* Match the pm_restore_gfp_mask() call in hibernate(). */ -pm_restrict_gfp_mask (); -/* Restore swap signature. */ error =swsusp_unmark ();if (error)
kernel/power/main.c +17 -5
@@ -31,23 +31,35 @@* held, unless the suspend/hibernate code is guaranteed not to run in parallel * with that modification). */ +static unsigned int saved_gfp_count;static gfp_t saved_gfp_mask;void pm_restore_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&system_transition_mutex)); -if (saved_gfp_mask) { - gfp_allowed_mask = saved_gfp_mask; - saved_gfp_mask =0 ; - } + +if (WARN_ON (!saved_gfp_count) || --saved_gfp_count) +return ; + + gfp_allowed_mask = saved_gfp_mask; + saved_gfp_mask =0 ; + +pm_pr_dbg ("GFP mask restored\n" ); }void pm_restrict_gfp_mask (void ) {WARN_ON (!mutex_is_locked (&system_transition_mutex)); -WARN_ON (saved_gfp_mask); + +if (saved_gfp_count++) { +WARN_ON ((saved_gfp_mask & ~(__GFP_IO | __GFP_FS)) != gfp_allowed_mask); +return ; + } + saved_gfp_mask = gfp_allowed_mask; gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS); + +pm_pr_dbg ("GFP mask restricted\n" ); }unsigned int lock_system_sleep (void )
Signature · 1 line
2.51.0