mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/amdkfd: lock event_mutex while counting events for CRIU
@ 2026-11-20  3:19 Changyul Lee
  2026-12-03 16:42 ` Kuehling, Felix
  0 siblings, 1 reply; 2+ messages in thread
From: Changyul Lee @ 2026-11-20  3:19 UTC (permalink / raw)
  To: Felix Kuehling, Alex Deucher, Christian König, David Airlie,
	Simona Vetter
  Cc: Rajneesh Bhardwaj, David Yat Sin, amd-gfx, dri-devel,
	linux-kernel, Changyul Lee

criu_get_process_object_info() holds p->mutex while counting events
in p->event_idr. Event creation and destruction use p->event_mutex,
so the event IDR can change during the walk. If an event is removed,
the walk can access a freed IDR node.

Hold p->event_mutex while counting events.
kfd_criu_checkpoint_events() uses the same lock when walking the
event IDR. Event creation and destruction do not acquire p->mutex,
so taking p->event_mutex while holding p->mutex preserves the lock
order.

Fixes: 40e8a766a761 ("drm/amdkfd: CRIU checkpoint and restore events")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus DRM_AMDGPU, HSA_AMD
and W=1.

 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 3d2136adb62b..20e3bbd073a5 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -2234,7 +2234,9 @@ static int criu_get_process_object_info(struct kfd_process *p,
 	if (ret)
 		return ret;
 
+	mutex_lock(&p->event_mutex);
 	num_events = kfd_get_num_events(p);
+	mutex_unlock(&p->event_mutex);
 
 	svm_range_get_info(p, &num_svm_ranges, &svm_priv_data_size);
 

base-commit: 8dd68a79583aaf6df6fe4feea3ee9e9f26b02993
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdkfd: lock event_mutex while counting events for CRIU
  2026-11-20  3:19 [PATCH] drm/amdkfd: lock event_mutex while counting events for CRIU Changyul Lee
@ 2026-12-03 16:42 ` Kuehling, Felix
  0 siblings, 0 replies; 2+ messages in thread
From: Kuehling, Felix @ 2026-12-03 16:42 UTC (permalink / raw)
  To: Changyul Lee, Alex Deucher, Christian König, David Airlie,
	Simona Vetter
  Cc: Rajneesh Bhardwaj, David Yat Sin, amd-gfx, dri-devel, linux-kernel

On 2026-11-19 22:19, Changyul Lee wrote:
> criu_get_process_object_info() holds p->mutex while counting events
> in p->event_idr. Event creation and destruction use p->event_mutex,
> so the event IDR can change during the walk. If an event is removed,
> the walk can access a freed IDR node.
>
> Hold p->event_mutex while counting events.
> kfd_criu_checkpoint_events() uses the same lock when walking the
> event IDR. Event creation and destruction do not acquire p->mutex,
> so taking p->event_mutex while holding p->mutex preserves the lock
> order.
>
> Fixes: 40e8a766a761 ("drm/amdkfd: CRIU checkpoint and restore events")
> Signed-off-by: Changyul Lee <lcy8047@gmail.com>

Reviewed-by: Felix Kuehling <felix.kuehling@amd.com>

I applied the patch to amd-staging-drm-next.

Thanks,
   Felix


> ---
> Found with a static analysis tool we are developing.
>
> Compile-tested only, with x86_64_defconfig plus DRM_AMDGPU, HSA_AMD
> and W=1.
>
>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 3d2136adb62b..20e3bbd073a5 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -2234,7 +2234,9 @@ static int criu_get_process_object_info(struct kfd_process *p,
>          if (ret)
>                  return ret;
>
> +       mutex_lock(&p->event_mutex);
>          num_events = kfd_get_num_events(p);
> +       mutex_unlock(&p->event_mutex);
>
>          svm_range_get_info(p, &num_svm_ranges, &svm_priv_data_size);
>
>
> base-commit: 8dd68a79583aaf6df6fe4feea3ee9e9f26b02993
> --
> 2.43.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03 16:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  3:19 [PATCH] drm/amdkfd: lock event_mutex while counting events for CRIU Changyul Lee
2026-12-03 16:42 ` Kuehling, Felix

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®