drm/amdgpu: don't take a per VM kernel BO for a page table
Subsystems (2)
PATCH 1/1 drm/amdgpu: don't take a per VM kernel BO for a page table
amdgpu_vm_bo_lock_lists() puts every BO which shares the resv of the root PD and is a ttm_bo_type_kernel BO on the page table lists. The CWSR TMA BO which amdgpu_cwsr_alloc() creates for every opened render node is such a BO, so it is treated as a page table: after a VRAM losing reset its bo_va moves to the page tables needing an update, and amdgpu_vm_update_pdes() tries to write its PDE. It has no parent page directory, so that fails, and fails again on every following submission of the file.
On navi48, submitting on a render node, then amdgpu_gpu_recover and submitting again, also with a new context:
amdgpu 0000:03:00.0: VRAM is lost due to GPU reset! amdgpu 0000:03:00.0: GPU reset(1) succeeded!
WARNING: amdgpu_vm_pt.c:671 at amdgpu_vm_pde_update+0x329/0x5d0 [amdgpu], CPU#0: vmreinit/2629 Call Trace: amdgpu_vm_update_pdes+0x262/0x5e0 [amdgpu] amdgpu_cs_ioctl+0x35c9/0x7a00 [amdgpu] drm_ioctl_kernel+0x180/0x320 [drm] drm_ioctl+0x530/0xcb0 [drm]
and every command submission fails with -EINVAL from then on.
Don't look at the BO type, let the creator of the vm_bo tell whether it is the root PD or a page table, like amdgpu_vm_bo_needs_update() already compares with the root PD instead of looking at the type. The TMA BO stays a kernel BO which userspace can't mmap.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 11 +++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +7 -4
@@ -162,7 +162,7 @@ amdgpu_vm_bo_lock_lists(struct amdgpu_vm_bo_base *vm_bo)/* No extra locking needed, protected by the root PD resv lock */ amdgpu_vm_assert_locked (vm); -if (bo->tbo.type == ttm_bo_type_kernel) +if (vm_bo->page_table)return &vm->kernel;return &vm->always_valid;
@@ -408,15 +408,18 @@ void amdgpu_vm_update_stats(struct amdgpu_vm_bo_base *base,* @base: base structure for tracking BO usage in a VM * @vm: vm to which bo is to be added * @bo: amdgpu buffer object +* @page_table: true if @bo is a PD/PT of @vm * * Initialize a bo_va_base structure and add it to the appropriate lists * */ void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, -struct amdgpu_vm *vm,struct amdgpu_bo *bo) +struct amdgpu_vm *vm,struct amdgpu_bo *bo, +bool page_table) { base->vm = vm; base->bo = bo; + base->page_table = page_table; base->next =NULL ;INIT_LIST_HEAD (&base->vm_status);
@@ -1805,7 +1808,7 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,if (bo_va ==NULL ) {return NULL ; } -amdgpu_vm_bo_base_init (&bo_va->base, vm, bo); +amdgpu_vm_bo_base_init (&bo_va->base, vm, bo, false); bo_va->ref_count =1 ; bo_va->last_pt_update =dma_fence_get_stub ();
@@ -2704,7 +2707,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, goto error_free_delayed; } -amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); +amdgpu_vm_bo_base_init (&vm->root, vm, root_bo, true); r =dma_resv_reserve_fences (root_bo->tbo.base.resv,1 );if (r) goto error_free_root;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5 -1
@@ -224,6 +224,9 @@ struct amdgpu_vm_bo_base {/* if the BO was moved and all mappings are invalid * protected by the BO being reserved */ bool moved; + +/* True for a PD/PT of this VM; constant after initialization. */ +bool page_table; };/*
@@ -470,7 +473,8 @@ int amdgpu_vm_flush_compute_tlb(struct amdgpu_device *adev,uint32_t flush_type, uint32_t xcc_mask);void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, -struct amdgpu_vm *vm,struct amdgpu_bo *bo); +struct amdgpu_vm *vm,struct amdgpu_bo *bo, +bool page_table); int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm, bool immediate, bool unlocked, bool flush_tlb, bool allow_override, struct amdgpu_sync *sync,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1 -1
@@ -542,7 +542,7 @@ static int amdgpu_vm_pt_alloc(struct amdgpu_vm_update_params *p,* freeing them up in the wrong order. */ pt_bo->parent =amdgpu_bo_ref (cursor->parent->bo); -amdgpu_vm_bo_base_init (entry, p->vm, pt_bo); +amdgpu_vm_bo_base_init (entry, p->vm, pt_bo, true); r =amdgpu_vm_pt_clear (p->adev, p->vm, pt, p->immediate);if (r) goto error_unpin;
Signature · 1 line
2.50.1
Christian König
maintainerQuoted 55 lines · Jesse Zhang
amdgpu_vm_bo_lock_lists()puts every BO which shares the resv of the root PD and is attm_bo_type_kernelBO on the page table lists. The CWSR TMA BO whichamdgpu_cwsr_alloc()creates for every opened render node is such a BO, so it is treated as a page table: after a VRAM losing reset itsbo_vamoves to the page tables needing an update, andamdgpu_vm_update_pdes()tries to write its PDE. It has no parent page directory, so that fails, and fails again on every following submission of the file.On navi48, submitting on a render node, then
amdgpu_gpu_recoverand submitting again, also with a new context:amdgpu 0000:03:00.0: VRAM is lost due to GPU reset! amdgpu 0000:03:00.0: GPU reset(1) succeeded!
WARNING: amdgpu_vm_pt.c:671 at amdgpu_vm_pde_update+0x329/0x5d0 [amdgpu], CPU#0: vmreinit/2629 Call Trace: amdgpu_vm_update_pdes+0x262/0x5e0 [amdgpu] amdgpu_cs_ioctl+0x35c9/0x7a00 [amdgpu] drm_ioctl_kernel+0x180/0x320 [drm] drm_ioctl+0x530/0xcb0 [drm]and every command submission fails with
-EINVALfrom then on.Don't look at the BO type, let the creator of the
vm_botell whether it is the root PD or a page table, likeamdgpu_vm_bo_needs_update()already compares with the root PD instead of looking at the type. The TMA BO stays a kernel BO which userspace can't mmap.Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 11 +++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-1@@ -162,7 +162,7 @@ amdgpu_vm_bo_lock_lists(struct amdgpu_vm_bo_base *vm_bo)/* No extra locking needed, protected by the root PD resv lock */ amdgpu_vm_assert_locked (vm); -if (bo->tbo.type == ttm_bo_type_kernel) +if (vm_bo->page_table)return &vm->kernel;return &vm->always_valid;@@ -408,15 +408,18 @@ void amdgpu_vm_update_stats(struct amdgpu_vm_bo_base *base,* @base: base structure for tracking BO usage in a VM * @vm: vm to which bo is to be added * @bo: amdgpu buffer object +* @page_table: true if @bo is a PD/PT of @vm * * Initialize a bo_va_base structure and add it to the appropriate lists
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_update_stats(struct amdgpu_vm_bo_base *base, · line 422
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1* */ void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, -struct amdgpu_vm *vm,struct amdgpu_bo *bo) +struct amdgpu_vm *vm,struct amdgpu_bo *bo, +bool page_table) { base->vm = vm; base->bo = bo; + base->page_table = page_table;
I think we should rather have a separate destroy function for page tables in the BO and then identify them by the bo->destroy pointer.
We already do it this way for the user and KFDs svm range BOs, see function amdgpu_bo_is_amdgpu_bo() and the destroy stuff above it.
Apart from that the approach looks solid to me.
Regards,
Christian.
Quoted 58 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2base->next =NULL ;INIT_LIST_HEAD (&base->vm_status);@@ -1805,7 +1808,7 @@ struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,if (bo_va ==NULL ) {return NULL ; } -amdgpu_vm_bo_base_init (&bo_va->base, vm, bo); +amdgpu_vm_bo_base_init (&bo_va->base, vm, bo, false); bo_va->ref_count =1 ; bo_va->last_pt_update =dma_fence_get_stub ();@@ -2704,7 +2707,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, goto error_free_delayed; } -amdgpu_vm_bo_base_init (&vm->root, vm, root_bo); +amdgpu_vm_bo_base_init (&vm->root, vm, root_bo, true); r =dma_resv_reserve_fences (root_bo->tbo.base.resv,1 );if (r) goto error_free_root;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +5
-1@@ -224,6 +224,9 @@ struct amdgpu_vm_bo_base {/* if the BO was moved and all mappings are invalid * protected by the BO being reserved */ bool moved; + +/* True for a PD/PT of this VM; constant after initialization. */ +bool page_table; };/* @@ -470,7 +473,8 @@ int amdgpu_vm_flush_compute_tlb(struct amdgpu_device *adev,uint32_t flush_type, uint32_t xcc_mask);void amdgpu_vm_bo_base_init (struct amdgpu_vm_bo_base *base, -struct amdgpu_vm *vm,struct amdgpu_bo *bo); +struct amdgpu_vm *vm,struct amdgpu_bo *bo, +bool page_table); int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm, bool immediate, bool unlocked, bool flush_tlb, bool allow_override, struct amdgpu_sync *sync,drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1
-1@@ -542,7 +542,7 @@ static int amdgpu_vm_pt_alloc(struct amdgpu_vm_update_params *p,* freeing them up in the wrong order. */ pt_bo->parent =amdgpu_bo_ref (cursor->parent->bo); -amdgpu_vm_bo_base_init (entry, p->vm, pt_bo); +amdgpu_vm_bo_base_init (entry, p->vm, pt_bo, true); r =amdgpu_vm_pt_clear (p->adev, p->vm, pt, p->immediate);if (r) goto error_unpin;