RE: [PATCH] drm/amdgpu: add ioctl to handle RAS poison error

2026-05-15 Thread Zhang, Yifan
AMD General

Thanks. Updated in v2.

-Original Message-
From: Alex Deucher 
Sent: Thursday, May 14, 2026 11:18 PM
To: Zhang, Yifan 
Cc: [email protected]; Deucher, Alexander 
; Koenig, Christian ; 
Kuehling, Felix ; Yat Sin, David 
; Russell, Kent ; Yuan, Perry 

Subject: Re: [PATCH] drm/amdgpu: add ioctl to handle RAS poison error

On Tue, May 12, 2026 at 9:19 AM Yifan Zhang  wrote:
>
> Add a new DRM_IOCTL_AMDGPU_USER_OPTIONS ioctl with the
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY option, allowing userspace
> (ROCr) to control per-process SIGBUS delivery.

Please include the proposed userspace in the commit message.
Additional comments below.

>
> Signed-off-by: Yifan Zhang 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  12 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  29 ++
> drivers/gpu/drm/amd/amdkfd/kfd_events.c | 114 +++-
>  include/uapi/drm/amdgpu_drm.h   |  23 +
>  5 files changed, 177 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 80b18bbd7f3a..653a2a516e18 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -455,6 +455,16 @@ struct amdgpu_fpriv {
>
> /** GPU partition selection */
> uint32_txcp_id;
> +
> +   /**
> +* @kfd_sigbus_delay_ms: Per-fd KFD SIGBUS delivery option (set via
> +* DRM_IOCTL_AMDGPU_USER_OPTIONS / 
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY).
> +*
> +*   0  - send SIGBUS immediately (default)
> +*   0x - suppress SIGBUS delivery
> +*   other  - delay SIGBUS delivery by this many milliseconds
> +*/
> +   atomic_tkfd_sigbus_delay_ms;
>  };
>
>  int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv
> **fpriv); @@ -1467,6 +1477,8 @@ int amdgpu_enable_vblank_kms(struct
> drm_crtc *crtc);  void amdgpu_disable_vblank_kms(struct drm_crtc
> *crtc);  int amdgpu_info_ioctl(struct drm_device *dev, void *data,
>   struct drm_file *filp);
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp);
>
>  /*
>   * functions used by amdgpu_encoder.c diff --git
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 99688391e70b..cad18bd6f8b3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -3078,6 +3078,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL, amdgpu_userq_signal_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES,
> amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
> +   DRM_IOCTL_DEF_DRV(AMDGPU_USER_OPTIONS,
> + amdgpu_user_options_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
>  };
>
>  static const struct drm_driver amdgpu_kms_driver = { diff --git
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 24526e92f9b8..7903587b8bbb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1423,6 +1423,35 @@ int amdgpu_info_ioctl(struct drm_device *dev, void 
> *data, struct drm_file *filp)
> return 0;
>  }
>
> +/**
> + * amdgpu_user_options_ioctl - set per-fd user options
> + *
> + * @dev: drm dev pointer
> + * @data: pointer to struct drm_amdgpu_user_options
> + * @filp: drm file
> + *
> + * Sets options stored on the per-file amdgpu_fpriv. Currently the
> +only
> + * supported option is %AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY which
> + * controls how KFD delivers SIGBUS for poison/RAS events to the
> +calling
> + * process (immediate, suppressed, or delayed by N milliseconds).
> + */
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp) {
> +   struct amdgpu_fpriv *fpriv = filp->driver_priv;
> +   struct drm_amdgpu_user_options *args = data;
> +
> +   switch (args->op) {
> +   case AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY:
> +   atomic_set(&fpriv->kfd_sigbus_delay_ms,
> +  args->kfd_sigbus_delay.value);
> +   return 0;
> +   default:
> +   DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
> +   return -EINVAL;
> +   }
> +}
> 

Re: [PATCH] drm/amdgpu: add ioctl to handle RAS poison error

