From: Zhu Lingshan <lingshan.zhu@amd.com>
To: Felix Kuehling <felix.kuehling@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 15:40:15 +0800 [thread overview]
Message-ID: <13836d37-3f09-4278-8599-ee8f3886e255@amd.com> (raw)
In-Reply-To: <c0fd1f01-ed4f-494d-8e9e-ae092a6ef1e1@amd.com>
On 3/4/2025 1:49 PM, Felix Kuehling wrote:
> 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);
Yes, this is better, I will use LIST_HEAD and remove the initialization in svm_range_add because we don't need to init them twice
By the way, I am not sure the lists are "output parameters", usually an output parameter should carry some information for other functions,
but here the lists are just defined, even not initialized, and are on the stack. Actually the callee only fills the lists and the caller itself use
the lists. I suggest to remove the "output parameters" in the code comments.
Thanks
Lingshan
> ...
>
> Regards,
> Felix
>
>
>> svms = &p->svms;
>>
>> mutex_lock(&process_info->lock);
next prev parent reply other threads:[~2025-03-04 7:40 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
2025-03-04 7:40 ` Zhu Lingshan [this message]
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=13836d37-3f09-4278-8599-ee8f3886e255@amd.com \
--to=lingshan.zhu@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=felix.kuehling@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.