On 2026-11-18 10:10, William Palacek wrote:
The ioctl takes p->mutex only to look up the pdd. p->pdds[] is filled
in create_process() before the process is published and freed only at
teardown, and the clock read that follows already uses the pdd without
the lock, so the lock protects nothing.

That's not completely true. kfd_process_device_data_by_id compares the gpu_id with pdd->user_gpu_id, which is updated under the p->mutex by criu_restore.

Regards,
  Felix



It does serialize every clock counter query of the process behind
whatever holds p->mutex. Threads submitting GPU work call this ioctl
(seen in a PyTorch workload on MI300X), so while one thread registered
and mapped a 32 GiB userptr, the others waited in it (205 ms measured
for one call).

Signed-off-by: William Palacek <[email protected]>
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 3d2136adb62b..9886bbd28ea2 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -745,9 +745,8 @@ static int kfd_ioctl_get_clock_counters(struct file *filep,
        struct kfd_ioctl_get_clock_counters_args *args = data;
        struct kfd_process_device *pdd;
- mutex_lock(&p->mutex);
+       /* p->pdds[] is fixed from process creation to teardown, no lock needed 
*/
        pdd = kfd_process_device_data_by_id(p, args->gpu_id);
-       mutex_unlock(&p->mutex);
        if (pdd)
                /* Reading GPU clock counter from KGD */
                args->gpu_clock_counter = 
amdgpu_amdkfd_get_gpu_clock_counter(pdd->dev->adev);

Reply via email to