drm/amdkfd: Dereference null return value
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: Dereference null return value
In the function pqm_uninit there is a call-assignment of "pdd = kfd_get_process_device_data" which could be null, and this value was later dereferenced without checking.
--- drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +4 -2
@@ -212,11 +212,13 @@ static void pqm_clean_queue_resource(struct process_queue_manager *pqm,void pqm_uninit (struct process_queue_manager *pqm) {struct process_queue_node *pqn, *next; -struct kfd_process_device *pdd;list_for_each_entry_safe (pqn, next, &pqm->queues, process_queue_list) {if (pqn->q) { - pdd =kfd_get_process_device_data (pqn->q->device, pqm->process); +struct kfd_process_device *pdd =kfd_get_process_device_data (pqn->q->device, + pqm->process); +if (WARN_ON (!pdd)) +return ;kfd_queue_unref_bo_vas (pdd, &pqn->q->properties);kfd_queue_release_buffers (pdd, &pqn->q->properties);pqm_clean_queue_resource (pqm, pqn);
Signature · 1 line
2.43.0
[Public]
________________________________
From: amd-gfx <[email protected]> on behalf of Andrew Martin <[email protected]>
Sent: Monday, December 2, 2024 7:45:55 a.m.
To: [email protected] <[email protected]>
Cc: Kuehling, Felix <[email protected]>; Tudor, Alexandru <[email protected]>; Martin, Andrew <[email protected]>; Martin, Andrew <[email protected]>
Subject: [PATCH v2] drm/amdkfd: Dereference null return value
In the function pqm_uninit there is a call-assignment of "pdd = kfd_get_process_device_data" which could be null, and this value was later dereferenced without checking.
--- drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +3 -2
@@ -212,11 +212,13 @@ static void pqm_clean_queue_resource(struct process_queue_manager *pqm,void pqm_uninit (struct process_queue_manager *pqm) {struct process_queue_node *pqn, *next; -struct kfd_process_device *pdd;list_for_each_entry_safe (pqn, next, &pqm->queues, process_queue_list) {if (pqn->q) { - pdd =kfd_get_process_device_data (pqn->q->device, pqm->process); +struct kfd_process_device *pdd =kfd_get_process_device_data (pqn->q->device, + pqm->process); +if (WARN_ON (!pdd))
Would we want a "continue" instead of "break" if the pdd is NULL? Just in case other ones in the list are still valid? Or is one NULL enough to just WARN and abort?
Kent
+ return;
kfd_queue_unref_bo_vas(pdd, &pqn->q->properties);
kfd_queue_release_buffers(pdd, &pqn->q->properties);
pqm_clean_queue_resource(pqm, pqn);--
2.43.0
Quoted 43 lines · Kent
[Public]
------------------------------------------------------------------------
*From:* amd-gfx <[email protected]> on behalf of Andrew Martin <[email protected]>
*Sent:* Monday, December 2, 2024 7:45:55 a.m.
*To:* [email protected] <[email protected]>
*Cc:* Kuehling, Felix <[email protected]>; Tudor, Alexandru <[email protected]>; Martin, Andrew <[email protected]>; Martin, Andrew <[email protected]> *Subject:* [PATCH v2] drm/amdkfd: Dereference null return valueIn the function
pqm_uninitthere is a call-assignment of "pdd =kfd_get_process_device_data" which could be null, and this value was later dereferenced without checking.Fixes fb91065851cd ("drm/amdkfd: Refactor queue wptr_bo GART mapping")Signed-off-by Andrew Martin <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 6 ++++--1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +3
-2@@ -212,11 +212,13 @@ static void pqm_clean_queue_resource(structprocess_queue_manager *pqm, void pqm_uninit(struct process_queue_manager *pqm) { struct process_queue_node *pqn, *next; - struct kfd_process_device *pdd; list_for_each_entry_safe(pqn, next, &pqm->queues, process_queue_list) { if (pqn->q) { - pdd =kfd_get_process_device_data (pqn->q->device, pqm->process); + struct kfd_process_device *pdd =kfd_get_process_device_data (pqn->q->device, + pqm->process); + if (WARN_ON(!pdd))
Quoted 1 line
Would we want a "continue" instead of "break" if the pdd is NULL? Just in case other ones in the list are still valid? Or is one NULL enough to just WARN and abort?
I agree, we should use "continue" here. We are leaking memory, but let's not leak more than necessary. With that fixed, the patch is
Thanks,
Felix
Quoted 11 lines
Kent
+ return;
kfd_queue_unref_bo_vas(pdd, &pqn->q->properties);kfd_queue_release_buffers(pdd, &pqn->q->properties);pqm_clean_queue_resource(pqm, pqn);Signature · 1 line
2.43.0
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 61 lines
-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Wednesday, December 4, 2024 7:01 PM
To: Russell, Kent <[email protected]>; Martin, Andrew <[email protected]>; [email protected]
Cc: Tudor, Alexandru <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: Dereference null return valueQuoted 6 lines · Kent
[Public]
Quoted 8 lines
----------------------------------------------------------------------
--
*From:* amd-gfx <[email protected]> on behalf of Andrew Martin <[email protected]>
*Sent:* Monday, December 2, 2024 7:45:55 a.m.
*To:* [email protected] <[email protected]> *Cc:* Kuehling, Felix <[email protected]>; Tudor, Alexandru <[email protected]>; Martin, AndrewQuoted 36 lines
Martin, Andrew <[email protected]>
*Subject:* [PATCH v2] drm/amdkfd: Dereference null return valueIn the function
pqm_uninitthere is a call-assignment of "pdd =kfd_get_process_device_data" which could be null, and this value was later dereferenced without checking.Fixes fb91065851cd ("drm/amdkfd: Refactor queue wptr_bo GARTmapping")
Signed-off-by Andrew Martin <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1
-2@@ -212,11 +212,13 @@ static void pqm_clean_queue_resource(structprocess_queue_manager *pqm, void pqm_uninit(struct process_queue_manager *pqm) { struct process_queue_node *pqn, *next; -struct kfd_process_device *pdd;list_for_each_entry_safe (pqn, next, &pqm->queues, process_queue_list) {if (pqn->q) { - pdd =kfd_get_process_device_data (pqn->q->device, pqm->process); + struct kfd_process_device *pdd =kfd_get_process_device_data(pqn->q->device,
+pqm->process);
+ if (WARN_ON(!pdd))
Quoted 7 lines
Quoted 3 lines
Would we want a "continue" instead of "break" if the pdd is NULL? Just in case other ones in the list are still valid? Or is one NULL enough to just WARN and abort?
I agree, we should use "continue" here. We are leaking memory, but let's not leak more than necessary. With that fixed, the patch is
Greetings Kent/Felix, sending peace.
Thanks, I will make the change, run the tests and send it out.
Quoted 20 lines
Reviewed-by Felix Kuehling <[email protected]>Thanks,
FelixQuoted 13 lines
Kent
+ return;
kfd_queue_unref_bo_vas(pdd,&pqn->q->properties);
kfd_queue_release_buffers(pdd,&pqn->q->properties); pqm_clean_queue_resource(pqm, pqn);--
2.43.0