Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4153246ybl; Mon, 3 Feb 2020 13:38:02 -0800 (PST) X-Google-Smtp-Source: APXvYqwjn9JDaof37N/Me/abi64vjc0iVuxmg4/V/v9WfBObWkEXCrlO72YppnSqGNDxNGY7meyl X-Received: by 2002:aca:f44a:: with SMTP id s71mr803589oih.7.1580765882058; Mon, 03 Feb 2020 13:38:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580765882; cv=none; d=google.com; s=arc-20160816; b=bKVKgfiMvG4In87YrjQAe+akerQYZrkHTAzATzQqm/J9F7rJohsr986J1bqfozaPHM 5Bi8SvhELSJxPK2BWJQP/5WHAlCUDs1iYrekYMMoDdC+q6kNPXtasOHXL5uV/epSjCe3 rfCSXTGIS511YzlWQapnQmcR/hgD3o68T7ftZI3SoShZeLJ5oon6QVbtR+vSHtqVnF3Y vwr/2+6IZUjqTJFN9NNL/SlLTzwqBIXkPBe16kdXRwpcwwUUucd+J8FQTciu6xY4yz/A Ny7wUK44macfxNBRYj4P+fUgN8bDViadtHvyLMqcztLuwaZiW9M1fYVOpzmbmGNdMWth xe9A== 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 :in-reply-to:references:mime-version:dkim-signature; bh=DPZ/wndNtGq4PmKFUPMXpdYlQfdeqHvXR9++rakqp3A=; b=KZZNCxkyJdhcQIWF7xWxEX93WZjYgZBdF3MfVUQl52XmcytwGZEJ5xdzBqp4F8uaQa IwGcbmwByQCPLazzmTL5TlRj6GkFePQWKK6G3guRa4tqmqqOpELx6fZAw8dT5hNpoJFL t1bhpGdsOEdpBjHRzLDcx8B2TDiCxLlnhzdVpb912zNxmItf8qzddO82Etbn4ZTJwwHT RL4wPvN3wm+gtZk5SImdF9zHEqHQAgGc1ZV5WS0oZgNSpCf1u+65zMlCx3eMzbTs9tVq rrOKybIBFIAgDgwiLzmGGatGa/ValzxG6CBzYXXpUe0WEUyPIELczwhE/EfxaTU9KSW9 rbtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FdjhlwgA; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x19si9323099otk.89.2020.02.03.13.37.49; Mon, 03 Feb 2020 13:38:02 -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=@gmail.com header.s=20161025 header.b=FdjhlwgA; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbgBCVfl (ORCPT + 99 others); Mon, 3 Feb 2020 16:35:41 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:41693 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbgBCVfk (ORCPT ); Mon, 3 Feb 2020 16:35:40 -0500 Received: by mail-io1-f66.google.com with SMTP id m25so18477154ioo.8 for ; Mon, 03 Feb 2020 13:35:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DPZ/wndNtGq4PmKFUPMXpdYlQfdeqHvXR9++rakqp3A=; b=FdjhlwgAGOu66VUqqDLXL/KJ9ELUF1MwQk+agEJRVCH+pVTOmaxVnqrfmnSiAL2jF3 m4glQpP80GbA416FOt9gGXQSX3nz90a+WxXPQ4vg7axvkIaV/3lL+wTrl96W20VXfKQK zLA2jtfrL1EaH0zwXKJ54PaSwVPDJ5rtDNQleh72twHKr6NkH0YIh0gW1j3FCasQtLXp wco3tGaqgrbn8hIud5AqfK7lo8TjucAZoXqFPa9BaSsTn/K1RBr9qewCFwEx0hFMg2wC GO13DPu3M52m9+In08KaiYGF7j004WQtZ+UcEsGh1R1YyFFrroz2FcFWNnL+tuDM9w9J cXDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DPZ/wndNtGq4PmKFUPMXpdYlQfdeqHvXR9++rakqp3A=; b=Xd00Rt2FyONJu4bbU9PkrEWwL+Y/naffZ9XVoUsYSFlNcqb0zTXo7Q3mwdxCSm9oRP VCD73YAAIy+HsvKlWRSVQRIKjFQKaJ/OAJbaouUCfMBJ0Uq85q4zfnr15w2g54fQAnNy YdZtXw/lFNnRIgT+zPZq4bNeYYRv0QE2DFjqlFaY+eYNP35CgdwVwqp0Q5CgxKUlVcB8 p3Cad+JqIHZ5gue2BtxLc9JZT5yeXiNzdJf/81FUlymCBC3Xi2XLK1UPvcPPY8olQ8YG MHfs43SUr1/OxHub115kx4ZL8pAzU9L880mQfHYwu+G6ORaj7mMMK6MHQttJOWif8T9I 4VvA== X-Gm-Message-State: APjAAAU8NwAGVLfaYEes3Qpdhcn/KNmbc5A/B9FIa7kuyqem3hud6DDb xi7TBQe2SEElaeTduULRox3OzZ18DPqIlJGqVaQ= X-Received: by 2002:a02:ccea:: with SMTP id l10mr13626895jaq.114.1580765739722; Mon, 03 Feb 2020 13:35:39 -0800 (PST) MIME-Version: 1.0 References: <20200113144035.10848-1-david@redhat.com> <20200113144035.10848-2-david@redhat.com> In-Reply-To: <20200113144035.10848-2-david@redhat.com> From: Alexander Duyck Date: Mon, 3 Feb 2020 13:35:29 -0800 Message-ID: Subject: Re: [PATCH v1 1/2] mm/page_alloc: fix and rework pfn handling in memmap_init_zone() To: David Hildenbrand Cc: LKML , linux-mm , Pavel Tatashin , Andrew Morton , Michal Hocko , Oscar Salvador , "Kirill A . Shutemov" 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 Mon, Jan 13, 2020 at 6:40 AM David Hildenbrand wrote: > > Let's update the pfn manually whenever we continue the loop. This makes > the code easier to read but also less error prone (and we can directly > fix one issue). > > When overlap_memmap_init() returns true, pfn is updated to > "memblock_region_memory_end_pfn(r)". So it already points at the *next* > pfn to process. Incrementing the pfn another time is wrong, we might > leave one uninitialized. I spotted this by inspecting the code, so I have > no idea if this is relevant in practise (with kernelcore=mirror). > > Fixes: a9a9e77fbf27 ("mm: move mirrored memory specific code outside of memmap_init_zone") > Cc: Pavel Tatashin > Cc: Andrew Morton > Cc: Michal Hocko > Cc: Oscar Salvador > Cc: Kirill A. Shutemov > Signed-off-by: David Hildenbrand > --- > mm/page_alloc.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index a41bd7341de1..a92791512077 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5905,18 +5905,20 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, > } > #endif > > - for (pfn = start_pfn; pfn < end_pfn; pfn++) { > + for (pfn = start_pfn; pfn < end_pfn; ) { > /* > * There can be holes in boot-time mem_map[]s handed to this > * function. They do not exist on hotplugged memory. > */ > if (context == MEMMAP_EARLY) { > if (!early_pfn_valid(pfn)) { > - pfn = next_pfn(pfn) - 1; > + pfn = next_pfn(pfn); > continue; > } > - if (!early_pfn_in_nid(pfn, nid)) > + if (!early_pfn_in_nid(pfn, nid)) { > + pfn++; > continue; > + } > if (overlap_memmap_init(zone, &pfn)) > continue; > if (defer_init(nid, pfn, end_pfn)) I'm pretty sure this is a bit broken. The overlap_memmap_init is going to return memblock_region_memory_end_pfn instead of the start of the next region. I think that is going to stick you in a mirrored region without advancing in that case. You would also need to have that case do a pfn++ before the continue; > @@ -5944,6 +5946,7 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, > set_pageblock_migratetype(page, MIGRATE_MOVABLE); > cond_resched(); > } > + pfn++; > } > } > > -- > 2.24.1 > >