On 11/18/2026 5:57 AM, Felix Kuehling wrote:

> If secondary context ID allocation fails, the context ID remains 0. Make
> that distinguishable from a valid context ID to avoid double-freeing
> context IDs.

Thanks and Reviewed-by: Zhu Lingshan <[email protected]>

>
> Fixes: fac682a1d1af ("amdkfd: identify a secondary kfd process by its id")
> Signed-off-by: Felix Kuehling <[email protected]>
> ---
>  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    | 2 +-
>  drivers/gpu/drm/amd/amdkfd/kfd_process.c | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h 
> b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> index 3292e616d36f..2c8716d45e3f 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
> @@ -1083,7 +1083,7 @@ struct kfd_process {
>  
>  #define KFD_PROCESS_TABLE_SIZE 8 /* bits: 256 entries */
>  #define KFD_CONTEXT_ID_PRIMARY       0xFFFF
> -#define KFD_CONTEXT_ID_MIN 0
> +#define KFD_CONTEXT_ID_MIN 1
>  
>  extern DECLARE_HASHTABLE(kfd_processes_table, KFD_PROCESS_TABLE_SIZE);
>  extern struct srcu_struct kfd_processes_srcu;
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index ffd11576a0bb..d1b6b6305439 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -950,7 +950,8 @@ static void kfd_process_free_id(struct kfd_process 
> *process)
>  {
>       struct kfd_process *primary_process;
>  
> -     if (process->context_id == KFD_CONTEXT_ID_PRIMARY)
> +     if (process->context_id == KFD_CONTEXT_ID_PRIMARY ||
> +         process->context_id < KFD_CONTEXT_ID_MIN)
>               return;
>  
>       primary_process = kfd_lookup_process_by_mm(process->lead_thread->mm);
> @@ -1790,7 +1791,6 @@ struct kfd_process *create_process(const struct 
> task_struct *thread, bool primar
>       return process;
>  
>  err_alloc_id:
> -     kfd_process_free_id(process);
>  err_register_notifier:
>       /*
>        * The process is already in kfd_processes_table, so find_process()

Reply via email to