From: Felix Kuehling <felix.kuehling@amd.com>
To: Zhu Lingshan <lingshan.zhu@amd.com>, alexander.deucher@amd.com
Cc: ray.huang@amd.com, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] amdkfd: initialize svm lists at where they are defined
Date: Tue, 4 Mar 2025 00:49:29 -0500 [thread overview]
Message-ID: <c0fd1f01-ed4f-494d-8e9e-ae092a6ef1e1@amd.com> (raw)
In-Reply-To: <20250221092355.336312-1-lingshan.zhu@amd.com>
On 2025-02-21 4:23, Zhu Lingshan wrote:
> 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.
The lists are clearly documented as output parameters in the svm_range_add function definition. I think it's more readable to do the list initialization in svm_range_add to keep the logic of the caller more readable. One suggestion inline that would move the initialization to the caller without cluttering the calling function's code.
>
> And we should not assume the callee would always
> initialize them
>
> Signed-off-by: Zhu Lingshan <lingshan.zhu@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);
> +
You could initialize these where they are defined by replacing the struct list_head ... definitions with
LIST_HEAD(update_list);
LIST_HEAD(insert_list);
...
Regards,
Felix
> svms = &p->svms;
>
> mutex_lock(&process_info->lock);
next prev parent reply other threads:[~2025-03-04 5:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-21 9:23 [PATCH] amdkfd: initialize svm lists at where they are defined Zhu Lingshan
2025-02-28 6:25 ` Zhu, Lingshan
2025-03-04 5:49 ` Felix Kuehling [this message]
2025-03-04 7:40 ` Zhu Lingshan
2025-03-04 15:16 ` Felix Kuehling
2025-03-05 3:11 ` Zhu Lingshan
2025-03-05 15:22 ` Felix Kuehling
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c0fd1f01-ed4f-494d-8e9e-ae092a6ef1e1@amd.com \
--to=felix.kuehling@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=lingshan.zhu@amd.com \
--cc=ray.huang@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.