Skip to contentSkip to conversation

drm/amdgpu: add ioctl to handle RAS poison error

PATCH Superseded Yifan Zhang 4 participants 11 messages May 15 – May 21

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdgpu: add ioctl to handle RAS poison error

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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
 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           |  25 ++++++
 5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +12 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
 	/** GPU partition selection */
 	uint32_t		xcp_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)
+	 *   0xFFFFFFFF - suppress SIGBUS delivery
+	 *   other      - delay SIGBUS delivery by this many milliseconds
+	 */
+	atomic_t		kfd_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
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 99688391e70b..cad18bd6f8b3 100644
@@ -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 = {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +29 -0
index 24526e92f9b8..7903587b8bbb 100644
@@ -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
  *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +112 -2

142 lines not on this page · raw message

include/uapi/drm/amdgpu_drm.h +25 -0
index 9f3090db2f16..dfc91d25c80d 100644
@@ -58,6 +58,7 @@ extern "C" {
 #define DRM_AMDGPU_USERQ_SIGNAL		0x17
 #define DRM_AMDGPU_USERQ_WAIT		0x18
 #define DRM_AMDGPU_GEM_LIST_HANDLES	0x19
+#define DRM_AMDGPU_USER_OPTIONS		0x1A
 
 #define DRM_IOCTL_AMDGPU_GEM_CREATE	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
 #define DRM_IOCTL_AMDGPU_GEM_MMAP	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
 #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
 #define DRM_IOCTL_AMDGPU_USERQ_WAIT	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
 #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
 /**
  * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
 #define AMDGPU_FAMILY_GC_11_5_4			154 /* GC 11.5.4 */
 #define AMDGPU_FAMILY_GC_12_0_0			152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY		0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED	0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+	__u32 op;
+	union {
+		struct {
+			__u16 value;
+			__u16 _pad;
+		} kfd_sigbus_delay;
+		__u32 _pad;
+	};
+};
+
 #if defined(__cplusplus)
 }
 #endif
Signature · 1 line
2.43.0
#1 lore raw
Quoted 274 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
 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           |  25 ++++++
 5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +12 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
        /** GPU partition selection */
        uint32_t                xcp_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)
