Received: by 10.213.65.68 with SMTP id h4csp18818imn; Thu, 15 Mar 2018 08:18:51 -0700 (PDT) X-Google-Smtp-Source: AG47ELtO7QwR5mAk6AY3C2B6lsfGR1aU6mJ+Anbhk+yCCPhgiHIB5DTbNLbt26oiV0Cjxwao4dgK X-Received: by 10.99.55.70 with SMTP id g6mr6996745pgn.284.1521127131681; Thu, 15 Mar 2018 08:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521127131; cv=none; d=google.com; s=arc-20160816; b=Nt9aI0NVLlPY2Y2uVAu4KQ09cZMdnWjW/C5u1qtfR2CjNSo2FHt5jZV7zOGWDFLCBl AANr9ENxvbL2DHkirWgU66dTMTI6As2+XiPALjZuAYqsLfSEBAKZwxJIME811fI6gk4P qCBvlcVacOoMpY/ay8YPY95Tk2Ahd72SWhCrP1GGZvlCLCIXdmBqkmvNK79GGoL5dJUL x7MbEYS+00segIVVuLpTqdBF34V7ShklWmzaMeWyfqnJBhfHxB6siU4cbdSetW/8WHTj lWHefV3ENdJ7KGSA9R9nTt28i+oc3OrlneGT9qcjGF/Uh+6d8rFRMOQR9izMdrQKunwZ ojvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=8nFrHmHLzK4iieXPNE8ie+9/rcoWUGLalw3R5/donqQ=; b=oDCjekWa+1u7nAEv34a8TTtXbFjrMWdouhDCWAjz6Z5O/4Lc0VuJTrF6Ut4bn7nckV Z4GJTLFnPtkCbkcMN50I/hu92+dAkIVwTYRF+Pv503oF1lJFjtRwhAQ7LRytKf0sKC1i 8Ei1LsBmsjBlqE5tHdbEZ5o+yn6i3/+ldVJBwLAB4716M4X1mC2/tRBe95gbdoy9qip8 NnKaCUMWaI8538p/lEClD6OoXXi21SRPvBHhE7YLmfONXnCr5v9fNubsDZ7NTVAWAAJy 9Cees1lWdfIWqgoTTyegroBg5MhLMqiIOpzG/pKyNea72yGjIO4TaY39iiZ1m4+oVOJC RZ2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PP2ckbv+; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i20si3534916pgn.711.2018.03.15.08.18.37; Thu, 15 Mar 2018 08:18:51 -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=@linaro.org header.s=google header.b=PP2ckbv+; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752668AbeCOPRW (ORCPT + 99 others); Thu, 15 Mar 2018 11:17:22 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:36977 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752504AbeCOPRV (ORCPT ); Thu, 15 Mar 2018 11:17:21 -0400 Received: by mail-io0-f195.google.com with SMTP id d71so9000310iog.4 for ; Thu, 15 Mar 2018 08:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8nFrHmHLzK4iieXPNE8ie+9/rcoWUGLalw3R5/donqQ=; b=PP2ckbv+R/lKP2iPGUiOidSa/3B5TsgbzJJxXCFr6NZ6yLWXRDa8MnmodoK3tjq/WF 3rd1UbzExvZBNtlMwAV32gHEb9UHAh0Z+21gYYb9VKjjOAAyTuuxuKS2je94BHJSzY65 AzA7yHVLKPRFYu6kAr5ufL+cQTEPF9TibWusE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8nFrHmHLzK4iieXPNE8ie+9/rcoWUGLalw3R5/donqQ=; b=FHDPrtlTKNBQLU8K4YjZ268lvT/0udWNzczGmsEoi7kB/TQidVh1Lnh0bvbNa99zYG xx3xLGwnc8oi8Iex5HQDiT96GWaMZO55AXoJy/t7xwBbcMk2i+D9y3Hnxr6yiBy9kJZ/ UzjSUS1+oPltGEItjv7NwijRCoIN7JR2AvELLPhs45n8zGQbmL0qv1vitXdHMv0yhcoX iEknON/+Kj14hhBE556+iJ0gRzHoBS5nQNDtQCRHUctEQMesChOtL+XgMOGVpso4Dd1z RpJyQDZjGlJcEvfUeSr6jl87m592fuZ9MQzMhqlTezPvu1Lw0mTj4ctm4Vv1zLsK47d+ paMg== X-Gm-Message-State: AElRT7GgTHGftNUcl1Xs8buPN/tyvPCU0dpiRisRrEhO/ou/xDIdXA2P +p5BLyLQ/r+sMa/v03vGCmlePWMSNQVdc29yalF/TQ== X-Received: by 10.107.41.16 with SMTP id p16mr9384128iop.173.1521127040195; Thu, 15 Mar 2018 08:17:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.18.137 with HTTP; Thu, 15 Mar 2018 08:17:19 -0700 (PDT) In-Reply-To: References: <20180314192937.12888-1-ard.biesheuvel@linaro.org> From: Ard Biesheuvel Date: Thu, 15 Mar 2018 15:17:19 +0000 Message-ID: Subject: Re: [PATCH v2] Revert "mm/page_alloc: fix memmap_init_zone pageblock alignment" To: Daniel Vacek Cc: linux-arm-kernel , open list , Mark Rutland , Will Deacon , Catalin Marinas , Marc Zyngier , Mel Gorman , Michal Hocko , Paul Burton , Pavel Tatashin , Vlastimil Babka , Andrew Morton , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15 March 2018 at 15:12, Daniel Vacek wrote: > On Thu, Mar 15, 2018 at 8:45 AM, Ard Biesheuvel > wrote: >> On 15 March 2018 at 07:44, Daniel Vacek wrote: >>> On Thu, Mar 15, 2018 at 8:36 AM, Ard Biesheuvel >>> wrote: >>>> On 15 March 2018 at 02:23, Daniel Vacek wrote: >>>>> On Wed, Mar 14, 2018 at 8:29 PM, Ard Biesheuvel >>>>> wrote: >>>>>> This reverts commit 864b75f9d6b0100bb24fdd9a20d156e7cda9b5ae. >>>>>> >>>>>> Commit 864b75f9d6b0 ("mm/page_alloc: fix memmap_init_zone pageblock >>>>>> alignment") modified the logic in memmap_init_zone() to initialize >>>>>> struct pages associated with invalid PFNs, to appease a VM_BUG_ON() >>>>>> in move_freepages(), which is redundant by its own admission, and >>>>>> dereferences struct page fields to obtain the zone without checking >>>>>> whether the struct pages in question are valid to begin with. >>>>>> >>>>>> Commit 864b75f9d6b0 only makes it worse, since the rounding it does >>>>>> may cause pfn assume the same value it had in a prior iteration of >>>>>> the loop, resulting in an infinite loop and a hang very early in the >>>>>> boot. Also, since it doesn't perform the same rounding on start_pfn >>>>>> itself but only on intermediate values following an invalid PFN, we >>>>>> may still hit the same VM_BUG_ON() as before. >>>>>> >>>>>> So instead, let's fix this at the core, and ensure that the BUG >>>>>> check doesn't dereference struct page fields of invalid pages. >>>>>> >>>>>> Fixes: 864b75f9d6b0 ("mm/page_alloc: fix memmap_init_zone pageblock alignment") >>>>>> Cc: Daniel Vacek >>>>>> Cc: Mel Gorman >>>>>> Cc: Michal Hocko >>>>>> Cc: Paul Burton >>>>>> Cc: Pavel Tatashin >>>>>> Cc: Vlastimil Babka >>>>>> Cc: Andrew Morton >>>>>> Cc: Linus Torvalds >>>>>> Signed-off-by: Ard Biesheuvel >>>>>> --- >>>>>> mm/page_alloc.c | 13 +++++-------- >>>>>> 1 file changed, 5 insertions(+), 8 deletions(-) >>>>>> >>>>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c >>>>>> index 3d974cb2a1a1..635d7dd29d7f 100644 >>>>>> --- a/mm/page_alloc.c >>>>>> +++ b/mm/page_alloc.c >>>>>> @@ -1910,7 +1910,9 @@ static int move_freepages(struct zone *zone, >>>>>> * Remove at a later date when no bug reports exist related to >>>>>> * grouping pages by mobility >>>>>> */ >>>>>> - VM_BUG_ON(page_zone(start_page) != page_zone(end_page)); >>>>>> + 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)); >>>>> >>>>> Hi, I am on vacation this week and I didn't have a chance to test this >>>>> yet but I am not sure this is correct. Generic pfn_valid() unlike the >>>>> arm{,64} arch specific versions returns true for all pfns in a section >>>>> if there is at least some memory mapped in that section. So I doubt >>>>> this prevents the crash I was targeting. I believe pfn_valid() does >>>>> not change a thing here :( >>>>> >>>> >>>> If this is the case, memblock_next_valid_pfn() is broken since it >>>> skips valid PFNs, and we should be fixing that instead. >>> >>> How do you define valid pfn? Maybe the generic version of pfn_valid() >>> should be fixed??? >>> >> >> memblock_next_valid_pfn() skips PFNs for which pfn_valid() returns >> true. That is clearly a bug. > > So pfn_valid() does not mean this frame is usable memory? > Who cares what it *means*? memblock_next_valid_pfn() has 'valid_pfn' in its name, so if passing pfn A returns B, and there exists a C such that A < C < B and pfn_valid(C) returns true, memblock_next_valid_pfn doesn't do what it says on the tin and should be fixed. You keep going on about how pfn_valid() does or does not do what you think, but that is really irrelevant. > OK, in that case we need to fix or revert memblock_next_valid_pfn(). > That works for me. > OK. You can add my ack to a patch that reverts it, and we can revisit it for the next cycle.