2026-05-14 Thread Alex Deucher
On Tue, May 12, 2026 at 9:19 AM Yifan Zhang  wrote:
>
> Add a new DRM_IOCTL_AMDGPU_USER_OPTIONS ioctl with the
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY option, allowing userspace (ROCr)
> to control per-process SIGBUS delivery.

Please include the proposed userspace in the commit message.
Additional comments below.

>
> Signed-off-by: Yifan Zhang 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  12 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  29 ++
>  drivers/gpu/drm/amd/amdkfd/kfd_events.c | 114 +++-
>  include/uapi/drm/amdgpu_drm.h   |  23 +
>  5 files changed, 177 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 80b18bbd7f3a..653a2a516e18 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -455,6 +455,16 @@ struct amdgpu_fpriv {
>
> /** GPU partition selection */
> uint32_txcp_id;
> +
> +   /**
> +* @kfd_sigbus_delay_ms: Per-fd KFD SIGBUS delivery option (set via
> +* DRM_IOCTL_AMDGPU_USER_OPTIONS / 
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY).
> +*
> +*   0  - send SIGBUS immediately (default)
> +*   0x - suppress SIGBUS delivery
> +*   other  - delay SIGBUS delivery by this many milliseconds
> +*/
> +   atomic_tkfd_sigbus_delay_ms;
>  };
>
>  int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
> @@ -1467,6 +1477,8 @@ int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
>  void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
>  int amdgpu_info_ioctl(struct drm_device *dev, void *data,
>   struct drm_file *filp);
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp);
>
>  /*
>   * functions used by amdgpu_encoder.c
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 99688391e70b..cad18bd6f8b3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -3078,6 +3078,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL, amdgpu_userq_signal_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, 
> amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
> +   DRM_IOCTL_DEF_DRV(AMDGPU_USER_OPTIONS, amdgpu_user_options_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
>  };
>
>  static const struct drm_driver amdgpu_kms_driver = {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 24526e92f9b8..7903587b8bbb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1423,6 +1423,35 @@ int amdgpu_info_ioctl(struct drm_device *dev, void 
> *data, struct drm_file *filp)
> return 0;
>  }
>
> +/**
> + * amdgpu_user_options_ioctl - set per-fd user options
> + *
> + * @dev: drm dev pointer
> + * @data: pointer to struct drm_amdgpu_user_options
> + * @filp: drm file
> + *
> + * Sets options stored on the per-file amdgpu_fpriv. Currently the only
> + * supported option is %AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY which
> + * controls how KFD delivers SIGBUS for poison/RAS events to the calling
> + * process (immediate, suppressed, or delayed by N milliseconds).
> + */
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp)
> +{
> +   struct amdgpu_fpriv *fpriv = filp->driver_priv;
> +   struct drm_amdgpu_user_options *args = data;
> +
> +   switch (args->op) {
> +   case AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY:
> +   atomic_set(&fpriv->kfd_sigbus_delay_ms,
> +  args->kfd_sigbus_delay.value);
> +   return 0;
> +   default:
> +   DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
> +   return -EINVAL;
> +   }
> +}
> +
>  /**
>   * amdgpu_driver_open_kms - drm callback for open
>   *
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> index e9be798c0a2b..2ff6348105b7 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> @@ -29,10 +29,12 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include "kfd_priv.h"
>  #include "kfd_events.h"
>  #include "kfd_device_queue_manager.h"
>  #include 
> +#include 
>
>  /*
>   * Wrapper around wait_queue_entry_t
> @@ -1337,6 +1339,115 @@ void kfd_signal_reset_event(struct kfd_node *dev)
> srcu_read_unlock(&kfd_processes_srcu, idx);
>  }
>
> +/*
> +

RE: [PATCH] drm/amdgpu: add ioctl to handle RAS poison error

2026-05-13 Thread Zhang, Yifan
AMD General

OK. PR of the ROCr patch :
https://github.com/ROCm/rocm-systems/pull/6062

-Original Message-
From: Alex Deucher 
Sent: Tuesday, May 12, 2026 9:27 PM
To: Zhang, Yifan 
Cc: [email protected]; Deucher, Alexander 
; Koenig, Christian ; 
Kuehling, Felix ; Yat Sin, David 
; Russell, Kent ; Yuan, Perry 

Subject: Re: [PATCH] drm/amdgpu: add ioctl to handle RAS poison error

On Tue, May 12, 2026 at 9:19 AM Yifan Zhang  wrote:
>
> Add a new DRM_IOCTL_AMDGPU_USER_OPTIONS ioctl with the
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY option, allowing userspace
> (ROCr) to control per-process SIGBUS delivery.

Please provide a link to the proposed userspace patches which use this new 
interface.

Alex

>
> Signed-off-by: Yifan Zhang 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  12 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  29 ++
> drivers/gpu/drm/amd/amdkfd/kfd_events.c | 114 +++-
>  include/uapi/drm/amdgpu_drm.h   |  23 +
>  5 files changed, 177 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 80b18bbd7f3a..653a2a516e18 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -455,6 +455,16 @@ struct amdgpu_fpriv {
>
> /** GPU partition selection */
> uint32_txcp_id;
> +
> +   /**
> +* @kfd_sigbus_delay_ms: Per-fd KFD SIGBUS delivery option (set via
> +* DRM_IOCTL_AMDGPU_USER_OPTIONS / 
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY).
> +*
> +*   0  - send SIGBUS immediately (default)
> +*   0x - suppress SIGBUS delivery
> +*   other  - delay SIGBUS delivery by this many milliseconds
> +*/
> +   atomic_tkfd_sigbus_delay_ms;
>  };
>
>  int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv
> **fpriv); @@ -1467,6 +1477,8 @@ int amdgpu_enable_vblank_kms(struct
> drm_crtc *crtc);  void amdgpu_disable_vblank_kms(struct drm_crtc
> *crtc);  int amdgpu_info_ioctl(struct drm_device *dev, void *data,
>   struct drm_file *filp);
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp);
>
>  /*
>   * functions used by amdgpu_encoder.c diff --git
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 99688391e70b..cad18bd6f8b3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -3078,6 +3078,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL, amdgpu_userq_signal_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES,
> amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
> +   DRM_IOCTL_DEF_DRV(AMDGPU_USER_OPTIONS,
> + amdgpu_user_options_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
>  };
>
>  static const struct drm_driver amdgpu_kms_driver = { diff --git
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 24526e92f9b8..7903587b8bbb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1423,6 +1423,35 @@ int amdgpu_info_ioctl(struct drm_device *dev, void 
> *data, struct drm_file *filp)
> return 0;
>  }
>
> +/**
> + * amdgpu_user_options_ioctl - set per-fd user options
> + *
> + * @dev: drm dev pointer
> + * @data: pointer to struct drm_amdgpu_user_options
> + * @filp: drm file
> + *
> + * Sets options stored on the per-file amdgpu_fpriv. Currently the
> +only
> + * supported option is %AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY which
> + * controls how KFD delivers SIGBUS for poison/RAS events to the
> +calling
> + * process (immediate, suppressed, or delayed by N milliseconds).
> + */
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp) {
> +   struct amdgpu_fpriv *fpriv = filp->driver_priv;
> +   struct drm_amdgpu_user_options *args = data;
> +
> +   switch (args->op) {
> +   case AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY:
> +   atomic_set(&fpriv->kfd_sigbus_delay_ms,
> +  args->kfd_sigbus_delay.value);
> +   return 0;
> +   default:
> +   DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
> + 

Re: [PATCH] drm/amdgpu: add ioctl to handle RAS poison error

2026-05-12 Thread Alex Deucher
On Tue, May 12, 2026 at 9:19 AM Yifan Zhang  wrote:
>
> Add a new DRM_IOCTL_AMDGPU_USER_OPTIONS ioctl with the
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY option, allowing userspace (ROCr)
> to control per-process SIGBUS delivery.

Please provide a link to the proposed userspace patches which use this
new interface.

Alex

>
> Signed-off-by: Yifan Zhang 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h |  12 +++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  29 ++
>  drivers/gpu/drm/amd/amdkfd/kfd_events.c | 114 +++-
>  include/uapi/drm/amdgpu_drm.h   |  23 +
>  5 files changed, 177 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 80b18bbd7f3a..653a2a516e18 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -455,6 +455,16 @@ struct amdgpu_fpriv {
>
> /** GPU partition selection */
> uint32_txcp_id;
> +
> +   /**
> +* @kfd_sigbus_delay_ms: Per-fd KFD SIGBUS delivery option (set via
> +* DRM_IOCTL_AMDGPU_USER_OPTIONS / 
> AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY).
> +*
> +*   0  - send SIGBUS immediately (default)
> +*   0x - suppress SIGBUS delivery
> +*   other  - delay SIGBUS delivery by this many milliseconds
> +*/
> +   atomic_tkfd_sigbus_delay_ms;
>  };
>
>  int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
> @@ -1467,6 +1477,8 @@ int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
>  void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
>  int amdgpu_info_ioctl(struct drm_device *dev, void *data,
>   struct drm_file *filp);
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp);
>
>  /*
>   * functions used by amdgpu_encoder.c
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 99688391e70b..cad18bd6f8b3 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> @@ -3078,6 +3078,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL, amdgpu_userq_signal_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
> DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, 
> amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
> +   DRM_IOCTL_DEF_DRV(AMDGPU_USER_OPTIONS, amdgpu_user_options_ioctl, 
> DRM_AUTH|DRM_RENDER_ALLOW),
>  };
>
>  static const struct drm_driver amdgpu_kms_driver = {
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index 24526e92f9b8..7903587b8bbb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1423,6 +1423,35 @@ int amdgpu_info_ioctl(struct drm_device *dev, void 
> *data, struct drm_file *filp)
> return 0;
>  }
>
> +/**
> + * amdgpu_user_options_ioctl - set per-fd user options
> + *
> + * @dev: drm dev pointer
> + * @data: pointer to struct drm_amdgpu_user_options
> + * @filp: drm file
> + *
> + * Sets options stored on the per-file amdgpu_fpriv. Currently the only
> + * supported option is %AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY which
> + * controls how KFD delivers SIGBUS for poison/RAS events to the calling
> + * process (immediate, suppressed, or delayed by N milliseconds).
> + */
> +int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
> + struct drm_file *filp)
> +{
> +   struct amdgpu_fpriv *fpriv = filp->driver_priv;
> +   struct drm_amdgpu_user_options *args = data;
> +
> +   switch (args->op) {
> +   case AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY:
> +   atomic_set(&fpriv->kfd_sigbus_delay_ms,
> +  args->kfd_sigbus_delay.value);
> +   return 0;
> +   default:
> +   DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
> +   return -EINVAL;
> +   }
> +}
> +
>  /**
>   * amdgpu_driver_open_kms - drm callback for open
>   *
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c 
> b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> index e9be798c0a2b..2ff6348105b7 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
> @@ -29,10 +29,12 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include "kfd_priv.h"
>  #include "kfd_events.h"
>  #include "kfd_device_queue_manager.h"
>  #include 
> +#include 
>
>  /*
>   * Wrapper around wait_queue_entry_t
> @@ -1337,6 +1339,115 @@ void kfd_signal_reset_event(struct kfd_node *dev)
> srcu_read_unlock(&kfd_processes_srcu, idx);
>  }
>
> +/*

[PATCH] drm/amdgpu: add ioctl to handle RAS poison error

2026-05-12 Thread Yifan Zhang
Add a new DRM_IOCTL_AMDGPU_USER_OPTIONS ioctl with the
AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY option, allowing userspace (ROCr)
to control per-process SIGBUS delivery.

Signed-off-by: Yifan Zhang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h |  12 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |   1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  29 ++
 drivers/gpu/drm/amd/amdkfd/kfd_events.c | 114 +++-
 include/uapi/drm/amdgpu_drm.h   |  23 +
 5 files changed, 177 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 80b18bbd7f3a..653a2a516e18 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
/** GPU partition selection */
uint32_txcp_id;
+
+   /**
+* @kfd_sigbus_delay_ms: Per-fd KFD SIGBUS delivery option (set via
+* DRM_IOCTL_AMDGPU_USER_OPTIONS / 
AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY).
+*
+*   0  - send SIGBUS immediately (default)
+*   0x - suppress SIGBUS delivery
+*   other  - delay SIGBUS delivery by this many milliseconds
+*/
+   atomic_tkfd_sigbus_delay_ms;
 };
 
 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv);
