From patchwork Thu Aug 1 06:08:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13749758 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 E12A4C3DA64 for ; Thu, 1 Aug 2024 06:13:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63B686B00C2; Thu, 1 Aug 2024 02:13:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5EAD96B00C4; Thu, 1 Aug 2024 02:13:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 465056B00C5; Thu, 1 Aug 2024 02:13:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1EB166B00C2 for ; Thu, 1 Aug 2024 02:13:42 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CD48FC0749 for ; Thu, 1 Aug 2024 06:13:41 +0000 (UTC) X-FDA: 82402660242.14.FB28762 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 2BDEF40018 for ; Thu, 1 Aug 2024 06:13:40 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SwRgUpUT; spf=pass (imf07.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=1722492764; 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=beSa2ytw03vDtMUwO44+OPbO35DnjhtJo4a2n5sRPP0=; b=tsZlYifCK0Ms9G2KClLQnYDG9e3IWQruIxhjX09pUybC+xaQliJLyYot04vZtgWXCfzoJr icj5HA3Q4d+3myjMwHBodcPALhMEbnORPptHe4Znu5lB/0QX+7ud2DyA3S+KNHtIKKmIh2 yiB/SFqeB+/4wwRfUHzY8RH2v78FcRM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722492764; a=rsa-sha256; cv=none; b=nxn1/ED3UJ684PrYIG4Ycl76rCeW/Me6BypJp+n23ULLJmjA1IKx9o5SVhAO1Cm8xy6Qod 7o748XmyN9VKuUvtw0Cc9InQbz+DbmPpM5aiVqRXq4bAZ+eryphFhDUpnN2fi9bVvtwX6L 1EUPiOqruXici0yV1XMc2pwU27EIn8s= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=SwRgUpUT; spf=pass (imf07.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 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 5E0476140C; Thu, 1 Aug 2024 06:13:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C93C9C4AF09; Thu, 1 Aug 2024 06:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722492819; bh=0axTSQ1nxfv7D2ZG6wVeXqDKtmMcvnEWpPqy/9HH1Dc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SwRgUpUTHSOGIldRInVeyCqw6m80FayJa3sU+7J4u7V5TbZwPWPsgG+eYe3gM1J3i KCO0CT47JVeiIbo3tNqDb6wQ9CawD5AQVmdlKLyJIOfgjBi60mrNlsEGUGLf+3w3o8 KT8AztBWuT1E6ZDQTEXkforNio3hhU3Cz6dWl8H+F/BO8cjctRqCFk5UWzb0qWBdbD OQkLeE7uqwXRDiiFSipOue9T4zSE/ClH3dexHbfGIBEXJXopbAT3hINNtGN5HDNyu/ Db00sxmjRdAnze9D6TYdtzsY3ajT+qwjcwzZZy+T4mv+CqIrSf+byLBfVVSSVDuFSE rMH52h/Xye5cQ== 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, Jonathan Cameron Subject: [PATCH v3 25/26] mm: make range-to-target_node lookup facility a part of numa_memblks Date: Thu, 1 Aug 2024 09:08:25 +0300 Message-ID: <20240801060826.559858-26-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-Rspamd-Queue-Id: 2BDEF40018 X-Stat-Signature: akwhsexr59yhoaaoyczx1o85enfsw618 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722492820-12830 X-HE-Meta: U2FsdGVkX1+Y7QSexYMy9EucTCpWbxq03ae1TLR4vWRiD0A/o23Q+AHdOSofgXTkh5idnJxYjUyq2ro95mEnayAcEIwjYxfqAnmK35mKCUmC+WobTuVj2j7RM5BPh78Fy7ZnhsOaMw1dKmDG7kdw8Eys/T6iQQvAffaq4buAgn1z/6Si/TRRGI+EyDUnxZUB06g9l9Sg77DXX1BPPh8uJWbMigzB6gFJqwV6Kx3inPi3k0gmGxOZl96x4uXZ+vCYv+RrndonH1LOlgI6ew0GkvMR8mmle/Q869q9+iXnD4IbleD2F4k14SmYAR7oAc5wfBJqIeSVEcurRlqdsavz4pAbYWvx7PfVKXg48/XkmlHpPnoDCT+tNi46vDtUK4vUidoVgbaubmX9eAGovlBD5mk3vqhx2R4rcjOKsBDSCUCghjaNp6V1sd6VVvljzESOR7Z4kwskaW6H/JSfDu+AFjSIyz3PfcVL+bjc65ihOhLJsSApLBPFTkiUQu7ebjePvJ9iL4JZBFAreMOfDaHmEp4ZXhaI0YAhCjkEWMJqcYtAU1zLMIZMMixtHfrUaI9iKAdKs69SJ3Le6t/zv+slYb5miQqhoStffnpJG4g74KXYKC+kpGlTUU7Jb6EdTZkIqdur5Rb6FAhKiE2ace3shPw3ypcQizP7NeqyClS0IMDvjFTaLFf2RfsiqsZRzodfyrcK+QGLPWjGbMHLdbNJOCtxnVx6P9wG+KEQ7mNnsbAjOcQ4sz8u2O3f5+8uG36AP+x33EPVVuMtM/4AZgUK7Fde8NqnIfYPXvqSzOjeMqTCwEQxSV5dpjbbTzrOINhuD0WKIrujo95abPtvvLwPR8aiHRJosZ1G6t1F5oYQmi4KUn2ylOg3cUH5gX+sA+PWWSWR6qvpdIy4YOObooIXh1t2ltRyGW5MRU12wwcKEl57xvIXF7G1BdkRmG/++S5ZWfbJezD8wnk+/27ronu 9TodRiXq VEOMcmzCzNtzQ+6m3qcRzsrH/bcqmNtzeLgsoP0r2QYg5UT18keHemetE/7XUS0DAIt4CLqKTQvOM/MaWePKb15fyWgAUr0IZZNm/atrFZO8Wy8GtToC2umc0GBsGNNsxJvX7rAplJscuSFyaGsxSaEYRqS8yp+SjJyB1jxUOwhzBehOCxThXxbEK0wq7QAaS2r21rf22JaO+e64NDvBD2IJuGEPWTtLUArct5C0Bu1uliJQAW5TfFcbowx9WpVLRsQdRm5SIS84/oR4tLHzJOgJYu56T8dnqUuAi717FQaKftrf5Pg+DZiVG/3KTY+xCpjOAJi6hfu/aTdyBqrmL8acN7vC3wrM/oDJRC0rBQ+8IEprYEjQZnzU+cg== 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)" The x86 implementation of range-to-target_node lookup (i.e. phys_to_target_node() and memory_add_physaddr_to_nid()) relies on numa_memblks. Since numa_memblks are now part of the generic code, move these functions from x86 to mm/numa_memblks.c and select CONFIG_NUMA_KEEP_MEMINFO when CONFIG_NUMA_MEMBLKS=y for dax and cxl. Signed-off-by: Mike Rapoport (Microsoft) Reviewed-by: Jonathan Cameron Tested-by: Zi Yan # for x86_64 and arm64 Reviewed-by: Dan Williams Acked-by: David Hildenbrand --- arch/x86/include/asm/sparsemem.h | 9 -------- arch/x86/mm/numa.c | 38 -------------------------------- drivers/cxl/Kconfig | 2 +- drivers/dax/Kconfig | 2 +- include/linux/numa_memblks.h | 7 ++++++ mm/numa.c | 1 + mm/numa_memblks.c | 38 ++++++++++++++++++++++++++++++++ 7 files changed, 48 insertions(+), 49 deletions(-) diff --git a/arch/x86/include/asm/sparsemem.h b/arch/x86/include/asm/sparsemem.h index 64df897c0ee3..3918c7a434f5 100644 --- a/arch/x86/include/asm/sparsemem.h +++ b/arch/x86/include/asm/sparsemem.h @@ -31,13 +31,4 @@ #endif /* CONFIG_SPARSEMEM */ -#ifndef __ASSEMBLY__ -#ifdef CONFIG_NUMA_KEEP_MEMINFO -extern int phys_to_target_node(phys_addr_t start); -#define phys_to_target_node phys_to_target_node -extern int memory_add_physaddr_to_nid(u64 start); -#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid -#endif -#endif /* __ASSEMBLY__ */ - #endif /* _ASM_X86_SPARSEMEM_H */ diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 16bc703c9272..8e790528805e 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -449,41 +449,3 @@ u64 __init numa_emu_dma_end(void) return PFN_PHYS(MAX_DMA32_PFN); } #endif /* CONFIG_NUMA_EMU */ - -#ifdef CONFIG_NUMA_KEEP_MEMINFO -static int meminfo_to_nid(struct numa_meminfo *mi, u64 start) -{ - int i; - - for (i = 0; i < mi->nr_blks; i++) - if (mi->blk[i].start <= start && mi->blk[i].end > start) - return mi->blk[i].nid; - return NUMA_NO_NODE; -} - -int phys_to_target_node(phys_addr_t start) -{ - int nid = meminfo_to_nid(&numa_meminfo, start); - - /* - * Prefer online nodes, but if reserved memory might be - * hot-added continue the search with reserved ranges. - */ - if (nid != NUMA_NO_NODE) - return nid; - - return meminfo_to_nid(&numa_reserved_meminfo, start); -} -EXPORT_SYMBOL_GPL(phys_to_target_node); - -int memory_add_physaddr_to_nid(u64 start) -{ - int nid = meminfo_to_nid(&numa_meminfo, start); - - if (nid == NUMA_NO_NODE) - nid = numa_meminfo.blk[0].nid; - return nid; -} -EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); - -#endif diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig index 99b5c25be079..29c192f20082 100644 --- a/drivers/cxl/Kconfig +++ b/drivers/cxl/Kconfig @@ -6,7 +6,7 @@ menuconfig CXL_BUS select FW_UPLOAD select PCI_DOE select FIRMWARE_TABLE - select NUMA_KEEP_MEMINFO if (NUMA && X86) + select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS help CXL is a bus that is electrically compatible with PCI Express, but layers three protocols on that signalling (CXL.io, CXL.cache, and diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig index a88744244149..d656e4c0eb84 100644 --- a/drivers/dax/Kconfig +++ b/drivers/dax/Kconfig @@ -30,7 +30,7 @@ config DEV_DAX_PMEM config DEV_DAX_HMEM tristate "HMEM DAX: direct access to 'specific purpose' memory" depends on EFI_SOFT_RESERVE - select NUMA_KEEP_MEMINFO if (NUMA && X86) + select NUMA_KEEP_MEMINFO if NUMA_MEMBLKS default DEV_DAX help EFI 2.8 platforms, and others, may advertise 'specific purpose' diff --git a/include/linux/numa_memblks.h b/include/linux/numa_memblks.h index 5c6e12ad0b7a..17d4bcc34091 100644 --- a/include/linux/numa_memblks.h +++ b/include/linux/numa_memblks.h @@ -46,6 +46,13 @@ static inline int numa_emu_cmdline(char *str) } #endif /* CONFIG_NUMA_EMU */ +#ifdef CONFIG_NUMA_KEEP_MEMINFO +extern int phys_to_target_node(phys_addr_t start); +#define phys_to_target_node phys_to_target_node +extern int memory_add_physaddr_to_nid(u64 start); +#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid +#endif /* CONFIG_NUMA_KEEP_MEMINFO */ + #endif /* CONFIG_NUMA_MEMBLKS */ #endif /* __NUMA_MEMBLKS_H */ diff --git a/mm/numa.c b/mm/numa.c index 67a0d7734a98..da27eb151dc5 100644 --- a/mm/numa.c +++ b/mm/numa.c @@ -3,6 +3,7 @@ #include #include #include +#include struct pglist_data *node_data[MAX_NUMNODES]; EXPORT_SYMBOL(node_data); diff --git a/mm/numa_memblks.c b/mm/numa_memblks.c index e4358ad92233..8609c6eb3998 100644 --- a/mm/numa_memblks.c +++ b/mm/numa_memblks.c @@ -528,3 +528,41 @@ int __init numa_fill_memblks(u64 start, u64 end) } return 0; } + +#ifdef CONFIG_NUMA_KEEP_MEMINFO +static int meminfo_to_nid(struct numa_meminfo *mi, u64 start) +{ + int i; + + for (i = 0; i < mi->nr_blks; i++) + if (mi->blk[i].start <= start && mi->blk[i].end > start) + return mi->blk[i].nid; + return NUMA_NO_NODE; +} + +int phys_to_target_node(phys_addr_t start) +{ + int nid = meminfo_to_nid(&numa_meminfo, start); + + /* + * Prefer online nodes, but if reserved memory might be + * hot-added continue the search with reserved ranges. + */ + if (nid != NUMA_NO_NODE) + return nid; + + return meminfo_to_nid(&numa_reserved_meminfo, start); +} +EXPORT_SYMBOL_GPL(phys_to_target_node); + +int memory_add_physaddr_to_nid(u64 start) +{ + int nid = meminfo_to_nid(&numa_meminfo, start); + + if (nid == NUMA_NO_NODE) + nid = numa_meminfo.blk[0].nid; + return nid; +} +EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid); + +#endif /* CONFIG_NUMA_KEEP_MEMINFO */