+        *   0xFFFFFFFF - suppress SIGBUS delivery
+        *   other      - delay SIGBUS delivery by this many milliseconds
+        */
+       atomic_t                kfd_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
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 99688391e70b..cad18bd6f8b3 100644
@@ -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 = {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +29 -0
index 24526e92f9b8..7903587b8bbb 100644
@@ -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
  *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +112 -2
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
 #include <linux/uaccess.h>
 #include <linux/mman.h>
 #include <linux/memory.h>
+#include <linux/workqueue.h>
 #include "kfd_priv.h"
 #include "kfd_events.h"
 #include "kfd_device_queue_manager.h"
 #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
 /*
  * 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 registered system-event callback handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process' amdgpu
+ * fds has been configured. This matches the slide deck's "Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+       struct delayed_work work;
+       struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work)
+{
+       struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                               struct kfd_sigbus_delayed_work, work);
+       struct kfd_process *p = dw->p;
+
+       if (p->lead_thread)
+               send_sig(SIGBUS, p->lead_thread, 0);
+
+       kfd_unref_process(p);
+       kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p)
+{
+       u32 result = 0;
+       int i;
+
+       for (i = 0; i < p->n_pdds; i++) {
+               struct kfd_process_device *pdd = p->pdds[i];
+               struct amdgpu_fpriv *drv_priv;
+               u32 v;
+
+               if (!pdd || !pdd->drm_file)
+                       continue;
+               if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                       continue;
+
+               v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+               if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                       return v;
+               if (v > result)
+                       result = v;
+       }
+
+       return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                        struct kfd_process *p)
+{
+       u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+       struct kfd_sigbus_delayed_work *dw;
+
+       if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+               dev_info(dev->adev->dev,
+                        "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                        p->lead_thread->comm, p->lead_thread->pid);
+               return;
+       }
+
+       if (delay_ms == 0)
+               goto send_now;
+
+       dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+       if (!dw)
+               goto send_now;
+
+       /* Take an extra reference for the delayed worker. */
+       kref_get(&p->ref);
+       dw->p = p;
+       INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+       dev_info(dev->adev->dev,
+                "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+                p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+       schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+       return;
+
+send_now:
+       send_sig(SIGBUS, p->lead_thread, 0);
+}
+
 void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
 {
        struct kfd_process *p = kfd_lookup_process_by_pasid(pasid, NULL);
@@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
        struct kfd_event *ev;
        uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
        int user_gpu_id;
-
        if (!p) {
                dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
                return; /* Presumably process exited. */
@@ -1391,7 +1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
        rcu_read_unlock();
 
        /* user application will handle SIGBUS signal */
-       send_sig(SIGBUS, p->lead_thread, 0);
+       kfd_signal_sigbus_with_delay(dev, p);
 
        kfd_unref_process(p);
 }
include/uapi/drm/amdgpu_drm.h +3 -0
index 9f3090db2f16..dfc91d25c80d 100644
@@ -58,6 +58,7 @@ extern "C" {
 #define DRM_AMDGPU_USERQ_SIGNAL                0x17
 #define DRM_AMDGPU_USERQ_WAIT          0x18
 #define DRM_AMDGPU_GEM_LIST_HANDLES    0x19
+#define DRM_AMDGPU_USER_OPTIONS                0x1A
 
 #define DRM_IOCTL_AMDGPU_GEM_CREATE    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
 #define DRM_IOCTL_AMDGPU_GEM_MMAP      DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
 #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL  DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
 #define DRM_IOCTL_AMDGPU_USERQ_WAIT    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
 #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS  DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
 /**
  * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
 #define AMDGPU_FAMILY_GC_11_5_4                        154 /* GC 11.5.4 */
 #define AMDGPU_FAMILY_GC_12_0_0                        152 /* GC 12.0.0 */
 
+/*

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_info_uq_metadata { · line 1688

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY                0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED  0xFFFFFFFFu

AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED should be 0xFFFFu

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_info_uq_metadata { · line 1697

Quoted 9 lines
include/uapi/drm/amdgpu_drm.h +9 -0
+
+struct drm_amdgpu_user_options {
+       __u32 op;
+       union {
+               struct {
+                       __u16 value;
+                       __u16 _pad;
+               } kfd_sigbus_delay;
+               __u32 _pad;

You can drop the __u32 _pad here. the op and value and u16 _pad are already aligned to 64 bits.

Alex

Quoted 9 lines
include/uapi/drm/amdgpu_drm.h +3 -1
+       };
+};
+
 #if defined(__cplusplus)
 }
 #endif
--

2.43.0

maintainer
#2 lore raw
Quoted 162 lines · Alex Deucher
Quoted 161 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
  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           |  25 ++++++
  5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +12 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
         /** GPU partition selection */
         uint32_t                xcp_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)
+        *   0xFFFFFFFF - suppress SIGBUS delivery
+        *   other      - delay SIGBUS delivery by this many milliseconds
+        */
+       atomic_t                kfd_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
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 99688391e70b..cad18bd6f8b3 100644
@@ -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 = {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +29 -0
index 24526e92f9b8..7903587b8bbb 100644
@@ -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
   *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +44 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
  #include <linux/uaccess.h>
  #include <linux/mman.h>
  #include <linux/memory.h>
+#include <linux/workqueue.h>
  #include "kfd_priv.h"
  #include "kfd_events.h"
  #include "kfd_device_queue_manager.h"
  #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
  /*
   * 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 registered system-event callback handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process' amdgpu
+ * fds has been configured. This matches the slide deck's "Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+       struct delayed_work work;
+       struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work)
+{
+       struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                               struct kfd_sigbus_delayed_work, work);
+       struct kfd_process *p = dw->p;
+
+       if (p->lead_thread)
+               send_sig(SIGBUS, p->lead_thread, 0);
+
+       kfd_unref_process(p);
+       kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of the
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1391

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +8 -0
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p)

If you're looking for the delay time for a specific GPU, you should also have a kfd_node *dev parameter.

Quoted 11 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1402

Quoted 11 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +11 -0
+{
+       u32 result = 0;
+       int i;
+
+       for (i = 0; i < p->n_pdds; i++) {
+               struct kfd_process_device *pdd = p->pdds[i];
+               struct amdgpu_fpriv *drv_priv;
+               u32 v;
+
+               if (!pdd || !pdd->drm_file)
+                       continue;

Then compare pdd->dev == dev.

Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +7 -0
+               if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                       continue;
+
+               v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+               if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                       return v;
+               if (v > result)
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1417

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +8 -0
+                       result = v;
+       }
+
+       return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                        struct kfd_process *p)

This function is called for a specific kfd_node.

Quoted 2 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1419

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
+{
+       u32 delay_ms = kfd_get_sigbus_delay_ms(p);

But the kfd_node is not passed to kfd_get_sigbus_delay_ms here. So you just get a random delay time from any GPU, not the one from the correct GPU.

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +5 -0
+       struct kfd_sigbus_delayed_work *dw;
+
+       if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+               dev_info(dev->adev->dev,
+                        "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1432

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +8 -0
+                        p->lead_thread->comm, p->lead_thread->pid);
+               return;
+       }
+
+       if (delay_ms == 0)
+               goto send_now;
+
+       dw = kzalloc(sizeof(*dw), GFP_ATOMIC);

You could avoid the dynamic memory allocation if the work struct were embedded in struct kfd_process_device.

Regards,
  Felix

Quoted 98 lines
Quoted 63 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +19 -2
+       if (!dw)
+               goto send_now;
+
+       /* Take an extra reference for the delayed worker. */
+       kref_get(&p->ref);
+       dw->p = p;
+       INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+       dev_info(dev->adev->dev,
+                "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+                p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+       schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+       return;
+
+send_now:
+       send_sig(SIGBUS, p->lead_thread, 0);
+}
+
  void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
  {
         struct kfd_process *p = kfd_lookup_process_by_pasid(pasid, NULL);
@@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
         struct kfd_event *ev;
         uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
         int user_gpu_id;
-
         if (!p) {
                 dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
                 return; /* Presumably process exited. */
@@ -1391,7 +1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
         rcu_read_unlock();
 
         /* user application will handle SIGBUS signal */
-       send_sig(SIGBUS, p->lead_thread, 0);
+       kfd_signal_sigbus_with_delay(dev, p);
 
         kfd_unref_process(p);
  }
include/uapi/drm/amdgpu_drm.h +3 -0
index 9f3090db2f16..dfc91d25c80d 100644
@@ -58,6 +58,7 @@ extern "C" {
  #define DRM_AMDGPU_USERQ_SIGNAL                0x17
  #define DRM_AMDGPU_USERQ_WAIT          0x18
  #define DRM_AMDGPU_GEM_LIST_HANDLES    0x19
+#define DRM_AMDGPU_USER_OPTIONS                0x1A
 
  #define DRM_IOCTL_AMDGPU_GEM_CREATE    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  #define DRM_IOCTL_AMDGPU_GEM_MMAP      DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
  #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL  DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
  #define DRM_IOCTL_AMDGPU_USERQ_WAIT    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
  #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS  DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
  /**
   * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
  #define AMDGPU_FAMILY_GC_11_5_4                        154 /* GC 11.5.4 */
  #define AMDGPU_FAMILY_GC_12_0_0                        152 /* GC 12.0.0 */
 
+/*

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_info_uq_metadata { · line 1688

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY                0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED  0xFFFFFFFFu

AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED should be 0xFFFFu

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_info_uq_metadata { · line 1697

Quoted 9 lines
include/uapi/drm/amdgpu_drm.h +9 -0
+
+struct drm_amdgpu_user_options {
+       __u32 op;
+       union {
+               struct {
+                       __u16 value;
+                       __u16 _pad;
+               } kfd_sigbus_delay;
+               __u32 _pad;

You can drop the __u32 _pad here. the op and value and u16 _pad are already aligned to 64 bits.

Alex

Quoted 9 lines
include/uapi/drm/amdgpu_drm.h +3 -1
+       };
+};
+
  #if defined(__cplusplus)
  }
  #endif
--

2.43.0

#3 lore raw
In reply to Yifan Zhang
Quoted 78 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
  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           |  25 ++++++
  5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +12 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
  	/** GPU partition selection */
  	uint32_t		xcp_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)
+	 *   0xFFFFFFFF - suppress SIGBUS delivery
+	 *   other      - delay SIGBUS delivery by this many milliseconds
+	 */
+	atomic_t		kfd_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
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
index 99688391e70b..cad18bd6f8b3 100644
@@ -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 = {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +12 -0
index 24526e92f9b8..7903587b8bbb 100644
@@ -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).
+ */

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1447

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 210 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+		return 0;
+	default:
+		DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+		return -EINVAL;
+	}
+}
+
  /**
   * amdgpu_driver_open_kms - drm callback for open
   *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +112 -2
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
  #include <linux/uaccess.h>
  #include <linux/mman.h>
  #include <linux/memory.h>
+#include <linux/workqueue.h>
  #include "kfd_priv.h"
  #include "kfd_events.h"
  #include "kfd_device_queue_manager.h"
  #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
  /*
   * 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 registered system-event callback handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process' amdgpu
+ * fds has been configured. This matches the slide deck's "Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+	struct delayed_work work;
+	struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work)
+{
+	struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+				struct kfd_sigbus_delayed_work, work);
+	struct kfd_process *p = dw->p;
+
+	if (p->lead_thread)
+		send_sig(SIGBUS, p->lead_thread, 0);
+
+	kfd_unref_process(p);
+	kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p)
+{
+	u32 result = 0;
+	int i;
+
+	for (i = 0; i < p->n_pdds; i++) {
+		struct kfd_process_device *pdd = p->pdds[i];
+		struct amdgpu_fpriv *drv_priv;
+		u32 v;
+
+		if (!pdd || !pdd->drm_file)
+			continue;
+		if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+			continue;
+
+		v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+		if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+			return v;
+		if (v > result)
+			result = v;
+	}
+
+	return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+					 struct kfd_process *p)
+{
+	u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+	struct kfd_sigbus_delayed_work *dw;
+
+	if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+		dev_info(dev->adev->dev,
+			 "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+			 p->lead_thread->comm, p->lead_thread->pid);
+		return;
+	}
+
+	if (delay_ms == 0)
+		goto send_now;
+
+	dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+	if (!dw)
+		goto send_now;
+
+	/* Take an extra reference for the delayed worker. */
+	kref_get(&p->ref);
+	dw->p = p;
+	INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+	dev_info(dev->adev->dev,
+		 "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+		 p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+	schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+	return;
+
+send_now:
+	send_sig(SIGBUS, p->lead_thread, 0);
+}
+
  void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
  {
  	struct kfd_process *p = kfd_lookup_process_by_pasid(pasid, NULL);
@@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
  	struct kfd_event *ev;
  	uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
  	int user_gpu_id;
-
  	if (!p) {
  		dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
  		return; /* Presumably process exited. */
@@ -1391,7 +1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
  	rcu_read_unlock();
 
  	/* user application will handle SIGBUS signal */
-	send_sig(SIGBUS, p->lead_thread, 0);
+	kfd_signal_sigbus_with_delay(dev, p);
 
  	kfd_unref_process(p);
  }
include/uapi/drm/amdgpu_drm.h +25 -0
index 9f3090db2f16..dfc91d25c80d 100644
@@ -58,6 +58,7 @@ extern "C" {
  #define DRM_AMDGPU_USERQ_SIGNAL		0x17
  #define DRM_AMDGPU_USERQ_WAIT		0x18
  #define DRM_AMDGPU_GEM_LIST_HANDLES	0x19
+#define DRM_AMDGPU_USER_OPTIONS		0x1A
 
  #define DRM_IOCTL_AMDGPU_GEM_CREATE	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  #define DRM_IOCTL_AMDGPU_GEM_MMAP	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
  #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
  #define DRM_IOCTL_AMDGPU_USERQ_WAIT	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
  #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS	DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
  /**
   * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
  #define AMDGPU_FAMILY_GC_11_5_4			154 /* GC 11.5.4 */
  #define AMDGPU_FAMILY_GC_12_0_0			152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY		0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED	0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+	__u32 op;
+	union {
+		struct {
+			__u16 value;
+			__u16 _pad;
+		} kfd_sigbus_delay;
+		__u32 _pad;
+	};
+};
+
  #if defined(__cplusplus)
  }
  #endif
#4 lore raw

AMD General

The signal itself is indeed process-scoped, but the policy is naturally per-device, because the poison event has a dev associated with it. ROCr already holds one amdgpu render fd per device, so attaching the option to amdgpu_fpriv lets the app configure each device independently with the handle it already has.

E.g.

Device A is driven by a worker that has its own RAS handler: set DISABLED on fd(A). Device B has no special handling: leave default / use a 10s safety timeout on fd(B).

Storing a single process-wide value would force the app to pick one policy for all GPUs it has open, which doesn't match how ROCr layers per-device handlers.

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 12:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 85 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
  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           |  25 ++++++
  5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
      /** GPU partition selection */
      uint32_t                xcp_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)
+      *   0xFFFFFFFF - suppress SIGBUS delivery
+      *   other      - delay SIGBUS delivery by this many milliseconds
+      */
+     atomic_t                kfd_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);
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
+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

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -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

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
@@ -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).
+ */

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1449

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 219 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+             return 0;
+     default:
+             DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+             return -EINVAL;
+     }
+}
+
  /**
   * amdgpu_driver_open_kms - drm callback for open
   *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
  #include <linux/uaccess.h>
  #include <linux/mman.h>
  #include <linux/memory.h>
+#include <linux/workqueue.h>
  #include "kfd_priv.h"
  #include "kfd_events.h"
  #include "kfd_device_queue_manager.h"
  #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
  /*
   * 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);

}

drivers/gpu/drm/amd/amdkfd/kfd_events.c +115 -1
+/*
+ * 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 registered system-event callback
+handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process'
+amdgpu
+ * fds has been configured. This matches the slide deck's
+"Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu where
+ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+     struct delayed_work work;
+     struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work) {
+     struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                             struct kfd_sigbus_delayed_work, work);
+     struct kfd_process *p = dw->p;
+
+     if (p->lead_thread)
+             send_sig(SIGBUS, p->lead_thread, 0);
+
+     kfd_unref_process(p);
+     kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses,
+it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                      struct kfd_process *p)
+{
+     u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+     struct kfd_sigbus_delayed_work *dw;
+
+     if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+             dev_info(dev->adev->dev,
+                      "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                      p->lead_thread->comm, p->lead_thread->pid);
+             return;
+     }
+
+     if (delay_ms == 0)
+             goto send_now;
+
+     dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+     if (!dw)
+             goto send_now;
+
+     /* Take an extra reference for the delayed worker. */
+     kref_get(&p->ref);
+     dw->p = p;
+     INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+     dev_info(dev->adev->dev,
+              "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+              p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+     schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+     return;
+
+send_now:
+     send_sig(SIGBUS, p->lead_thread, 0); }
+
  void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
  {
      struct kfd_process *p = kfd_lookup_process_by_pasid(pasid, NULL);
@@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
      struct kfd_event *ev;
      uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
      int user_gpu_id;
-
      if (!p) {
              dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
              return; /* Presumably process exited. */ @@ -1391,7 +1501,7 @@

void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)

      rcu_read_unlock();

      /* user application will handle SIGBUS signal */
drivers/gpu/drm/amd/amdkfd/kfd_events.c +1 -1
-     send_sig(SIGBUS, p->lead_thread, 0);
+     kfd_signal_sigbus_with_delay(dev, p);
 
      kfd_unref_process(p);
  }
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index 9f3090db2f16..dfc91d25c80d 100644

