Skip to contentSkip to conversation

cxl/test: Map mock device nodes to an online node

PATCH Superseded Davidlohr Bueso 5 participants 6 messages Jul 23 – Aug 19 CXL

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Davidlohr Bueso

author maintainer
#0 lore raw

PATCH 1/1 cxl/test: Map mock device nodes to an online node

cxl_mem_init() assigns alternating NUMA nodes to the mock memdevs to model multi-node topologies. On a single-node host node 1 has no pgdat, and the first node-aware allocation in an odd device's probe faults on a NULL zonelist:

  Oops: general protection fault, probably for non-canonical address 0xdffffc00000006e3
  KASAN: probably user-memory-access in range [0x0000000000003718-0x000000000000371f]
  Workqueue: async async_run_entry_fn
  RIP: __alloc_frozen_pages_noprof+0x288
   new_slab
   ___slab_alloc
   __kmalloc_node_track_caller_noprof
   devm_kmalloc
   cxl_mock_mem_probe

Map the requested node to an online one, as dax_hmem already does for its target node.

Fixes cf1f6877b088 ("cxl/memdev: Add numa_node attribute")
Fixes e41c8452b9b2 ("tools/testing/cxl: Add a single-port host-bridge regression config")
Fixes c9435dbee119 ("tools/testing/cxl: Add an RCH topology")

---
Found while regression testing unrelated work.

 tools/testing/cxl/test/cxl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/cxl/test/cxl.c +3 -3
index ef92dd35e030..5156516a82d2 100644
@@ -1748,7 +1748,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_mem;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
 		if (rc)
@@ -1763,7 +1763,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_single;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem_single[i]);
 		if (rc)
@@ -1779,7 +1779,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_rcd;
 		pdev->dev.parent = &rch->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_rcd[i]);
 		if (rc)
Signature · 1 line
2.39.5
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Davidlohr Bueso

cxl_mem_init() assigns alternating NUMA nodes to the mock memdevs to model multi-node topologies. On a single-node host node 1 has no pgdat, and the first node-aware allocation in an odd device's probe faults on a NULL zonelist:

  Oops: general protection fault, probably for non-canonical address 0xdffffc00000006e3
  KASAN: probably user-memory-access in range [0x0000000000003718-0x000000000000371f]
  Workqueue: async async_run_entry_fn
  RIP: __alloc_frozen_pages_noprof+0x288
   new_slab
   ___slab_alloc
   __kmalloc_node_track_caller_noprof
   devm_kmalloc
   cxl_mock_mem_probe
Quoted 7 lines

Map the requested node to an online one, as dax_hmem already does for its target node.

Fixes cf1f6877b088 ("cxl/memdev: Add numa_node attribute")
Fixes e41c8452b9b2 ("tools/testing/cxl: Add a single-port host-bridge regression config")
Fixes c9435dbee119 ("tools/testing/cxl: Add an RCH topology")
Quoted 37 lines

---
Found while regression testing unrelated work.

 tools/testing/cxl/test/cxl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/cxl/test/cxl.c +3 -3
index ef92dd35e030..5156516a82d2 100644
@@ -1748,7 +1748,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_mem;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
 		if (rc)
@@ -1763,7 +1763,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_single;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem_single[i]);
 		if (rc)
@@ -1779,7 +1779,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_rcd;
 		pdev->dev.parent = &rch->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_rcd[i]);
 		if (rc)
maintainer Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Davidlohr Bueso
Quoted 18 lines · Davidlohr Bueso

cxl_mem_init() assigns alternating NUMA nodes to the mock memdevs to model multi-node topologies. On a single-node host node 1 has no pgdat, and the first node-aware allocation in an odd device's probe faults on a NULL zonelist:

  Oops: general protection fault, probably for non-canonical address 0xdffffc00000006e3
  KASAN: probably user-memory-access in range [0x0000000000003718-0x000000000000371f]
  Workqueue: async async_run_entry_fn
  RIP: __alloc_frozen_pages_noprof+0x288
   new_slab
   ___slab_alloc
   __kmalloc_node_track_caller_noprof
   devm_kmalloc
   cxl_mock_mem_probe

Map the requested node to an online one, as dax_hmem already does for its target node.

Quoted 6 lines
Fixes cf1f6877b088 ("cxl/memdev: Add numa_node attribute")
Fixes e41c8452b9b2 ("tools/testing/cxl: Add a single-port host-bridge regression config")
Fixes c9435dbee119 ("tools/testing/cxl: Add an RCH topology")

