Skip to content

Commit 8a235ef

Browse files
rjwysockilenb
authored andcommitted
Hibernation: Handle DEBUG_PAGEALLOC on x86
Make hibernation work with CONFIG_DEBUG_PAGEALLOC set on x86, by checking if the pages to be copied are marked as present in the kernel mapping and temporarily marking them as present if that's not the case. No functional modifications are introduced if CONFIG_DEBUG_PAGEALLOC is unset. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent e80af3a commit 8a235ef

3 files changed

Lines changed: 53 additions & 14 deletions

File tree

‎arch/x86/mm/pageattr.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,24 @@ void kernel_map_pages(struct page *page, int numpages, int enable)
899899
*/
900900
cpa_fill_pool();
901901
}
902-
#endif
902+
903+
#ifdef CONFIG_HIBERNATION
904+
905+
bool kernel_page_present(struct page *page)
906+
{
907+
unsigned int level;
908+
pte_t *pte;
909+
910+
if (PageHighMem(page))
911+
return false;
912+
913+
pte = lookup_address((unsigned long)page_address(page), &level);
914+
return (pte_val(*pte) & _PAGE_PRESENT);
915+
}
916+
917+
#endif /* CONFIG_HIBERNATION */
918+
919+
#endif /* CONFIG_DEBUG_PAGEALLOC */
903920

904921
/*
905922
* The testcases use internal knowledge of the implementation that shouldn't

‎include/linux/mm.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,12 +1171,18 @@ static inline void enable_debug_pagealloc(void)
11711171
{
11721172
debug_pagealloc_enabled = 1;
11731173
}
1174+
#ifdef CONFIG_HIBERNATION
1175+
extern bool kernel_page_present(struct page *page);
1176+
#endif /* CONFIG_HIBERNATION */
11741177
#else
11751178
static inline void
11761179
kernel_map_pages(struct page *page, int numpages, int enable) {}
11771180
static inline void enable_debug_pagealloc(void)
11781181
{
11791182
}
1183+
#ifdef CONFIG_HIBERNATION
1184+
static inline bool kernel_page_present(struct page *page) { return true; }
1185+
#endif /* CONFIG_HIBERNATION */
11801186
#endif
11811187

11821188
extern struct vm_area_struct *get_gate_vma(struct task_struct *tsk);

‎kernel/power/snapshot.c‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ static inline void *saveable_highmem_page(unsigned long pfn) { return NULL; }
875875
#endif /* CONFIG_HIGHMEM */
876876

877877
/**
878-
* saveable - Determine whether a non-highmem page should be included in
879-
* the suspend image.
878+
* saveable_page - Determine whether a non-highmem page should be included
879+
* in the suspend image.
880880
*
881881
* We should save the page if it isn't Nosave, and is not in the range
882882
* of pages statically defined as 'unsaveable', and it isn't a part of
@@ -897,7 +897,8 @@ static struct page *saveable_page(unsigned long pfn)
897897
if (swsusp_page_is_forbidden(page) || swsusp_page_is_free(page))
898898
return NULL;
899899

900-
if (PageReserved(page) && pfn_is_nosave(pfn))
900+
if (PageReserved(page)
901+
&& (!kernel_page_present(page) || pfn_is_nosave(pfn)))
901902
return NULL;
902903

903904
return page;
@@ -938,6 +939,25 @@ static inline void do_copy_page(long *dst, long *src)
938939
*dst++ = *src++;
939940
}
940941

942+
943+
/**
944+
* safe_copy_page - check if the page we are going to copy is marked as
945+
* present in the kernel page tables (this always is the case if
946+
* CONFIG_DEBUG_PAGEALLOC is not set and in that case
947+
* kernel_page_present() always returns 'true').
948+
*/
949+
static void safe_copy_page(void *dst, struct page *s_page)
950+
{
951+
if (kernel_page_present(s_page)) {
952+
do_copy_page(dst, page_address(s_page));
953+
} else {
954+
kernel_map_pages(s_page, 1, 1);
955+
do_copy_page(dst, page_address(s_page));
956+
kernel_map_pages(s_page, 1, 0);
957+
}
958+
}
959+
960+
941961
#ifdef CONFIG_HIGHMEM
942962
static inline struct page *
943963
page_is_saveable(struct zone *zone, unsigned long pfn)
@@ -946,8 +966,7 @@ page_is_saveable(struct zone *zone, unsigned long pfn)
946966
saveable_highmem_page(pfn) : saveable_page(pfn);
947967
}
948968

949-
static inline void
950-
copy_data_page(unsigned long dst_pfn, unsigned long src_pfn)
969+
static void copy_data_page(unsigned long dst_pfn, unsigned long src_pfn)
951970
{
952971
struct page *s_page, *d_page;
953972
void *src, *dst;
@@ -961,29 +980,26 @@ copy_data_page(unsigned long dst_pfn, unsigned long src_pfn)
961980
kunmap_atomic(src, KM_USER0);
962981
kunmap_atomic(dst, KM_USER1);
963982
} else {
964-
src = page_address(s_page);
965983
if (PageHighMem(d_page)) {
966984
/* Page pointed to by src may contain some kernel
967985
* data modified by kmap_atomic()
968986
*/
969-
do_copy_page(buffer, src);
987+
safe_copy_page(buffer, s_page);
970988
dst = kmap_atomic(pfn_to_page(dst_pfn), KM_USER0);
971989
memcpy(dst, buffer, PAGE_SIZE);
972990
kunmap_atomic(dst, KM_USER0);
973991
} else {
974-
dst = page_address(d_page);
975-
do_copy_page(dst, src);
992+
safe_copy_page(page_address(d_page), s_page);
976993
}
977994
}
978995
}
979996
#else
980997
#define page_is_saveable(zone, pfn) saveable_page(pfn)
981998

982-
static inline void
983-
copy_data_page(unsigned long dst_pfn, unsigned long src_pfn)
999+
static inline void copy_data_page(unsigned long dst_pfn, unsigned long src_pfn)
9841000
{
985-
do_copy_page(page_address(pfn_to_page(dst_pfn)),
986-
page_address(pfn_to_page(src_pfn)));
1001+
safe_copy_page(page_address(pfn_to_page(dst_pfn)),
1002+
pfn_to_page(src_pfn));
9871003
}
9881004
#endif /* CONFIG_HIGHMEM */
9891005

0 commit comments

Comments
 (0)