include/uapi/drm/amdgpu_drm.h +26 -0
@@ -58,6 +58,7 @@ extern "C" {
  #define DRM_AMDGPU_USERQ_SIGNAL             0x17
  #define DRM_AMDGPU_USERQ_WAIT               0x18
  #define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
+#define DRM_AMDGPU_USER_OPTIONS              0x1A
 
  #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
  #define DRM_IOCTL_AMDGPU_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
  #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
  #define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
  #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE
+ DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
  /**
   * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
  #define AMDGPU_FAMILY_GC_11_5_4                     154 /* GC 11.5.4 */
  #define AMDGPU_FAMILY_GC_12_0_0                     152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY              0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED        0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+     __u32 op;
+     union {
+             struct {
+                     __u16 value;
+                     __u16 _pad;
+             } kfd_sigbus_delay;
+             __u32 _pad;
+     };
+};
+
  #if defined(__cplusplus)
  }
  #endif
#5 lore raw
Quoted 11 lines · Yifan

AMD General

The signal itself is indeed process-scoped, but the policy is naturally per-device, because the poison event has a dev associated with it. ROCr already holds one amdgpu render fd per device, so attaching the option to amdgpu_fpriv lets the app configure each device independently with the handle it already has.

E.g.

Device A is driven by a worker that has its own RAS handler: set DISABLED on fd(A). Device B has no special handling: leave default / use a 10s safety timeout on fd(B).