---
Found while regression testing unrelated work.

Hi Davidlohr,

Thanks for fixing up cxl-test!
My short response is:

And the long version is, I tested this and it failed somewhere else. I have CONFIG_PINCTRL=y so the first node aware allocation lands in the device core, not in cxl_mock_mem_probe(). Looks like:

BUG: unable to handle page fault for address: 0000000000002d18
    RIP: 0010:__alloc_frozen_pages_noprof+0x120/0x310
     allocate_slab
     new_slab
     __slab_alloc_node
     __kmalloc_node_track_caller_noprof
     devm_kmalloc
     pinctrl_bind_pins
     really_probe

We (me) had not seen this because our cxl_test guests always have two or more CPU-and-memory nodes, plus memory-only and nvdimm nodes on top. Node 1 is online, so numa_map_to_online_node() is a no-op.

It reproduces with a single -numa node holding the CPUs and all memory. That is one proximity domain, node_possible_map == {0}, no pgdat for node 1.

These settings appear as different presets for folks using run_qemu [1]. The 'tiny' option must be selected to hit this.

I'm thinking about how to work 'tiny' into the regular regression runs.

Good find Davidlohr!

-- Alison

[1] https://github.com/pmem/run_qemu

Quoted 38 lines
 tools/testing/cxl/test/cxl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/cxl/test/cxl.c +3 -3
index ef92dd35e030..5156516a82d2 100644
@@ -1748,7 +1748,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_mem;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
 		if (rc)
@@ -1763,7 +1763,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_single;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem_single[i]);
 		if (rc)
@@ -1779,7 +1779,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_rcd;
 		pdev->dev.parent = &rch->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_rcd[i]);
 		if (rc)
Signature · 1 line
2.39.5
Tested-by on v1 1/1
#3 lore raw
In reply to Davidlohr Bueso
Quoted 62 lines · Davidlohr Bueso

cxl_mem_init() assigns alternating NUMA nodes to the mock memdevs to model multi-node topologies. On a single-node host node 1 has no pgdat, and the first node-aware allocation in an odd device's probe faults on a NULL zonelist:

  Oops: general protection fault, probably for non-canonical address 0xdffffc00000006e3
  KASAN: probably user-memory-access in range [0x0000000000003718-0x000000000000371f]
  Workqueue: async async_run_entry_fn
  RIP: __alloc_frozen_pages_noprof+0x288
   new_slab
   ___slab_alloc
   __kmalloc_node_track_caller_noprof
   devm_kmalloc
   cxl_mock_mem_probe

Map the requested node to an online one, as dax_hmem already does for its target node.

Fixes cf1f6877b088 ("cxl/memdev: Add numa_node attribute")
Fixes e41c8452b9b2 ("tools/testing/cxl: Add a single-port host-bridge regression config")
Fixes c9435dbee119 ("tools/testing/cxl: Add an RCH topology")

---
Found while regression testing unrelated work.

 tools/testing/cxl/test/cxl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/cxl/test/cxl.c +3 -3
index ef92dd35e030..5156516a82d2 100644
@@ -1748,7 +1748,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_mem;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
 		if (rc)
@@ -1763,7 +1763,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_single;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem_single[i]);
 		if (rc)
@@ -1779,7 +1779,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_rcd;
 		pdev->dev.parent = &rch->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_rcd[i]);
 		if (rc)
Signature · 1 line
2.39.5

Hi Davidlohr,

I was hitting the same repeated crash while running modprobe cxl_test on a single-node virtme-ng guest.

For reference, the guest had only NUMA node 0 available and online:

# cat /sys/devices/system/node/possible 0  # cat /sys/devices/system/node/online 0

The crash followed the same path:

__alloc_frozen_pages_noprof new_slab ___slab_alloc __kmalloc_node_track_caller_noprof devm_kmalloc cxl_mock_mem_probe

I found this patch while looking through the linux-cxl archives and applied the same numa_map_to_online_node() fix to my current cxl/next tree.

The code has changed since this patch was posted. The original patch updates three sites in cxl_mem_init(), while current cxl/next has those corresponding sites under cxl_type3_mem_init(), along with a separate cxl_type2_mem_init() path.

After applying the equivalent changes to the three set_dev_node() calls in cxl_type3_mem_init(), the repeated crash is resolved and modprobe cxl_test succeeds.

I also noticed that cxl_type2_mem_init() now has:

set_dev_node(&pdev->dev, i % 2);

