linux-stable/kernel/power
Chen Yu f17d1bc393 PM: hibernate: Do not get block device exclusively in test_resume mode
[ Upstream commit 5904de0d73 ]

The system refused to do a test_resume because it found that the
swap device has already been taken by someone else. Specifically,
the swsusp_check()->blkdev_get_by_dev(FMODE_EXCL) is supposed to
do this check.

Steps to reproduce:
 dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo |
       awk '/MemTotal/ {print $2}') count=1024 conv=notrunc
 mkswap /swapfile
 swapon /swapfile
 swap-offset /swapfile
 echo 34816 > /sys/power/resume_offset
 echo test_resume > /sys/power/disk
 echo disk > /sys/power/state

 PM: Using 3 thread(s) for compression
 PM: Compressing and saving image data (293150 pages)...
 PM: Image saving progress:   0%
 PM: Image saving progress:  10%
 ata1: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
 ata1.00: configured for UDMA/100
 ata2: SATA link down (SStatus 0 SControl 300)
 ata5: SATA link down (SStatus 0 SControl 300)
 ata6: SATA link down (SStatus 0 SControl 300)
 ata3: SATA link down (SStatus 0 SControl 300)
 ata4: SATA link down (SStatus 0 SControl 300)
 PM: Image saving progress:  20%
 PM: Image saving progress:  30%
 PM: Image saving progress:  40%
 PM: Image saving progress:  50%
 pcieport 0000:00:02.5: pciehp: Slot(0-5): No device found
 PM: Image saving progress:  60%
 PM: Image saving progress:  70%
 PM: Image saving progress:  80%
 PM: Image saving progress:  90%
 PM: Image saving done
 PM: hibernation: Wrote 1172600 kbytes in 2.70 seconds (434.29 MB/s)
 PM: S|
 PM: hibernation: Basic memory bitmaps freed
 PM: Image not found (code -16)

This is because when using the swapfile as the hibernation storage,
the block device where the swapfile is located has already been mounted
by the OS distribution(usually mounted as the rootfs). This is not
an issue for normal hibernation, because software_resume()->swsusp_check()
happens before the block device(rootfs) mount. But it is a problem for the
test_resume mode. Because when test_resume happens, the block device has
been mounted already.

Thus remove the FMODE_EXCL for test_resume mode. This would not be a
problem because in test_resume stage, the processes have already been
frozen, and the race condition described in
Commit 39fbef4b0f ("PM: hibernate: Get block device exclusively in swsusp_check()")
is unlikely to happen.

Fixes: 39fbef4b0f ("PM: hibernate: Get block device exclusively in swsusp_check()")
Reported-by: Yifan Li <yifan2.li@intel.com>
Suggested-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Tested-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Tested-by: Wendy Wang <wendy.wang@intel.com>
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-05-11 23:17:36 +09:00
..
Kconfig PM: sleep: Remove "select SRCU" 2023-01-20 17:53:07 +01:00
Makefile PM: sleep: Narrow down -DDEBUG on kernel/power/ files 2022-04-13 16:34:01 +02:00
autosleep.c PM: sleep: fix typos in comments 2021-04-08 19:37:21 +02:00
console.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
energy_model.c PM: EM: fix memory leak with using debugfs_lookup() 2023-02-09 20:36:10 +01:00
hibernate.c PM: hibernate: Do not get block device exclusively in test_resume mode 2023-05-11 23:17:36 +09:00
main.c freezer,sched: Rewrite core freezer logic 2022-09-07 21:53:50 +02:00
power.h PM: hibernate: Turn snapshot_test into global variable 2023-05-11 23:17:36 +09:00
poweroff.c kernel/power: constify sysrq_key_op 2020-05-15 14:53:20 +02:00
process.c PM: sleep: Refine error message in try_to_freeze_tasks() 2022-12-06 12:04:34 +01:00
qos.c PM: QoS: Add check to make sure CPU freq is non-negative 2022-07-26 20:48:33 +02:00
snapshot.c PM: hibernate: Complain about memory map mismatches during resume 2022-12-01 19:20:14 +01:00
suspend.c Scheduler changes for v6.1: 2022-10-10 09:10:28 -07:00
suspend_test.c PM: suspend: fix return value of __setup handler 2022-03-01 18:55:07 +01:00
swap.c PM: hibernate: Do not get block device exclusively in test_resume mode 2023-05-11 23:17:36 +09:00
user.c freezer: Have {,un}lock_system_sleep() save/restore flags 2022-09-07 21:53:48 +02:00
wakelock.c PM: wakeup: simplify the output logic of pm_show_wakelocks() 2022-01-25 18:27:02 +01:00