Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4243530ybl; Mon, 3 Feb 2020 15:19:51 -0800 (PST) X-Google-Smtp-Source: APXvYqx3rBqKfaXmJirlhZw612jp8GUEYNWWrfNCMxKxb0rJNoiz/dzLaBHjIap4xN/fFEGXpXza X-Received: by 2002:a9d:664a:: with SMTP id q10mr18718587otm.298.1580771991177; Mon, 03 Feb 2020 15:19:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580771991; cv=none; d=google.com; s=arc-20160816; b=scOtjM22CFfAMlxJB9ejh7vkLWs+mesuxKb4JQKRNxV3QvizwLePA1yn7/k9srpx3g II8cd8Fe1f4OVO3XKvdqvbbQhRL1jyfT++K0xWKM6gayHZq26CBWYBUv3Cs1KzIhDr2T Yyn2zFKsbeEaiuRuEzVarcXa9VlAZd4mDaNQyeqiCRMQp/10yL3iCkguxDKDT2DzZ77u LWN85nNkNim7qt+bxU86darsMoABj7sHlG1QW00wOB/0CYhIcAGyrviYUdJIqolIHbu2 kPBVepSik2vQO0vYeQAZUb9nYL1IcVxIxyjgJ05EOraoaLClS8G7UOmRv7PwKZL/eh1V Exrw== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+tDvtzVGg2KSq7T5luQWCSg6VFxYPHqxgUAO4e7oxrs=; b=hTD+IHY25xARVf2TJW/iIzF2gPtM4d12XFIcUFyiKQguMN60siWhXIaCSF5awVxe1v 7QztSzdGxVJcy485OJunAu85xZznl5K+z+FSvm4ZiJF++hGVJ+ckG2nM0PL68VKdSLft oJ9V1D/bePoOOLjiTkdTIPShftp0MNviVQX3wcQUc0sukPHpIkIDty2eewzniobya5jN +8S8fjAEfRzXXEzLw4BULoxbiX68srLKXbewix5JxYZruQQvivpmB8oAyZ9ufC8/dS82 UR06IujHGtKFDv7J4/wZSdIkqZja+Qrggy003fnqthsZ81u3Q3ElpBsSI/kBkPpmYoPa Z/8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SnOMM6Gj; 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 e26si4968988oii.88.2020.02.03.15.19.39; Mon, 03 Feb 2020 15:19:51 -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=SnOMM6Gj; 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 S1726971AbgBCXRn (ORCPT + 99 others); Mon, 3 Feb 2020 18:17:43 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:42764 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726369AbgBCXRm (ORCPT ); Mon, 3 Feb 2020 18:17:42 -0500 Received: by mail-io1-f66.google.com with SMTP id s6so8360148iol.9 for ; Mon, 03 Feb 2020 15:17:42 -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:content-transfer-encoding; bh=+tDvtzVGg2KSq7T5luQWCSg6VFxYPHqxgUAO4e7oxrs=; b=SnOMM6GjX6albBnFz8qLixcUOyXC8NzNWszG/RXLPpxwBZwdulnjgWIV7sUDv3dm1h 0vcdUuSS+bYM5GCByB42Vz1YnGDXJukXxHIy4FdfV+8MWXO6lwD1G7pwh7p/5c6Zzf2V 85pIMMPa7wtQdF0RMzn5M7yJDEfREvbumwZD1NoyyH0CLiRHg7stvIF6r+Dukr+4zPtH lB/pVI4cbP9dseg8oAaH9qbm6rFiPK52oYXjPvlIzcSoLgYc7wdcL8/1yNicnC5H+dzb BjMRBXfu9UEqfwHxBWYXhKEgWaLMVcdWNLKk940V3LKOIGxRKRszsTZdFloZOMKOUx+4 yL0g== 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:content-transfer-encoding; bh=+tDvtzVGg2KSq7T5luQWCSg6VFxYPHqxgUAO4e7oxrs=; b=jklsJ3NpekGVOLXUVEOogvCTV7koVhIoLUjyRUZd/Qoz5vXoGSP2bNHLyzB1PFBRVY EcVXyYpPLRh6MRENdJoB1vrxUZ1a5F0+qp57ojuUGakYqjiqsBF1eML8F878Ihrn5dpg Wz6kc61Z2tPraKd6ybZurdDXB8gj8aKKzn+QCrL8Ql57CQdxQt98LpWAr4QPdGY8Oy2e rfRV3IqYurhe5PvI4JbhfdoHclW7ssc059fO38jPJllWyWEhX0kL/trfPC7VGFBabGOO drREgNxC7KMevIc8KoS4cSF4pnmBKxyg5MkHPKJSdpNOxTsS1qYSusgNb6U0AvK89ikx qdsQ== X-Gm-Message-State: APjAAAXDMyMrTXdei1QGADKXcDHyjKOJnFZ5q6JkBIFKP7Ky0ICRMYE8 vq17Cfj6Lmt1DcCfdXV6+IZ4fXNBghzRxcavUps= X-Received: by 2002:a6b:6e06:: with SMTP id d6mr20095773ioh.95.1580771861858; Mon, 03 Feb 2020 15:17:41 -0800 (PST) MIME-Version: 1.0 References: <1583F4CF-6CD8-4AB6-A2F6-60E6AEE5D5B2@redhat.com> In-Reply-To: <1583F4CF-6CD8-4AB6-A2F6-60E6AEE5D5B2@redhat.com> From: Alexander Duyck Date: Mon, 3 Feb 2020 15:17:30 -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" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 3, 2020 at 1:44 PM David Hildenbrand wrote: > > > > > Am 03.02.2020 um 22:35 schrieb Alexander Duyck : > > > > =EF=BB=BFOn Mon, Jan 13, 2020 at 6:40 AM David Hildenbrand wrote: > >> > >> Let's update the pfn manually whenever we continue the loop. This make= s > >> 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 h= ave > >> no idea if this is relevant in practise (with kernelcore=3Dmirror). > >> > >> Fixes: a9a9e77fbf27 ("mm: move mirrored memory specific code outside o= f 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 =3D start_pfn; pfn < end_pfn; pfn++) { > >> + for (pfn =3D 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 =3D=3D MEMMAP_EARLY) { > >> if (!early_pfn_valid(pfn)) { > >> - pfn =3D next_pfn(pfn) - 1; > >> + pfn =3D 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; > > Thanks for having a look. > > Did you read the description regarding this change? Actually I hadn't read it all that closely, so my bad on that. The part that had caught my attention though was that memblock_region_memory_end is using PFN_DOWN to identify the end of the memory region, Given that we probably shouldn't be messing with the PFNs that may contain any of this memory it might make more sense to use memblock_region_reserved_end_pfn which uses PFN_UP so that we exclude all memory that is in the mirrored region just in case something doesn't end on a PFN aligned boundary. If we know that the mirrored region is going to always be page size aligned then I guess you are good to go. That was the only thing I wasn't sure about. Reviewed-by: Alexander Duyck