diff mbox series

[RFC,6/8] arm64: mm: numa_fill_memblks() to add a memblock.reserved region if match.

Message ID 20240529171236.32002-7-Jonathan.Cameron@huawei.com (mailing list archive)
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
CXL memory hotplug relies on additional NUMA nodes being created
for any CXL Fixed Memory Window if there is no suitable one created
by system firmware. To detect if system firmware has created one look
for any normal memblock that overlaps with the Fixed Memory Window that
has a NUMA node (nid) set.

If one is found, add a region with the same nid to memblock.reserved
so we can match it later when CXL memory is hotplugged.
If not, add a region anyway because a suitable NUMA node will be
set later. So for now use NUMA_NO_NODE.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 arch/arm64/mm/init.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Yuquan Wang Aug. 1, 2024, 7:54 a.m. UTC | #1
On Wed, May 29, 2024 at 06:12:34PM +0100, Jonathan Cameron wrote:
> CXL memory hotplug relies on additional NUMA nodes being created
> for any CXL Fixed Memory Window if there is no suitable one created
> by system firmware. To detect if system firmware has created one look
> for any normal memblock that overlaps with the Fixed Memory Window that
> has a NUMA node (nid) set.
> 
> If one is found, add a region with the same nid to memblock.reserved
> so we can match it later when CXL memory is hotplugged.
> If not, add a region anyway because a suitable NUMA node will be
> set later. So for now use NUMA_NO_NODE.
> 
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  arch/arm64/mm/init.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
> index 6a2f21b1bb58..27941f22db1c 100644
> --- a/arch/arm64/mm/init.c
> +++ b/arch/arm64/mm/init.c
> @@ -50,6 +50,32 @@
>  
>  #ifdef CONFIG_NUMA
>  
> +/*
> + * Scan existing memblocks and if this region overlaps with a region with
> + * a nid set, add a reserved memblock.
> + */
> +int __init numa_fill_memblks(u64 start, u64 end)
> +{
> +	struct memblock_region *region;
> +
> +	for_each_mem_region(region) {
> +		int nid = memblock_get_region_node(region);
> +
> +		if (nid == NUMA_NO_NODE)
> +			continue;
> +		if (!(end < region->base || start >= region->base + region->size)) {
> +			memblock_add_reserved_node(start, end - start, nid,
> +						   MEMBLOCK_RSRV_NOINIT);
> +			return 0;
> +		}
> +	}
> +
> +	memblock_add_reserved_node(start, end - start, NUMA_NO_NODE,
> +				   MEMBLOCK_RSRV_NOINIT);
> +
> +	return NUMA_NO_MEMBLK;
> +}
> +
>  static int __memory_add_physaddr_to_nid(u64 addr)
>  {
>  	unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);
> -- 
> 2.39.2
>

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

Patch

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 6a2f21b1bb58..27941f22db1c 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -50,6 +50,32 @@ 
 
 #ifdef CONFIG_NUMA
 
+/*
+ * Scan existing memblocks and if this region overlaps with a region with
+ * a nid set, add a reserved memblock.
+ */
+int __init numa_fill_memblks(u64 start, u64 end)
+{
+	struct memblock_region *region;
+
+	for_each_mem_region(region) {
+		int nid = memblock_get_region_node(region);
+
+		if (nid == NUMA_NO_NODE)
+			continue;
+		if (!(end < region->base || start >= region->base + region->size)) {
+			memblock_add_reserved_node(start, end - start, nid,
+						   MEMBLOCK_RSRV_NOINIT);
+			return 0;
+		}
+	}
+
+	memblock_add_reserved_node(start, end - start, NUMA_NO_NODE,
+				   MEMBLOCK_RSRV_NOINIT);
+
+	return NUMA_NO_MEMBLK;
+}
+
 static int __memory_add_physaddr_to_nid(u64 addr)
 {
 	unsigned long start_pfn, end_pfn, pfn = PHYS_PFN(addr);