Received: by 10.223.176.5 with SMTP id f5csp1885834wra; Wed, 31 Jan 2018 13:06:45 -0800 (PST) X-Google-Smtp-Source: AH8x225FnrJfwWmqh74HvNSwiLdzNM1Mb2Ya2Ja8ugIJ8asu6d1SmqGG+1A/5+8reD8lAugA+Vo2 X-Received: by 10.99.42.9 with SMTP id q9mr17303440pgq.325.1517432805136; Wed, 31 Jan 2018 13:06:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517432805; cv=none; d=google.com; s=arc-20160816; b=zfwrwpYYnt1gkVkCfOtxPfCkAjxIviqkg1RbGofdQDMIqVZlQSsLi7xkAJCt2RL+SP MJD0CODGMjFhlJSkJTFi+kTK/AoTMyn3G23KGgdbFFBom/Zcx7oFhO7OqVSJkwp0wZYy /RiWdWqkdyhsrqLO1/LALNH1Mf+DMUgUAtlX4GH4H5sJUec2DA41uDE4O1XkHvtt1MXN 5Iy5j5dXGDwcZMcpbWj+l8xmnggOIse+t6JHvgkMY722VOAkDoG5us5vjVuIiX9ywXPV CLFtDU+1rCI1gcsfjE9T1TFPq109lG6LftwFGD0lzIfl7NaiH1lTL2Q++UnMqjk78W0G EvGA== 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=FgseKHRG/YzU9F2lkGqxwwgzBq2G7XDd9vplYsM+A5k=; b=rvQGcJiCDrNDt/zWR+KQsSMnZSlnlA8V9NbV9QuljxoND+SLatf4Sdim579qUbuM1q Hd7ZrIo1FrmmikiDkCQG4G23n3KwDoJJOGimsPi3O1Mm8SWVjfY8wTfmkAEXAsUrH1RB NNdnRGuHZz+UY731dxax+dgpQJIuKVuXnNhKxzeblyed2wzx2J77YTx8CyfhAg3Wk+V1 OeqXJ6tZjGVEPv7NmzYw7QX7nxlTK8gtG3aAE//yKB2RcBYJL2HbP/7l4IZHKYyW5eNq CPLEmaB+3Rzl9rhMo/RiygtiplPAcmKj1ptWeaKP1qRDNCuZAEw6TM/uaz3KWBKbee/f EtdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=jYbqVsWF; 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 d8si107076pfl.79.2018.01.31.13.06.30; Wed, 31 Jan 2018 13:06:45 -0800 (PST) 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=jYbqVsWF; 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 S1752951AbeAaVFk (ORCPT + 99 others); Wed, 31 Jan 2018 16:05:40 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:34650 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751985AbeAaVDh (ORCPT ); Wed, 31 Jan 2018 16:03:37 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w0VL22TP028905; Wed, 31 Jan 2018 21:03:23 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=FgseKHRG/YzU9F2lkGqxwwgzBq2G7XDd9vplYsM+A5k=; b=jYbqVsWFlrKiXh6X7R+Vr+y7UKVmCrZ2FaovpRxGceKms6iwsXKopjreE0p7p9F9biED ix4s778EK/sjkacUoN7SaRO1UXjpgkr2fA4h94SsSrk7qDcEvhGLRCwl7ZHLAcHcmIiW Ed2zfjop1FlaGtKn1440V9prTBJy3btKDrYtcH2EngXA25/OnCLRODDFc9Fwrzyqwqmt 9uT7EBOt4tHcv5EPH4RcME/vb/Ff1z6EE/EHkGb0gzUiB1fHtqgZy2kfaB0acjcwJsDh M3I+pdJmVWYBg+ZC3QWr8TdkdkhpeRK/L5WahMaU+/mN5SVije4/eU4YVKKyF/hsvBQV JA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2fuc8kk2qd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 31 Jan 2018 21:03:23 +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 w0VL3N79006619 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 31 Jan 2018 21:03:23 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w0VL3LAc012058; Wed, 31 Jan 2018 21:03:21 GMT Received: from localhost.localdomain (/98.216.35.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 31 Jan 2018 13:03:21 -0800 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 Subject: [PATCH v2 1/2] mm: uninitialized struct page poisoning sanity checking Date: Wed, 31 Jan 2018 16:02:59 -0500 Message-Id: <20180131210300.22963-2-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180131210300.22963-1-pasha.tatashin@oracle.com> References: <20180131210300.22963-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8791 signatures=668659 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-1801310262 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 to poison pattern when the are accessed. The pattern is all ones. Since, node id is also stored in struct page, and may be accessed quiet early we add the enforcement into page_to_nid() function as well. Signed-off-by: Pavel Tatashin --- include/linux/mm.h | 4 +++- include/linux/page-flags.h | 22 +++++++++++++++++----- mm/memblock.c | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 42b7154291e4..e0281de2cb13 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -896,7 +896,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 3ec44e27aa9d..743644b73359 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -161,9 +161,18 @@ static __always_inline int PageCompound(struct page *page) return test_bit(PG_head, &page->flags) || PageTail(page); } +#define PAGE_POISON_PATTERN ~0ul +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. * @@ -181,17 +190,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/memblock.c b/mm/memblock.c index 5a9ca2a1751b..d85c8754e0ce 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1373,7 +1373,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.1