[PATCH v6 09/11] drm/amdgpu: validate the shared bo for tracking usage size
Christian König
christian.koenig at amd.com
Fri Jul 11 12:14:26 UTC 2025
On 11.07.25 11:39, Prike Liang wrote:
> It requires validating the shared BO before updating its usage
> size; otherwise, there is a potential NULL pointer error when the
> BO released improperly.
Clear NAK to that. You are obviously working around a bug elsewhere.
Regards,
Christian.
>
> Signed-off-by: Prike Liang <Prike.Liang at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 25 +++++++++++++++++++++----
> 1 file changed, 21 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index f042372d9f2e..a574effdd3ec 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -321,12 +321,26 @@ static void amdgpu_vm_bo_reset_state_machine(struct amdgpu_vm *vm)
> */
> static void amdgpu_vm_update_shared(struct amdgpu_vm_bo_base *base)
> {
> - struct amdgpu_vm *vm = base->vm;
> - struct amdgpu_bo *bo = base->bo;
> - uint64_t size = amdgpu_bo_size(bo);
> - uint32_t bo_memtype = amdgpu_bo_mem_stats_placement(bo);
> + struct amdgpu_vm *vm;
> + struct amdgpu_bo *bo;
> + uint64_t size = 0;
> + uint32_t bo_memtype = TTM_PL_SYSTEM;
> bool shared;
>
> + if (likely(base)) {
> + vm = base->vm;
> + bo = base->bo;
> + } else {
> + return;
> + }
> +
> + if (likely(bo)) {
> + size = amdgpu_bo_size(bo);
> + bo_memtype = amdgpu_bo_mem_stats_placement(bo);
> + } else {
> + return;
> + }
> +
> spin_lock(&vm->status_lock);
> shared = drm_gem_object_is_shared_for_memory_stats(&bo->tbo.base);
> if (base->shared != shared) {
> @@ -353,6 +367,9 @@ void amdgpu_vm_bo_update_shared(struct amdgpu_bo *bo)
> {
> struct amdgpu_vm_bo_base *base;
>
> + if (unlikely(!bo))
> + return;
> +
> for (base = bo->vm_bo; base; base = base->next)
> amdgpu_vm_update_shared(base);
> }
More information about the amd-gfx
mailing list