Storing a single process-wide value would force the app to pick one policy for all GPUs it has open, which doesn't match how ROCr layers per-device handlers.

From a process's perspective, what it wants to do - isn't it to delay the signal if any of the devices it uses gets into poison error situation and buy some time to clean up?

Thanks,
Lijo

Quoted 335 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 12:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 85 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
   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           |  25 ++++++
   5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
       /** GPU partition selection */
       uint32_t                xcp_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)
+      *   0xFFFFFFFF - suppress SIGBUS delivery
+      *   other      - delay SIGBUS delivery by this many milliseconds
+      */
+     atomic_t                kfd_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);
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
+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

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -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

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
@@ -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).
+ */

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1449

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 219 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+             return 0;
+     default:
+             DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+             return -EINVAL;
+     }
+}
+
   /**
    * amdgpu_driver_open_kms - drm callback for open
    *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
   #include <linux/uaccess.h>
   #include <linux/mman.h>
   #include <linux/memory.h>
+#include <linux/workqueue.h>
   #include "kfd_priv.h"
   #include "kfd_events.h"
   #include "kfd_device_queue_manager.h"
   #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
   /*
    * 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);

}

drivers/gpu/drm/amd/amdkfd/kfd_events.c +115 -1
+/*
+ * 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 registered system-event callback
+handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process'
+amdgpu
+ * fds has been configured. This matches the slide deck's
+"Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu where
+ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+     struct delayed_work work;
+     struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work) {
+     struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                             struct kfd_sigbus_delayed_work, work);
+     struct kfd_process *p = dw->p;
+
+     if (p->lead_thread)
+             send_sig(SIGBUS, p->lead_thread, 0);
+
+     kfd_unref_process(p);
+     kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses,
+it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                      struct kfd_process *p)
+{
+     u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+     struct kfd_sigbus_delayed_work *dw;
+
+     if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+             dev_info(dev->adev->dev,
+                      "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                      p->lead_thread->comm, p->lead_thread->pid);
+             return;
+     }
+
+     if (delay_ms == 0)
+             goto send_now;
+
+     dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+     if (!dw)
+             goto send_now;
+
+     /* Take an extra reference for the delayed worker. */
+     kref_get(&p->ref);
+     dw->p = p;
+     INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+     dev_info(dev->adev->dev,
+              "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+              p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+     schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+     return;
+
+send_now:
+     send_sig(SIGBUS, p->lead_thread, 0); }
+
   void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
   {
       struct kfd_process *p = kfd_lookup_process_by_pasid(pasid, NULL);
@@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
       struct kfd_event *ev;
       uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
       int user_gpu_id;
-
       if (!p) {
               dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
               return; /* Presumably process exited. */ @@ -1391,7 +1501,7 @@

void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)

       rcu_read_unlock();

       /* user application will handle SIGBUS signal */
drivers/gpu/drm/amd/amdkfd/kfd_events.c +1 -1
-     send_sig(SIGBUS, p->lead_thread, 0);
+     kfd_signal_sigbus_with_delay(dev, p);
 
       kfd_unref_process(p);
   }
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index 9f3090db2f16..dfc91d25c80d 100644

include/uapi/drm/amdgpu_drm.h +26 -0
@@ -58,6 +58,7 @@ extern "C" {
   #define DRM_AMDGPU_USERQ_SIGNAL             0x17
   #define DRM_AMDGPU_USERQ_WAIT               0x18
   #define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
+#define DRM_AMDGPU_USER_OPTIONS              0x1A
 
   #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
   #define DRM_IOCTL_AMDGPU_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
   #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
   #define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
   #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE
+ DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
   /**
    * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
   #define AMDGPU_FAMILY_GC_11_5_4                     154 /* GC 11.5.4 */
   #define AMDGPU_FAMILY_GC_12_0_0                     152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY              0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED        0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+     __u32 op;
+     union {
+             struct {
+                     __u16 value;
+                     __u16 _pad;
+             } kfd_sigbus_delay;
+             __u32 _pad;
+     };
+};
+
   #if defined(__cplusplus)
   }
   #endif
#6 lore raw

AMD General

Yes, the mux of per device delay time happens in kfd_get_sigbus_delay_ms. But we still need some per device storage to store all the delay times.

Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +27 -0
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses,
+it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1414

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +8 -0
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 1:31 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 11 lines · Yifan

AMD General

The signal itself is indeed process-scoped, but the policy is naturally per-device, because the poison event has a dev associated with it. ROCr already holds one amdgpu render fd per device, so attaching the option to amdgpu_fpriv lets the app configure each device independently with the handle it already has.

E.g.

Device A is driven by a worker that has its own RAS handler: set DISABLED on fd(A). Device B has no special handling: leave default / use a 10s safety timeout on fd(B).

Storing a single process-wide value would force the app to pick one policy for all GPUs it has open, which doesn't match how ROCr layers per-device handlers.

From a process's perspective, what it wants to do - isn't it to delay the signal if any of the devices it uses gets into poison error situation and buy some time to clean up?

Thanks,
Lijo

Quoted 339 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 12:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 85 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
   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           |  25 ++++++
   5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
       /** GPU partition selection */
       uint32_t                xcp_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)
+      *   0xFFFFFFFF - suppress SIGBUS delivery
+      *   other      - delay SIGBUS delivery by this many milliseconds
+      */
+     atomic_t                kfd_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);
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
+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

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -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

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
@@ -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).

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1449

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+ */
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 219 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+             return 0;
+     default:
+             DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+             return -EINVAL;
+     }
+}
+
   /**
    * amdgpu_driver_open_kms - drm callback for open
    *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
   #include <linux/uaccess.h>
   #include <linux/mman.h>
   #include <linux/memory.h>
+#include <linux/workqueue.h>
   #include "kfd_priv.h"
   #include "kfd_events.h"
   #include "kfd_device_queue_manager.h"
   #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
   /*
    * 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);

}

drivers/gpu/drm/amd/amdkfd/kfd_events.c +114 -0
+/*
+ * 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 registered system-event callback
+handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process'
+amdgpu
+ * fds has been configured. This matches the slide deck's
+"Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu
+where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+     struct delayed_work work;
+     struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work) {
+     struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                             struct kfd_sigbus_delayed_work, work);
+     struct kfd_process *p = dw->p;
+
+     if (p->lead_thread)
+             send_sig(SIGBUS, p->lead_thread, 0);
+
+     kfd_unref_process(p);
+     kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses,
+it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                      struct kfd_process *p) {
+     u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+     struct kfd_sigbus_delayed_work *dw;
+
+     if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+             dev_info(dev->adev->dev,
+                      "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                      p->lead_thread->comm, p->lead_thread->pid);
+             return;
+     }
+
+     if (delay_ms == 0)
+             goto send_now;
+
+     dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+     if (!dw)
+             goto send_now;
+
+     /* Take an extra reference for the delayed worker. */
+     kref_get(&p->ref);
+     dw->p = p;
+     INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+     dev_info(dev->adev->dev,
+              "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+              p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+     schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+     return;
+
+send_now:
+     send_sig(SIGBUS, p->lead_thread, 0); }
+
   void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
   {
       struct kfd_process *p = kfd_lookup_process_by_pasid(pasid,

NULL); @@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)

       struct kfd_event *ev;
       uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
       int user_gpu_id;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -2
