Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu: cleared PDE addr passed as incr in amdgpu_vm_pt_clear() It also noticed 1 related pre-existing issue this patch does not introduce: - [Critical] drm/amdgpu: unchecked update() return in amdgpu_vm_pte_update_flags() [1] --
commit 989da6857bfdb3b7b6591cb250770217b86c1b11 Author: Bob Zhou <[email protected]> drm/amdgpu: keep the address of cleared PDEs with translate further This commit passes an address pointer into amdgpu_vm_pt_clear_flags() so that callers receive the PDE address generated by amdgpu_gmc_get_vm_pde() when clearing page directories. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c > index a6d389c08524f..6aabd9f5291c2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c [ ... ] > @@ -395,7 +393,7 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct > amdgpu_vm *vm, > struct amdgpu_bo *ancestor = &vmbo->bo; > struct amdgpu_bo *bo = &vmbo->bo; > unsigned int entries; > - uint64_t flags; > + uint64_t value = 0, flags; > int r, idx; > > /* Figure out our place in the hierarchy */ > @@ -430,8 +428,9 @@ int amdgpu_vm_pt_clear(struct amdgpu_device *adev, struct > amdgpu_vm *vm, > if (r) > goto exit; > > - flags = amdgpu_vm_pt_clear_flags(adev, vm, level); > - r = vm->update_funcs->update(¶ms, vmbo, 0, 0, entries, 0, flags); > + flags = amdgpu_vm_pt_clear_flags(adev, vm, level, &value); > + r = vm->update_funcs->update(¶ms, vmbo, 0, 0, entries, value, > + flags); > if (r) > goto exit; > [Severity: High] Does this pass value as the incr argument instead of the addr argument to vm->update_funcs->update()? drivers/gpu/drm/amd/amdgpu/amdgpu_vm_internal.h:struct amdgpu_vm_update_funcs { ... int (*update)(struct amdgpu_vm_update_params *p, struct amdgpu_bo_vm *bo, uint64_t pe, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags); ... } Because addr is left at 0 and value is passed as incr, entry 0 of a cleared PDB0 on GMC v9 with translate_further enabled is still written with address 0, and subsequent entries increment by 0x1000 per entry (leaving bit 12 clear on all even entries) instead of writing value to every entry, causing GPU VM faults during page table walks. Should value be passed as the fourth argument (addr) and 0 as the sixth argument (incr)? > @@ -724,7 +723,8 @@ static void amdgpu_vm_pte_update_flags(struct > amdgpu_vm_update_params *params, > > } else if (!(flags & AMDGPU_PTE_VALID) && > !(flags & AMDGPU_PTE_PRT_FLAG(params->adev))) { > - flags |= amdgpu_vm_pt_clear_flags(adev, params->vm, level); > + flags |= amdgpu_vm_pt_clear_flags(adev, params->vm, level, > + &addr); > } > > /* [Severity: Critical] This problem wasn't introduced by this patch, but can amdgpu_vm_pte_update_flags() cause a NULL pointer dereference on params->job [1] by ignoring the return value of params->vm->update_funcs->update()? drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c:amdgpu_vm_sdma_update() { ... if (ndw < 32) { r = amdgpu_vm_sdma_commit(p, NULL); if (r) return r; r = amdgpu_vm_sdma_alloc_job(p, count, AMDGPU_KERNEL_JOB_ID_VM_UPDATE); if (r) return r; } ... pte = (uint64_t *)&(p->job->ibs->ptr[p->num_dw_left]); ... } When amdgpu_vm_sdma_commit() runs during amdgpu_vm_sdma_update() and the subsequent amdgpu_vm_sdma_alloc_job() fails, p->job is left NULL. Because amdgpu_vm_pte_update_flags() returns void and discards the error, the loop in amdgpu_vm_ptes_update() continues and the next call to amdgpu_vm_sdma_update() or amdgpu_vm_sdma_commit() dereferences the NULL p->job pointer. [1] https://sashiko.dev/#/bug/linux-1897ae3a-7a03-49b7-b2ae-54c63b21478f -- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
