diff mbox series

[v2,2/2] PM: hibernate: Fix the exclusive get block device in test_resume mode

Message ID e2279c339fcf919cffa4802b4e32974dc8950513.1693972725.git.yu.c.chen@intel.com (mailing list archive)
State Mainlined, archived
Headers show
Series Fix the hibernation test_resume's swapfile open mode | expand

Commit Message

Chen Yu Sept. 6, 2023, 4:18 a.m. UTC
commit 5904de0d735b ("PM: hibernate: Do not get block device exclusively
in test_resume mode") fixes a hibernation issue under test_resume mode.
That commit is supposed to open the block device in non-exclusive mode
when in test_resume. However the code did the opposite, which is against
its description.

In summary, the swap device is only opened exclusively by swsusp_check()
with its corresponding *close(), and must be in non test_resume mode.
This is to avoid the race condition that different processes scribble the
device at the same time. All the other cases should use non-exclusive mode.

Fix it by really disabling exclusive mode under test_resume.

Fixes: 5904de0d735b ("PM: hibernate: Do not get block device exclusively in test_resume mode")
Reported-by: syzbot+38d04642cea49f3a3d2e@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/lkml/000000000000761f5f0603324129@google.com/
Reported-by: Pengfei Xu <pengfei.xu@intel.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
---
 kernel/power/hibernate.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Feng, ChenzhouX Sept. 6, 2023, 5:27 a.m. UTC | #1
> -----邮件原件-----
> 发件人: Chen, Yu C <yu.c.chen@intel.com>
> 发送时间: Wednesday, September 6, 2023 12:19
> 收件人: Rafael J. Wysocki <rafael@kernel.org>; Brown, Len
> <len.brown@intel.com>; Pavel Machek <pavel@ucw.cz>
> 抄送: linux-pm@vger.kernel.org; linux-kernel@vger.kernel.org; Feng, ChenzhouX
> <chenzhoux.feng@intel.com>; Xu, Pengfei <pengfei.xu@intel.com>; Chen, Yu C
> <yu.c.chen@intel.com>;
> syzbot+38d04642cea49f3a3d2e@syzkaller.appspotmail.com
> 主题: [PATCH v2 2/2] PM: hibernate: Fix the exclusive get block device in
> test_resume mode
> 
> commit 5904de0d735b ("PM: hibernate: Do not get block device exclusively in
> test_resume mode") fixes a hibernation issue under test_resume mode.
> That commit is supposed to open the block device in non-exclusive mode when in
> test_resume. However the code did the opposite, which is against its description.
> 
> In summary, the swap device is only opened exclusively by swsusp_check() with
> its corresponding *close(), and must be in non test_resume mode.
> This is to avoid the race condition that different processes scribble the device at
> the same time. All the other cases should use non-exclusive mode.
> 
> Fix it by really disabling exclusive mode under test_resume.
> 
> Fixes: 5904de0d735b ("PM: hibernate: Do not get block device exclusively in
> test_resume mode")
> Reported-by: syzbot+38d04642cea49f3a3d2e@syzkaller.appspotmail.com
> Closes:
> https://lore.kernel.org/lkml/000000000000761f5f0603324129@google.com/
> Reported-by: Pengfei Xu <pengfei.xu@intel.com>
> Signed-off-by: Chen Yu <yu.c.chen@intel.com>

It works on my machine, for the whole series,
Tested-by: Chenzhou Feng <chenzhoux.feng@intel.com>

thanks,
Chenzhou
diff mbox series

Patch

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 2b4a946a6ff5..8d35b9f9aaa3 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -786,9 +786,9 @@  int hibernate(void)
 	unlock_device_hotplug();
 	if (snapshot_test) {
 		pm_pr_dbg("Checking hibernation image\n");
-		error = swsusp_check(snapshot_test);
+		error = swsusp_check(false);
 		if (!error)
-			error = load_image_and_restore(snapshot_test);
+			error = load_image_and_restore(false);
 	}
 	thaw_processes();
 
@@ -945,14 +945,14 @@  static int software_resume(void)
 	pm_pr_dbg("Looking for hibernation image.\n");
 
 	mutex_lock(&system_transition_mutex);
-	error = swsusp_check(false);
+	error = swsusp_check(true);
 	if (error)
 		goto Unlock;
 
 	/* The snapshot device should not be opened while we're running */
 	if (!hibernate_acquire()) {
 		error = -EBUSY;
-		swsusp_close(false);
+		swsusp_close(true);
 		goto Unlock;
 	}
 
@@ -973,7 +973,7 @@  static int software_resume(void)
 		goto Close_Finish;
 	}
 
-	error = load_image_and_restore(false);
+	error = load_image_and_restore(true);
 	thaw_processes();
  Finish:
 	pm_notifier_call_chain(PM_POST_RESTORE);
@@ -987,7 +987,7 @@  static int software_resume(void)
 	pm_pr_dbg("Hibernation image not present or could not be loaded.\n");
 	return error;
  Close_Finish:
-	swsusp_close(false);
+	swsusp_close(true);
 	goto Finish;
 }