diff mbox series

[RFC,1/8] arm64: numa: Introduce a memory_add_physaddr_to_nid()

Message ID 20240529171236.32002-2-Jonathan.Cameron@huawei.com
State New, archived
Headers show
Series arm64/memblock: Handling of CXL Fixed Memory Windows. | expand

Commit Message

Jonathan Cameron May 29, 2024, 5:12 p.m. UTC
From: Dan Williams <dan.j.williams@intel.com>

Based heavily on Dan William's earlier attempt to introduce this
infrastruture for all architectures so I've kept his authorship. [1]

arm64 stores it's numa data in memblock. Add a memblock generic
way to interrogate that data for memory_Add_physaddr_to_nid.

Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Jia He <justin.he@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Link: https://lore.kernel.org/r/159457120334.754248.12908401960465408733.stgit@dwillia2-desk3.amr.corp.intel.com [1]
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 arch/arm64/include/asm/sparsemem.h |  4 ++++
 arch/arm64/mm/init.c               | 29 +++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

Comments

Yuquan Wang Aug. 1, 2024, 7:50 a.m. UTC | #1
On Wed, May 29, 2024 at 06:12:29PM +0100, Jonathan Cameron wrote:
> From: Dan Williams <dan.j.williams@intel.com>
> 
> Based heavily on Dan William's earlier attempt to introduce this
> infrastruture for all architectures so I've kept his authorship. [1]
> 
> arm64 stores it's numa data in memblock. Add a memblock generic
> way to interrogate that data for memory_Add_physaddr_to_nid.
> 
> Cc: Mike Rapoport <rppt@linux.ibm.com>
> Cc: Jia He <justin.he@arm.com>
> Cc: Will Deacon <will@kernel.org>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> Link: https://lore.kernel.org/r/159457120334.754248.12908401960465408733.stgit@dwillia2-desk3.amr.corp.intel.com [1]
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  arch/arm64/include/asm/sparsemem.h |  4 ++++
>  arch/arm64/mm/init.c               | 29 +++++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/arch/arm64/include/asm/sparsemem.h b/arch/arm64/include/asm/sparsemem.h
> index 8a8acc220371..8dd1b6a718fa 100644
> --- a/arch/arm64/include/asm/sparsemem.h
> +++ b/arch/arm64/include/asm/sparsemem.h
> @@ -26,4 +26,8 @@
>  #define SECTION_SIZE_BITS 27
>  #endif /* CONFIG_ARM64_64K_PAGES */
>  
> +#ifndef __ASSEMBLY__
> +extern int memory_add_physaddr_to_nid(u64 addr);
> +#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
> +#endif /* __ASSEMBLY__ */
>  #endif
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 9b5ab6818f7f..f310cbd349ba 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -48,6 +48,35 @@
>  #include <asm/alternative.h>
>  #include <asm/xen/swiotlb-xen.h>
>  
> +#ifdef CONFIG_NUMA
> +
> +static int __memory_add_physaddr_to_nid(u64 addr)
> +{
> +	unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
> +	int nid;
> +
> +	for_each_online_node(nid) {
> +		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
> +		if (pfn >= start_pfn && pfn <= end_pfn)
> +			return nid;
> +	}
> +	return NUMA_NO_NODE;
> +}
> +
> +int memory_add_physaddr_to_nid(u64 start)
> +{
> +	int nid = __memory_add_physaddr_to_nid(start);
> +
> +	/* Default to node0 as not all callers are prepared for this to fail */
> +	if (nid == NUMA_NO_NODE)
> +		return 0;
> +
> +	return nid;
> +}
> +EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
> +
> +#endif /* CONFIG_NUMA */
> +
>  /*
>   * We need to be able to catch inadvertent references to memstart_addr
>   * that occur (potentially in generic code) before arm64_memblock_init()
> -- 
> 2.39.2
>

Tested-off-by: Yuquan Wang <wangyuquan1236@phytium.com.cn>
diff mbox series

Patch

diff --git a/arch/arm64/include/asm/sparsemem.h b/arch/arm64/include/asm/sparsemem.h
index 8a8acc220371..8dd1b6a718fa 100644
--- a/arch/arm64/include/asm/sparsemem.h
+++ b/arch/arm64/include/asm/sparsemem.h
@@ -26,4 +26,8 @@ 
 #define SECTION_SIZE_BITS 27
 #endif /* CONFIG_ARM64_64K_PAGES */
 
+#ifndef __ASSEMBLY__
+extern int memory_add_physaddr_to_nid(u64 addr);
+#define memory_add_physaddr_to_nid memory_add_physaddr_to_nid
+#endif /* __ASSEMBLY__ */
 #endif
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 9b5ab6818f7f..f310cbd349ba 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -48,6 +48,35 @@ 
 #include <asm/alternative.h>
 #include <asm/xen/swiotlb-xen.h>
 
+#ifdef CONFIG_NUMA
+
+static int __memory_add_physaddr_to_nid(u64 addr)
+{
+	unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
+	int nid;
+
+	for_each_online_node(nid) {
+		get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
+		if (pfn >= start_pfn && pfn <= end_pfn)
+			return nid;
+	}
+	return NUMA_NO_NODE;
+}
+
+int memory_add_physaddr_to_nid(u64 start)
+{
+	int nid = __memory_add_physaddr_to_nid(start);
+
+	/* Default to node0 as not all callers are prepared for this to fail */
+	if (nid == NUMA_NO_NODE)
+		return 0;
+
+	return nid;
+}
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
+
+#endif /* CONFIG_NUMA */
+
 /*
  * We need to be able to catch inadvertent references to memstart_addr
  * that occur (potentially in generic code) before arm64_memblock_init()