@@ -1467,6 +1477,8 @@ int amdgpu_enable_vblank_kms(struct drm_crtc *crtc);
 void amdgpu_disable_vblank_kms(struct drm_crtc *crtc);
 int amdgpu_info_ioctl(struct drm_device *dev, void *data,
  struct drm_file *filp);
+int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp);
 
 /*
  * functions used by amdgpu_encoder.c
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 99688391e70b..cad18bd6f8b3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -3078,6 +3078,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL, amdgpu_userq_signal_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, 
amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+   DRM_IOCTL_DEF_DRV(AMDGPU_USER_OPTIONS, amdgpu_user_options_ioctl, 
DRM_AUTH|DRM_RENDER_ALLOW),
 };
 
 static const struct drm_driver amdgpu_kms_driver = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 24526e92f9b8..7903587b8bbb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -1423,6 +1423,35 @@ int amdgpu_info_ioctl(struct drm_device *dev, void 
*data, struct drm_file *filp)
return 0;
 }
 
+/**
+ * amdgpu_user_options_ioctl - set per-fd user options
+ *
+ * @dev: drm dev pointer
+ * @data: pointer to struct drm_amdgpu_user_options
+ * @filp: drm file
+ *
+ * Sets options stored on the per-file amdgpu_fpriv. Currently the only
+ * supported option is %AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY which
+ * controls how KFD delivers SIGBUS for poison/RAS events to the calling
+ * process (immediate, suppressed, or delayed by N milliseconds).
+ */
+int amdgpu_user_options_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp)
+{
+   struct amdgpu_fpriv *fpriv = filp->driver_priv;
+   struct drm_amdgpu_user_options *args = data;
+
+   switch (args->op) {
+   case AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY:
+   atomic_set(&fpriv->kfd_sigbus_delay_ms,
+  args->kfd_sigbus_delay.value);
+   return 0;
+   default:
+   DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+   return -EINVAL;
+   }
+}
+
 /**
  * amdgpu_driver_open_kms - drm callback for open
  *
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
index e9be798c0a2b..2ff6348105b7 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c
@@ -29,10 +29,12 @@
 #include 
 #include 
 #include 
+#include 
 #include "kfd_priv.h"
 #include "kfd_events.h"
 #include "kfd_device_queue_manager.h"
 #include 
+#include 
 
 /*
  * Wrapper around wait_queue_entry_t
@@ -1337,6 +1339,115 @@ void kfd_signal_reset_event(struct kfd_node *dev)
srcu_read_unlock(&kfd_processes_srcu, idx);
 }
 
+/*
+ * Per-process opt-in for poison-consumption SIGBUS handling.
+ *
+ * Default: kernel sends SIGBUS to the process immediately when poison is
+ * consumed, in addition to delivering the KFD HW/MEMORY exception events.
+ *
+ * Userspace (ROCr) can opt-in per-process via the
+ * DRM_IOCTL_AMDGPU_USER_OPTIONS / AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ * option. This lets the app's reg