Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1008972ybl; Tue, 13 Aug 2019 06:07:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxymlOGvcNvC/SGS+24hM7fZOsvzH3DlfFXfaXWwcNMpxSR4QCZx8yTwPOPX285Dhe1wDVB X-Received: by 2002:a63:f118:: with SMTP id f24mr35115561pgi.322.1565701628487; Tue, 13 Aug 2019 06:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565701628; cv=none; d=google.com; s=arc-20160816; b=mB7Ikqu9SRZAFUWo366vnYbqPzHM380ThS4D2H/40rw5HbplrHes/N0VkPUNzRL5DM /wA5PuFgakAB8wlr7zin/9fRjWcgeIBsIODT5oomSOCQPoyIXKJ5sMsqLiXmBxZjbDr7 Xv8alEraXx6idYYqgEk4Xpx/9bYUvWBOLTmkRBvhqLbdzFo2OOSzJrz4QSOthIQHCdXv HEE0B8QwxaCiT/8db2ERRBpn5uyQdaOk++65A3vPT7LRMH8WcmUBhDyOBfE4wubo4Ix3 Gxz6uj/cDxjnF0oDZfjxBNxdSW1i+lzH0+0U3eOUFRlqN5tnZPMV8z58jfMgWf+OmW0d VfCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=/DV/fO7DywBVG6WOVOeA4vagHf8HNs3mPhlBVXnJ23A=; b=OcnnyR4eV7ehmU0s1fnKYSXrxngwOVSn8tSjz0pzy5ttFMlGJLGBTFPeGddjnzpJVA OYp7XUGAOvYgldU8BsjYUnxc4ocCQvaWIsN49eUYkrSfjX+I6AC5HxpFE+G7njzDV41D 7mmJPW0sKDK0RFYvE6TasXqhn4GwOFVU2VCSJ4O6fHX2iOcVgTXhiyaD3kG+Bj8+8LHt um0w5FLgcC6pWIRWbHIQT8/4lSR1p9SPlXiHZjv6KmPNws58z+1Rc3/RG5MpiNQ7uAH5 m+gI3eM0NC0Dq/iRO++ttuG8htXC/pwsQgvZDXiqPTffEIqArmS3R3mdg/CoISXWNBF/ dRhw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x5si447523pln.274.2019.08.13.06.06.51; Tue, 13 Aug 2019 06:07:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728864AbfHMNDT (ORCPT + 99 others); Tue, 13 Aug 2019 09:03:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:45246 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727621AbfHMNDT (ORCPT ); Tue, 13 Aug 2019 09:03:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 25C0DAD95; Tue, 13 Aug 2019 13:03:16 +0000 (UTC) Subject: Re: [patch] mm, page_alloc: move_freepages should not examine struct page of reserved memory To: David Rientjes , Andrew Morton Cc: Naoya Horiguchi , Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: From: Vlastimil Babka Openpgp: preference=signencrypt Autocrypt: addr=vbabka@suse.cz; prefer-encrypt=mutual; keydata= mQINBFZdmxYBEADsw/SiUSjB0dM+vSh95UkgcHjzEVBlby/Fg+g42O7LAEkCYXi/vvq31JTB K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underbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/13/19 5:37 AM, David Rientjes wrote: > After commit 907ec5fca3dc ("mm: zero remaining unavailable struct pages"), > struct page of reserved memory is zeroed. This causes page->flags to be 0 > and fixes issues related to reading /proc/kpageflags, for example, of > reserved memory. > > The VM_BUG_ON() in move_freepages_block(), however, assumes that > page_zone() is meaningful even for reserved memory. That assumption is no > longer true after the aforementioned commit. How comes that move_freepages_block() gets called on reserved memory in the first place? > There's no reason why move_freepages_block() should be testing the > legitimacy of page_zone() for reserved memory; its scope is limited only > to pages on the zone's freelist. > > Note that pfn_valid() can be true for reserved memory: there is a backing > struct page. The check for page_to_nid(page) is also buggy but reserved > memory normally only appears on node 0 so the zeroing doesn't affect this. > > Move the debug checks to after verifying PageBuddy is true. This isolates > the scope of the checks to only be for buddy pages which are on the zone's > freelist which move_freepages_block() is operating on. In this case, an > incorrect node or zone is a bug worthy of being warned about (and the > examination of struct page is acceptable bcause this memory is not > reserved). > > Signed-off-by: David Rientjes > --- > mm/page_alloc.c | 19 ++++--------------- > 1 file changed, 4 insertions(+), 15 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -2238,27 +2238,12 @@ static int move_freepages(struct zone *zone, > unsigned int order; > int pages_moved = 0; > > -#ifndef CONFIG_HOLES_IN_ZONE > - /* > - * page_zone is not safe to call in this context when > - * CONFIG_HOLES_IN_ZONE is set. This bug check is probably redundant > - * anyway as we check zone boundaries in move_freepages_block(). > - * Remove at a later date when no bug reports exist related to > - * grouping pages by mobility > - */ > - VM_BUG_ON(pfn_valid(page_to_pfn(start_page)) && > - pfn_valid(page_to_pfn(end_page)) && > - page_zone(start_page) != page_zone(end_page)); > -#endif > for (page = start_page; page <= end_page;) { > if (!pfn_valid_within(page_to_pfn(page))) { > page++; > continue; > } > > - /* Make sure we are not inadvertently changing nodes */ > - VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page); > - > if (!PageBuddy(page)) { > /* > * We assume that pages that could be isolated for > @@ -2273,6 +2258,10 @@ static int move_freepages(struct zone *zone, > continue; > } > > + /* Make sure we are not inadvertently changing nodes */ > + VM_BUG_ON_PAGE(page_to_nid(page) != zone_to_nid(zone), page); > + VM_BUG_ON_PAGE(page_zone(page) != zone, page); The later check implies the former check, so if it's to stay, the first one could be removed and comment adjusted s/nodes/zones/ > + > order = page_order(page); > move_to_free_area(page, &zone->free_area[order], migratetype); > page += 1 << order; >