From patchwork Thu Aug 1 06:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13749753 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 AE4A3C3DA64 for ; Thu, 1 Aug 2024 06:12:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F09E6B008A; Thu, 1 Aug 2024 02:12:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3519C6B00A3; Thu, 1 Aug 2024 02:12:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AEB66B00A7; Thu, 1 Aug 2024 02:12:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E45506B008A for ; Thu, 1 Aug 2024 02:12:47 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A20BC1A086E for ; Thu, 1 Aug 2024 06:12:47 +0000 (UTC) X-FDA: 82402657974.30.3BEF294 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 47FDF4001F for ; Thu, 1 Aug 2024 06:12:44 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cM+9PrKx; spf=pass (imf01.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1722492721; 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=6L11AkWXzvzFvLqi5aeDLEwHRjun9uu1ZDZpDd9A4CM=; b=yyxHiJQIw8kb0JxDZOUQg7H6KCH1hXfdR/eSWQtSCAtxJ0fmAheg012mBIzTYarG5FqOP5 4EnZRNwZR8sPZFGsjLpLtVs58KokYMsdwEGZa8tJJCV/63PvcMmJqCGRtBvKPsu3BnpIa0 EhMv7GPMj/Z7hB+pi42n9heyH3o2aio= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cM+9PrKx; spf=pass (imf01.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 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=1722492721; a=rsa-sha256; cv=none; b=B9zm3hi4FgtH29vNp+l/+5TgT4UALySkiqAFm1Ph0do+NR2LbhT4o7seh+bVzbg10crH9O 9MLhn2Z/14JXY3QH1LGRme2w2728+7TRIMVNhpMfjLILj4J2JluxVQa1FXY355MRRmuZPD fD0ftCpmkHR+7lzd3nyBNSrcFTwDPrs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id EC673CE1802; Thu, 1 Aug 2024 06:12:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AED7C4AF09; Thu, 1 Aug 2024 06:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722492761; bh=B9e+Vd7n2gq8wb2Fh7KBYHmuFxFa1foqgAS054Jbgm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cM+9PrKx9YzehJ5LjHBDoW2YtM/B15bwu3McVI62IfdyXscxPeo0HrtLEBaWMjQ5p HIQOodTGXKYIB4eQ5R1NoHMMvwzOP97BZTThg3CMbUj5vQ6cFIyj6EMGhDUFNgOvKu oTOZqCnfajcH/aPpC10wLy4Qc6v2xhpsLDiB3lXsjiVPx9njslGver0boDogOuHWWm d2AaXAMfINeqUYABkdOTthBNZpsQWO6gprMUXNlIQQf/YDvcT8CsvZITx/LyC+F6Xy umjL3iUOG1zg+qLbCCc9lk1wpSl6KSHpF3ZosnJOIR8SqsgJuRBIPE4+tl8qB4n0pc EfT3heZmT2ucg== 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" , Davidlohr Bueso , Greg Kroah-Hartman , Heiko Carstens , Huacai Chen , Ingo Molnar , Jiaxun Yang , John Paul Adrian Glaubitz , Jonathan Cameron , Jonathan Corbet , Michael Ellerman , Mike Rapoport , Palmer Dabbelt , "Rafael J. Wysocki" , Rob Herring , Samuel Holland , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Will Deacon , Zi Yan , devicetree@vger.kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cxl@vger.kernel.org, linux-doc@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, nvdimm@lists.linux.dev, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v3 20/26] mm: numa_memblks: introduce numa_memblks_init Date: Thu, 1 Aug 2024 09:08:20 +0300 Message-ID: <20240801060826.559858-21-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240801060826.559858-1-rppt@kernel.org> References: <20240801060826.559858-1-rppt@kernel.org> MIME-Version: 1.0 X-Stat-Signature: acwcpey4jhcstmfubdriop7mfgxd5sta X-Rspam-User: X-Rspamd-Queue-Id: 47FDF4001F X-Rspamd-Server: rspam02 X-HE-Tag: 1722492764-5291 X-HE-Meta: U2FsdGVkX1+6l3CwDWHbPs2oYYdSYWXGKUhDr9boQHwrBd3UnjfBaJNVHU+LBM6ptETe7LgwkrvdBkknLsswNQD8n7lVuS0OSd+4XaoddUjE3YS2aeyeeqrocWMKxG8sKCI5kakckY2rQtd+9H5gqW82UtjluQgA38tQeaKmgbSfayJK8HQcz2XL/v7yHbUadk81Rv9dLR5XgVMeYWCdmCe09bkJsRIp9NVVOJGTcD274Vzo2q9Im/x54kSr8S+FqUVI7wW5VzVP7lCNd2dxx5PczoaCdLvzfp7CnBcWmrKvI2U0hyWehZFndWByY9DPaND4nKMaPAoBdzXG8adHnHuWMmKIeKxJ43UbtaWxeIu6PgdBwPR/amKpCL7FsxtP5wy5PYqbl4CeL/xqiyUOpLgXhEod0YfyPZyfeb+Eae0YQTy5hjzoYl9fTxaTwXE2xeoit17FBP/Og0TGb5m6+/0i4Oxu2hGMgftVDnVy2ICeclsr84odf1z8LVoKVBTtCIJUI2VmiMsvj4DjwF2OuRAtg+NO2bogVqzYXcGYoaRUZxBcVfWAu2H6aWdCO1+a37W7rA4yc9pOv3uG7OmYCkylTZoVq+vmUDXQndzDDrtLJyX6zccQgCud6NRoARVp5FcqnXB2eFM/EgWMhTFLrzf7YyG/eYwte34UQjnEU135OlaDimHpjm+lOCvkCFN7T3JXVX5SUcsRNR0SlZOyjhIW9AmA7d9bFDk3RePsH8F+QnMCY1GiM+KvrsB3BokenMK+LulSqaoC8DomGJfwif40jN037j2Yu+YPAksVYOLZXHJwkckjujXSTzDUc6r0LN3q87NU+WiLtSZuMwpCfdGzpbzdWb7YueybxGANm9i3fBXFuCoA5iii5pvG3GjrGQJiR7rWbDB0QS+Q0gFV0D8ZNAkNh8Q+ole9m2tFYgLe3RNiUyClOZCFqK5W7VryA5vXaHlzSU4RNfyJWoB hl99O4JH gTqwejuuU2VoaXxouzSMhBlPrqXcZZ+h8nmliXorPxE1L2rFV94XdL+sOr+Zx5XUZw5eHcJSv3foXmOINpEQQPysYQdFD/mw/fIZwdPj4OMVIck5BROIULojR5M1avAelo6mOsti/ln4arcvZQsT8D6tIroUfBtdFADkGSaqabFl8XVf8VINQDnZNZ1+DrpxHAYx0WhPWfGKweM22JjmciSUQU9sezpW/MU5G0icobCTD1EGcGfp+ipEeHDSVKusM2+vAu0a5MrZ+M44O3wKMkuMAweeuvNm0yXVmmxq5w4LOhnIz3Wl+muDVqyoIFP3HVBxQ7Aet1YSClbzxOoNlD8rzU13K2hC/nJvc 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)" Move most of x86::numa_init() to numa_memblks so that the latter will be more self-contained. With this numa_memblk data structures should not be exposed to the architecture specific code. Signed-off-by: Mike Rapoport (Microsoft) Tested-by: Zi Yan # for x86_64 and arm64 Reviewed-by: Jonathan Cameron Acked-by: David Hildenbrand --- arch/x86/mm/numa.c | 40 ++++------------------------------- include/linux/numa_memblks.h | 3 +++ mm/numa_memblks.c | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 36 deletions(-) diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 8eb15578625e..16bc703c9272 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -115,13 +115,9 @@ void __init setup_node_to_cpumask_map(void) pr_debug("Node to cpumask map for %u nodes\n", nr_node_ids); } -static int __init numa_register_memblks(struct numa_meminfo *mi) +static int __init numa_register_nodes(void) { - int nid, err; - - err = numa_register_meminfo(mi); - if (err) - return err; + int nid; if (!memblock_validate_numa_coverage(SZ_1M)) return -EINVAL; @@ -171,39 +167,11 @@ static int __init numa_init(int (*init_func)(void)) for (i = 0; i < MAX_LOCAL_APIC; i++) set_apicid_to_node(i, NUMA_NO_NODE); - nodes_clear(numa_nodes_parsed); - nodes_clear(node_possible_map); - nodes_clear(node_online_map); - memset(&numa_meminfo, 0, sizeof(numa_meminfo)); - WARN_ON(memblock_set_node(0, ULLONG_MAX, &memblock.memory, - NUMA_NO_NODE)); - WARN_ON(memblock_set_node(0, ULLONG_MAX, &memblock.reserved, - NUMA_NO_NODE)); - /* In case that parsing SRAT failed. */ - WARN_ON(memblock_clear_hotplug(0, ULLONG_MAX)); - numa_reset_distance(); - - ret = init_func(); + ret = numa_memblks_init(init_func, /* memblock_force_top_down */ true); if (ret < 0) return ret; - /* - * We reset memblock back to the top-down direction - * here because if we configured ACPI_NUMA, we have - * parsed SRAT in init_func(). It is ok to have the - * reset here even if we did't configure ACPI_NUMA - * or acpi numa init fails and fallbacks to dummy - * numa init. - */ - memblock_set_bottom_up(false); - - ret = numa_cleanup_meminfo(&numa_meminfo); - if (ret < 0) - return ret; - - numa_emulation(&numa_meminfo, numa_distance_cnt); - - ret = numa_register_memblks(&numa_meminfo); + ret = numa_register_nodes(); if (ret < 0) return ret; diff --git a/include/linux/numa_memblks.h b/include/linux/numa_memblks.h index f81f98678074..07381320848f 100644 --- a/include/linux/numa_memblks.h +++ b/include/linux/numa_memblks.h @@ -34,6 +34,9 @@ int __init numa_register_meminfo(struct numa_meminfo *mi); void __init numa_nodemask_from_meminfo(nodemask_t *nodemask, const struct numa_meminfo *mi); +int __init numa_memblks_init(int (*init_func)(void), + bool memblock_force_top_down); + #ifdef CONFIG_NUMA_EMU int numa_emu_cmdline(char *str); void __init numa_emu_update_cpu_to_node(int *emu_nid_to_phys, diff --git a/mm/numa_memblks.c b/mm/numa_memblks.c index e3c3519725d4..7749b6f6b250 100644 --- a/mm/numa_memblks.c +++ b/mm/numa_memblks.c @@ -415,6 +415,47 @@ int __init numa_register_meminfo(struct numa_meminfo *mi) return 0; } +int __init numa_memblks_init(int (*init_func)(void), + bool memblock_force_top_down) +{ + int ret; + + nodes_clear(numa_nodes_parsed); + nodes_clear(node_possible_map); + nodes_clear(node_online_map); + memset(&numa_meminfo, 0, sizeof(numa_meminfo)); + WARN_ON(memblock_set_node(0, ULLONG_MAX, &memblock.memory, + NUMA_NO_NODE)); + WARN_ON(memblock_set_node(0, ULLONG_MAX, &memblock.reserved, + NUMA_NO_NODE)); + /* In case that parsing SRAT failed. */ + WARN_ON(memblock_clear_hotplug(0, ULLONG_MAX)); + numa_reset_distance(); + + ret = init_func(); + if (ret < 0) + return ret; + + /* + * We reset memblock back to the top-down direction + * here because if we configured ACPI_NUMA, we have + * parsed SRAT in init_func(). It is ok to have the + * reset here even if we did't configure ACPI_NUMA + * or acpi numa init fails and fallbacks to dummy + * numa init. + */ + if (memblock_force_top_down) + memblock_set_bottom_up(false); + + ret = numa_cleanup_meminfo(&numa_meminfo); + if (ret < 0) + return ret; + + numa_emulation(&numa_meminfo, numa_distance_cnt); + + return numa_register_meminfo(&numa_meminfo); +} + static int __init cmp_memblk(const void *a, const void *b) { const struct numa_memblk *ma = *(const struct numa_memblk **)a;