From patchwork Tue Jul 23 06:41:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13739448 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 78938C3DA63 for ; Tue, 23 Jul 2024 06:46:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DE096B00B6; Tue, 23 Jul 2024 02:46:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 065906B00B8; Tue, 23 Jul 2024 02:46:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E22016B00B9; Tue, 23 Jul 2024 02:46:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BD91F6B00B6 for ; Tue, 23 Jul 2024 02:46:16 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 20CD841C9F for ; Tue, 23 Jul 2024 06:46:16 +0000 (UTC) X-FDA: 82370083152.28.0F3135A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf03.hostedemail.com (Postfix) with ESMTP id C9F5220018 for ; Tue, 23 Jul 2024 06:46:13 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ntd+jqKC; spf=pass (imf03.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=1721717112; 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=B56A3RFx4+8h26gV5w8yLOzvNYXFit95iiy/6g4/hcw=; b=P2/kB2dYxsMHv5jWAeWnsBsS4yaBYsTtst8meq9BEwmOFpj5EbqR5F3lW//+bPdBv+ggWV p5Hbvxt0xtiB8HbRxjRvtspSZPKtzaS3FFtYWwu5/7me8GKJwtHVAgD2xJ9tffP3vLJGhX kn4tBncVQgw+ti03sVkztal9l80wrcE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Ntd+jqKC; spf=pass (imf03.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=1721717112; a=rsa-sha256; cv=none; b=AiOw3D5LHQX++ubffgPqxCVNLR3fY4xV+6tQ0RqB1zGVoMvF4IxX2R6ju3DtrMg+X9uidX 8NUhwJ6sdelVeXP0/leUWRY5F+I798/NE26AlXTASydBgoSAQcZpHgxx6bIp4AIlknlFNH 80TQupG3daz2up4p9xe8Ts1+rpGGrfw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 3B21ECE0DA0; Tue, 23 Jul 2024 06:46:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F421C4AF09; Tue, 23 Jul 2024 06:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721717170; bh=kD57Jpdf1Sifrg0HuWEuP1eEmN5e3TwpoxqLH1SlKlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ntd+jqKCTeoDnExqCCdBPL7lv8CDP772xGvpJYnoZB3H1j5K4RaH1Pm3hR5MWjY2F mbNgHo/qOcYQJ2f3LkNpJ2aJhWE5NDhNohDv5Y9x7zkMfJqfewkRJCmGmr8Kt3hLHw QOlKJXxNpgbtrruPZxfNG/pJ+VzgN6ZMT7DkBpingearXPAtfb2U0n8SibZi/+LeH0 x/4CucxKu2uwRSNRBQsKuBvzPemwWatFIN+LX+NZa6PcrSDsTSMSIYm/V3ac/p/Nl+ iXzOBbWEJbd6omVeZW9TKKP/31EDm43NyeP/lxVBXrGVoR+lfACPRO3bnQTDaDngVg BbxVg2bri0umw== 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 v2 20/25] mm: numa_memblks: introduce numa_memblks_init Date: Tue, 23 Jul 2024 09:41:51 +0300 Message-ID: <20240723064156.4009477-21-rppt@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240723064156.4009477-1-rppt@kernel.org> References: <20240723064156.4009477-1-rppt@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C9F5220018 X-Stat-Signature: 4w8f3knigjai8fz8jbfghobixheggwik X-Rspam-User: X-HE-Tag: 1721717173-189383 X-HE-Meta: U2FsdGVkX18szJ4JdbIGiTxkzFV0AWlqnniuxgcl0ZwDeKIsuaRek7BhzJ2JAVIwASPlLZxZllZxVIsTt/MvKgm3ZAku5FxSuTj//2Yn5qQLixYUxRyem3tVWF6ZQd6usPwssV9zX5JztLfLaA4dpwSTkiN7MGZZN5DFSMiLKpUlvwPCOGHSS2nSS6uWUSCj+HToAeLI87mA7uQnZ8JB/RGvMCxqHxq1RCnqNkP3GH11ABsMXrs1gx/WqLdoIJ0BjtlDFeEXm4fQpSckXe2j++w7HYrrmtNSZtAb1YzE83x/5t3P4Rjzs5giMJ1nHyw6FtNW0t4qi6icIqaDLkdpLqY6BoypajBcvRGGiHh0F+01ljdFOEP217MpIKdnB7oEenMG11MS1GtOGIPp/TieHPUGwT8bZddce2vdyy1p8TQKbVkO2pOL387tVtACBuJobQeDGlmeP4w3sGCa1zvcZJdL/Fx+TKZ39/Dkr/xZfpqjW0wyNf721TKFVnd9JENINBJYiEsDIZO1Hmsbp4sbAfUVqH5m2ki5v5NC00ZykWZXGHat3zkj09zXoOvdaH0lbNQQBRWFCr1SseSwiewXHQ05AwKKFsTVx38vDgACyu4wEYnmmkdmVbVDs10SyuBmiBU6samw8wrA3cWxiL5eMy6IsVSY62u/QL0j2mLgAc/w2l/0dpFTdeGubIJGRMwDy5JhYFH/neNd/TKo4Id+VS/6wzJDgK33PNh7D8P31KWdFz3cI8pKXaDqwyEknRHbTXFnN+9zlDyFsL1RtMf0tf0S4/hRG/i/OjHpcSASxGSfePfkYvH02m3QnDNb/BNRoa6Xto1H2m0LieNUeJY8gmlMkacwIkziBLjDjjNkXSYYwJTLJYStRLGxEaVprBsYAAGm+DCyW2dAyY6amAqQFXTO1wU+jovujbs5nNRGI0NX/K70ZvQ5PbREuYmnVyEvVGUSQGuu1XAHUiimyuF z+w7EJvX Rth9tNlrsdejG8bY/bJxoCo15ytIvHtzckFMolbQFxfJhtEnPstTM3Iftj49UrevRDIfW9fq8PDbObcUj9pMLYKUF2V1zvpMykK3/lt4yRwwWwu0qJ9Puri9P4XPCJfVSmKidPqW3MTjTYYdyN+lH46rUXUtJaBI3CQwCuuFsHywMcvVbZWVMGFmlgHduKxd6Sg8BQ42l4yQewv4zY+6ok9LgAyFDWkRqUrjWST4QVDbZbsK58xQRJlLgk9/fJ9UoEVksgg5McDqkDqBuCGraqh95X9E58DpMvDfmdNZBk4+yQVWHfalDzpPhVUmdEf9y/h3i 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) --- 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;