Skip to content

Commit 6197ab9

Browse files
Matthew Wilcox (Oracle)torvalds
authored andcommitted
mm: improve dump_page() for compound pages
There was no protection against a corrupted struct page having an implausible compound_head(). Sanity check that a compound page has a head within reach of the maximum allocatable page (this will need to be adjusted if one of the plans to allocate 1GB pages comes to fruition). In addition, - Print the mapping pointer using %p insted of %px. The actual value of the pointer can be read out of the raw page dump and using %p gives a chance to correlate it with an earlier printk of the mapping pointer - Print the mapping pointer from the head page, not the tail page (the tail ->mapping pointer may be in use for other purposes, eg part of a list_head) - Print the order of the page for compound pages - Dump the raw head page as well as the raw page - Print the refcount from the head page, not the tail page Suggested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Co-developed-by: John Hubbard <jhubbard@nvidia.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: John Hubbard <jhubbard@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Ira Weiny <ira.weiny@intel.com> Cc: Jan Kara <jack@suse.cz> Cc: Jérôme Glisse <jglisse@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christoph Hellwig <hch@infradead.org> Cc: Dan Williams <dan.j.williams@intel.com> Cc: Dave Chinner <david@fromorbit.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Shuah Khan <shuah@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> Link: http://lkml.kernel.org/r/20200211001536.1027652-12-jhubbard@nvidia.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent be87141 commit 6197ab9

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

‎mm/debug.c‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ const struct trace_print_flags vmaflag_names[] = {
4444

4545
void __dump_page(struct page *page, const char *reason)
4646
{
47+
struct page *head = compound_head(page);
4748
struct address_space *mapping;
4849
bool page_poisoned = PagePoisoned(page);
50+
bool compound = PageCompound(page);
4951
/*
5052
* Accessing the pageblock without the zone lock. It could change to
5153
* "isolate" again in the meantime, but since we are just dumping the
@@ -66,25 +68,32 @@ void __dump_page(struct page *page, const char *reason)
6668
goto hex_only;
6769
}
6870

69-
mapping = page_mapping(page);
71+
if (page < head || (page >= head + MAX_ORDER_NR_PAGES)) {
72+
/* Corrupt page, cannot call page_mapping */
73+
mapping = page->mapping;
74+
head = page;
75+
compound = false;
76+
} else {
77+
mapping = page_mapping(page);
78+
}
7079

7180
/*
7281
* Avoid VM_BUG_ON() in page_mapcount().
7382
* page->_mapcount space in struct page is used by sl[aou]b pages to
7483
* encode own info.
7584
*/
76-
mapcount = PageSlab(page) ? 0 : page_mapcount(page);
85+
mapcount = PageSlab(head) ? 0 : page_mapcount(page);
7786

78-
if (PageCompound(page))
79-
pr_warn("page:%px refcount:%d mapcount:%d mapping:%px "
80-
"index:%#lx compound_mapcount: %d\n",
81-
page, page_ref_count(page), mapcount,
82-
page->mapping, page_to_pgoff(page),
83-
compound_mapcount(page));
87+
if (compound)
88+
pr_warn("page:%px refcount:%d mapcount:%d mapping:%p "
89+
"index:%#lx head:%px order:%u compound_mapcount:%d\n",
90+
page, page_ref_count(head), mapcount,
91+
mapping, page_to_pgoff(page), head,
92+
compound_order(head), compound_mapcount(page));
8493
else
85-
pr_warn("page:%px refcount:%d mapcount:%d mapping:%px index:%#lx\n",
94+
pr_warn("page:%px refcount:%d mapcount:%d mapping:%p index:%#lx\n",
8695
page, page_ref_count(page), mapcount,
87-
page->mapping, page_to_pgoff(page));
96+
mapping, page_to_pgoff(page));
8897
if (PageKsm(page))
8998
type = "ksm ";
9099
else if (PageAnon(page))
@@ -106,6 +115,10 @@ void __dump_page(struct page *page, const char *reason)
106115
print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32,
107116
sizeof(unsigned long), page,
108117
sizeof(struct page), false);
118+
if (head != page)
119+
print_hex_dump(KERN_WARNING, "head: ", DUMP_PREFIX_NONE, 32,
120+
sizeof(unsigned long), head,
121+
sizeof(struct page), false);
109122

110123
if (reason)
111124
pr_warn("page dumped because: %s\n", reason);

0 commit comments

Comments
 (0)