[PATCH] amdkfd: initialize svm lists at where they are defined

Zhu, Lingshan Lingshan.Zhu at amd.com
Fri Feb 28 06:25:11 UTC 2025


[Public]

Ping

-----Original Message-----
From: Zhu, Lingshan <Lingshan.Zhu at amd.com>
Sent: Friday, February 21, 2025 5:24 PM
To: Kuehling, Felix <Felix.Kuehling at amd.com>; Deucher, Alexander <Alexander.Deucher at amd.com>
Cc: Huang, Ray <Ray.Huang at amd.com>; amd-gfx at lists.freedesktop.org; Zhu, Lingshan <Lingshan.Zhu at amd.com>
Subject: [PATCH] amdkfd: initialize svm lists at where they are defined

This commit initialized svm lists at where they are defined. This is defensive programing for security and consistency.

Initalizing variables ensures that their states are always valid, avoiding issues caused by uninitialized variables that could lead to unpredictable behaviros.

And we should not assume the callee would always initialize them

Signed-off-by: Zhu Lingshan <lingshan.zhu at amd.com>
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index bd3e20d981e0..cbc997449379 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -2130,11 +2130,7 @@ svm_range_add(struct kfd_process *p, uint64_t start, uint64_t size,

        pr_debug("svms 0x%p [0x%llx 0x%lx]\n", &p->svms, start, last);

-       INIT_LIST_HEAD(update_list);
-       INIT_LIST_HEAD(insert_list);
-       INIT_LIST_HEAD(remove_list);
        INIT_LIST_HEAD(&new_list);
-       INIT_LIST_HEAD(remap_list);

        node = interval_tree_iter_first(&svms->objects, start, last);
        while (node) {
@@ -3635,6 +3631,11 @@ svm_range_set_attr(struct kfd_process *p, struct mm_struct *mm,
        if (r)
                return r;

+       INIT_LIST_HEAD(&update_list);
+       INIT_LIST_HEAD(&insert_list);
+       INIT_LIST_HEAD(&remove_list);
+       INIT_LIST_HEAD(&remap_list);
+
        svms = &p->svms;

        mutex_lock(&process_info->lock);
--
2.47.1



More information about the amd-gfx mailing list