From patchwork Tue Jul 23 06:41:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13739452 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 C0C18C3DA49 for ; Tue, 23 Jul 2024 06:47:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 571378D0003; Tue, 23 Jul 2024 02:47:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 521D28D0002; Tue, 23 Jul 2024 02:47:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C2638D0003; Tue, 23 Jul 2024 02:47:00 -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 1D95D8D0002 for ; Tue, 23 Jul 2024 02:47:00 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CB2471A1B42 for ; Tue, 23 Jul 2024 06:46:59 +0000 (UTC) X-FDA: 82370084958.28.D835B1B Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id 1FDCD2000A for ; Tue, 23 Jul 2024 06:46:57 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jgAoC+Hc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721717180; a=rsa-sha256; cv=none; b=MgHZ+cZWYENV11vBtdpMKj9x0kcxn8YylkMuI+Zmp2Z4b2xcwgUzR2VBPiZOUW+e55ONNw 6PpVvdU7GI3ONH8hiRmkaTrKWGElxZr4CHeVmbvIC7gBs2KKlFCFuKT3YNslooIGAop0PC /lqY+VMXaGXkiDA2H5+/HEarJAvMHVI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jgAoC+Hc; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721717180; 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=sV9LLs7WokxoWYOpX4a3m2YB0FWn3Fpsr1uVqrV41eg=; b=PKI98lwCnPDQy/WjgA6ONk/2UOl2IlaI0I64gqslGbtnszwZHn3lGvr5eemOiAC8BSgQ+T NNjXc9EIf/i5egzQHt5VUn/BwxO3dG0ZrLP1WBjTKJYw16jFPE4XCWTqQpHQUg/lgeS6oh 7iJyy9zvIXhjDPChvu88YYPbht8wuis= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 533B560D17; Tue, 23 Jul 2024 06:46:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDFFDC4AF12; Tue, 23 Jul 2024 06:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1721717217; bh=emeCYa9405g7/z24yhBWS68KWW8+Lb3s/YOK8bOaThI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgAoC+Hcal9bWK9k7ho6yBYf06kymWVllDUMPiOaeuFSG/wojxIxKcWyED4DoWkCl ZyPnLzk1UZksRbBGs+vwS6J3QRkp5NCWUyBtV2hPxbzh2xDsZ8HA+/i+k9yezOal8u zhjJSmaqAV92XU7hpKX6nY/kRVxDgU4f5bxdcxuLSfaiLoEIwLORtA6VE/d1oMTTUm Pqc1pcChaNRo/+GbV4+lfx2+t+YfKTxY+qn5wYaSZxtCRIZx8059ZX38rWfyX1IoPG OdZJdrg7fImaUDMXuKWgBftxFVlRAZKp9u8sSnRW4s39ogVzgJG0rOPKH30S5pFCFo G7ZwK7pI1cKjg== 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 v2 24/25] mm: make range-to-target_node lookup facility a part of numa_memblks Date: Tue, 23 Jul 2024 09:41:55 +0300 Message-ID: <20240723064156.4009477-25-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: rspam12 X-Rspamd-Queue-Id: 1FDCD2000A X-Stat-Signature: ck55h57r7isbmfct8u7y7d5iosm4gtmq X-Rspam-User: X-HE-Tag: 1721717217-942665 X-HE-Meta: U2FsdGVkX1+0m6DNuACti90fM0oN9rlXXDZGOBEjXz1Hr2N0GW8+VOnto40l0OBHzCvx5H08e/fKATfr5PxLDXn/vSdXppp04dWcyQi/rGuLlmoSth1W3p8VMhec69xcQzcwKsmCNQS8MpEtyvyhHn4AEnPrc4y3QO9+qrY0K/6SPGVDkkK+m6eZXzA0MW5Mz9KfRky4g+M1MGMcR3fFtyvDX+k6MnkSiUe7aQsL4YBTWdD746MB1DtalowTqoKb51Ax9BHWZvcJwHAbYI6mZgUmY/5yVC3qhusaMcOpjb9JFp2iZ8Lclbo+H4GAU0dobtCCJZjzScgJRALhUC5/gfo8Qy6go+u6i27C2H8XJDmutgszMTw71FiLoyZNHM9puzWy7tcGZ65rSOFBWivrNfuu7v/w2qnH/Wub324mmF1WGRA4jPq2Gdcuy8f/YGBiCVafLPJ7dxW9qMWCfBp9GBLw2PlqY0+k2rnmp8gb6RNSZdmeb7q6wxq7mfUJPAjCBj9A9W3d9NEYT1DB96kCrE676834iMdzm+BQ+GbYvi6bCvW7zqjrNln5V52nX8imQgioFv5AWdeQu25KTezb6Ue0Bk1Lp6HD8FPVHWs1PTfLnHhePMYNZz8krkZznMcQgJMq6K4szD3FpyL5heYiqpP8YoQGcrPY00pw/GFy8ikAbljrIeKj9rgA8M4PkKhmBC9XPsgHKphHPeV7ceO481QtSc+YSvt3XZHlwrZYf207Fy2hkQaB79eVymhzgIM+/XlKp1IfXMf3GKDMNWCD0+toHxl7AzmLQk5uHP7FBOoYdz/+xc9iXcMk0/yBvVLZisYwOOUKudEJswB5OU7/0Dgzs74Ir+ehie1Hgz6iL+ZkT+d+cDkl8ULfYfFGWKzcIT9YthUjmCPunCuyMOLpyMj3sXJiqqGm5lLdn+yH1A9oIAShhCv+/Bri/h3wXdNH6T7zOfhHOYLqS3yzTOs rXGJsR+a KD/bZjyuc7ALIY4g8EbujFlvYPUQE+5njjdPSDyhfsMjEOn0skHcgCAqgXeSoUitbY501/OftBQ4oqZC/5B4piLC6opVlfjSvqOn0VrB3v2J1k3w52IRRY9PATJtoLiy5hwdKzu1KceXQbEi/0FSpPVS/awx4DnZfxbg9jl8D0C3DMZy+VuComWHcjeLLmNI+vGh0OIByLPcxR2Vgu+pvgAB0p5I2Ym9YNcGHf7W3BvMMEzc5UcqgZm4QXqOfn4rvqOEbM5KhXHpFtABJ/vpjGEt4FjqtqfmrITd8jjQ30JM72pSmmfmpZPpgLOakTYBUynGKee6368+ZVVKWbRWKdl2qRVF1eNKMDW8P 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 --- 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 */