-
       if (!p) {
               dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
               return; /* Presumably process exited. */ @@ -1391,7
+1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
       rcu_read_unlock();
 
       /* user application will handle SIGBUS signal */
-     send_sig(SIGBUS, p->lead_thread, 0);
+     kfd_signal_sigbus_with_delay(dev, p);
 
       kfd_unref_process(p);
   }
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index 9f3090db2f16..dfc91d25c80d 100644

include/uapi/drm/amdgpu_drm.h +1 -0
@@ -58,6 +58,7 @@ extern "C" {
   #define DRM_AMDGPU_USERQ_SIGNAL             0x17
   #define DRM_AMDGPU_USERQ_WAIT               0x18
   #define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
+#define DRM_AMDGPU_USER_OPTIONS              0x1A
 
   #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
   #define DRM_IOCTL_AMDGPU_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
   #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
   #define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
   #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES

DRM_IOWR(DRM_COMMAND_BASE
+ DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)

include/uapi/drm/amdgpu_drm.h +24 -0
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
   /**
    * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
   #define AMDGPU_FAMILY_GC_11_5_4                     154 /* GC 11.5.4 */
   #define AMDGPU_FAMILY_GC_12_0_0                     152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY              0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED        0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+     __u32 op;
+     union {
+             struct {
+                     __u16 value;
+                     __u16 _pad;
+             } kfd_sigbus_delay;
+             __u32 _pad;
+     };
+};
+
   #if defined(__cplusplus)
   }
   #endif
#7 lore raw
Quoted 4 lines · Yifan

AMD General

Yes, the mux of per device delay time happens in kfd_get_sigbus_delay_ms. But we still need some per device storage to store all the delay times.

Which is why I said it doesn't make any sense as the signal is sent to the process and not at a device level. Also, in XGMI systems, a poison error could affect all of the devices and the intention of the signal is to prevent propagation/consumption of bad data.

Thanks,
Lijo

Quoted 406 lines
Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +27 -0
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses,
+it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1414

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +8 -0
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 1:31 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 11 lines · Yifan

AMD General

The signal itself is indeed process-scoped, but the policy is naturally per-device, because the poison event has a dev associated with it. ROCr already holds one amdgpu render fd per device, so attaching the option to amdgpu_fpriv lets the app configure each device independently with the handle it already has.

E.g.

Device A is driven by a worker that has its own RAS handler: set DISABLED on fd(A). Device B has no special handling: leave default / use a 10s safety timeout on fd(B).

Storing a single process-wide value would force the app to pick one policy for all GPUs it has open, which doesn't match how ROCr layers per-device handlers.

From a process's perspective, what it wants to do - isn't it to delay the signal if any of the devices it uses gets into poison error situation and buy some time to clean up?

Thanks,
Lijo

Quoted 339 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 12:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 85 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
    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           |  25 ++++++
    5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
        /** GPU partition selection */
        uint32_t                xcp_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)
+      *   0xFFFFFFFF - suppress SIGBUS delivery
+      *   other      - delay SIGBUS delivery by this many milliseconds
+      */
+     atomic_t                kfd_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);
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
+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

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -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

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
@@ -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).

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1449

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+ */
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 219 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+             return 0;
+     default:
+             DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+             return -EINVAL;
+     }
+}
+
    /**
     * amdgpu_driver_open_kms - drm callback for open
     *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
    #include <linux/uaccess.h>
    #include <linux/mman.h>
    #include <linux/memory.h>
+#include <linux/workqueue.h>
    #include "kfd_priv.h"
    #include "kfd_events.h"
    #include "kfd_device_queue_manager.h"
    #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
    /*
     * 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);
    }
drivers/gpu/drm/amd/amdkfd/kfd_events.c +114 -0
+/*
+ * 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 registered system-event callback
+handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process'
+amdgpu
+ * fds has been configured. This matches the slide deck's
+"Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu
+where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+     struct delayed_work work;
+     struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work) {
+     struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                             struct kfd_sigbus_delayed_work, work);
+     struct kfd_process *p = dw->p;
+
+     if (p->lead_thread)
+             send_sig(SIGBUS, p->lead_thread, 0);
+
+     kfd_unref_process(p);
+     kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it uses,
+it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                      struct kfd_process *p) {
+     u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+     struct kfd_sigbus_delayed_work *dw;
+
+     if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+             dev_info(dev->adev->dev,
+                      "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                      p->lead_thread->comm, p->lead_thread->pid);
+             return;
+     }
+
+     if (delay_ms == 0)
+             goto send_now;
+
+     dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+     if (!dw)
+             goto send_now;
+
+     /* Take an extra reference for the delayed worker. */
+     kref_get(&p->ref);
+     dw->p = p;
+     INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+     dev_info(dev->adev->dev,
+              "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+              p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+     schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+     return;
+
+send_now:
+     send_sig(SIGBUS, p->lead_thread, 0); }
+
    void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
    {
        struct kfd_process *p = kfd_lookup_process_by_pasid(pasid,

NULL); @@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)

        struct kfd_event *ev;
        uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
        int user_gpu_id;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -2
-
        if (!p) {
                dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
                return; /* Presumably process exited. */ @@ -1391,7
+1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
        rcu_read_unlock();
 
        /* user application will handle SIGBUS signal */
-     send_sig(SIGBUS, p->lead_thread, 0);
+     kfd_signal_sigbus_with_delay(dev, p);
 
        kfd_unref_process(p);
    }
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index 9f3090db2f16..dfc91d25c80d 100644

include/uapi/drm/amdgpu_drm.h +1 -0
@@ -58,6 +58,7 @@ extern "C" {
    #define DRM_AMDGPU_USERQ_SIGNAL             0x17
    #define DRM_AMDGPU_USERQ_WAIT               0x18
    #define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
+#define DRM_AMDGPU_USER_OPTIONS              0x1A
 
    #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
    #define DRM_IOCTL_AMDGPU_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
    #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
    #define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
    #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES

DRM_IOWR(DRM_COMMAND_BASE
+ DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)

include/uapi/drm/amdgpu_drm.h +24 -0
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
    /**
     * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
    #define AMDGPU_FAMILY_GC_11_5_4                     154 /* GC 11.5.4 */
    #define AMDGPU_FAMILY_GC_12_0_0                     152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY              0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED        0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+     __u32 op;
+     union {
+             struct {
+                     __u16 value;
+                     __u16 _pad;
+             } kfd_sigbus_delay;
+             __u32 _pad;
+     };
+};
+
    #if defined(__cplusplus)
    }
    #endif
#8 lore raw

AMD General

But we need a per device storage for each process fd and iterate them when RAS poison happens, right ? Would you pls give a example of the data structure you are proposing ?

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 2:03 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 4 lines · Yifan