NR_CXL_TYPE2_ACCEL is currently 1, so this does not trigger the offline-node case today, but perhaps it would be worth using numa_map_to_online_node() there as well for consistency and future expansion.

Thanks,
Shaikh

Reviewed-by on v1 1/1
#4 lore raw
In reply to Davidlohr Bueso
Quoted 15 lines · Davidlohr Bueso

cxl_mem_init() assigns alternating NUMA nodes to the mock memdevs to model multi-node topologies. On a single-node host node 1 has no pgdat, and the first node-aware allocation in an odd device's probe faults on a NULL zonelist:

  Oops: general protection fault, probably for non-canonical address 0xdffffc00000006e3
  KASAN: probably user-memory-access in range [0x0000000000003718-0x000000000000371f]
  Workqueue: async async_run_entry_fn
  RIP: __alloc_frozen_pages_noprof+0x288
   new_slab
   ___slab_alloc
   __kmalloc_node_track_caller_noprof
   devm_kmalloc
   cxl_mock_mem_probe
Quoted 6 lines

Map the requested node to an online one, as dax_hmem already does for its target node.

Fixes cf1f6877b088 ("cxl/memdev: Add numa_node attribute")
Fixes e41c8452b9b2 ("tools/testing/cxl: Add a single-port host-bridge regression config")
Fixes c9435dbee119 ("tools/testing/cxl: Add an RCH topology")

I think should only have a single fixes tag? Otherwise seems it seems unclear where/how to backport?

Quoted 1 line
Quoted 41 lines

---
Found while regression testing unrelated work.

 tools/testing/cxl/test/cxl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/cxl/test/cxl.c +3 -3
index ef92dd35e030..5156516a82d2 100644
@@ -1748,7 +1748,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_mem;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
 		if (rc)
@@ -1763,7 +1763,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_single;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem_single[i]);
 		if (rc)
@@ -1779,7 +1779,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_rcd;
 		pdev->dev.parent = &rch->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_rcd[i]);
 		if (rc)
Signature · 1 line
2.39.5
maintainer
#5 lore raw
Quoted 19 lines · Gregory Price
Quoted 18 lines · Davidlohr Bueso

cxl_mem_init() assigns alternating NUMA nodes to the mock memdevs to model multi-node topologies. On a single-node host node 1 has no pgdat, and the first node-aware allocation in an odd device's probe faults on a NULL zonelist:

  Oops: general protection fault, probably for non-canonical address 0xdffffc00000006e3
  KASAN: probably user-memory-access in range [0x0000000000003718-0x000000000000371f]
  Workqueue: async async_run_entry_fn
  RIP: __alloc_frozen_pages_noprof+0x288
   new_slab
   ___slab_alloc
   __kmalloc_node_track_caller_noprof
   devm_kmalloc
   cxl_mock_mem_probe

Map the requested node to an online one, as dax_hmem already does for its target node.

Quoted 6 lines
Quoted 3 lines
Fixes cf1f6877b088 ("cxl/memdev: Add numa_node attribute")
Fixes e41c8452b9b2 ("tools/testing/cxl: Add a single-port host-bridge regression config")
Fixes c9435dbee119 ("tools/testing/cxl: Add an RCH topology")

I think should only have a single fixes tag? Otherwise seems it seems unclear where/how to backport?

Issues started with this commit:

Fixes 17c38c88294d ("slab: remove cpu (partial) slabs usage from allocation paths")

But we probably should just use this:

Fixes cf1f6877b088 ("cxl/memdev: Add numa_node attribute")

Also, this patch needs to be rebased for v7.3-rc1 due type2 changes for 7.3.

DJ

Quoted 46 lines
Quoted 2 lines
Quoted 41 lines

---
Found while regression testing unrelated work.

 tools/testing/cxl/test/cxl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/cxl/test/cxl.c +3 -3
index ef92dd35e030..5156516a82d2 100644
@@ -1748,7 +1748,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_mem;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem[i]);
 		if (rc)
@@ -1763,7 +1763,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_single;
 		pdev->dev.parent = &dport->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_mem_single[i]);
 		if (rc)
@@ -1779,7 +1779,7 @@ static int cxl_mem_init(void)
 		if (!pdev)
 			goto err_rcd;
 		pdev->dev.parent = &rch->dev;
-		set_dev_node(&pdev->dev, i % 2);
+		set_dev_node(&pdev->dev, numa_map_to_online_node(i % 2));
 
 		rc = cxl_mock_platform_device_add(pdev, &cxl_rcd[i]);
 		if (rc)
Signature · 1 line
2.39.5