Skip to contentSkip to conversation

drm/amdkfd: Initialize kfd_gpu_cache_info for KFD topology

PATCH Superseded Joseph Greathouse 3 participants 5 messages Feb 6, 2024 – Feb 7, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: Initialize kfd_gpu_cache_info for KFD topology

The current kfd_gpu_cache_info structure is only partially filled in for some architectures. This means that for devices where we do not fill in some fields, we can returned uninitialized values through the KFD topology. Zero out the kfd_gpu_cache_info before asking the remaining fields to be filled in by lower-level functions.

---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
index 3df2a8ad86fb..67c1e7f84750 100644
@@ -1707,6 +1707,7 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct
 
 	gpu_processor_id = dev->node_props.simd_id_base;
 
+	memset(cache_info, 0, sizeof(struct kfd_gpu_cache_info) * KFD_MAX_CACHE_TYPES);
 	pcache_info = cache_info;
 	num_of_cache_types = kfd_get_gpu_cache_info(kdev, &pcache_info);
 	if (!num_of_cache_types) {
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 8 lines · Joseph Greathouse

The current kfd_gpu_cache_info structure is only partially filled in for some architectures. This means that for devices where we do not fill in some fields, we can returned uninitialized values through the KFD topology. Zero out the kfd_gpu_cache_info before asking the remaining fields to be filled in by lower-level functions.

This fixes your previous patch "drm/amdkfd: Add cache line sizes to KFD topology". Alex, I think the previous patch hasn't gone upstream yet. Do you want a Fixes: tag or is is possible to squash this with Joe's previous patch before upstreaming?

One nit-pick below.

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct · line 1710

Quoted 13 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
index 3df2a8ad86fb..67c1e7f84750 100644
@@ -1707,6 +1707,7 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct
 
  	gpu_processor_id = dev->node_props.simd_id_base;
 
+	memset(cache_info, 0, sizeof(struct kfd_gpu_cache_info) * KFD_MAX_CACHE_TYPES);

Just use sizeof(cache_info). No need to calculate the size of the array and risk getting it wrong.

Regards,
  Felix

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
  	pcache_info = cache_info;
  	num_of_cache_types = kfd_get_gpu_cache_info(kdev, &pcache_info);
  	if (!num_of_cache_types) {
#2 lore raw

[AMD Official Use Only - General]

Quoted 18 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Tuesday, February 6, 2024 4:15 PM
To: Greathouse, Joseph <[email protected]>; amd- [email protected]; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdkfd: Initialize kfd_gpu_cache_info for KFD topology

Quoted 7 lines · Joseph Greathouse

The current kfd_gpu_cache_info structure is only partially filled in for some architectures. This means that for devices where we do not fill in some fields, we can returned uninitialized values through the KFD topology.
Zero out the kfd_gpu_cache_info before asking the remaining fields to be filled in by lower-level functions.

Quoted 6 lines
Quoted 1 line

This fixes your previous patch "drm/amdkfd: Add cache line sizes to KFD topology". Alex, I think the previous patch hasn't gone upstream yet. Do you want a Fixes: tag or is is possible to squash this with Joe's previous patch before upstreaming?

Either way. I can fix up the tag when we upstream or squash it.

Alex

Quoted 31 lines

One nit-pick below.

Quoted 14 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
index 3df2a8ad86fb..67c1e7f84750 100644
@@ -1707,6 +1707,7 @@ static void kfd_fill_cache_non_crat_info(struct

kfd_topology_device *dev, struct

    gpu_processor_id = dev->node_props.simd_id_base;

drivers/gpu/drm/amd/amdkfd/kfd_topology.c

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2 -0
+   memset(cache_info, 0, sizeof(struct kfd_gpu_cache_info) *
+KFD_MAX_CACHE_TYPES);

Just use sizeof(cache_info). No need to calculate the size of the array and risk getting it wrong.

Regards,
Felix

Quoted 3 lines
    pcache_info = cache_info;
    num_of_cache_types = kfd_get_gpu_cache_info(kdev, &pcache_info);
    if (!num_of_cache_types) {
#3 lore raw

PATCH v2 1/1 drm/amdkfd: Initialize kfd_gpu_cache_info for KFD topology

In reply to Felix Kuehling

The current kfd_gpu_cache_info structure is only partially filled in for some architectures. This means that for devices where we do not fill in some fields, we can returned uninitialized values through the KFD topology. Zero out the kfd_gpu_cache_info before asking the remaining fields to be filled in by lower-level functions.

Fixes 04756ac9a24c ("drm/amdkfd: Add cache line sizes to KFD topology")
---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
index 3df2a8ad86fb..5cb0465493b8 100644
@@ -1707,6 +1707,7 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct
 
 	gpu_processor_id = dev->node_props.simd_id_base;
 
+	memset(cache_info, 0, sizeof(cache_info));
 	pcache_info = cache_info;
 	num_of_cache_types = kfd_get_gpu_cache_info(kdev, &pcache_info);
 	if (!num_of_cache_types) {
Signature · 1 line
2.20.1
maintainer Reviewed-by on v2 1/1
#4 lore raw
Quoted 9 lines · Joseph Greathouse

The current kfd_gpu_cache_info structure is only partially filled in for some architectures. This means that for devices where we do not fill in some fields, we can returned uninitialized values through the KFD topology. Zero out the kfd_gpu_cache_info before asking the remaining fields to be filled in by lower-level functions.

Fixes 04756ac9a24c ("drm/amdkfd: Add cache line sizes to KFD topology")
Quoted 16 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
index 3df2a8ad86fb..5cb0465493b8 100644
@@ -1707,6 +1707,7 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct
 
  	gpu_processor_id = dev->node_props.simd_id_base;
 
+	memset(cache_info, 0, sizeof(cache_info));
  	pcache_info = cache_info;
  	num_of_cache_types = kfd_get_gpu_cache_info(kdev, &pcache_info);
  	if (!num_of_cache_types) {