AMD General

Yes, the mux of per device delay time happens in kfd_get_sigbus_delay_ms. But we still need some per device storage to store all the delay times.

Which is why I said it doesn't make any sense as the signal is sent to the process and not at a device level. Also, in XGMI systems, a poison error could affect all of the devices and the intention of the signal is to prevent propagation/consumption of bad data.

Thanks,
Lijo

Quoted 412 lines
Quoted 27 lines
Quoted 27 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +27 -0
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it
+uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
Quoted 8 lines

drivers/gpu/drm/amd/amdkfd/kfd_events.c void kfd_signal_reset_event(struct kfd_node *dev) · line 1414

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_events.c +8 -0
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 1:31 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 11 lines · Yifan

AMD General

The signal itself is indeed process-scoped, but the policy is naturally per-device, because the poison event has a dev associated with it. ROCr already holds one amdgpu render fd per device, so attaching the option to amdgpu_fpriv lets the app configure each device independently with the handle it already has.

E.g.

Device A is driven by a worker that has its own RAS handler: set DISABLED on fd(A). Device B has no special handling: leave default / use a 10s safety timeout on fd(B).

Storing a single process-wide value would force the app to pick one policy for all GPUs it has open, which doesn't match how ROCr layers per-device handlers.

From a process's perspective, what it wants to do - isn't it to delay the signal if any of the devices it uses gets into poison error situation and buy some time to clean up?

Thanks,
Lijo

Quoted 341 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 12:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 85 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
    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           |  25 ++++++
    5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
        /** GPU partition selection */
        uint32_t                xcp_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)
+      *   0xFFFFFFFF - suppress SIGBUS delivery
+      *   other      - delay SIGBUS delivery by this many milliseconds
+      */
+     atomic_t                kfd_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);
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
+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

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -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

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
@@ -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).

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1449

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+ */
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 220 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+             return 0;
+     default:
+             DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+             return -EINVAL;
+     }
+}
+
    /**
     * amdgpu_driver_open_kms - drm callback for open
     *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
    #include <linux/uaccess.h>
    #include <linux/mman.h>
    #include <linux/memory.h>
+#include <linux/workqueue.h>
    #include "kfd_priv.h"
    #include "kfd_events.h"
    #include "kfd_device_queue_manager.h"
    #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
    /*
     * 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);
    }
drivers/gpu/drm/amd/amdkfd/kfd_events.c +114 -0
+/*
+ * 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 registered system-event callback
+handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process'
+amdgpu
+ * fds has been configured. This matches the slide deck's
+"Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu
+where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+     struct delayed_work work;
+     struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work) {
+     struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                             struct kfd_sigbus_delayed_work, work);
+     struct kfd_process *p = dw->p;
+
+     if (p->lead_thread)
+             send_sig(SIGBUS, p->lead_thread, 0);
+
+     kfd_unref_process(p);
+     kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it
+uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                      struct kfd_process *p) {
+     u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+     struct kfd_sigbus_delayed_work *dw;
+
+     if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+             dev_info(dev->adev->dev,
+                      "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                      p->lead_thread->comm, p->lead_thread->pid);
+             return;
+     }
+
+     if (delay_ms == 0)
+             goto send_now;
+
+     dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+     if (!dw)
+             goto send_now;
+
+     /* Take an extra reference for the delayed worker. */
+     kref_get(&p->ref);
+     dw->p = p;
+     INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+     dev_info(dev->adev->dev,
+              "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+              p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+     schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+     return;
+
+send_now:
+     send_sig(SIGBUS, p->lead_thread, 0); }
+
    void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
    {
        struct kfd_process *p = kfd_lookup_process_by_pasid(pasid,

NULL); @@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)

        struct kfd_event *ev;
        uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
        int user_gpu_id;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +3 -2
-
        if (!p) {
                dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
                return; /* Presumably process exited. */ @@ -1391,7
+1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node
+*dev, u32 pasid)
        rcu_read_unlock();
 
        /* user application will handle SIGBUS signal */
-     send_sig(SIGBUS, p->lead_thread, 0);
+     kfd_signal_sigbus_with_delay(dev, p);
 
        kfd_unref_process(p);
    }
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index 9f3090db2f16..dfc91d25c80d 100644

include/uapi/drm/amdgpu_drm.h +1 -0
@@ -58,6 +58,7 @@ extern "C" {
    #define DRM_AMDGPU_USERQ_SIGNAL             0x17
    #define DRM_AMDGPU_USERQ_WAIT               0x18
    #define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
+#define DRM_AMDGPU_USER_OPTIONS              0x1A
 
    #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
    #define DRM_IOCTL_AMDGPU_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
    #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
    #define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
    #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES

DRM_IOWR(DRM_COMMAND_BASE
+ DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)

include/uapi/drm/amdgpu_drm.h +24 -0
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
    /**
     * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
    #define AMDGPU_FAMILY_GC_11_5_4                     154 /* GC 11.5.4 */
    #define AMDGPU_FAMILY_GC_12_0_0                     152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY              0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED        0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+     __u32 op;
+     union {
+             struct {
+                     __u16 value;
+                     __u16 _pad;
+             } kfd_sigbus_delay;
+             __u32 _pad;
+     };
+};
+
    #if defined(__cplusplus)
    }
    #endif
#9 lore raw
Quoted 4 lines · Yifan

AMD General

But we need a per device storage for each process fd and iterate them when RAS poison happens, right ? Would you pls give a example of the data structure you are proposing ?

I see it as a property of the process, just keep it within the process structure.

Thanks,
Lijo

Quoted 436 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 2:03 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 4 lines · Yifan

AMD General

Yes, the mux of per device delay time happens in kfd_get_sigbus_delay_ms. But we still need some per device storage to store all the delay times.

Which is why I said it doesn't make any sense as the signal is sent to the process and not at a device level. Also, in XGMI systems, a poison error could affect all of the devices and the intention of the signal is to prevent propagation/consumption of bad data.

Thanks,
Lijo

Quoted 412 lines
Quoted 27 lines
Quoted 27 lines
(quoted diff) +27 -0
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it
+uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 1:31 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 11 lines · Yifan

AMD General

The signal itself is indeed process-scoped, but the policy is naturally per-device, because the poison event has a dev associated with it. ROCr already holds one amdgpu render fd per device, so attaching the option to amdgpu_fpriv lets the app configure each device independently with the handle it already has.

E.g.

Device A is driven by a worker that has its own RAS handler: set DISABLED on fd(A). Device B has no special handling: leave default / use a 10s safety timeout on fd(B).

Storing a single process-wide value would force the app to pick one policy for all GPUs it has open, which doesn't match how ROCr layers per-device handlers.

From a process's perspective, what it wants to do - isn't it to delay the signal if any of the devices it uses gets into poison error situation and buy some time to clean up?

Thanks,
Lijo

Quoted 341 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 12:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 85 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
     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           |  25 ++++++
     5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
         /** GPU partition selection */
         uint32_t                xcp_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)
