From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95077145A19; Fri, 19 Jul 2024 16:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721406537; cv=none; b=U+i9bXFZk+qPCd3Iz2s0pIOE0VyhNvqXLR/07nNP/sFoGw4ZPNDEqqhRtZEHGDEcbHadRVEMfi47ORmj668dSgGMewRHa6VEn3lYlRU/Ce8iaq2itIKF4ORRf8pjAg+e65+M5JQrV/kSDCsT6pPmlcjKRK81PqCkYi86SCFV7+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721406537; c=relaxed/simple; bh=N1pdKNBGQDY1wRXXdSL7Pu0XSWIwV9tnznh+gOEKyG8=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uPcq5XOae/QSfvQsausuJ3JlZKal0ZA+thVyxIBBr/gzS4M7nN+GfpfBikIDhhplyT0KxK3pPv4le7DmsyGzcA/Sht90K0/pTw80TYAOYZc7baeRnS8TGWVejWuVNcLi/4iFPjE0uUaIgKKByBnIOctlmO7Ds624OVoOmW7f8QI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WQZn61R1mz6K7Fc; Sat, 20 Jul 2024 00:26:34 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 9E616140517; Sat, 20 Jul 2024 00:28:51 +0800 (CST) Received: from localhost (10.48.157.16) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 19 Jul 2024 17:28:50 +0100 Date: Fri, 19 Jul 2024 17:28:49 +0100 From: Jonathan Cameron To: Mike Rapoport CC: , Alexander Gordeev , Andreas Larsson , "Andrew Morton" , Arnd Bergmann , "Borislav Petkov" , Catalin Marinas , Christophe Leroy , Dan Williams , Dave Hansen , David Hildenbrand , "David S. Miller" , Greg Kroah-Hartman , Heiko Carstens , Huacai Chen , Ingo Molnar , Jiaxun Yang , "John Paul Adrian Glaubitz" , Michael Ellerman , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , "Thomas Bogendoerfer" , Thomas Gleixner , Vasily Gorbik , Will Deacon , , , , , , , , , , , , , , , Subject: Re: [PATCH 06/17] x86/numa: simplify numa_distance allocation Message-ID: <20240719172849.000019a0@Huawei.com> In-Reply-To: <20240716111346.3676969-7-rppt@kernel.org> References: <20240716111346.3676969-1-rppt@kernel.org> <20240716111346.3676969-7-rppt@kernel.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500005.china.huawei.com (7.191.163.240) On Tue, 16 Jul 2024 14:13:35 +0300 Mike Rapoport wrote: > From: "Mike Rapoport (Microsoft)" > > Allocation of numa_distance uses memblock_phys_alloc_range() to limit > allocation to be below the last mapped page. > > But NUMA initializaition runs after the direct map is populated and initialization (one too many 'i's) > there is also code in setup_arch() that adjusts memblock limit to > reflect how much memory is already mapped in the direct map. > > Simplify the allocation of numa_distance and use plain memblock_alloc(). > This makes the code clearer and ensures that when numa_distance is not > allocated it is always NULL. Doesn't this break the comment in numa_set_distance() kernel-doc? " * If such table cannot be allocated, a warning is printed and further * calls are ignored until the distance table is reset with * numa_reset_distance(). " Superficially that looks to be to avoid repeatedly hitting the singleton bit at the top of numa_set_distance() as SRAT or similar parsing occurs. > > Signed-off-by: Mike Rapoport (Microsoft) > --- > arch/x86/mm/numa.c | 12 +++--------- > 1 file changed, 3 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c > index 5e1dde26674b..ab2d4ecef786 100644 > --- a/arch/x86/mm/numa.c > +++ b/arch/x86/mm/numa.c > @@ -319,8 +319,7 @@ void __init numa_reset_distance(void) > { > size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]); > > - /* numa_distance could be 1LU marking allocation failure, test cnt */ > - if (numa_distance_cnt) > + if (numa_distance) > memblock_free(numa_distance, size); > numa_distance_cnt = 0; > numa_distance = NULL; /* enable table creation */ > @@ -331,7 +330,6 @@ static int __init numa_alloc_distance(void) > nodemask_t nodes_parsed; > size_t size; > int i, j, cnt = 0; > - u64 phys; > > /* size the new table and allocate it */ > nodes_parsed = numa_nodes_parsed; > @@ -342,16 +340,12 @@ static int __init numa_alloc_distance(void) > cnt++; > size = cnt * cnt * sizeof(numa_distance[0]); > > - phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0, > - PFN_PHYS(max_pfn_mapped)); > - if (!phys) { > + numa_distance = memblock_alloc(size, PAGE_SIZE); > + if (!numa_distance) { > pr_warn("Warning: can't allocate distance table!\n"); > - /* don't retry until explicitly reset */ > - numa_distance = (void *)1LU; > return -ENOMEM; > } > > - numa_distance = __va(phys); > numa_distance_cnt = cnt; > > /* fill with the default distances */ 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EBE5CC3DA59 for ; Fri, 19 Jul 2024 17:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:CC:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Qtui43RIkh0cCRdberqFDeII2FKkpK468OA05IlzzPA=; b=dAyHsY50//kDHK sJDnaFRIc7/NszSl9gxUOtNr9ZK3gPCTNC35l/8p6pst9IJjc98oFJUA3H8kAtVh35rU/81skRqHg usam55aqFjulBwZ7nybISwj3cnN35HpjhSpm440eEBCT+gldRTkItmpFlSuSLEfIUPlKdTCMPQ+w7 FeIT6EYXFqE5JEPPBZoUTDOqYaZ8WOiJcxBSSzN/DBkCL3Ur5G5v79/eh1LontkND2oQgdkQPgTsZ 2jTcEPsh6nwhmydEqNPR+PMKiFBlrgslS1ZsZwo9hwI2PKlExix7TzPiAyBpCkIfznTKpZPXc500z fRG93dUgILW9LW89rMYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUrRa-00000003OIq-26nE; Fri, 19 Jul 2024 17:30:58 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sUqTa-00000003Huo-3IK9; Fri, 19 Jul 2024 16:29:00 +0000 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WQZn61R1mz6K7Fc; Sat, 20 Jul 2024 00:26:34 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 9E616140517; Sat, 20 Jul 2024 00:28:51 +0800 (CST) Received: from localhost (10.48.157.16) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 19 Jul 2024 17:28:50 +0100 Date: Fri, 19 Jul 2024 17:28:49 +0100 From: Jonathan Cameron To: Mike Rapoport CC: , Alexander Gordeev , Andreas Larsson , "Andrew Morton" , Arnd Bergmann , "Borislav Petkov" , Catalin Marinas , Christophe Leroy , Dan Williams , Dave Hansen , David Hildenbrand , "David S. Miller" , Greg Kroah-Hartman , Heiko Carstens , Huacai Chen , Ingo Molnar , Jiaxun Yang , "John Paul Adrian Glaubitz" , Michael Ellerman , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , "Thomas Bogendoerfer" , Thomas Gleixner , Vasily Gorbik , Will Deacon , , , , , , , , , , , , , , , Subject: Re: [PATCH 06/17] x86/numa: simplify numa_distance allocation Message-ID: <20240719172849.000019a0@Huawei.com> In-Reply-To: <20240716111346.3676969-7-rppt@kernel.org> References: <20240716111346.3676969-1-rppt@kernel.org> <20240716111346.3676969-7-rppt@kernel.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 X-Originating-IP: [10.48.157.16] X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240719_092859_151486_BC310754 X-CRM114-Status: GOOD ( 23.19 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Tue, 16 Jul 2024 14:13:35 +0300 Mike Rapoport wrote: > From: "Mike Rapoport (Microsoft)" > > Allocation of numa_distance uses memblock_phys_alloc_range() to limit > allocation to be below the last mapped page. > > But NUMA initializaition runs after the direct map is populated and initialization (one too many 'i's) > there is also code in setup_arch() that adjusts memblock limit to > reflect how much memory is already mapped in the direct map. > > Simplify the allocation of numa_distance and use plain memblock_alloc(). > This makes the code clearer and ensures that when numa_distance is not > allocated it is always NULL. Doesn't this break the comment in numa_set_distance() kernel-doc? " * If such table cannot be allocated, a warning is printed and further * calls are ignored until the distance table is reset with * numa_reset_distance(). " Superficially that looks to be to avoid repeatedly hitting the singleton bit at the top of numa_set_distance() as SRAT or similar parsing occurs. > > Signed-off-by: Mike Rapoport (Microsoft) > --- > arch/x86/mm/numa.c | 12 +++--------- > 1 file changed, 3 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c > index 5e1dde26674b..ab2d4ecef786 100644 > --- a/arch/x86/mm/numa.c > +++ b/arch/x86/mm/numa.c > @@ -319,8 +319,7 @@ void __init numa_reset_distance(void) > { > size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]); > > - /* numa_distance could be 1LU marking allocation failure, test cnt */ > - if (numa_distance_cnt) > + if (numa_distance) > memblock_free(numa_distance, size); > numa_distance_cnt = 0; > numa_distance = NULL; /* enable table creation */ > @@ -331,7 +330,6 @@ static int __init numa_alloc_distance(void) > nodemask_t nodes_parsed; > size_t size; > int i, j, cnt = 0; > - u64 phys; > > /* size the new table and allocate it */ > nodes_parsed = numa_nodes_parsed; > @@ -342,16 +340,12 @@ static int __init numa_alloc_distance(void) > cnt++; > size = cnt * cnt * sizeof(numa_distance[0]); > > - phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0, > - PFN_PHYS(max_pfn_mapped)); > - if (!phys) { > + numa_distance = memblock_alloc(size, PAGE_SIZE); > + if (!numa_distance) { > pr_warn("Warning: can't allocate distance table!\n"); > - /* don't retry until explicitly reset */ > - numa_distance = (void *)1LU; > return -ENOMEM; > } > > - numa_distance = __va(phys); > numa_distance_cnt = cnt; > > /* fill with the default distances */ _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2C33FC3DA5D for ; Fri, 19 Jul 2024 16:29:23 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WQZrK5Lwpz3flh for ; Sat, 20 Jul 2024 02:29:21 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=huawei.com (client-ip=185.176.79.56; helo=frasgout.his.huawei.com; envelope-from=jonathan.cameron@huawei.com; receiver=lists.ozlabs.org) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WQZqv1fTcz3cdy for ; Sat, 20 Jul 2024 02:28:56 +1000 (AEST) Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WQZn61R1mz6K7Fc; Sat, 20 Jul 2024 00:26:34 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 9E616140517; Sat, 20 Jul 2024 00:28:51 +0800 (CST) Received: from localhost (10.48.157.16) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 19 Jul 2024 17:28:50 +0100 Date: Fri, 19 Jul 2024 17:28:49 +0100 From: Jonathan Cameron To: Mike Rapoport Subject: Re: [PATCH 06/17] x86/numa: simplify numa_distance allocation Message-ID: <20240719172849.000019a0@Huawei.com> In-Reply-To: <20240716111346.3676969-7-rppt@kernel.org> References: <20240716111346.3676969-1-rppt@kernel.org> <20240716111346.3676969-7-rppt@kernel.org> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.48.157.16] X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500005.china.huawei.com (7.191.163.240) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nvdimm@lists.linux.dev, x86@kernel.org, Andreas Larsson , Catalin Marinas , Dave Hansen , David Hildenbrand , Jiaxun Yang , linux-mips@vger.kernel.org, linux-mm@kvack.org, sparclinux@vger.kernel.org, Alexander Gordeev , Will Deacon , Thomas Gleixner , linux-arch@vger.kernel.org, Rob Herring , Vasily Gorbik , linux-sh@vger.kernel.org, Huacai Chen , Christophe Leroy , linux-acpi@vger.kernel.org, Ingo Molnar , devicetree@vger.kernel.org, Arnd Bergmann , linux-s390@vger.kernel.org, Heiko Carstens , Borislav Petkov , linux-cxl@vger.kernel.org, loongarch@lists.linux.dev, John Paul Adrian Glaubitz , Dan Williams , linux-arm-kernel@lists.infradead.org, Thomas Bogendoerfer , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , "Rafael J. Wysocki" , Andrew Morton , linuxppc-dev@lists.ozlabs.org, "David S. Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, 16 Jul 2024 14:13:35 +0300 Mike Rapoport wrote: > From: "Mike Rapoport (Microsoft)" > > Allocation of numa_distance uses memblock_phys_alloc_range() to limit > allocation to be below the last mapped page. > > But NUMA initializaition runs after the direct map is populated and initialization (one too many 'i's) > there is also code in setup_arch() that adjusts memblock limit to > reflect how much memory is already mapped in the direct map. > > Simplify the allocation of numa_distance and use plain memblock_alloc(). > This makes the code clearer and ensures that when numa_distance is not > allocated it is always NULL. Doesn't this break the comment in numa_set_distance() kernel-doc? " * If such table cannot be allocated, a warning is printed and further * calls are ignored until the distance table is reset with * numa_reset_distance(). " Superficially that looks to be to avoid repeatedly hitting the singleton bit at the top of numa_set_distance() as SRAT or similar parsing occurs. > > Signed-off-by: Mike Rapoport (Microsoft) > --- > arch/x86/mm/numa.c | 12 +++--------- > 1 file changed, 3 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c > index 5e1dde26674b..ab2d4ecef786 100644 > --- a/arch/x86/mm/numa.c > +++ b/arch/x86/mm/numa.c > @@ -319,8 +319,7 @@ void __init numa_reset_distance(void) > { > size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]); > > - /* numa_distance could be 1LU marking allocation failure, test cnt */ > - if (numa_distance_cnt) > + if (numa_distance) > memblock_free(numa_distance, size); > numa_distance_cnt = 0; > numa_distance = NULL; /* enable table creation */ > @@ -331,7 +330,6 @@ static int __init numa_alloc_distance(void) > nodemask_t nodes_parsed; > size_t size; > int i, j, cnt = 0; > - u64 phys; > > /* size the new table and allocate it */ > nodes_parsed = numa_nodes_parsed; > @@ -342,16 +340,12 @@ static int __init numa_alloc_distance(void) > cnt++; > size = cnt * cnt * sizeof(numa_distance[0]); > > - phys = memblock_phys_alloc_range(size, PAGE_SIZE, 0, > - PFN_PHYS(max_pfn_mapped)); > - if (!phys) { > + numa_distance = memblock_alloc(size, PAGE_SIZE); > + if (!numa_distance) { > pr_warn("Warning: can't allocate distance table!\n"); > - /* don't retry until explicitly reset */ > - numa_distance = (void *)1LU; > return -ENOMEM; > } > > - numa_distance = __va(phys); > numa_distance_cnt = cnt; > > /* fill with the default distances */