Jiri Slaby 991d48
From: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Jiri Slaby 991d48
Date: Tue, 4 Apr 2023 09:44:33 +0530
Jiri Slaby 991d48
Subject: [PATCH] powerpc/papr_scm: Update the NUMA distance table for the
Jiri Slaby 991d48
 target node
Jiri Slaby 991d48
References: bsc#1012628
Jiri Slaby 991d48
Patch-mainline: 6.2.12
Jiri Slaby 991d48
Git-commit: b277fc793daf258877b4c0744b52f69d6e6ba22e
Jiri Slaby 991d48
Jiri Slaby 991d48
[ Upstream commit b277fc793daf258877b4c0744b52f69d6e6ba22e ]
Jiri Slaby 991d48
Jiri Slaby 991d48
Platform device helper routines won't update the NUMA distance table
Jiri Slaby 991d48
while creating a platform device, even if the device is present on a
Jiri Slaby 991d48
NUMA node that doesn't have memory or CPU. This is especially true for
Jiri Slaby 991d48
pmem devices. If the target node of the pmem device is not online, we
Jiri Slaby 991d48
find the nearest online node to the device and associate the pmem device
Jiri Slaby 991d48
with that online node. To find the nearest online node, we should have
Jiri Slaby 991d48
the numa distance table updated correctly. Update the distance
Jiri Slaby 991d48
information during the device probe.
Jiri Slaby 991d48
Jiri Slaby 991d48
For a papr scm device on NUMA node 3 distance_lookup_table value for
Jiri Slaby 991d48
distance_ref_points_depth = 2 before and after fix is below:
Jiri Slaby 991d48
Jiri Slaby 991d48
Before fix:
Jiri Slaby 991d48
  node 3 distance depth 0  - 0
Jiri Slaby 991d48
  node 3 distance depth 1  - 0
Jiri Slaby 991d48
  node 4 distance depth 0  - 4
Jiri Slaby 991d48
  node 4 distance depth 1  - 2
Jiri Slaby 991d48
  node 5 distance depth 0  - 5
Jiri Slaby 991d48
  node 5 distance depth 1  - 1
Jiri Slaby 991d48
Jiri Slaby 991d48
After fix
Jiri Slaby 991d48
  node 3 distance depth 0  - 3
Jiri Slaby 991d48
  node 3 distance depth 1  - 1
Jiri Slaby 991d48
  node 4 distance depth 0  - 4
Jiri Slaby 991d48
  node 4 distance depth 1  - 2
Jiri Slaby 991d48
  node 5 distance depth 0  - 5
Jiri Slaby 991d48
  node 5 distance depth 1  - 1
Jiri Slaby 991d48
Jiri Slaby 991d48
Without the fix, the nearest numa node to the pmem device (NUMA node 3)
Jiri Slaby 991d48
will be picked as 4. After the fix, we get the correct numa node which
Jiri Slaby 991d48
is 5.
Jiri Slaby 991d48
Jiri Slaby 991d48
Fixes: da1115fdbd6e ("powerpc/nvdimm: Pick nearby online node if the device node is not online")
Jiri Slaby 991d48
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Jiri Slaby 991d48
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Jiri Slaby 991d48
Link: https://msgid.link/20230404041433.1781804-1-aneesh.kumar@linux.ibm.com
Jiri Slaby 991d48
Signed-off-by: Sasha Levin <sashal@kernel.org>
Jiri Slaby 991d48
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Jiri Slaby 991d48
---
Jiri Slaby 991d48
 arch/powerpc/mm/numa.c                    | 1 +
Jiri Slaby 991d48
 arch/powerpc/platforms/pseries/papr_scm.c | 7 +++++++
Jiri Slaby 991d48
 2 files changed, 8 insertions(+)
Jiri Slaby 991d48
Jiri Slaby 991d48
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
Jiri Slaby 991d48
index b44ce719..16cfe56b 100644
Jiri Slaby 991d48
--- a/arch/powerpc/mm/numa.c
Jiri Slaby 991d48
+++ b/arch/powerpc/mm/numa.c
Jiri Slaby 991d48
@@ -366,6 +366,7 @@ void update_numa_distance(struct device_node *node)
Jiri Slaby 991d48
 	WARN(numa_distance_table[nid][nid] == -1,
Jiri Slaby 991d48
 	     "NUMA distance details for node %d not provided\n", nid);
Jiri Slaby 991d48
 }
Jiri Slaby 991d48
+EXPORT_SYMBOL_GPL(update_numa_distance);
Jiri Slaby 991d48
 
Jiri Slaby 991d48
 /*
Jiri Slaby 991d48
  * ibm,numa-lookup-index-table= {N, domainid1, domainid2, ..... domainidN}
Jiri Slaby 991d48
diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
Jiri Slaby 991d48
index 2f838552..1a53e048 100644
Jiri Slaby 991d48
--- a/arch/powerpc/platforms/pseries/papr_scm.c
Jiri Slaby 991d48
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
Jiri Slaby 991d48
@@ -1428,6 +1428,13 @@ static int papr_scm_probe(struct platform_device *pdev)
Jiri Slaby 991d48
 		return -ENODEV;
Jiri Slaby 991d48
 	}
Jiri Slaby 991d48
 
Jiri Slaby 991d48
+	/*
Jiri Slaby 991d48
+	 * open firmware platform device create won't update the NUMA 
Jiri Slaby 991d48
+	 * distance table. For PAPR SCM devices we use numa_map_to_online_node()
Jiri Slaby 991d48
+	 * to find the nearest online NUMA node and that requires correct
Jiri Slaby 991d48
+	 * distance table information.
Jiri Slaby 991d48
+	 */
Jiri Slaby 991d48
+	update_numa_distance(dn);
Jiri Slaby 991d48
 
Jiri Slaby 991d48
 	p = kzalloc(sizeof(*p), GFP_KERNEL);
Jiri Slaby 991d48
 	if (!p)
Jiri Slaby 991d48
-- 
Jiri Slaby 991d48
2.35.3
Jiri Slaby 991d48