+      *   0xFFFFFFFF - suppress SIGBUS delivery
+      *   other      - delay SIGBUS delivery by this many milliseconds
+      */
+     atomic_t                kfd_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);
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
+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

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -0
@@ -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

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
@@ -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).

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1449

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+ */
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 220 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+             return 0;
+     default:
+             DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+             return -EINVAL;
+     }
+}
+
     /**
      * amdgpu_driver_open_kms - drm callback for open
      *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
     #include <linux/uaccess.h>
     #include <linux/mman.h>
     #include <linux/memory.h>
+#include <linux/workqueue.h>
     #include "kfd_priv.h"
     #include "kfd_events.h"
     #include "kfd_device_queue_manager.h"
     #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
     /*
      * 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);
     }
drivers/gpu/drm/amd/amdkfd/kfd_events.c +114 -0
+/*
+ * 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 registered system-event callback
+handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process'
+amdgpu
+ * fds has been configured. This matches the slide deck's
+"Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu
+where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+     struct delayed_work work;
+     struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work) {
+     struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                             struct kfd_sigbus_delayed_work, work);
+     struct kfd_process *p = dw->p;
+
+     if (p->lead_thread)
+             send_sig(SIGBUS, p->lead_thread, 0);
+
+     kfd_unref_process(p);
+     kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all of
+the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it
+uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                      struct kfd_process *p) {
+     u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+     struct kfd_sigbus_delayed_work *dw;
+
+     if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+             dev_info(dev->adev->dev,
+                      "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                      p->lead_thread->comm, p->lead_thread->pid);
+             return;
+     }
+
+     if (delay_ms == 0)
+             goto send_now;
+
+     dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+     if (!dw)
+             goto send_now;
+
+     /* Take an extra reference for the delayed worker. */
+     kref_get(&p->ref);
+     dw->p = p;
+     INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+     dev_info(dev->adev->dev,
+              "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+              p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+     schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+     return;
+
+send_now:
+     send_sig(SIGBUS, p->lead_thread, 0); }
+
     void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
     {
         struct kfd_process *p = kfd_lookup_process_by_pasid(pasid,

NULL); @@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)

         struct kfd_event *ev;
         uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
         int user_gpu_id;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +3 -2
-
         if (!p) {
                 dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
                 return; /* Presumably process exited. */ @@ -1391,7
+1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node
+*dev, u32 pasid)
         rcu_read_unlock();
 
         /* user application will handle SIGBUS signal */
-     send_sig(SIGBUS, p->lead_thread, 0);
+     kfd_signal_sigbus_with_delay(dev, p);
 
         kfd_unref_process(p);
     }
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index 9f3090db2f16..dfc91d25c80d 100644

include/uapi/drm/amdgpu_drm.h +1 -0
@@ -58,6 +58,7 @@ extern "C" {
     #define DRM_AMDGPU_USERQ_SIGNAL             0x17
     #define DRM_AMDGPU_USERQ_WAIT               0x18
     #define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
+#define DRM_AMDGPU_USER_OPTIONS              0x1A
 
     #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
     #define DRM_IOCTL_AMDGPU_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
     #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
     #define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
     #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES

DRM_IOWR(DRM_COMMAND_BASE
+ DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)

include/uapi/drm/amdgpu_drm.h +24 -0
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
     /**
      * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
     #define AMDGPU_FAMILY_GC_11_5_4                     154 /* GC 11.5.4 */
     #define AMDGPU_FAMILY_GC_12_0_0                     152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY              0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED        0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+     __u32 op;
+     union {
+             struct {
+                     __u16 value;
+                     __u16 _pad;
+             } kfd_sigbus_delay;
+             __u32 _pad;
+     };
+};
+
     #if defined(__cplusplus)
     }
     #endif
#10 lore raw

AMD General

At second thought, we don't need to consider per device value since the delay time is set by env var, which should be only a copy during the process life cycle. I agree to put delay time var in kfd_process.

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 2:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 4 lines · Yifan

AMD General

But we need a per device storage for each process fd and iterate them when RAS poison happens, right ? Would you pls give a example of the data structure you are proposing ?

I see it as a property of the process, just keep it within the process structure.

Thanks,
Lijo

Quoted 443 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 2:03 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 4 lines · Yifan

AMD General

Yes, the mux of per device delay time happens in kfd_get_sigbus_delay_ms. But we still need some per device storage to store all the delay times.

Which is why I said it doesn't make any sense as the signal is sent to the process and not at a device level. Also, in XGMI systems, a poison error could affect all of the devices and the intention of the signal is to prevent propagation/consumption of bad data.

Thanks,
Lijo

Quoted 415 lines
Quoted 27 lines
Quoted 27 lines
(quoted diff) +27 -0
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all
+of the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it
+uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 1:31 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 11 lines · Yifan

AMD General

The signal itself is indeed process-scoped, but the policy is naturally per-device, because the poison event has a dev associated with it. ROCr already holds one amdgpu render fd per device, so attaching the option to amdgpu_fpriv lets the app configure each device independently with the handle it already has.

E.g.

Device A is driven by a worker that has its own RAS handler: set DISABLED on fd(A). Device B has no special handling: leave default / use a 10s safety timeout on fd(B).

Storing a single process-wide value would force the app to pick one policy for all GPUs it has open, which doesn't match how ROCr layers per-device handlers.

From a process's perspective, what it wants to do - isn't it to delay the signal if any of the devices it uses gets into poison error situation and buy some time to clean up?

Thanks,
Lijo

Quoted 343 lines

Best Regards,
Yifan

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Thursday, May 21, 2026 12:35 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Kuehling, Felix <[email protected]>; Yat Sin, David <[email protected]>; Russell, Kent <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdgpu: add ioctl to handle RAS poison error

Quoted 85 lines · 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.

Userspace for this can be found at:
https://github.com/ROCm/rocm-systems/pull/6148

---
     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           |  25 ++++++
     5 files changed, 179 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 5d7bfa59424a..6a5459b59af2 100644
@@ -455,6 +455,16 @@ struct amdgpu_fpriv {
 
         /** GPU partition selection */
         uint32_t                xcp_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)
+      *   0xFFFFFFFF - suppress SIGBUS delivery
+      *   other      - delay SIGBUS delivery by this many milliseconds
+      */
+     atomic_t                kfd_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);
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
+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

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -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

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +14 -0
@@ -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).

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1449

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10 -0
+ */
+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);

Why this is stored at device level? A signal is process specific. I think the delay should be associated with the process regardless of multi-dev scenario.

Thanks,
Lijo

