Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp943816ybg; Wed, 29 Jul 2020 01:34:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYZJFghY+4t/KAc3ZbpjyP0ICuRSVhvDv5xBvmP97dMF8tPaolvJWVfh03WZyes3ZXx+RV X-Received: by 2002:aa7:d043:: with SMTP id n3mr30807367edo.102.1596011667981; Wed, 29 Jul 2020 01:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596011667; cv=none; d=google.com; s=arc-20160816; b=zK6FT09l0+ksnu1eUU0XijfsG0VVq4qzqIi2EExSaZePE3/O2hL8Hqv/KVPN6tTKCO KINrT4azOyEVODLaarJylSYm9TNBfNZ92GnEx/vcb/ADgXJGsa8M/J81CWcWHB7A4yUo 3qZ43cTnEPrRWSmWyvhe6GxqDzGuGVc5EYNADrfD0/iVqDxLkMXSe0DsZiMPe4X6oK7i EpUo84TEJRiBzj8P+nK3/FHhAESm1vBTGd/F4HxbRI69q33NNVMwC3oE3tbIsDdcaWaT rc3oKnWNY2x7U+JfRE+UY/+tG4MKxblc/HBB6m9weid0oPvnobuBDNVG2zoV0JF32NkH 0swg== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=sVXs/TbLH42dNE8thYPlFWa4ITfZSFIcpI77VMuf5tI=; b=v6bYZvLBvcDLszU3OD0P2qRenUxMoSwINYo9Cnc6w9mlZUbnP6BGg2o7cu02d80rjP enROnfJbwZclMzUB5EuUR7Qb1aCbk+VCVo2ivastwITy/AP0MEzkJOStcd2o9pbGQadl v1bY7qoHX/VFcPbOLipng4y6VIJCI39OSCj25MrGzckUU3BOQXBjeVJPSQ2O03koPxmr qA1L3Nn5HFbXLSeoWBNH08aonT4zWIr9v62zqpsvlTVwm9/aJDCU2jUctgDjDRXwh6Zu qOdaFw2aiz5/Pim1DGfDgGu/oZiOIeoLoH07vSr+7gzFGh8xCLeXibKdmHqrE5tsugew f8Xw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b12si602519ejl.139.2020.07.29.01.34.06; Wed, 29 Jul 2020 01:34:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727816AbgG2IcC (ORCPT + 99 others); Wed, 29 Jul 2020 04:32:02 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2548 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726707AbgG2IcB (ORCPT ); Wed, 29 Jul 2020 04:32:01 -0400 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > }