Add GPU page fault query interface
Subsystems (3)
Alex Deucher
maintainercover Add GPU page fault query interface
This patch set adds support for an application to query GPU page faults. It's useful for debugging and there are vulkan extensions that could make use of this. Preliminary user space code which uses this can be found here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23238
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/298
Note, that I made a small change to the vmhub definition to decouple it from how the kernel tracks vmhubs so that we have a consistent user view even if we decide to add more vmhubs like we recently did for gfx 9.4.3.
I've also pushed the changed to:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/gpu_fault_info_ioctl
Alex Deucher (3):
drm/amdgpu: add cached GPU fault structure to vm struct drm/amdgpu: cache gpuvm fault information for gmc7+ drm/amdgpu: add new INFO ioctl query for the last GPU page fault
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 16 +++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 45 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 31 +++++++++++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 11 +++--- include/uapi/drm/amdgpu_drm.h | 16 +++++++++ 10 files changed, 126 insertions(+), 8 deletions(-)
Signature · 1 line
2.40.1
Alex Deucher
maintainerPATCH 1/3 drm/amdgpu: add cached GPU fault structure to vm struct
When we get a GPU pge fault, cache the fault for later analysis.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 ++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 18 +++++++++++++++ 2 files changed, 49 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +31 -0
@@ -2631,3 +2631,34 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m) total_done_objs); }#endif + +/** +* amdgpu_vm_update_fault_cache - update cached fault into. +* @adev: amdgpu device pointer +* @pasid: PASID of the VM +* @addr: Address of the fault +* @status: fault status register +* @vmhub: which vmhub got the fault +* +* Cache the fault info for later use by userspace in debuggging. +*/ +void amdgpu_vm_update_fault_cache (struct amdgpu_device *adev, +unsigned int pasid, +uint64_t addr, +uint32_t status, +unsigned int vmhub) +{ +struct amdgpu_vm *vm; +unsigned long flags; + +xa_lock_irqsave (&adev->vm_manager.pasids, flags); + + vm =xa_load (&adev->vm_manager.pasids, pasid); +if (vm) { + vm->fault_info.addr = addr; + vm->fault_info.status = status; + vm->fault_info.vmhub = vmhub; + } +xa_unlock_irqrestore (&adev->vm_manager.pasids, flags); +} +
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +18 -0
@@ -244,6 +244,15 @@ struct amdgpu_vm_update_funcs { struct dma_fence **fence); }; +struct amdgpu_vm_fault_info { +/* fault address */ +uint64_t addr; +/* fault status register */ +uint32_t status; +/* which vmhub? gfxhub, mmhub, etc. */ +unsigned int vmhub; +}; +struct amdgpu_vm {/* tree of virtual addresses mapped */ struct rb_root_cached va;
@@ -332,6 +341,9 @@ struct amdgpu_vm {/* Memory partition number, -1 means any partition */ int8_t mem_id; + +/* cached fault info */ +struct amdgpu_vm_fault_info fault_info; };struct amdgpu_vm_manager {
@@ -540,4 +552,10 @@ static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm) mutex_unlock(&vm->eviction_lock); } +void amdgpu_vm_update_fault_cache (struct amdgpu_device *adev, +unsigned int pasid, +uint64_t addr, +uint32_t status, +unsigned int vmhub); +#endif
Signature · 1 line
2.40.1
RE: [PATCH 1/3] drm/amdgpu: add cached GPU fault structure to vm struct
[Public]
3 nitpick comments.
Quoted 11 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, May 26, 2023 12:52 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; [email protected]
Subject: [PATCH 1/3] drm/amdgpu: add cached GPU fault structure to vm structWhen we get a GPU pge fault, cache the fault for later analysis.
A spelling typo, s/pge/page
Quoted 15 lines
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 31 ++++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 18 +++++++++++++++ 2 files changed, 49 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0
-0@@ -2631,3 +2631,34 @@ void amdgpu_debugfs_vm_bo_info(struct amdgpu_vm *vm, struct seq_file *m)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_debugfs_vm_bo_info(struct · line 2640
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7
-0total_done_objs); }#endif + +/** +* amdgpu_vm_update_fault_cache - update cached fault into. +* @adev: amdgpu device pointer +* @pasid: PASID of the VM +* @addr: Address of the fault +* @status: fault status register
I guess this 'status' means the status from fault status register.
Quoted 3 lines
+ * @vmhub: which vmhub got the fault
+ *
+ * Cache the fault info for later use by userspace in debuggging.
A spelling typo, s/debuggging/debugging.
Regards,
Guchun
Quoted 65 lines
+ */
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +19
-0+void amdgpu_vm_update_fault_cache (struct amdgpu_device *adev, +unsigned int pasid, +uint64_t addr, +uint32_t status, +unsigned int vmhub) +{ +struct amdgpu_vm *vm; +unsigned long flags; + +xa_lock_irqsave (&adev->vm_manager.pasids, flags); + + vm =xa_load (&adev->vm_manager.pasids, pasid); +if (vm) { + vm->fault_info.addr = addr; + vm->fault_info.status = status; + vm->fault_info.vmhub = vmhub; + } +xa_unlock_irqrestore (&adev->vm_manager.pasids, flags); } +drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +18
-0@@ -244,6 +244,15 @@ struct amdgpu_vm_update_funcs { struct dma_fence **fence); }; +struct amdgpu_vm_fault_info { +/* fault address */ +uint64_t addr; +/* fault status register */ +uint32_t status; +/* which vmhub? gfxhub, mmhub, etc. */ +unsigned int vmhub; +}; +struct amdgpu_vm {/* tree of virtual addresses mapped */ struct rb_root_cached va;@@ -332,6 +341,9 @@ struct amdgpu_vm {/* Memory partition number, -1 means any partition */ int8_t mem_id; + +/* cached fault info */ +struct amdgpu_vm_fault_info fault_info; };struct amdgpu_vm_manager {@@ -540,4 +552,10 @@ static inline void amdgpu_vm_eviction_unlock(struct amdgpu_vm *vm) mutex_unlock(&vm->eviction_lock); } +void amdgpu_vm_update_fault_cache (struct amdgpu_device *adev, +unsigned int pasid, +uint64_t addr, +uint32_t status, +unsigned int vmhub); +#endif
--
2.40.1
Alex Deucher
maintainerPATCH 2/3 drm/amdgpu: cache gpuvm fault information for gmc7+
In reply to Alex DeucherCache the current fault info in the vm struct. This can be queried by userspace later to help debug UMDs.
--- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 3 +++ drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 +++ drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 3 +++ drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 3 +++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 11 +++++++---- 5 files changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +3 -0
@@ -155,6 +155,9 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device *adev, status =RREG32 (hub->vm_l2_pro_fault_status);WREG32_P (hub->vm_l2_pro_fault_cntl,1 , ~1 ); + +amdgpu_vm_update_fault_cache (adev, entry->pasid, addr, status, + entry->vmid_src ?AMDGPU_MMHUB0 (0 ) :AMDGPU_GFXHUB (0 )); }if (!printk_ratelimit ())
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +3 -0
@@ -115,6 +115,9 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, status =RREG32 (hub->vm_l2_pro_fault_status);WREG32_P (hub->vm_l2_pro_fault_cntl,1 , ~1 ); + +amdgpu_vm_update_fault_cache (adev, entry->pasid, addr, status, + entry->vmid_src ?AMDGPU_MMHUB0 (0 ) :AMDGPU_GFXHUB (0 )); }if (printk_ratelimit ()) {
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -0
@@ -1272,6 +1272,9 @@ static int gmc_v7_0_process_interrupt(struct amdgpu_device *adev,if (!addr && !status)return 0 ; +amdgpu_vm_update_fault_cache (adev, entry->pasid, + ((u64 )addr) <<AMDGPU_GPU_PAGE_SHIFT , status,AMDGPU_GFXHUB (0 )); +if (amdgpu_vm_fault_stop ==AMDGPU_VM_FAULT_STOP_FIRST )gmc_v7_0_set_fault_enable_default (adev, false);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +3 -0
@@ -1447,6 +1447,9 @@ static int gmc_v8_0_process_interrupt(struct amdgpu_device *adev,if (!addr && !status)return 0 ; +amdgpu_vm_update_fault_cache (adev, entry->pasid, + ((u64 )addr) <<AMDGPU_GPU_PAGE_SHIFT , status,AMDGPU_GFXHUB (0 )); +if (amdgpu_vm_fault_stop ==AMDGPU_VM_FAULT_STOP_FIRST )gmc_v8_0_set_fault_enable_default (adev, false);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -4
@@ -555,6 +555,7 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,struct amdgpu_vmhub *hub;const char *mmhub_cid;const char *hub_name; +unsigned int vmhub;u64 addr;uint32_t cam_index =0 ;int ret, xcc_id =0 ;
@@ -567,10 +568,10 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,if (entry->client_id ==SOC15_IH_CLIENTID_VMC ) { hub_name ="mmhub0" ; - hub = &adev->vmhub[AMDGPU_MMHUB0 (node_id /4 )]; + vmhub =AMDGPU_MMHUB0 (node_id /4 ); }else if (entry->client_id ==SOC15_IH_CLIENTID_VMC1 ) { hub_name ="mmhub1" ; - hub = &adev->vmhub[AMDGPU_MMHUB1 (0 )]; + vmhub =AMDGPU_MMHUB1 (0 ); }else { hub_name ="gfxhub0" ;if (adev->gfx.funcs->ih_node_to_logical_xcc) {
@@ -579,8 +580,9 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,if (xcc_id <0 ) xcc_id =0 ; } - hub = &adev->vmhub[xcc_id]; + vmhub = xcc_id; } + hub = &adev->vmhub[vmhub];if (retry_fault) {if (adev->irq.retry_cam_enabled) {
@@ -626,7 +628,6 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev,if (!printk_ratelimit ())return 0 ; -memset (&task_info,0 ,sizeof (struct amdgpu_task_info ));amdgpu_vm_get_task_info (adev, entry->pasid, &task_info);
@@ -663,6 +664,8 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device *adev, rw =REG_GET_FIELD (status,VM_L2_PROTECTION_FAULT_STATUS ,RW );WREG32_P (hub->vm_l2_pro_fault_cntl,1 , ~1 ); +amdgpu_vm_update_fault_cache (adev, entry->pasid, addr, status, vmhub); +dev_err (adev->dev,"VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n" , status);
Signature · 1 line
2.40.1
Alex Deucher
maintainerPATCH 3/3 drm/amdgpu: add new INFO ioctl query for the last GPU page fault
In reply to Alex DeucherAdd a interface to query the last GPU page fault for the process. Useful for debugging context lost errors.
v2: split vmhub representation between kernel and userspace
Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23238
libdrm MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23238
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 16 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 13 ++++++++++--- include/uapi/drm/amdgpu_drm.h | 16 ++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
@@ -112,9 +112,10 @@* gl1c_cache_size, gl2c_cache_size, mall_size, enabled_rb_pipes_mask_hi * 3.53.0 - Support for GFX11 CP GFX shadowing * 3.54.0 - Add AMDGPU_CTX_QUERY2_FLAGS_RESET_IN_PROGRESS support +* - 3.55.0 - Add AMDGPU_INFO_GPUVM_FAULT query */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 54 +#define KMS_DRIVER_MINOR 55#define KMS_DRIVER_PATCHLEVEL 0unsigned int amdgpu_vram_limit =UINT_MAX ;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +16 -0
@@ -1163,6 +1163,22 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)return copy_to_user (out, max_ibs,min ((size_t )size,sizeof (max_ibs))) ? -EFAULT :0 ; } +case AMDGPU_INFO_GPUVM_FAULT : { +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct amdgpu_vm *vm = &fpriv->vm; +struct drm_amdgpu_info_gpuvm_fault gpuvm_fault; + +if (!vm) +return -EINVAL ; + +memset (&gpuvm_fault,0 ,sizeof (gpuvm_fault)); + gpuvm_fault.addr = vm->fault_info.addr; + gpuvm_fault.status = vm->fault_info.status; + gpuvm_fault.vmhub = vm->fault_info.vmhub; + +return copy_to_user (out, &gpuvm_fault, +min ((size_t )size,sizeof (gpuvm_fault))) ? -EFAULT :0 ; + }default :DRM_DEBUG_KMS ("Invalid request %d\n" , info->query);return -EINVAL ;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15 -1
@@ -2657,7 +2657,21 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,if (vm) { vm->fault_info.addr = addr; vm->fault_info.status = status; - vm->fault_info.vmhub = vmhub; +if (AMDGPU_IS_GFXHUB (vmhub)) { + vm->fault_info.vmhub =AMDGPU_VMHUB_TYPE_GFX ; + vm->fault_info.vmhub |= + (vmhub -AMDGPU_GFXHUB_START ) <<AMDGPU_VMHUB_IDX_SHIFT ; + }else if (AMDGPU_IS_MMHUB0 (vmhub)) { + vm->fault_info.vmhub =AMDGPU_VMHUB_TYPE_MM0 ; + vm->fault_info.vmhub |= + (vmhub -AMDGPU_MMHUB0_START ) <<AMDGPU_VMHUB_IDX_SHIFT ; + }else if (AMDGPU_IS_MMHUB1 (vmhub)) { + vm->fault_info.vmhub =AMDGPU_VMHUB_TYPE_MM1 ; + vm->fault_info.vmhub |= + (vmhub -AMDGPU_MMHUB1_START ) <<AMDGPU_VMHUB_IDX_SHIFT ; + }else { +WARN_ONCE (1 ,"Invalid vmhub %u\n" , vmhub); + } }xa_unlock_irqrestore (&adev->vm_manager.pasids, flags); }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +10 -3
@@ -116,9 +116,16 @@ struct amdgpu_mem_stats;* layout: max 8 GFXHUB + 4 MMHUB0 + 1 MMHUB1 */ #define AMDGPU_MAX_VMHUBS 13 -#define AMDGPU_GFXHUB (x) (x) -#define AMDGPU_MMHUB0 (x) (8 + x) -#define AMDGPU_MMHUB1 (x) (8 + 4 + x) +#define AMDGPU_GFXHUB_START 0 +#define AMDGPU_MMHUB0_START 8 +#define AMDGPU_MMHUB1_START 12 +#define AMDGPU_GFXHUB (x) (AMDGPU_GFXHUB_START + (x)) +#define AMDGPU_MMHUB0 (x) (AMDGPU_MMHUB0_START + (x)) +#define AMDGPU_MMHUB1 (x) (AMDGPU_MMHUB1_START + (x)) + +#define AMDGPU_IS_GFXHUB (x) ((x) >= AMDGPU_GFXHUB_START && (x) < AMDGPU_MMHUB0_START) +#define AMDGPU_IS_MMHUB0 (x) ((x) >= AMDGPU_MMHUB0_START && (x) < AMDGPU_MMHUB1_START) +#define AMDGPU_IS_MMHUB1 (x) ((x) >= AMDGPU_MMHUB1_START && (x) < AMDGPU_MAX_VMHUBS)/* Reserve 2MB at top/bottom of address space for kernel use */ #define AMDGPU_VA_RESERVED_SIZE (2ULL << 20)
include/uapi/drm/amdgpu_drm.h +16 -0
@@ -890,6 +890,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {#define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1/* Query the max number of IBs per gang per submission */ #define AMDGPU_INFO_MAX_IBS 0x22 +/* query last page fault info */ +#define AMDGPU_INFO_GPUVM_FAULT 0x23#define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0#define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
@@ -1215,6 +1217,20 @@ struct drm_amdgpu_info_video_caps {struct drm_amdgpu_info_video_codec_info codec_info[AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT ]; }; +#define AMDGPU_VMHUB_TYPE_MASK 0xff +#define AMDGPU_VMHUB_TYPE_SHIFT 0 +#define AMDGPU_VMHUB_TYPE_GFX 0 +#define AMDGPU_VMHUB_TYPE_MM0 1 +#define AMDGPU_VMHUB_TYPE_MM1 2 +#define AMDGPU_VMHUB_IDX_MASK 0xff00 +#define AMDGPU_VMHUB_IDX_SHIFT 8 + +struct drm_amdgpu_info_gpuvm_fault { +__u64 addr; +__u32 status; +__u32 vmhub; +}; +/* * Supported GPU families */
Signature · 1 line
2.40.1
Re: [PATCH 3/3] drm/amdgpu: add new INFO ioctl query for the last GPU page fault
Am 25.05.23 um 18:52 schrieb Alex Deucher:
Quoted 44 lines
Add a interface to query the last GPU page fault for the process. Useful for debugging context lost errors.
v2: split vmhub representation between kernel and userspace
Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23238
libdrm MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23238Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 16 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 13 ++++++++++--- include/uapi/drm/amdgpu_drm.h | 16 ++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -112,9 +112,10 @@* gl1c_cache_size, gl2c_cache_size, mall_size, enabled_rb_pipes_mask_hi * 3.53.0 - Support for GFX11 CP GFX shadowing * 3.54.0 - Add AMDGPU_CTX_QUERY2_FLAGS_RESET_IN_PROGRESS support +* - 3.55.0 - Add AMDGPU_INFO_GPUVM_FAULT query */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 54 +#define KMS_DRIVER_MINOR 55#define KMS_DRIVER_PATCHLEVEL 0unsigned int amdgpu_vram_limit =UINT_MAX ;drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-0@@ -1163,6 +1163,22 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)return copy_to_user (out, max_ibs,min ((size_t )size,sizeof (max_ibs))) ? -EFAULT :0 ; } +case AMDGPU_INFO_GPUVM_FAULT : { +struct amdgpu_fpriv *fpriv = filp->driver_priv;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1177
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +10
-0+struct amdgpu_vm *vm = &fpriv->vm; +struct drm_amdgpu_info_gpuvm_fault gpuvm_fault; + +if (!vm) +return -EINVAL ; + +memset (&gpuvm_fault,0 ,sizeof (gpuvm_fault)); + gpuvm_fault.addr = vm->fault_info.addr; + gpuvm_fault.status = vm->fault_info.status; + gpuvm_fault.vmhub = vm->fault_info.vmhub;
You need something to provide locking and barrier here. I suggest to just grab the xa lock.
Quoted 72 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4
-0+ +return copy_to_user (out, &gpuvm_fault, +min ((size_t )size,sizeof (gpuvm_fault))) ? -EFAULT :0 ; + }default :DRM_DEBUG_KMS ("Invalid request %d\n" , info->query);return -EINVAL ;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +15
-1@@ -2657,7 +2657,21 @@ void amdgpu_vm_update_fault_cache(struct amdgpu_device *adev,if (vm) { vm->fault_info.addr = addr; vm->fault_info.status = status; - vm->fault_info.vmhub = vmhub; +if (AMDGPU_IS_GFXHUB (vmhub)) { + vm->fault_info.vmhub =AMDGPU_VMHUB_TYPE_GFX ; + vm->fault_info.vmhub |= + (vmhub -AMDGPU_GFXHUB_START ) <<AMDGPU_VMHUB_IDX_SHIFT ; + }else if (AMDGPU_IS_MMHUB0 (vmhub)) { + vm->fault_info.vmhub =AMDGPU_VMHUB_TYPE_MM0 ; + vm->fault_info.vmhub |= + (vmhub -AMDGPU_MMHUB0_START ) <<AMDGPU_VMHUB_IDX_SHIFT ; + }else if (AMDGPU_IS_MMHUB1 (vmhub)) { + vm->fault_info.vmhub =AMDGPU_VMHUB_TYPE_MM1 ; + vm->fault_info.vmhub |= + (vmhub -AMDGPU_MMHUB1_START ) <<AMDGPU_VMHUB_IDX_SHIFT ; + }else { +WARN_ONCE (1 ,"Invalid vmhub %u\n" , vmhub); + } }xa_unlock_irqrestore (&adev->vm_manager.pasids, flags); }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +10
-3@@ -116,9 +116,16 @@ struct amdgpu_mem_stats;* layout: max 8 GFXHUB + 4 MMHUB0 + 1 MMHUB1 */ #define AMDGPU_MAX_VMHUBS 13 -#define AMDGPU_GFXHUB (x) (x) -#define AMDGPU_MMHUB0 (x) (8 + x) -#define AMDGPU_MMHUB1 (x) (8 + 4 + x) +#define AMDGPU_GFXHUB_START 0 +#define AMDGPU_MMHUB0_START 8 +#define AMDGPU_MMHUB1_START 12 +#define AMDGPU_GFXHUB (x) (AMDGPU_GFXHUB_START + (x)) +#define AMDGPU_MMHUB0 (x) (AMDGPU_MMHUB0_START + (x)) +#define AMDGPU_MMHUB1 (x) (AMDGPU_MMHUB1_START + (x)) + +#define AMDGPU_IS_GFXHUB (x) ((x) >= AMDGPU_GFXHUB_START && (x) < AMDGPU_MMHUB0_START) +#define AMDGPU_IS_MMHUB0 (x) ((x) >= AMDGPU_MMHUB0_START && (x) < AMDGPU_MMHUB1_START) +#define AMDGPU_IS_MMHUB1 (x) ((x) >= AMDGPU_MMHUB1_START && (x) < AMDGPU_MAX_VMHUBS)/* Reserve 2MB at top/bottom of address space for kernel use */ #define AMDGPU_VA_RESERVED_SIZE (2ULL << 20)include/uapi/drm/amdgpu_drm.h +2
-0@@ -890,6 +890,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {#define AMDGPU_INFO_VIDEO_CAPS_ENCODE 1/* Query the max number of IBs per gang per submission */ #define AMDGPU_INFO_MAX_IBS 0x22 +/* query last page fault info */ +#define AMDGPU_INFO_GPUVM_FAULT 0x23#define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0#define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_info_video_caps { · line 1226
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +7
-0@@ -1215,6 +1217,20 @@ struct drm_amdgpu_info_video_caps {struct drm_amdgpu_info_video_codec_info codec_info[AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_COUNT ]; }; +#define AMDGPU_VMHUB_TYPE_MASK 0xff +#define AMDGPU_VMHUB_TYPE_SHIFT 0 +#define AMDGPU_VMHUB_TYPE_GFX 0 +#define AMDGPU_VMHUB_TYPE_MM0 1 +#define AMDGPU_VMHUB_TYPE_MM1 2 +#define AMDGPU_VMHUB_IDX_MASK 0xff00 +#define AMDGPU_VMHUB_IDX_SHIFT 8
IIRC UMR already established the standard to put the hub type in the higher bits and the hub number/VMID in the lower ones.
Probably best to sync up with Tom so that both interfaces use the same numbering.
Apart from that looks good to me.
Christian.
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +7
-0+ +struct drm_amdgpu_info_gpuvm_fault { +__u64 addr; +__u32 status; +__u32 vmhub; +}; +/* * Supported GPU families */
Ping on this series?
Alex
Quoted 37 lines · Alex Deucher
This patch set adds support for an application to query GPU page faults. It's useful for debugging and there are vulkan extensions that could make use of this. Preliminary user space code which uses this can be found here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23238
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/298Note, that I made a small change to the vmhub definition to decouple it from how the kernel tracks vmhubs so that we have a consistent user view even if we decide to add more vmhubs like we recently did for gfx 9.4.3.
I've also pushed the changed to:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/gpu_fault_info_ioctlAlex Deucher (3):
drm/amdgpu: add cached GPU fault structure to vm struct drm/amdgpu: cache gpuvm fault information for gmc7+ drm/amdgpu: add new INFO ioctl query for the last GPU page faultdrivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 16 +++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 45 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 31 +++++++++++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 11 +++--- include/uapi/drm/amdgpu_drm.h | 16 +++++++++ 10 files changed, 126 insertions(+), 8 deletions(-)--
2.40.1
[Public]
With the 3 nitpicks fixed in patch 1, the series are: Acked-by: Guchun Chen <[email protected]>
Regards,
Guchun
Quoted 53 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Tuesday, June 6, 2023 11:40 PM
To: Deucher, Alexander <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 0/3] Add GPU page fault query interfacePing on this series?
Alex
Quoted 18 lines · Alex Deucher
This patch set adds support for an application to query GPU page faults. It's useful for debugging and there are vulkan extensions that could make use of this. Preliminary user space code which uses this can be found here:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23238
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/298Note, that I made a small change to the vmhub definition to decouple it from how the kernel tracks vmhubs so that we have a consistent user view even if we decide to add more vmhubs like we recently did for gfx 9.4.3.
I've also pushed the changed to:
https://gitlab.freedesktop.org/agd5f/linux/-/commits/gpu_fault_info_io
ctlQuoted 8 lines
Alex Deucher (3):
drm/amdgpu: add cached GPU fault structure to vm struct drm/amdgpu: cache gpuvm fault information for gmc7+ drm/amdgpu: add new INFO ioctl query for the last GPU page faultdrivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c| 16 +++++++++drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c| 45+++++++++++++++++++++++++
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 31 +++++++++++++++-- drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 3 ++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 11 +++--- include/uapi/drm/amdgpu_drm.h | 16 +++++++++ 10 files changed, 126 insertions(+), 8 deletions(-)--
2.40.1