Quoted 221 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +7 -0
+             return 0;
+     default:
+             DRM_DEBUG_KMS("Invalid user option op %u\n", args->op);
+             return -EINVAL;
+     }
+}
+
     /**
      * amdgpu_driver_open_kms - drm callback for open
      *
drivers/gpu/drm/amd/amdkfd/kfd_events.c +2 -0
index e9be798c0a2b..2ff6348105b7 100644
@@ -29,10 +29,12 @@
     #include <linux/uaccess.h>
     #include <linux/mman.h>
     #include <linux/memory.h>
+#include <linux/workqueue.h>
     #include "kfd_priv.h"
     #include "kfd_events.h"
     #include "kfd_device_queue_manager.h"
     #include <linux/device.h>
+#include <uapi/drm/amdgpu_drm.h>
 
     /*
      * 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);
     }
drivers/gpu/drm/amd/amdkfd/kfd_events.c +114 -0
+/*
+ * 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 registered system-event callback
+handle the
+ * RAS error first, instead of being killed by SIGBUS.
+ *
+ * Encoded value (set on any of the process' amdgpu render fds):
+ *   0          - default: SIGBUS immediately (no opt-in)
+ *   0xFFFFFFFF - opt-in, never escalate to SIGBUS
+ *   N (other)  - opt-in, escalate to SIGBUS after N ms if app does not
+ *                handle the error in time (safety timeout)
+ *
+ * Per-process scope: the option is honored if ANY of the process'
+amdgpu
+ * fds has been configured. This matches the slide deck's
+"Per-process,
+ * App set at init" semantics, while keeping the UAPI on amdgpu
+where ROCr
+ * sets it.
+ */
+struct kfd_sigbus_delayed_work {
+     struct delayed_work work;
+     struct kfd_process *p;
+};
+
+static void kfd_signal_sigbus_delayed_fn(struct work_struct *work) {
+     struct kfd_sigbus_delayed_work *dw = container_of(to_delayed_work(work),
+                             struct kfd_sigbus_delayed_work, work);
+     struct kfd_process *p = dw->p;
+
+     if (p->lead_thread)
+             send_sig(SIGBUS, p->lead_thread, 0);
+
+     kfd_unref_process(p);
+     kfree(dw);
+}
+
+/*
+ * Resolve the per-process SIGBUS opt-in setting by scanning all
+of the
+ * process' KFD pdds (each backed by an amdgpu render fd). Returns
+the
+ * "most lenient" value across all fds, in this priority:
+ *   DISABLED (no SIGBUS)  >  any non-zero timeout  >  0 (immediate)
+ *
+ * Rationale: if the app has explicitly opted in on any GPU it
+uses, it
+ * wants the chance to handle the error in userspace.
+ */
+static u32 kfd_get_sigbus_delay_ms(struct kfd_process *p) {
+     u32 result = 0;
+     int i;
+
+     for (i = 0; i < p->n_pdds; i++) {
+             struct kfd_process_device *pdd = p->pdds[i];
+             struct amdgpu_fpriv *drv_priv;
+             u32 v;
+
+             if (!pdd || !pdd->drm_file)
+                     continue;
+             if (amdgpu_file_to_fpriv(pdd->drm_file, &drv_priv))
+                     continue;
+
+             v = atomic_read(&drv_priv->kfd_sigbus_delay_ms);
+             if (v == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED)
+                     return v;
+             if (v > result)
+                     result = v;
+     }
+
+     return result;
+}
+
+static void kfd_signal_sigbus_with_delay(struct kfd_node *dev,
+                                      struct kfd_process *p) {
+     u32 delay_ms = kfd_get_sigbus_delay_ms(p);
+     struct kfd_sigbus_delayed_work *dw;
+
+     if (delay_ms == AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED) {
+             dev_info(dev->adev->dev,
+                      "SIGBUS suppressed for process %s(pid:%d): app opted in to handle RAS error\n",
+                      p->lead_thread->comm, p->lead_thread->pid);
+             return;
+     }
+
+     if (delay_ms == 0)
+             goto send_now;
+
+     dw = kzalloc(sizeof(*dw), GFP_ATOMIC);
+     if (!dw)
+             goto send_now;
+
+     /* Take an extra reference for the delayed worker. */
+     kref_get(&p->ref);
+     dw->p = p;
+     INIT_DELAYED_WORK(&dw->work, kfd_signal_sigbus_delayed_fn);
+
+     dev_info(dev->adev->dev,
+              "Deferring SIGBUS to process %s(pid:%d) by %u ms (RAS error opt-in safety timeout)\n",
+              p->lead_thread->comm, p->lead_thread->pid, delay_ms);
+     schedule_delayed_work(&dw->work, msecs_to_jiffies(delay_ms));
+     return;
+
+send_now:
+     send_sig(SIGBUS, p->lead_thread, 0); }
+
     void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)
     {
         struct kfd_process *p = kfd_lookup_process_by_pasid(pasid,

NULL); @@ -1345,7 +1456,6 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid)

         struct kfd_event *ev;
         uint32_t id = KFD_FIRST_NONSIGNAL_EVENT_ID;
         int user_gpu_id;
drivers/gpu/drm/amd/amdkfd/kfd_events.c +3 -3
-
         if (!p) {
                 dev_warn(dev->adev->dev, "Not find process with pasid:%d\n", pasid);
                 return; /* Presumably process exited. */ @@
-1391,7
+1501,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node
+*dev, u32 pasid)
         rcu_read_unlock();
 
         /* user application will handle SIGBUS signal */
-     send_sig(SIGBUS, p->lead_thread, 0);
+     kfd_signal_sigbus_with_delay(dev, p);
 
         kfd_unref_process(p);
     }
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index 9f3090db2f16..dfc91d25c80d 100644

include/uapi/drm/amdgpu_drm.h +1 -0
@@ -58,6 +58,7 @@ extern "C" {
     #define DRM_AMDGPU_USERQ_SIGNAL             0x17
     #define DRM_AMDGPU_USERQ_WAIT               0x18
     #define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
+#define DRM_AMDGPU_USER_OPTIONS              0x1A
 
     #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
     #define DRM_IOCTL_AMDGPU_GEM_MMAP   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {
     #define DRM_IOCTL_AMDGPU_USERQ_SIGNAL       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)
     #define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
     #define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES

DRM_IOWR(DRM_COMMAND_BASE
+ DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)

include/uapi/drm/amdgpu_drm.h +24 -0
+#define DRM_IOCTL_AMDGPU_USER_OPTIONS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USER_OPTIONS, struct drm_amdgpu_user_options)
 
     /**
      * DOC: memory domains
@@ -1673,6 +1675,29 @@ struct drm_amdgpu_info_uq_metadata {
     #define AMDGPU_FAMILY_GC_11_5_4                     154 /* GC 11.5.4 */
     #define AMDGPU_FAMILY_GC_12_0_0                     152 /* GC 12.0.0 */
 
+/*
+ * Definition of user options
+ *
+ * option: AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY
+ *    0:          Disable sigbus delay - SIGBUS will be raised immediately
+ *    0xFFFFFFFF: SIGBUS will not be raised
+ *    other:      Set the sigbus delay in milliseconds
+ */
+#define AMDGPU_USER_OPTIONS_OP_KFD_SIGBUS_DELAY              0
+
+#define AMDGPU_USER_OPTIONS_KFD_SIGBUS_DELAY_DISABLED        0xFFFFFFFFu
+
+struct drm_amdgpu_user_options {
+     __u32 op;
+     union {
+             struct {
+                     __u16 value;
+                     __u16 _pad;
+             } kfd_sigbus_delay;
+             __u32 _pad;
+     };
+};
+
     #if defined(__cplusplus)
     }
     #endif