Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp474683ybl; Wed, 14 Aug 2019 00:43:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqz80jx1sf8442vaxHIobELyCbau10/rMXn6vRmHvSS7yQIwxGRZ9qYayY/ojWBRDPJ1hugo X-Received: by 2002:a17:902:12d:: with SMTP id 42mr39427050plb.187.1565768612174; Wed, 14 Aug 2019 00:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565768612; cv=none; d=google.com; s=arc-20160816; b=zNNI6ke7+IMIz5vgfdb6Aa6jKAoRBb/B1Ya16sRnh4fn7YdNcFFZlByryMrziU2Pkg KBRlFb433ddv+Z5cCZnCHvA06s1DqMyT5Qbr8355LaoJk7zOsny9FcAiSfvlE+F8cVIV XDfT25cd8BP0YgmQX2jkxv5lhDLreEXoBKlOfijcEqJC/iHAlPsYOXwUJpf45Fqz9dfE iMfLnqPijQOomR9iqeoLdpmf6ggp56twfkVV7WYAssApPhvhs7B4cQc2bsIya5o51dQu Y4QSaVOz0Q9b6PVmLn92SyNHKdlyg4RBfdHLihjJKg7uQuEft0NL4aIGdRm5aZiJZrFu DmIg== 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:from:references:cc:to:subject; bh=n7+YAhvH+jrijvlLRq01ZiF34qeBwG8YAKKTCycKme0=; b=sKnueB//rC8qA7MDak/86S3KnCROGGkEoTojHhRu5zb3MmEdfb9H6jjVTSEem2VEMC zC1ayobMn7joLBOfrx/YHuPBzaqw4Qohc4rpd00fHMsI75In6Lm1CTYkyB1YX6DHcQJ+ KlwHr9wIbKdl2eMf+zHJtOIQA0Mx24dbNt+jW4J6n9hoNrgE/rypdVnLGArZwv1jx235 55eOHtKVCxS/B6/vTEE9PMk7DTyryGCeDqw5taEd8rfhnHIkueDdq6oF0TIPChxWqQ3e 8w1QLF1/5BJ2ZYHK8m9vCMcLCB1lFC43a3ZOUkD8QSZbnl1lWF8INSLvPJOcmtEpM83L zZkA== 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 h30si2441337pjb.45.2019.08.14.00.42.49; Wed, 14 Aug 2019 00:43:32 -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 S1726530AbfHNHmK (ORCPT + 99 others); Wed, 14 Aug 2019 03:42:10 -0400 Received: from mx2.suse.de ([195.135.220.15]:56406 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725895AbfHNHmK (ORCPT ); Wed, 14 Aug 2019 03:42:10 -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 C23E4ADE0; Wed, 14 Aug 2019 07:42:08 +0000 (UTC) Subject: Re: [patch] mm, page_alloc: move_freepages should not examine struct page of reserved memory To: David Rientjes Cc: Andrew Morton , Naoya Horiguchi , Mel Gorman , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <3aadeed1-3f38-267d-8dae-839e10a2f9d2@suse.cz> From: Vlastimil Babka Message-ID: <643d3680-9994-ce58-037f-b1fc123ff8bd@suse.cz> Date: Wed, 14 Aug 2019 09:42:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/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 7:22 PM, David Rientjes wrote: > On Tue, 13 Aug 2019, Vlastimil Babka 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? >> > > It's simply math after finding a valid free page from the per-zone free > area to use as fallback. We find the beginning and end of the pageblock > of the valid page and that can bring us into memory that was reserved per > the e820. pfn_valid() is still true (it's backed by a struct page), but > since it's zero'd we shouldn't make any inferences here about comparing > its node or zone. The current node check just happens to succeed most of > the time by luck because reserved memory typically appears on node 0. > > The fix here is to validate that we actually have buddy pages before > testing if there's any type of zone or node strangeness going on. I see, thanks. >> > @@ -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/ >> > > Does it? The first is checking for a corrupted page_to_nid the second is > checking for a corrupted or unexpected page_zone. What's being tested > here is the state of struct page, as it was previous to this patch, not > the state of struct zone. page_zone() calls page_to_nid() internally, so if nid was wrong, the resulting zone pointer would be also wrong. But if you want more fine grained bug output, that's fine.