On 8/13/26 19:06, Pierre-Eric Pelloux-Prayer wrote:
> Add a per-device boolean to control whether GPU recovery is attempted
> on a hang, independently of the global amdgpu.gpu_recovery module
> parameter. It defaults to true and is exposed as a write to the
> existing amdgpu_gpu_recover debugfs file, so a single device can have
> auto-recovery disabled without affecting every other GPU in the
> system.
> 
> amdgpu_device_should_recover_gpu() now takes this flag into account.
> 
> Assisted-by: Claude:Sonnet 5
> Signed-off-by: Pierre-Eric Pelloux-Prayer <[email protected]>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  7 +++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  5 +++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 21 +++++++++++++++++----
>  3 files changed, 29 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 7974f9b7944f..21b33dc34edf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -957,6 +957,13 @@ struct amdgpu_device {
>  
>       struct amdgpu_uma_carveout_info uma_info;
>  
> +     /* Whether this device is allowed to attempt GPU recovery on a hang.
> +      * Defaults to true; can be turned off per-device (e.g. via the
> +      * amdgpu_gpu_recover debugfs file) independently of the global
> +      * amdgpu.gpu_recovery module parameter.
> +      */
> +     bool gpu_recovery_allowed;

The funcationality sounds sane to me, but the naming is just horrible.

We should probably use something like gpu_recovery_enabled instead.

Regards,
Christian.

> +
>       /* KFD
>        * Must be last --ends in a flexible-array member.
>        */
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 964efec0d335..5578d5f64937 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -4034,6 +4034,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>               }
>       }
>  
> +     adev->gpu_recovery_allowed = true;
> +
>  fence_driver_init:
>       /* Fence driver */
>       r = amdgpu_fence_driver_sw_init(adev);
> @@ -4834,6 +4836,9 @@ bool amdgpu_device_should_recover_gpu(struct 
> amdgpu_device *adev)
>       if (amdgpu_gpu_recovery == 0)
>               goto disabled;
>  
> +     if (!adev->gpu_recovery_allowed)
> +             goto disabled;
> +
>       /* Skip soft reset check in fatal error mode */
>       if (!amdgpu_ras_is_poison_mode_supported(adev))
>               return true;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> index 3043ad041bb4..707e69d8bb11 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> @@ -975,9 +975,13 @@ static int amdgpu_debugfs_fence_info_show(struct 
> seq_file *m, void *unused)
>  }
>  
>  /*
> - * amdgpu_debugfs_gpu_recover - manually trigger a gpu reset & recover
> + * amdgpu_debugfs_gpu_recover - manually trigger a gpu reset & recover,
> + * and control whether this device is allowed to auto-recover from a hang.
>   *
> - * Manually trigger a gpu reset at the next fence wait.
> + * Read triggers a gpu reset at the next fence wait.
> + *
> + * Write 0/1 to disable/enable auto GPU recovery for this device
> + * (equivalent to amdgpu.gpu_recovery=0, but scoped to this device only).
>   */
>  static int gpu_recover_get(void *data, u64 *val)
>  {
> @@ -1001,8 +1005,17 @@ static int gpu_recover_get(void *data, u64 *val)
>       return 0;
>  }
>  
> +static int gpu_recover_set(void *data, u64 val)
> +{
> +     struct amdgpu_device *adev = (struct amdgpu_device *)data;
> +
> +     adev->gpu_recovery_allowed = !!val;
> +
> +     return 0;
> +}
> +
>  DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_fence_info);
> -DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gpu_recover_fops, gpu_recover_get, 
> NULL,
> +DEFINE_DEBUGFS_ATTRIBUTE(amdgpu_debugfs_gpu_recover_fops, gpu_recover_get, 
> gpu_recover_set,
>                        "%lld\n");
>  
>  static void amdgpu_debugfs_reset_work(struct work_struct *work)
> @@ -1037,7 +1050,7 @@ void amdgpu_debugfs_fence_init(struct amdgpu_device 
> *adev)
>       if (!amdgpu_sriov_vf(adev)) {
>  
>               INIT_WORK(&adev->reset_work, amdgpu_debugfs_reset_work);
> -             debugfs_create_file("amdgpu_gpu_recover", 0444, root, adev,
> +             debugfs_create_file("amdgpu_gpu_recover", 0644, root, adev,
>                                   &amdgpu_debugfs_gpu_recover_fops);
>       }
>  #endif

Reply via email to