android_kernel_samsung_sm8650/kernel/power
Pavankumar Kondeti df6e6fc38f UPSTREAM: PM: hibernate: Fix copying the zero bitmap to safe pages
The following crash is observed 100% of the time during resume from
the hibernation on a x86 QEMU system.

[   12.931887]  ? __die_body+0x1a/0x60
[   12.932324]  ? page_fault_oops+0x156/0x420
[   12.932824]  ? search_exception_tables+0x37/0x50
[   12.933389]  ? fixup_exception+0x21/0x300
[   12.933889]  ? exc_page_fault+0x69/0x150
[   12.934371]  ? asm_exc_page_fault+0x26/0x30
[   12.934869]  ? get_buffer.constprop.0+0xac/0x100
[   12.935428]  snapshot_write_next+0x7c/0x9f0
[   12.935929]  ? submit_bio_noacct_nocheck+0x2c2/0x370
[   12.936530]  ? submit_bio_noacct+0x44/0x2c0
[   12.937035]  ? hib_submit_io+0xa5/0x110
[   12.937501]  load_image+0x83/0x1a0
[   12.937919]  swsusp_read+0x17f/0x1d0
[   12.938355]  ? create_basic_memory_bitmaps+0x1b7/0x240
[   12.938967]  load_image_and_restore+0x45/0xc0
[   12.939494]  software_resume+0x13c/0x180
[   12.939994]  resume_store+0xa3/0x1d0

The commit being fixed introduced a bug in copying the zero bitmap
to safe pages. A temporary bitmap is allocated with PG_ANY flag in
prepare_image() to make a copy of zero bitmap after the unsafe pages
are marked. Freeing this temporary bitmap with PG_UNSAFE_KEEP later
results in an inconsistent state of unsafe pages. Since free bit is
left as is for this temporary bitmap after free, these pages are
treated as unsafe pages when they are allocated again. This results
in incorrect calculation of the number of pages pre-allocated for the
image.

nr_pages = (nr_zero_pages + nr_copy_pages) - nr_highmem - allocated_unsafe_pages;

The allocate_unsafe_pages is estimated to be higher than the actual
which results in running short of pages in safe_pages_list. Hence the
crash is observed in get_buffer() due to NULL pointer access of
safe_pages_list.

Fix this issue by creating the temporary zero bitmap from safe pages
(free bit not set) so that the corresponding free bits can be cleared
while freeing this bitmap.

Bug: 311131385
(cherry picked from commit b21f18ef964b2c71aa0b451df6d17b7bcad8280d
 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master)
Fixes: 005e8dddd497 ("PM: hibernate: don't store zero pages in the image file")
Suggested-by:: Brian Geffon <bgeffon@google.com>
Signed-off-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Reviewed-by: Brian Geffon <bgeffon@google.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Change-Id: Id68699710e40c5e8eec227bfe0d8311c1e788d5e
Signed-off-by: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Signed-off-by: Mukesh Pilaniya <quic_mpilaniy@quicinc.com>
2023-11-27 17:04:26 +00: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-03-10 09:33:53 +01:00
hibernate.c PM: hibernate: Do not get block device exclusively in test_resume mode 2023-05-11 23:03:38 +09:00
Kconfig pm/sleep: Add PM_USERSPACE_AUTOSLEEP Kconfig 2022-07-01 10:39:20 +02:00
main.c freezer,sched: Rewrite core freezer logic 2022-09-07 21:53:50 +02:00
Makefile Merge 09583dfed2 ("Merge tag 'pm-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm") into android-mainline 2022-06-07 18:10:15 +02:00
power.h PM: hibernate: Turn snapshot_test into global variable 2023-05-11 23:03:38 +09:00
poweroff.c kernel/power: constify sysrq_key_op 2020-05-15 14:53:20 +02:00
process.c ANDROID: power: add vendor hooks for try_to_freeze fail 2023-03-13 20:34:25 +00:00
qos.c Merge 6.1.40 into android14-6.1-lts 2023-09-05 16:35:01 +00:00
snapshot.c UPSTREAM: PM: hibernate: Fix copying the zero bitmap to safe pages 2023-11-27 17:04:26 +00:00
suspend_test.c PM: suspend: fix return value of __setup handler 2022-03-01 18:55:07 +01:00
suspend.c ANDROID: power: Add vendor hook for suspend 2023-10-26 18:10:06 +00:00
swap.c Merge 6.1.28 into android14-6.1-lts 2023-06-09 20:20:52 +00: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
wakeup_reason.c ANDROID: power: Export log_{suspend_abort,abnormal_wakeup}_reason 2020-08-25 00:32:03 +00:00