Received: by 10.213.65.68 with SMTP id h4csp3831217imn; Tue, 3 Apr 2018 11:20:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx49GII9fOfr+66xLRY9KgdK9yszP3oP4hqWjvHx1Vd5ESckGfJn93mjlE0OErnIP7+hx7d3v X-Received: by 2002:a17:902:68c2:: with SMTP id x2-v6mr15207881plm.129.1522779658354; Tue, 03 Apr 2018 11:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522779658; cv=none; d=google.com; s=arc-20160816; b=IAH9kUkrnXIlTwI6/olTK2w1JTfcIaPms/Pmv4gETtK8/JspKJTyenultv+diWTd5E JLTfx40jpQnIXY5/aCEyQ6FXUR6SCdwqauP0g4os/28bC2kZM4nXHPQpp7rLunkPKhXi x+RyRtyskQ+8oeGBLSRNEF6YSSxET54lSQkOXj/z01I5pcuc/EF/jGB06L3DxmEg3Jxl kHxim5k+YnFqdyWJ00WmmqusxW9zVyhd36PquPAHfjrhzaRlM8IFLk8zTvxjFX8htBrW sOvJPPPiwL9CkNSf65GhX+TN/I265vAvKJIj22OkR1Dg3T+jR6HAViq/2kENGVtr4t3y Bavw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=JP7qA5JcT+wqOb7RVpOFDVlx2i5XyWG+Cw4itYScSU8=; b=a8wBOJSPZXSPTGr/7bBfgFiFovj6iQadtv7Z0QA8Lu0F1DGCkWquhfd+KcH30Ewibh +UjLr5R4qfMT5cN5+E/iz2EZOY5O7z7jlNDnUdQosbm6/3wyCvMS6ZmVeNuGBAFc96cm nfgKXTavN/UfdtoI9MqpurZgxT5OVmTZIvc3OeHe/Iv+IxEkSVOXl7yZX9MKefYfWExj 3mqVeppo44r81ZH+9/jdz6pu0ol+LPbgwD3hXITYruuTgaTxKf3YX96Ptupg2jBJdQaN i9mnvzc/JYNBvX25d6LaB8MXZj89458mbXbQRG1QP2etZruz+FsXzXyPfp/5Rn6Dulpu ZaUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=BvGNom9e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si2388802pgc.381.2018.04.03.11.20.44; Tue, 03 Apr 2018 11:20:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=BvGNom9e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753261AbeDCSRz (ORCPT + 99 others); Tue, 3 Apr 2018 14:17:55 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:47870 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753162AbeDCSRX (ORCPT ); Tue, 3 Apr 2018 14:17:23 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w33IGvhb171330; Tue, 3 Apr 2018 18:16:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=JP7qA5JcT+wqOb7RVpOFDVlx2i5XyWG+Cw4itYScSU8=; b=BvGNom9eLuA7FYPA22U+/5mrvZEmTinMNajzOFaiiFnB2BO2GY554UKzB5sghzmMrpcY lq80ExzyTOPI6fnnYlGQUcxyLBic3kOZVTxrtnqG4QFnEOFAMJG7cribtCiIN6RvexnR voASODI1cWPIbswME03djzRhyHcvlo0isfScv9QrLbWgXixBqX5apiY4T1IXZDJi5ogj Ddlj/hRlq9GHnOvUhZUO+wiYWm7MebNTzdkxi771qa6DgUZ6ixqkH1IvpjapsWQ7MuBq B4/dai45xInz5gUOz4OJMCPmbK9RFCFbe6KZQd9PkRE1ztk/IpQwqdKAYVAahWiaOZIg nw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2h4erm000u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Apr 2018 18:16:56 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w33IGtUc021242 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Apr 2018 18:16:56 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w33IGrYc001418; Tue, 3 Apr 2018 18:16:54 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 11:16:53 -0700 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, akpm@linux-foundation.org, mgorman@techsingularity.net, mhocko@suse.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, vbabka@suse.cz, bharata@linux.vnet.ibm.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, dan.j.williams@intel.com, kirill.shutemov@linux.intel.com, bhe@redhat.com, alexander.levin@microsoft.com Subject: [v6 3/6] mm: add uninitialized struct page poisoning sanity checking Date: Tue, 3 Apr 2018 14:16:40 -0400 Message-Id: <20180403181643.28127-4-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180403181643.28127-1-pasha.tatashin@oracle.com> References: <20180403181643.28127-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8852 signatures=668697 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804030185 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During boot we poison struct page memory in order to ensure that no one is accessing this memory until the struct pages are initialized in __init_single_page(). This patch adds more scrutiny to this checking by making sure that flags do not equal the poison pattern when they are accessed. The pattern is all ones. Since node id is also stored in struct page, and may be accessed quite early, we add this enforcement into page_to_nid() function as well. Note, this is applicable only when NODE_NOT_IN_PAGE_FLAGS=n Signed-off-by: Pavel Tatashin Reviewed-by: Ingo Molnar Acked-by: Michal Hocko --- include/linux/mm.h | 4 +++- include/linux/page-flags.h | 22 +++++++++++++++++----- mm/debug.c | 14 +++++++++++--- mm/memblock.c | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index ccac10682ce5..7261b4745e4c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -894,7 +894,9 @@ extern int page_to_nid(const struct page *page); #else static inline int page_to_nid(const struct page *page) { - return (page->flags >> NODES_PGSHIFT) & NODES_MASK; + struct page *p = (struct page *)page; + + return (PF_POISONED_CHECK(p)->flags >> NODES_PGSHIFT) & NODES_MASK; } #endif diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 50c2b8786831..e34a27727b9a 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -156,9 +156,18 @@ static __always_inline int PageCompound(struct page *page) return test_bit(PG_head, &page->flags) || PageTail(page); } +#define PAGE_POISON_PATTERN -1l +static inline int PagePoisoned(const struct page *page) +{ + return page->flags == PAGE_POISON_PATTERN; +} + /* * Page flags policies wrt compound pages * + * PF_POISONED_CHECK + * check if this struct page poisoned/uninitialized + * * PF_ANY: * the page flag is relevant for small, head and tail pages. * @@ -176,17 +185,20 @@ static __always_inline int PageCompound(struct page *page) * PF_NO_COMPOUND: * the page flag is not relevant for compound pages. */ -#define PF_ANY(page, enforce) page -#define PF_HEAD(page, enforce) compound_head(page) +#define PF_POISONED_CHECK(page) ({ \ + VM_BUG_ON_PGFLAGS(PagePoisoned(page), page); \ + page; }) +#define PF_ANY(page, enforce) PF_POISONED_CHECK(page) +#define PF_HEAD(page, enforce) PF_POISONED_CHECK(compound_head(page)) #define PF_ONLY_HEAD(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(PageTail(page), page); \ - page;}) + PF_POISONED_CHECK(page); }) #define PF_NO_TAIL(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(enforce && PageTail(page), page); \ - compound_head(page);}) + PF_POISONED_CHECK(compound_head(page)); }) #define PF_NO_COMPOUND(page, enforce) ({ \ VM_BUG_ON_PGFLAGS(enforce && PageCompound(page), page); \ - page;}) + PF_POISONED_CHECK(page); }) /* * Macros to create function definitions for page flags diff --git a/mm/debug.c b/mm/debug.c index 56e2d9125ea5..25d5f5560e63 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -43,12 +43,20 @@ const struct trace_print_flags vmaflag_names[] = { void __dump_page(struct page *page, const char *reason) { + bool page_poisoned = PagePoisoned(page); + int mapcount; + + if (page_poisoned) { + pr_emerg("page:%px is uninitialized and poisoned", page); + goto hex_only; + } + /* * Avoid VM_BUG_ON() in page_mapcount(). * page->_mapcount space in struct page is used by sl[aou]b pages to * encode own info. */ - int mapcount = PageSlab(page) ? 0 : page_mapcount(page); + mapcount = PageSlab(page) ? 0 : page_mapcount(page); pr_emerg("page:%px count:%d mapcount:%d mapping:%px index:%#lx", page, page_ref_count(page), mapcount, @@ -59,7 +67,7 @@ void __dump_page(struct page *page, const char *reason) BUILD_BUG_ON(ARRAY_SIZE(pageflag_names) != __NR_PAGEFLAGS + 1); pr_emerg("flags: %#lx(%pGp)\n", page->flags, &page->flags); - +hex_only: print_hex_dump(KERN_ALERT, "raw: ", DUMP_PREFIX_NONE, 32, sizeof(unsigned long), page, sizeof(struct page), false); @@ -68,7 +76,7 @@ void __dump_page(struct page *page, const char *reason) pr_alert("page dumped because: %s\n", reason); #ifdef CONFIG_MEMCG - if (page->mem_cgroup) + if (!page_poisoned && page->mem_cgroup) pr_alert("page->mem_cgroup:%px\n", page->mem_cgroup); #endif } diff --git a/mm/memblock.c b/mm/memblock.c index 48376bd33274..c720881b739c 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1345,7 +1345,7 @@ void * __init memblock_virt_alloc_try_nid_raw( min_addr, max_addr, nid); #ifdef CONFIG_DEBUG_VM if (ptr && size > 0) - memset(ptr, 0xff, size); + memset(ptr, PAGE_POISON_PATTERN, size); #endif return ptr; } -- 2.16.3