From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29586C433E0 for ; Wed, 29 Jul 2020 08:32:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E265F206D4 for ; Wed, 29 Jul 2020 08:32:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E265F206D4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=Huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7A8986B0005; Wed, 29 Jul 2020 04:32:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75B468D0001; Wed, 29 Jul 2020 04:32:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6473D6B0007; Wed, 29 Jul 2020 04:32:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 4D6F86B0005 for ; Wed, 29 Jul 2020 04:32:01 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 09871117E9 for ; Wed, 29 Jul 2020 08:32:01 +0000 (UTC) X-FDA: 77090445642.01.tin23_1208d0826f71 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id CF5C4101EBA09 for ; Wed, 29 Jul 2020 08:32:00 +0000 (UTC) X-HE-Tag: tin23_1208d0826f71 X-Filterd-Recvd-Size: 7737 Received: from huawei.com (lhrrgout.huawei.com [185.176.76.210]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 29 Jul 2020 08:32:00 +0000 (UTC) Received: from lhreml710-chm.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id 2439AD46260FB3D2AD69; Wed, 29 Jul 2020 09:31:58 +0100 (IST) Received: from localhost (10.52.120.141) by lhreml710-chm.china.huawei.com (10.201.108.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Wed, 29 Jul 2020 09:31:56 +0100 Date: Wed, 29 Jul 2020 09:30:31 +0100 From: Jonathan Cameron To: Mike Rapoport CC: Andrew Morton , , Peter Zijlstra , Benjamin Herrenschmidt , Dave Hansen , , Max Filippov , "Paul Mackerras" , , , Will Deacon , "Stafford Horne" , , , Yoshinori Sato , Michael Ellerman , , Russell King , Mike Rapoport , , Ingo Molnar , Catalin Marinas , , , , Borislav Petkov , "Andy Lutomirski" , Paul Walmsley , Thomas Gleixner , , Michal Simek , , , , , "Palmer Dabbelt" , Christoph Hellwig Subject: Re: [PATCH 04/15] arm64: numa: simplify dummy_numa_init() Message-ID: <20200729093031.0000316b@Huawei.com> In-Reply-To: <20200728051153.1590-5-rppt@kernel.org> References: <20200728051153.1590-1-rppt@kernel.org> <20200728051153.1590-5-rppt@kernel.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.52.120.141] X-ClientProxiedBy: lhreml738-chm.china.huawei.com (10.201.108.188) To lhreml710-chm.china.huawei.com (10.201.108.61) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: CF5C4101EBA09 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, 28 Jul 2020 08:11:42 +0300 Mike Rapoport wrote: > From: Mike Rapoport > > dummy_numa_init() loops over memblock.memory and passes nid=0 to > numa_add_memblk() which essentially wraps memblock_set_node(). However, > memblock_set_node() can cope with entire memory span itself, so the loop > over memblock.memory regions is redundant. > > Replace the loop with a single call to memblock_set_node() to the entire > memory. Hi Mike, I had a similar patch I was going to post shortly so can add a bit more on the advantages of this one. Beyond cleaning up, it also fixes an issue with a buggy ACPI firmware in which the SRAT table covers some but not all of the memory in the EFI memory map. Stealing bits from the draft cover letter I had for that... > This issue can be easily triggered by having an SRAT table which fails > to cover all elements of the EFI memory map. > > This firmware error is detected and a warning printed. e.g. > "NUMA: Warning: invalid memblk node 64 [mem 0x240000000-0x27fffffff]" > At that point we fall back to dummy_numa_init(). > > However, the failed ACPI init has left us with our memblocks all broken > up as we split them when trying to assign them to NUMA nodes. > > We then iterate over the memblocks and add them to node 0. > > for_each_memblock(memory, mblk) { > ret = numa_add_memblk(0, mblk->base, mblk->base + mblk->size); > if (!ret) > continue; > pr_err("NUMA init failed\n"); > return ret; > } > > numa_add_memblk() calls memblock_set_node() which merges regions that > were previously split up during the earlier attempt to add them to different > nodes during parsing of SRAT. > > This means elements are moved in the memblock array and we can end up > in a different memblock after the call to numa_add_memblk(). > Result is: > > Unable to handle kernel paging request at virtual address 0000000000003a40 > Mem abort info: > ESR = 0x96000004 > EC = 0x25: DABT (current EL), IL = 32 bits > SET = 0, FnV = 0 > EA = 0, S1PTW = 0 > Data abort info: > ISV = 0, ISS = 0x00000004 > CM = 0, WnR = 0 > [0000000000003a40] user address but active_mm is swapper > Internal error: Oops: 96000004 [#1] PREEMPT SMP > > ... > > Call trace: > sparse_init_nid+0x5c/0x2b0 > sparse_init+0x138/0x170 > bootmem_init+0x80/0xe0 > setup_arch+0x2a0/0x5fc > start_kernel+0x8c/0x648 > > As an illustrative example: > EFI table has one block of memory. > memblks[0] = [0...0x2f] so we start with a single memblock. > > SRAT has > [0x00...0x0f] in node 0 > [0x10...0x1f] in node 1 > but no entry covering > [0x20...0x2f]. > > Whilst parsing SRAT the single memblock is broken into 3. > memblks[0] = [0x00...0x0f] in node 0 > memblks[1] = [0x10...0x1f] in node 1 > memblks[2] = [0x20...0x2f] in node MAX_NUM_NODES (invalid value) > > A sanity check parse then detects the invalid section and acpi_numa_init > fails. We then fall back to the dummy path. > > That iterates over the memblocks. We'll use i an index in the array of memblocks > > i = 0; > memblks[0] = [0x00...0x0f] set to node0. > merge doesn't do anything because the neighbouring memblock is still in node1. > > i = 1 > memblks[1] = [0x10...0x1f] set to node 0. > merge combines memblock 0 and 1 to give a new set of memblocks. > > memblks[0] = [0x00..0x1f] in node 0 > memblks[1] = [0x20..0x2f] in node MAX_NUM_NODES. > > i = 2 off the end of the now reduced array of memblocks, so exit the loop. > (if we restart the loop here everything will be fine). > > Later sparse_init_nid tries to use the node of the second memblock to index > somethings and boom. > > Signed-off-by: Mike Rapoport Acked-by: Jonathan Cameron > --- > arch/arm64/mm/numa.c | 13 +++++-------- > 1 file changed, 5 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/mm/numa.c b/arch/arm64/mm/numa.c > index aafcee3e3f7e..0cbdbcc885fb 100644 > --- a/arch/arm64/mm/numa.c > +++ b/arch/arm64/mm/numa.c > @@ -423,19 +423,16 @@ static int __init numa_init(int (*init_func)(void)) > */ > static int __init dummy_numa_init(void) > { > + phys_addr_t start = memblock_start_of_DRAM(); > + phys_addr_t end = memblock_end_of_DRAM(); > int ret; > - struct memblock_region *mblk; > > if (numa_off) > pr_info("NUMA disabled\n"); /* Forced off on command line. */ > - pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", > - memblock_start_of_DRAM(), memblock_end_of_DRAM() - 1); > - > - for_each_memblock(memory, mblk) { > - ret = numa_add_memblk(0, mblk->base, mblk->base + mblk->size); > - if (!ret) > - continue; > + pr_info("Faking a node at [mem %#018Lx-%#018Lx]\n", start, end - 1); > > + ret = numa_add_memblk(0, start, end); > + if (ret) { > pr_err("NUMA init failed\n"); > return ret; > }