From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3F37C04EB5 for ; Sat, 8 Feb 2020 04:44:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 794DE2082E for ; Sat, 8 Feb 2020 04:44:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="o5vAFhB4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 794DE2082E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C39006B0003; Fri, 7 Feb 2020 23:44:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BE92D6B0005; Fri, 7 Feb 2020 23:44:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B000E6B0007; Fri, 7 Feb 2020 23:44:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0152.hostedemail.com [216.40.44.152]) by kanga.kvack.org (Postfix) with ESMTP id 988256B0003 for ; Fri, 7 Feb 2020 23:44:39 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 313D5181AC9CC for ; Sat, 8 Feb 2020 04:44:39 +0000 (UTC) X-FDA: 76465719078.22.legs63_b5abea72a54c X-HE-Tag: legs63_b5abea72a54c X-Filterd-Recvd-Size: 5198 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Sat, 8 Feb 2020 04:44:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=aanmgn983/R76BnvnWKSBXA3+MkJf1l9WbmNyzL+I7E=; b=o5vAFhB4KFVif47DLSBS3y3oIT XrsrgQ9VASioQX2rjaDXq+g+wiR/NU49ZzQ0lHdQHSOIcxa+5FOuK+yMKuzEF/AKY2ruSjNZL37vb QvWjTdqqjnl67uF2yIFsYQ0oJJGCBqHlP5ERDT84lIY3L/IbaHi7jwp8VsVGypa0g9TO2F0J54YUc 7Y2Kca4cezdmYtAWhs67n1zfMSawmbRoVBSDOhS1S2eXIn6ZqGeI1zhxMzmoPJFLVWsxP15WZyWZQ jy7Xtxu/fZB8HD+hoGWY1er8Ld5cg06fWo6+O4mkqiuFrzwF7ay+iVz1NrBMp496nkKTF/UXrlJI/ UgpbE6HA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j0Hyq-0007ot-IT; Sat, 08 Feb 2020 04:44:32 +0000 From: Matthew Wilcox To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , "Kirill A . Shutemov" , John Hubbard Subject: [PATCH] mm: Improve dump_page() for compound pages Date: Fri, 7 Feb 2020 20:44:15 -0800 Message-Id: <20200208044415.30012-1-willy@infradead.org> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: "Matthew Wilcox (Oracle)" 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 Co-developed-by: John Hubbard Signed-off-by: Matthew Wilcox (Oracle) --- mm/debug.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/mm/debug.c b/mm/debug.c index ecccd9f17801..3594951cc408 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -44,8 +44,10 @@ const struct trace_print_flags vmaflag_names[] =3D { =20 void __dump_page(struct page *page, const char *reason) { + struct page *head =3D compound_head(page); struct address_space *mapping; bool page_poisoned =3D PagePoisoned(page); + bool compound =3D PageCompound(page); /* * Accessing the pageblock without the zone lock. It could change to * "isolate" again in the meantime, but since we are just dumping the @@ -66,25 +68,32 @@ void __dump_page(struct page *page, const char *reaso= n) goto hex_only; } =20 - mapping =3D page_mapping(page); + if (page < head || (page >=3D head + MAX_ORDER_NR_PAGES)) { + /* Corrupt page, cannot call page_mapping */ + mapping =3D page->mapping; + head =3D page; + compound =3D false; + } else { + mapping =3D page_mapping(page); + } =20 /* * Avoid VM_BUG_ON() in page_mapcount(). * page->_mapcount space in struct page is used by sl[aou]b pages to * encode own info. */ - mapcount =3D PageSlab(page) ? 0 : page_mapcount(page); + mapcount =3D PageSlab(head) ? 0 : page_mapcount(head); =20 - if (PageCompound(page)) - pr_warn("page:%px refcount:%d mapcount:%d mapping:%px " - "index:%#lx compound_mapcount: %d\n", - page, page_ref_count(page), mapcount, - page->mapping, page_to_pgoff(page), - compound_mapcount(page)); + if (compound) + pr_warn("page:%px refcount:%d mapcount:%d mapping:%p " + "index:%#lx head:%px order:%u compound_mapcount:%d\n", + page, page_ref_count(head), mapcount, + mapping, page_to_pgoff(page), head, + compound_order(head), compound_mapcount(page)); else - pr_warn("page:%px refcount:%d mapcount:%d mapping:%px index:%#lx\n", + pr_warn("page:%px refcount:%d mapcount:%d mapping:%p index:%#lx\n", page, page_ref_count(page), mapcount, - page->mapping, page_to_pgoff(page)); + mapping, page_to_pgoff(page)); if (PageKsm(page)) type =3D "ksm "; else if (PageAnon(page)) @@ -106,6 +115,10 @@ void __dump_page(struct page *page, const char *reas= on) print_hex_dump(KERN_WARNING, "raw: ", DUMP_PREFIX_NONE, 32, sizeof(unsigned long), page, sizeof(struct page), false); + if (head !=3D page) + print_hex_dump(KERN_WARNING, "head: ", DUMP_PREFIX_NONE, 32, + sizeof(unsigned long), head, + sizeof(struct page), false); =20 if (reason) pr_warn("page dumped because: %s\n", reason); --=20 2.24.1