drm/amdgpu: include ip discovery data in devcoredump
Subsystems (2)
PATCH v2 1/6 drm/amdgpu: include ip discovery data in devcoredump
This is the best way to describe the GPU to a tool loading the devcoredump.
--- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 42 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h | 3 ++ 3 files changed, 47 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +2 -0
@@ -262,6 +262,8 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count, } } +amdgpu_discovery_dump (coredump->adev, &p); +/* IP firmware information */ drm_printf (&p,"\nIP Firmwares\n" );amdgpu_devcoredump_fw_info (coredump->adev, &p);
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +42 -0
48 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h +3 -0
@@ -30,6 +30,7 @@#define DISCOVERY_TMR_OFFSET (64 << 10)struct ip_discovery_top ; +struct drm_printer ;struct amdgpu_discovery_info {struct debugfs_blob_wrapper debugfs_blob;
@@ -47,4 +48,6 @@ int amdgpu_discovery_get_nps_info(struct amdgpu_device *adev,struct amdgpu_gmc_memrange **ranges, int *range_cnt, bool refresh); +void amdgpu_discovery_dump (struct amdgpu_device *adev,struct drm_printer *p); +#endif /* __AMDGPU_DISCOVERY__ */
Signature · 1 line
2.43.0
PATCH v2 2/6 drm/amdgpu: move devcoredump generation to a worker
Update the way drm_coredump_printer is used based on its documentation and Xe's code: the main idea is to generate the final version in one go and then use memcpy to return the chunks requested by the caller of amdgpu_devcoredump_read.
The generation is moved to a separate worker thread.
This cuts the time to copy the dump from 40s to ~0s on my machine.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 ++ .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 66 +++++++++++++++++-- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 9 +++ 3 files changed, 74 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +5 -0
@@ -1200,6 +1200,11 @@ struct amdgpu_device {struct amdgpu_reset_domain *reset_domain; +#ifdef CONFIG_DEV_COREDUMP +/* If a coredump state capture is in progress don't start a new one. */ +bool coredump_in_progress; +#endif +struct mutex benchmark_mutex;bool scpm_enabled;
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +60 -6
113 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +9 -0
@@ -35,9 +35,18 @@ struct amdgpu_coredump_info {struct amdgpu_device *adev;struct amdgpu_task_info reset_task_info;struct timespec64 reset_time; + +struct work_struct work; +bool skip_vram_check;bool reset_vram_lost;struct amdgpu_ring *ring; +/* Readable form of coredevdump, generate once to speed up +* reading it (see drm_coredump_printer's documentation). +*/ +ssize_t formatted_size; + char *formatted; + };#endif
Signature · 1 line
2.43.0
Christian König
maintainerRe: [PATCH v2 2/6] drm/amdgpu: move devcoredump generation to a worker
Quoted 22 lines · Pierre-Eric Pelloux-Prayer
Update the way
drm_coredump_printeris used based on its documentation and Xe's code: the main idea is to generate the final version in one go and then use memcpy to return the chunks requested by the caller ofamdgpu_devcoredump_read.The generation is moved to a separate worker thread.
This cuts the time to copy the dump from 40s to ~0s on my machine.
Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>Acked-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 ++ .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 66 +++++++++++++++++-- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 9 +++ 3 files changed, 74 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_device { · line 1206
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -1200,6 +1200,11 @@ struct amdgpu_device {struct amdgpu_reset_domain *reset_domain; +#ifdef CONFIG_DEV_COREDUMP +/* If a coredump state capture is in progress don't start a new one. */ +bool coredump_in_progress; +#endif
Don't keep that as state around, gather it directly from the work item.
Quoted 101 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+struct mutex benchmark_mutex;bool scpm_enabled;drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +52
-4@@ -34,6 +34,8 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, }#else +#define AMDGPU_CORE_DUMP_SIZE_MAX (256 * 1024 * 1024) +const char *hw_ip_names[MAX_HWIP ] = { [GC_HWIP ] ="GC" , [HDP_HWIP] = "HDP",@@ -196,11 +198,9 @@ static void amdgpu_devcoredump_fw_info(struct amdgpu_device *adev, }static ssize_t -amdgpu_devcoredump_read (char *buffer,loff_t offset,size_t count, -void *data,size_t datalen) +amdgpu_devcoredump_format (char *buffer,size_t count,struct amdgpu_coredump_info *coredump) {struct drm_printer p; -struct amdgpu_coredump_info *coredump = data;struct drm_print_iterator iter;struct amdgpu_vm_fault_info *fault_info;struct amdgpu_ip_block *ip_block;@@ -208,7 +208,6 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count, iter.data = buffer; iter.offset =0 ; - iter.start = offset; iter.remain = count; p =drm_coredump_printer (&iter);@@ -323,11 +322,60 @@ amdgpu_devcoredump_read(char *buffer, loff_t offset, size_t count,return count - iter.remain; } +static ssize_t +amdgpu_devcoredump_read (char *buffer,loff_t offset,size_t count, +void *data,size_t datalen) +{ +struct amdgpu_coredump_info *coredump = data; +ssize_t byte_copied; + +if (!coredump) +return -ENODEV ; + +flush_work (&coredump->work); + +if (!coredump->formatted) +return -ENODEV ; + +if (offset >= coredump->formatted_size) +return 0 ; + + byte_copied = count < coredump->formatted_size - offset ? count : + coredump->formatted_size - offset; +memcpy (buffer, coredump->formatted + offset, byte_copied); + +return byte_copied; +} +static void amdgpu_devcoredump_free (void *data) { +struct amdgpu_coredump_info *coredump = data; + +cancel_work_sync (&coredump->work); + coredump->adev->coredump_in_progress = false; +kfree (coredump->formatted);kfree (data); } +static void amdgpu_devcoredump_deferred_work (struct work_struct *work) +{ +struct amdgpu_coredump_info *coredump =container_of (work,typeof (*coredump), work); + +dev_coredumpm (coredump->adev->dev,THIS_MODULE , coredump,0 ,GFP_NOWAIT , + amdgpu_devcoredump_read, amdgpu_devcoredump_free); + +/* Do a one-time preparation of the coredump output because +* repeatingly calling drm_coredump_printer is very slow. +*/ + coredump->formatted_size = +amdgpu_devcoredump_format (NULL ,AMDGPU_CORE_DUMP_SIZE_MAX , coredump); + coredump->formatted =kvzalloc (coredump->formatted_size,GFP_KERNEL ); +if (!coredump->formatted) +return ; +amdgpu_devcoredump_format (coredump->formatted, coredump->formatted_size, coredump); + coredump->adev->coredump_in_progress = false; +} +void amdgpu_coredump (struct amdgpu_device *adev,bool skip_vram_check,bool vram_lost,struct amdgpu_job *job) {@@ -335,10 +383,15 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,struct amdgpu_coredump_info *coredump;
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, · line 393
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +4
-0struct drm_sched_job *s_job; +if (adev->coredump_in_progress) +return ; + coredump =kzalloc (sizeof (*coredump),GFP_NOWAIT );if (!coredump)return ; + adev->coredump_in_progress = true;
That is racy, clearly don't do that.
Regards,
Christian.
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +4
-2+ coredump->skip_vram_check = skip_vram_check; coredump->reset_vram_lost = vram_lost;@@ -361,8 +414,9 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,ktime_get_ts64 (&coredump->reset_time); -dev_coredumpm (dev->dev,THIS_MODULE , coredump,0 ,GFP_NOWAIT , - amdgpu_devcoredump_read, amdgpu_devcoredump_free); +/* Kick off coredump formatting to a worker thread. */ +INIT_WORK (&coredump->work, amdgpu_devcoredump_deferred_work); +queue_work (system_unbound_wq, &coredump->work);drm_info (dev,"AMDGPU device coredump file has been created\n" ); drm_info(dev, "Check your /sys/class/drm/card%d/device/devcoredump/data\n",drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +9
-0@@ -35,9 +35,18 @@ struct amdgpu_coredump_info {struct amdgpu_device *adev;struct amdgpu_task_info reset_task_info;struct timespec64 reset_time; + +struct work_struct work; +bool skip_vram_check;bool reset_vram_lost;struct amdgpu_ring *ring; +/* Readable form of coredevdump, generate once to speed up +* reading it (see drm_coredump_printer's documentation). +*/ +ssize_t formatted_size; + char *formatted; + };#endif
PATCH v2 3/6 drm/amdgpu: save ring content before resetting the device
In reply to Pierre-Eric Pelloux-PrayerOtherwise the content might not be relevant.
When a coredump is generated the rings with outstanding fences are saved and then printed to the final devcoredump from the worker thread.
Since this requires memory allocation, the ring capture might be missing from the generated devcoredump.
--- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 85 +++++++++++++++---- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 13 ++- 2 files changed, 81 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +69 -16
@@ -204,7 +204,9 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_infstruct drm_print_iterator iter;struct amdgpu_vm_fault_info *fault_info;struct amdgpu_ip_block *ip_block; -int ver; +struct amdgpu_ring *ring; +int ver, i, j; +u32 ring_idx, off; iter.data = buffer; iter.offset =0 ;
@@ -294,23 +296,25 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_inf/* Add ring buffer information */ drm_printf (&p,"Ring buffer information\n" ); -for (int i =0 ; i < coredump->adev->num_rings; i++) { -int j =0 ; -struct amdgpu_ring *ring = coredump->adev->rings[i]; +if (coredump->num_rings) { +for (i =0 ; i < coredump->num_rings; i++) { + ring_idx = coredump->rings[i].ring_index; + ring = coredump->adev->rings[ring_idx]; + off = coredump->rings[i].offset; -drm_printf (&p,"ring name: %s\n" , ring->name); -drm_printf (&p,"Rptr: 0x%llx Wptr: 0x%llx RB mask: %x\n" , -amdgpu_ring_get_rptr (ring), -amdgpu_ring_get_wptr (ring), - ring->buf_mask); -drm_printf (&p,"Ring size in dwords: %d\n" , - ring->ring_size /4 ); -drm_printf (&p,"Ring contents\n" ); -drm_printf (&p,"Offset \t Value\n" ); +drm_printf (&p,"ring name: %s\n" , ring->name); +drm_printf (&p,"Rptr: 0x%llx Wptr: 0x%llx RB mask: %x\n" , + coredump->rings[i].rptr, + coredump->rings[i].wptr, + ring->buf_mask); +drm_printf (&p,"Ring size in dwords: %d\n" , + ring->ring_size /4 ); +drm_printf (&p,"Ring contents\n" ); +drm_printf (&p,"Offset \t Value\n" ); -while (j < ring->ring_size) { -drm_printf (&p,"0x%x \t 0x%x\n" , j, ring->ring[j /4 ]); - j +=4 ; +for (j =0 ; j < ring->ring_size; j +=4 ) +drm_printf (&p,"0x%x \t 0x%x\n" , j, + coredump->rings_dw[off + j /4 ]); } }
@@ -354,6 +358,8 @@ static void amdgpu_devcoredump_free(void *data)cancel_work_sync (&coredump->work); coredump->adev->coredump_in_progress = false;kfree (coredump->formatted); +kfree (coredump->rings); +kfree (coredump->rings_dw);kfree (data); }
@@ -382,6 +388,12 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,struct drm_device *dev =adev_to_drm (adev);struct amdgpu_coredump_info *coredump;struct drm_sched_job *s_job; +u64 total_ring_size, ring_count; +struct amdgpu_ring *ring; +int i, off, idx; + +if (adev->coredump_in_progress) +return ;if (adev->coredump_in_progress)return ;
@@ -410,6 +422,47 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->ring =to_amdgpu_ring (s_job->sched); } +/* Dump ring content if memory allocation succeeds. */ + ring_count =0 ; + total_ring_size =0 ; +for (i =0 ; i < adev->num_rings; i++) { + ring = adev->rings[i]; + +/* Only dump rings with unsignalled fences. */ +if (atomic_read (&ring->fence_drv.last_seq) == ring->fence_drv.sync_seq && + coredump->ring != ring) +continue ; + + total_ring_size += ring->ring_size; + ring_count++; + } + coredump->rings_dw =kzalloc (total_ring_size,GFP_NOWAIT ); + coredump->rings =kcalloc (ring_count,sizeof (struct amdgpu_coredump_ring ),GFP_NOWAIT ); +if (coredump->rings && coredump->rings_dw) { +for (i =0 , off =0 , idx =0 ; i < adev->num_rings; i++) { + ring = adev->rings[i]; + +if (atomic_read (&ring->fence_drv.last_seq) == ring->fence_drv.sync_seq && + coredump->ring != ring) +continue ; + + coredump->rings[idx].ring_index = ring->idx; + coredump->rings[idx].rptr =amdgpu_ring_get_rptr (ring); + coredump->rings[idx].wptr =amdgpu_ring_get_wptr (ring); + coredump->rings[idx].offset = off; + +memcpy (&coredump->rings_dw[off], ring->ring, ring->ring_size); + off += ring->ring_size; + idx++; + } + coredump->num_rings = idx; + }else { +kfree (coredump->rings_dw); +kfree (coredump->rings); + coredump->rings_dw =NULL ; + coredump->rings =NULL ; + } + coredump->adev = adev;ktime_get_ts64 (&coredump->reset_time);
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +12 -1
@@ -31,6 +31,13 @@#define AMDGPU_COREDUMP_VERSION "1" +struct amdgpu_coredump_ring { +u64 rptr; +u64 wptr; +u32 ring_index; +u32 offset; +}; +struct amdgpu_coredump_info {struct amdgpu_device *adev;struct amdgpu_task_info reset_task_info;
@@ -41,12 +48,16 @@ struct amdgpu_coredump_info {bool skip_vram_check;bool reset_vram_lost;struct amdgpu_ring *ring; + +struct amdgpu_coredump_ring *rings; +u32 *rings_dw; +u32 num_rings; +/* Readable form of coredevdump, generate once to speed up * reading it (see drm_coredump_printer's documentation). */ ssize_t formatted_size; char *formatted; - };#endif
Signature · 1 line
2.43.0
PATCH v2 4/6 drm/amdgpu: extract amdgpu_vm_lock_by_pasid from amdgpu_vm_handle_fault
In reply to Pierre-Eric Pelloux-PrayerThis is tricky to implement right and we're going to need it from the devcoredump.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 84 +++++++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 + 2 files changed, 57 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +54 -30
@@ -2930,6 +2930,50 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)return 0 ; } +/** +* amdgpu_vm_lock_by_pasid - return an amdgpu_vm and its root bo from a pasid, if possible. +* @adev: amdgpu device pointer +* @root: root BO of the VM +* @pasid: PASID of the VM +* The caller needs to unreserve and unref the root bo on success. +*/ +struct amdgpu_vm *amdgpu_vm_lock_by_pasid (struct amdgpu_device *adev, +struct amdgpu_bo **root,u32 pasid) +{ +unsigned long irqflags; +struct amdgpu_vm *vm; +int r; + +xa_lock_irqsave (&adev->vm_manager.pasids, irqflags); + vm =xa_load (&adev->vm_manager.pasids, pasid); + *root = vm ?amdgpu_bo_ref (vm->root.bo) :NULL ; +xa_unlock_irqrestore (&adev->vm_manager.pasids, irqflags); + +if (!*root) +return NULL ; + + r =amdgpu_bo_reserve (*root, true); +if (r) + goto error_unref; + +/* Double check that the VM still exists */ +xa_lock_irqsave (&adev->vm_manager.pasids, irqflags); + vm =xa_load (&adev->vm_manager.pasids, pasid); +if (vm && vm->root.bo != *root) + vm =NULL ; +xa_unlock_irqrestore (&adev->vm_manager.pasids, irqflags); +if (!vm) + goto error_unlock; + +return vm; +error_unlock: +amdgpu_bo_unreserve (*root); + +error_unref: +amdgpu_bo_unref (root); +return NULL ; +} +/** * amdgpu_vm_handle_fault - graceful handling of VM faults. * @adev: amdgpu device pointer
@@ -2945,50 +2989,31 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)* shouldn't be reported any more. */ bool amdgpu_vm_handle_fault (struct amdgpu_device *adev,u32 pasid, -u32 vmid,u32 node_id,uint64_t addr,uint64_t ts, -bool write_fault) +u32 vmid,u32 node_id,uint64_t addr, +uint64_t ts,bool write_fault) {bool is_compute_context = false;struct amdgpu_bo *root; -unsigned long irqflags;uint64_t value, flags;struct amdgpu_vm *vm;int r; -xa_lock_irqsave (&adev->vm_manager.pasids, irqflags); - vm =xa_load (&adev->vm_manager.pasids, pasid); -if (vm) { - root =amdgpu_bo_ref (vm->root.bo); - is_compute_context = vm->is_compute_context; - }else { - root =NULL ; - } -xa_unlock_irqrestore (&adev->vm_manager.pasids, irqflags); - -if (!root) + vm =amdgpu_vm_lock_by_pasid (adev, &root, pasid); +if (!vm)return false; + is_compute_context = vm->is_compute_context; + addr /=AMDGPU_GPU_PAGE_SIZE ; -if (is_compute_context && !svm_range_restore_pages (adev, pasid, vmid, - node_id, addr, ts, write_fault)) { +if (is_compute_context && + !svm_range_restore_pages (adev, pasid, vmid, node_id, addr, + ts, write_fault)) { +amdgpu_bo_unreserve (root);amdgpu_bo_unref (&root);return true; } - r =amdgpu_bo_reserve (root, true); -if (r) - goto error_unref; - -/* Double check that the VM still exists */ -xa_lock_irqsave (&adev->vm_manager.pasids, irqflags); - vm =xa_load (&adev->vm_manager.pasids, pasid); -if (vm && vm->root.bo != root) - vm =NULL ; -xa_unlock_irqrestore (&adev->vm_manager.pasids, irqflags); -if (!vm) - goto error_unlock; - flags =AMDGPU_PTE_VALID |AMDGPU_PTE_SNOOPED |AMDGPU_PTE_SYSTEM ;
@@ -3027,7 +3052,6 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid,if (r <0 )dev_err (adev->dev,"Can't handle page fault (%d)\n" , r); -error_unref:amdgpu_bo_unref (&root);return false;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -0
@@ -589,6 +589,9 @@ bool amdgpu_vm_handle_fault(struct amdgpu_device *adev, u32 pasid, u32 vmid, u32 node_id, uint64_t addr, uint64_t ts, bool write_fault); +struct amdgpu_vm *amdgpu_vm_lock_by_pasid (struct amdgpu_device *adev, +struct amdgpu_bo **root,u32 pasid); +void amdgpu_vm_set_task_info (struct amdgpu_vm *vm); void amdgpu_vm_move_to_lru_tail(struct amdgpu_device *adev,
Signature · 1 line
2.43.0
PATCH v2 5/6 drm/amdgpu: store ib info for devcoredump
In reply to Pierre-Eric Pelloux-PrayerStore the basic state of IBs so we can read it back in the amdgpu_devcoredump_format function.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 13 ++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +10 -3
@@ -387,6 +387,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, {struct drm_device *dev =adev_to_drm (adev);struct amdgpu_coredump_info *coredump; +size_t size =sizeof (*coredump);struct drm_sched_job *s_job;u64 total_ring_size, ring_count;struct amdgpu_ring *ring;
@@ -395,10 +396,10 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,if (adev->coredump_in_progress)return ; -if (adev->coredump_in_progress) -return ; +if (job && job->pasid) + size +=sizeof (struct amdgpu_coredump_ib_info ) * job->num_ibs; - coredump =kzalloc (sizeof (*coredump),GFP_NOWAIT ); + coredump =kzalloc (size,GFP_NOWAIT );if (!coredump)return ;
@@ -406,6 +407,7 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->skip_vram_check = skip_vram_check; coredump->reset_vram_lost = vram_lost; + coredump->pasid = job->pasid;if (job && job->pasid) {struct amdgpu_task_info *ti;
@@ -415,6 +417,11 @@ void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check, coredump->reset_task_info = *ti;amdgpu_vm_put_task_info (ti); } + coredump->num_ibs = job->num_ibs; +for (i =0 ; i < job->num_ibs; ++i) { + coredump->ibs[i].gpu_addr = job->ibs[i].gpu_addr; + coredump->ibs[i].ib_size_dw = job->ibs[i].length_dw; + } }if (job) {
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.h +9 -0
@@ -38,6 +38,11 @@ struct amdgpu_coredump_ring {u32 offset; }; +struct amdgpu_coredump_ib_info { +uint64_t gpu_addr; +u32 ib_size_dw; +}; +struct amdgpu_coredump_info {struct amdgpu_device *adev;struct amdgpu_task_info reset_task_info;
@@ -58,6 +63,10 @@ struct amdgpu_coredump_info {*/ ssize_t formatted_size;char *formatted; + +unsigned int pasid; +int num_ibs; + struct amdgpu_coredump_ib_info ibs[] __counted_by(num_ibs); };#endif
Signature · 1 line
2.43.0
PATCH v2 6/6 drm/amdgpu: dump job ibs in the devcoredump
In reply to Pierre-Eric Pelloux-PrayerNow that we have a worker thread, we can try to access the IBs of the job. The process is:
* get the VM from the PASID
* get the BO from its VA and the VM
* map the BO for CPU access
* copy everything, then add it to the dump
Each step can fail so we have to be cautious.
These operations can be slow so when amdgpu_devcoredump_format is called only to determine the size of the buffer we skip all of them and assume they will succeed.
---
v2: added some comments
---
--- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +92 -1
@@ -200,14 +200,24 @@ static void amdgpu_devcoredump_fw_info(struct amdgpu_device *adev,static ssize_t amdgpu_devcoredump_format (char *buffer,size_t count,struct amdgpu_coredump_info *coredump) { +struct amdgpu_device *adev = coredump->adev;struct drm_printer p;struct drm_print_iterator iter;struct amdgpu_vm_fault_info *fault_info; +struct amdgpu_bo_va_mapping *mapping;struct amdgpu_ip_block *ip_block; +struct amdgpu_res_cursor cursor; +struct amdgpu_bo *abo, *root; +uint64_t va_start, offset;struct amdgpu_ring *ring; -int ver, i, j; +struct amdgpu_vm *vm; +u32 *ib_content; +uint8_t *kptr; +int ver, i, j, r;u32 ring_idx, off; +bool sizing_pass; + sizing_pass = buffer ==NULL ; iter.data = buffer; iter.offset =0 ; iter.remain = count;
@@ -323,6 +333,87 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_infelse if (coredump->reset_vram_lost)drm_printf (&p,"VRAM is lost due to GPU reset!\n" ); +if (coredump->num_ibs) { +/* Don't try to lookup the VM or map the BOs when calculating the +* size required to store the devcoredump. +*/ +if (sizing_pass) + vm =NULL ; +else + vm =amdgpu_vm_lock_by_pasid (adev, &root, coredump->pasid); + +for (int i =0 ; i < coredump->num_ibs && (sizing_pass || vm); i++) { + ib_content =kvmalloc_array (coredump->ibs[i].ib_size_dw,4 , +GFP_KERNEL ); +if (!ib_content) +continue ; + +/* vm=NULL can only happen when 'sizing_pass' is true. Skip to the +* drm_printf() calls (ib_content doesn't need to be initialized +* as its content won't be written anywhere). +*/ +if (!vm) + goto output_ib_content; + + va_start = coredump->ibs[i].gpu_addr &AMDGPU_GMC_HOLE_MASK ; + mapping =amdgpu_vm_bo_lookup_mapping (vm, va_start /AMDGPU_GPU_PAGE_SIZE ); +if (!mapping) + goto free_ib_content; + + offset = va_start - (mapping->start *AMDGPU_GPU_PAGE_SIZE ); + abo =amdgpu_bo_ref (mapping->bo_va->base.bo); + r =amdgpu_bo_reserve (abo, false); +if (r) + goto free_ib_content; + +if (abo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS ) { + off =0 ; + +if (abo->tbo.resource->mem_type !=TTM_PL_VRAM ) + goto unreserve_abo; + +amdgpu_res_first (abo->tbo.resource, offset, + coredump->ibs[i].ib_size_dw *4 , + &cursor); +while (cursor.remaining) { +amdgpu_device_mm_access (adev, cursor.start /4 , + &ib_content[off], cursor.size /4 , + false); + off += cursor.size; +amdgpu_res_next (&cursor, cursor.size); + } + }else { + r =ttm_bo_kmap (&abo->tbo,0 , +PFN_UP (abo->tbo.base.size), + &abo->kmap); +if (r) + goto unreserve_abo; + + kptr =amdgpu_bo_kptr (abo); + kptr += offset; +memcpy (ib_content, kptr, + coredump->ibs[i].ib_size_dw *4 ); + +amdgpu_bo_kunmap (abo); + } + +output_ib_content: +drm_printf (&p,"\nIB #%d 0x%llx %d dw\n" , + i, coredump->ibs[i].gpu_addr, coredump->ibs[i].ib_size_dw); +for (int j =0 ; j < coredump->ibs[i].ib_size_dw; j++) +drm_printf (&p,"0x%08x\n" , ib_content[j]); +unreserve_abo: +if (vm) +amdgpu_bo_unreserve (abo); +free_ib_content: +kfree (ib_content); + } +if (vm) { +amdgpu_bo_unreserve (root); +amdgpu_bo_unref (&root); + } + } +return count - iter.remain; }
Signature · 1 line
2.43.0
Re: [PATCH v2 6/6] drm/amdgpu: dump job ibs in the devcoredump
Quoted 12 lines · Pierre-Eric Pelloux-Prayer
Now that we have a worker thread, we can try to access the IBs of the job. The process is:
* get the VM from the PASID
* get the BO from its VA and the VM
* map the BO for CPU access
* copy everything, then add it to the dump
Each step can fail so we have to be cautious.
These operations can be slow so whenamdgpu_devcoredump_formatis called only to determine the size of the buffer we skip all of them and assume they will succeed.
Quoted 5 lines
---
v2: added some comments
---Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>
Quoted 125 lines
--- .../gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c +92
-2@@ -200,14 +200,24 @@ static void amdgpu_devcoredump_fw_info(struct amdgpu_device *adev,static ssize_t amdgpu_devcoredump_format (char *buffer,size_t count,struct amdgpu_coredump_info *coredump) { +struct amdgpu_device *adev = coredump->adev;struct drm_printer p;struct drm_print_iterator iter;struct amdgpu_vm_fault_info *fault_info; +struct amdgpu_bo_va_mapping *mapping;struct amdgpu_ip_block *ip_block; +struct amdgpu_res_cursor cursor; +struct amdgpu_bo *abo, *root; +uint64_t va_start, offset;struct amdgpu_ring *ring; -int ver, i, j; +struct amdgpu_vm *vm; +u32 *ib_content; +uint8_t *kptr; +int ver, i, j, r;u32 ring_idx, off; +bool sizing_pass; + sizing_pass = buffer ==NULL ; iter.data = buffer; iter.offset =0 ; iter.remain = count;@@ -323,6 +333,87 @@ amdgpu_devcoredump_format(char *buffer, size_t count, struct amdgpu_coredump_infelse if (coredump->reset_vram_lost)drm_printf (&p,"VRAM is lost due to GPU reset!\n" ); +if (coredump->num_ibs) { +/* Don't try to lookup the VM or map the BOs when calculating the +* size required to store the devcoredump. +*/ +if (sizing_pass) + vm =NULL ; +else + vm =amdgpu_vm_lock_by_pasid (adev, &root, coredump->pasid); + +for (int i =0 ; i < coredump->num_ibs && (sizing_pass || vm); i++) { + ib_content =kvmalloc_array (coredump->ibs[i].ib_size_dw,4 , +GFP_KERNEL ); +if (!ib_content) +continue ; + +/* vm=NULL can only happen when 'sizing_pass' is true. Skip to the +* drm_printf() calls (ib_content doesn't need to be initialized +* as its content won't be written anywhere). +*/ +if (!vm) + goto output_ib_content; + + va_start = coredump->ibs[i].gpu_addr &AMDGPU_GMC_HOLE_MASK ; + mapping =amdgpu_vm_bo_lookup_mapping (vm, va_start /AMDGPU_GPU_PAGE_SIZE ); +if (!mapping) + goto free_ib_content; + + offset = va_start - (mapping->start *AMDGPU_GPU_PAGE_SIZE ); + abo =amdgpu_bo_ref (mapping->bo_va->base.bo); + r =amdgpu_bo_reserve (abo, false); +if (r) + goto free_ib_content; + +if (abo->flags &AMDGPU_GEM_CREATE_NO_CPU_ACCESS ) { + off =0 ; + +if (abo->tbo.resource->mem_type !=TTM_PL_VRAM ) + goto unreserve_abo; + +amdgpu_res_first (abo->tbo.resource, offset, + coredump->ibs[i].ib_size_dw *4 , + &cursor); +while (cursor.remaining) { +amdgpu_device_mm_access (adev, cursor.start /4 , + &ib_content[off], cursor.size /4 , + false); + off += cursor.size; +amdgpu_res_next (&cursor, cursor.size); + } + }else { + r =ttm_bo_kmap (&abo->tbo,0 , +PFN_UP (abo->tbo.base.size), + &abo->kmap); +if (r) + goto unreserve_abo; + + kptr =amdgpu_bo_kptr (abo); + kptr += offset; +memcpy (ib_content, kptr, + coredump->ibs[i].ib_size_dw *4 ); + +amdgpu_bo_kunmap (abo); + } + +output_ib_content: +drm_printf (&p,"\nIB #%d 0x%llx %d dw\n" , + i, coredump->ibs[i].gpu_addr, coredump->ibs[i].ib_size_dw); +for (int j =0 ; j < coredump->ibs[i].ib_size_dw; j++) +drm_printf (&p,"0x%08x\n" , ib_content[j]); +unreserve_abo: +if (vm) +amdgpu_bo_unreserve (abo); +free_ib_content: +kfree (ib_content); + } +if (vm) { +amdgpu_bo_unreserve (root); +amdgpu_bo_unref (&root); + } + } +return count - iter.remain; } --2.43.0