From patchwork Tue Aug 15 09:33:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 9901469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A217C60230 for ; Tue, 15 Aug 2017 09:33:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 910612880B for ; Tue, 15 Aug 2017 09:33:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8593028816; Tue, 15 Aug 2017 09:33:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 13FF22880B for ; Tue, 15 Aug 2017 09:33:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Pd6VCfKdz4WvvWgUCW446X3YA8/qDUBqlhgIETdGLLE=; b=KQojo7EkvwA9p9 sJ8Wqzv9pF2Dy1f2PdO1JIBy0YzP2AZvv4fK6zb5T2aYsTMk0gljBXItIizI0doWQ0pWgGAVNoNbN 7ohWuJRJbliDK6+7pNaOEnIo8Gn/pa8lat+BP3kRLVM05o0MwCstKE14DzFid2lnL0kK6ruZOn2Tw EvXXCDJM5wg4Jq78KikQpnrNX5V3OH+kkyHCir+LJ57BRYMa/XLhAwLUJY/dQt5+b4aNQfvEvLgN+ jHZwPNqgpkgN+HKTeZUOFp5uohXeLdDHm0y8UphslUV5kSWDNWV5gPfNGXWWAmQBvAl/9Ay16R6mv syVLCSwwtWuxHubXi6/Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dhYEC-0004s0-KC; Tue, 15 Aug 2017 09:33:36 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dhYE7-0004mF-T0 for linux-arm-kernel@lists.infradead.org; Tue, 15 Aug 2017 09:33:34 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E9BBDAE95; Tue, 15 Aug 2017 09:33:09 +0000 (UTC) Date: Tue, 15 Aug 2017 11:33:07 +0200 From: Michal Hocko To: Pavel Tatashin Subject: Re: [v6 05/15] mm: don't accessed uninitialized struct pages Message-ID: <20170815093306.GC29067@dhcp22.suse.cz> References: <1502138329-123460-1-git-send-email-pasha.tatashin@oracle.com> <1502138329-123460-6-git-send-email-pasha.tatashin@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1502138329-123460-6-git-send-email-pasha.tatashin@oracle.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170815_023332_232441_956C30F5 X-CRM114-Status: GOOD ( 15.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-s390@vger.kernel.org, ard.biesheuvel@linaro.org, sam@ravnborg.org, borntraeger@de.ibm.com, will.deacon@arm.com, x86@kernel.org, heiko.carstens@de.ibm.com, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, willy@infradead.org, catalin.marinas@arm.com, sparclinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, davem@davemloft.net, linux-arm-kernel@lists.infradead.org, Mel Gorman Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP [CC Mel - the original patch was http://lkml.kernel.org/r/1502138329-123460-6-git-send-email-pasha.tatashin@oracle.com] On Mon 07-08-17 16:38:39, Pavel Tatashin wrote: > In deferred_init_memmap() where all deferred struct pages are initialized > we have a check like this: > > if (page->flags) { > VM_BUG_ON(page_zone(page) != zone); > goto free_range; > } > > This way we are checking if the current deferred page has already been > initialized. It works, because memory for struct pages has been zeroed, and > the only way flags are not zero if it went through __init_single_page() > before. But, once we change the current behavior and won't zero the memory > in memblock allocator, we cannot trust anything inside "struct page"es > until they are initialized. This patch fixes this. > > This patch defines a new accessor memblock_get_reserved_pfn_range() > which returns successive ranges of reserved PFNs. deferred_init_memmap() > calls it to determine if a PFN and its struct page has already been > initialized. Maybe I am missing something but how can we see reserved ranges here when for_each_mem_pfn_range iterates over memblock.memory? The loop is rather complex but I am wondering whether the page->flags check is needed at all. We shouldn't have duplicated memblocks covering the same pfn ranges so we cannot initialize the same range multiple times, right? Reserved ranges are excluded altogether so how exactly can we see an initialized struct page? In other words, why this simply doesn't work? diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 90e331e4c077..987a340a5bed 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1524,11 +1524,6 @@ static int __init deferred_init_memmap(void *data) cond_resched(); } - if (page->flags) { - VM_BUG_ON(page_zone(page) != zone); - goto free_range; - } - __init_single_page(page, pfn, zid, nid); if (!free_base_page) { free_base_page = page;