]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdkfd: Check debug trap enable before write dbg_ev_file
authorLin.Cao <lincao12@amd.com>
Wed, 24 Apr 2024 03:27:16 +0000 (11:27 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 8 May 2024 19:17:05 +0000 (15:17 -0400)
In interrupt context, write dbg_ev_file will be run by work queue. It
will cause write dbg_ev_file execution after debug_trap_disable, which
will cause NULL pointer access.
v2: cancel work "debug_event_workarea" before set dbg_ev_file as NULL.

Signed-off-by: Lin.Cao <lincao12@amd.com>
Reviewed-by: Jonathan Kim <jonathan.kim@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_debug.c

index 45b1975b149a985f24b1ba29c97804049a79c2d3..3f27bab7a50243b70f2ca767b4e493ca359fe910 100644 (file)
@@ -104,7 +104,8 @@ void debug_event_write_work_handler(struct work_struct *work)
                        struct kfd_process,
                        debug_event_workarea);
 
-       kernel_write(process->dbg_ev_file, &write_data, 1, &pos);
+       if (process->debug_trap_enabled && process->dbg_ev_file)
+               kernel_write(process->dbg_ev_file, &write_data, 1, &pos);
 }
 
 /* update process/device/queue exception status, write to descriptor
@@ -656,6 +657,7 @@ int kfd_dbg_trap_disable(struct kfd_process *target)
        else if (target->runtime_info.runtime_state != DEBUG_RUNTIME_STATE_DISABLED)
                target->runtime_info.runtime_state = DEBUG_RUNTIME_STATE_ENABLED;
 
+       cancel_work_sync(&target->debug_event_workarea);
        fput(target->dbg_ev_file);
        target->dbg_ev_file = NULL;