In heterogeneous or non-uniform NUMA systems, a NUMA node may be
CPU-less, memory-less, or both CPU-less and memory-less.

Previously, kfd_create_vcrat_image_cpu() assumed that every online NUMA
node contained both compute units and memory, attempting to create both
CU and memory CRAT entries unconditionally for every online node.

Add explicit guards to:
1. Only create Compute Unit CRAT entries if the NUMA node has valid
   CPU cores (kfd_numa_node_to_apic_id() != -1).
2. Only create Memory CRAT entries if the NUMA node actually contains
   memory (node_state(numa_node_id, N_MEMORY)).

This avoids emitting invalid or empty CRAT subtype entries for CPU-less,
memory-less, or both CPU-less and memory-less NUMA nodes in virtual CRAT
generation.

Co-developed-by: Donet Tom <[email protected]>
Signed-off-by: Donet Tom <[email protected]>
Signed-off-by: Dhruv B <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 40 +++++++++++++++------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index d4739db1c14c..489ddf68b751 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -1944,28 +1944,32 @@ static int kfd_create_vcrat_image_cpu(void 
*pcrat_image, size_t *size)
                        continue;
 
                /* Fill in Subtype: Compute Unit */
-               ret = kfd_fill_cu_for_cpu(numa_node_id, &avail_size,
-                       crat_table->num_domains,
-                       (struct crat_subtype_computeunit *)sub_type_hdr);
-               if (ret < 0)
-                       return ret;
-               crat_table->length += sub_type_hdr->length;
-               crat_table->total_entries++;
+               if (kfd_numa_node_to_apic_id(numa_node_id) != -1) {
+                       ret = kfd_fill_cu_for_cpu(numa_node_id, &avail_size,
+                                                 crat_table->num_domains,
+                                                 (struct 
crat_subtype_computeunit *)sub_type_hdr);
+                       if (ret < 0)
+                               return ret;
+                       crat_table->length += sub_type_hdr->length;
+                       crat_table->total_entries++;
 
-               sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
-                       sub_type_hdr->length);
+                       sub_type_hdr = (typeof(sub_type_hdr))((char 
*)sub_type_hdr +
+                               sub_type_hdr->length);
+               }
 
                /* Fill in Subtype: Memory */
-               ret = kfd_fill_mem_info_for_cpu(numa_node_id, &avail_size,
-                       crat_table->num_domains,
-                       (struct crat_subtype_memory *)sub_type_hdr);
-               if (ret < 0)
-                       return ret;
-               crat_table->length += sub_type_hdr->length;
-               crat_table->total_entries++;
+               if (node_state(numa_node_id, N_MEMORY)) {
+                       ret = kfd_fill_mem_info_for_cpu(numa_node_id, 
&avail_size,
+                                                       crat_table->num_domains,
+                                                       (struct 
crat_subtype_memory *)sub_type_hdr);
+                       if (ret < 0)
+                               return ret;
+                       crat_table->length += sub_type_hdr->length;
+                       crat_table->total_entries++;
 
-               sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
-                       sub_type_hdr->length);
+                       sub_type_hdr = (typeof(sub_type_hdr))((char 
*)sub_type_hdr +
+                               sub_type_hdr->length);
+               }
 
                /* Fill in Subtype: IO Link */
 #if defined(CONFIG_X86_64) && !defined(CONFIG_UML)
-- 
2.54.0 (Apple Git-157)

Reply via email to