From: Jonathan Kim <[email protected]>

GFX 1250 allows the debugger to subcribe to LDS out-of-range read/write
memory violations.
Bump IOCTL minor version and flag KFD capabilities for enablement
hint.

Signed-off-by: Jonathan Kim <[email protected]>
Reviewed-by: Felix Kuehling <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_debug.c    | 7 +++++++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 4 ++++
 include/uapi/linux/kfd_ioctl.h            | 4 +++-
 include/uapi/linux/kfd_sysfs.h            | 3 ++-
 4 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
index ba9a09b6589a6..f83e1238c1b3d 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
@@ -519,6 +519,7 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, 
uint32_t *flags)
                struct kfd_topology_device *topo_dev =
                                
kfd_topology_device_by_id(target->pdds[i]->dev->id);
                uint32_t caps = topo_dev->node_props.capability;
+               uint32_t caps2 = topo_dev->node_props.capability2;
 
                if (!(caps & 
HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED) &&
                        (*flags & KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP)) {
@@ -531,6 +532,12 @@ int kfd_dbg_trap_set_flags(struct kfd_process *target, 
uint32_t *flags)
                        *flags = prev_flags;
                        return -EACCES;
                }
+
+               if (!(caps2 & 
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED) &&
+                   (*flags & KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE)) {
+                       *flags = prev_flags;
+                       return -EACCES;
+               }
        }
 
        target->dbg_flags = *flags;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index a0990dd2378c1..7a402c9c1b6e6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -2028,6 +2028,10 @@ static void kfd_topology_set_capabilities(struct 
kfd_topology_device *dev)
                if (KFD_GC_VERSION(dev->gpu) >= IP_VERSION(12, 0, 0))
                        dev->node_props.capability |=
                                
HSA_CAP_TRAP_DEBUG_PRECISE_ALU_OPERATIONS_SUPPORTED;
+
+               if (KFD_GC_VERSION(dev->gpu) >= IP_VERSION(12, 1, 0))
+                       dev->node_props.capability2 |=
+                               
HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED;
        }
 
        kfd_topology_set_dbg_firmware_support(dev);
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 4d0c1a53f9d51..6e91875c10baa 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -46,9 +46,10 @@
  * - 1.18 - Rename pad in set_memory_policy_args to misc_process_flag
  * - 1.19 - Add a new ioctl to craete secondary kfd processes
  * - 1.20 - Trap handler support for expert scheduling mode available
+ * - 1.21 - Debugger support to subscribe to LDS out-of-address exceptions
  */
 #define KFD_IOCTL_MAJOR_VERSION 1
-#define KFD_IOCTL_MINOR_VERSION 20
+#define KFD_IOCTL_MINOR_VERSION 21
 
 struct kfd_ioctl_get_version_args {
        __u32 major_version;    /* from KFD */
@@ -947,6 +948,7 @@ enum kfd_dbg_trap_address_watch_mode {
 enum kfd_dbg_trap_flags {
        KFD_DBG_TRAP_FLAG_SINGLE_MEM_OP = 1,
        KFD_DBG_TRAP_FLAG_SINGLE_ALU_OP = 2,
+       KFD_DBG_TRAP_FLAG_LDS_OUT_OF_ADDR_RANGE = 4
 };
 
 /* Trap exceptions */
diff --git a/include/uapi/linux/kfd_sysfs.h b/include/uapi/linux/kfd_sysfs.h
index 1125fe47959fa..0b6ce2f3c8871 100644
--- a/include/uapi/linux/kfd_sysfs.h
+++ b/include/uapi/linux/kfd_sysfs.h
@@ -64,7 +64,8 @@
 #define HSA_CAP_RESERVED                                       0x000f8000
 
 #define HSA_CAP2_PER_SDMA_QUEUE_RESET_SUPPORTED                        
0x00000001
-#define HSA_CAP2_RESERVED                                      0xfffffffe
+#define HSA_CAP2_TRAP_DEBUG_LDS_OUT_OF_ADDR_RANGE_SUPPORTED    0x00000002
+#define HSA_CAP2_RESERVED                                      0xfffffffc
 
 /* debug_prop bits in node properties */
 #define HSA_DBG_WATCH_ADDR_MASK_LO_BIT_MASK     0x0000000f
-- 
2.51.1

Reply via email to