From patchwork Tue Jul 16 11:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13734333 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EA36C3DA49 for ; Tue, 16 Jul 2024 11:15:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CFB86B009A; Tue, 16 Jul 2024 07:15:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 980A16B009B; Tue, 16 Jul 2024 07:15:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8473E6B009C; Tue, 16 Jul 2024 07:15:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6781B6B009A for ; Tue, 16 Jul 2024 07:15:10 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 198534052D for ; Tue, 16 Jul 2024 11:15:10 +0000 (UTC) X-FDA: 82345359180.07.9480848 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf20.hostedemail.com (Postfix) with ESMTP id 45B631C0030 for ; Tue, 16 Jul 2024 11:15:08 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eUYe44Ch; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721128478; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=P1YS+euSMVkpWWJuwys7wR1kvUQs2d7FUlc59UK+jLs=; b=nUPgFpo/fik7f7OcgKw6uk+6LzMRTGi+uYlyiOlj/S65zLBiCRHJMhf404J/bCQtg3/tvc UH0JbxjZJZpcuXQnyQEp2FUdoTrwBxzqh8/dE9yipp+aalgJbJ37GJjIupM/2m6diY0WFe 9kY1MXRE4GEn9sAHrMTzWjt1/z5GgCA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=eUYe44Ch; spf=pass (imf20.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721128478; a=rsa-sha256; cv=none; b=fN7C2f87DXX1RkVw40aJCnhsoWzdeSjOdF06R6VhHuS+nb0zRwJpP2j3rtMxXbn0stHXaR MfMOYPOqSuyuYulGIWV3Nq2V8mS4uyJIlXDM9RX4Q3YBJ84BNEniWcCBPEoY67soDC+TFB Bu1A7xhkiQ60NjLBw/+sPlwJ1lHZZTM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7886460B9F; Tue, 16 Jul 2024 11:15:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DCECC116B1; Tue, 16 Jul 2024 11:14:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721128507; bh=GElWHq2qRIT8py39Ko6uJRewjseLB9ydLgZveNWdQ+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eUYe44ChrhAY+EIKXqRBxJW/GGnRiqr4keNuzA8k+5ofeJ4HBvR/n8QM0J61no1f2 abiQBz3/QII7idJTs0afg3rMGY90A9xGmtBhYCNbiK9q4iubegCmxJf7NrcoovNvKG qQRxvsWN8oXJMXkni0JawCEhHK8wA6sAxUA+cca/xtj4Q9hkmUftsVcp/KiDWJ6cLF 921Vh4BmVDEODNmwHfRepZDaSRiM/CEFqWbhNtHQKO/A34nitM0llJ5YCV7ixvsAcB JHNcrvbEtQV/XUjf4mxX16sZ1+VCT2rSdlrKQOTKpNfcPTqTHU8isN0T/2V75O32aW WPUTqww3gzW2A== From: Mike Rapoport To: linux-kernel@vger.kernel.org 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 , Jonathan Cameron , Michael Ellerman , Mike Rapoport , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Will Deacon , linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: [PATCH 06/17] x86/numa: simplify numa_distance allocation Date: Tue, 16 Jul 2024 14:13:35 +0300 Message-ID: <20240716111346.3676969-7-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240716111346.3676969-1-rppt@kernel.org> References: <20240716111346.3676969-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: k841wwpzug4st4b1hopi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wwN6 2+vZbMK/GZVBnTMtd2KzZnAsNY6n8zANUIJzHZx2X5++T8Z+OwnE+JMxLfKeRkNohPa/XMLeq/bzoTv0VakVBY/rJLJOOoac6ZlyOnrfVjZ9J3SMhLOCWYeNh2npBN11iu4igXQP8uhW+V0Ct1YMkKbBLiQJnDcwMrZux1lRqLCvztQhZdZNcD6kQPQ563xBcKsay4uhpx4PY33jVBE9PgmbXVcay4MF+tLXNMoiCLEyx3yEj7YFEAFqT+sSUrWeeZgtNK8dadHgnwC7HQ7gvBZpsmU1furBzLpGT 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: List-Subscribe: List-Unsubscribe: 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 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. 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 */