Skip to contentSkip to conversation

drm/amdgpu: fix check in amdgpu_hmm_invalidate_gfx

PATCH In review Christian König 3 participants 4 messages Jun 26 – Jun 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: fix check in amdgpu_hmm_invalidate_gfx

For a short moment during alloc/free the userptr BO is not part of his VM, so bo->vm_bo can be NULL.

Keep a reference to the VM root PD as parent of the userptr BO so that we can always use that to wait for all submissions of the VM instead of only the one involving the userptr BO.

Fixes 5cd5f99b7b9b ("drm/amdgpu: fix waiting for all submissions for userptrs")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 28f89ae8ca74..686be2bb8c37 100644
@@ -535,6 +535,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
 	bo = gem_to_amdgpu_bo(gobj);
 	bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
 	bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT;
+	bo->parent = amdgpu_bo_ref(fpriv->vm.root.bo);
 	r = amdgpu_ttm_tt_set_userptr(&bo->tbo, args->addr, args->flags);
 	if (r)
 		goto release_object;
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -2
index b38788228d0b..eaf02f90fddf 100644
@@ -67,7 +67,6 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
 {
 	struct amdgpu_bo *bo = container_of(mni, struct amdgpu_bo, notifier);
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-	struct amdgpu_bo *vm_root = bo->vm_bo->vm->root.bo;
 	long r;
 
 	if (!mmu_notifier_range_blockable(range))
@@ -78,7 +77,7 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
 	mmu_interval_set_seq(mni, cur_seq);
 
 	amdgpu_vm_bo_invalidate(bo, false);
-	r = dma_resv_wait_timeout(vm_root->tbo.base.resv,
+	r = dma_resv_wait_timeout(bo->parent->tbo.base.resv,
 				  DMA_RESV_USAGE_BOOKKEEP, false,
 				  MAX_SCHEDULE_TIMEOUT);
 	mutex_unlock(&adev->notifier_lock);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · Christian König

For a short moment during alloc/free the userptr BO is not part of his VM, so bo->vm_bo can be NULL.

Keep a reference to the VM root PD as parent of the userptr BO so that we can always use that to wait for all submissions of the VM instead of only the one involving the userptr BO.

Fixes 5cd5f99b7b9b ("drm/amdgpu: fix waiting for all submissions for userptrs")
Quoted 10 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
index 28f89ae8ca74..686be2bb8c37 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, · line 538

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
@@ -535,6 +535,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
        bo = gem_to_amdgpu_bo(gobj);
        bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
        bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT;
+       bo->parent = amdgpu_bo_ref(fpriv->vm.root.bo);

Do you need an unref to match this?

Alex

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
        r = amdgpu_ttm_tt_set_userptr(&bo->tbo, args->addr, args->flags);
        if (r)
                goto release_object;
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -3
index b38788228d0b..eaf02f90fddf 100644
@@ -67,7 +67,6 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
 {
        struct amdgpu_bo *bo = container_of(mni, struct amdgpu_bo, notifier);
        struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-       struct amdgpu_bo *vm_root = bo->vm_bo->vm->root.bo;
        long r;
 
        if (!mmu_notifier_range_blockable(range))
@@ -78,7 +77,7 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
        mmu_interval_set_seq(mni, cur_seq);
 
        amdgpu_vm_bo_invalidate(bo, false);
-       r = dma_resv_wait_timeout(vm_root->tbo.base.resv,
+       r = dma_resv_wait_timeout(bo->parent->tbo.base.resv,
                                  DMA_RESV_USAGE_BOOKKEEP, false,
                                  MAX_SCHEDULE_TIMEOUT);
        mutex_unlock(&adev->notifier_lock);
--

2.43.0

maintainer
#2 lore raw
Quoted 20 lines · Alex Deucher
Quoted 10 lines · Christian König

For a short moment during alloc/free the userptr BO is not part of his VM, so bo->vm_bo can be NULL.

Keep a reference to the VM root PD as parent of the userptr BO so that we can always use that to wait for all submissions of the VM instead of only the one involving the userptr BO.

Fixes 5cd5f99b7b9b ("drm/amdgpu: fix waiting for all submissions for userptrs")
Quoted 5 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, · line 538

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 28f89ae8ca74..686be2bb8c37 100644
@@ -535,6 +535,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
        bo = gem_to_amdgpu_bo(gobj);
        bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
        bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT;
+       bo->parent = amdgpu_bo_ref(fpriv->vm.root.bo);

Do you need an unref to match this?

That's in amdgpu_bo_destroy(), we use bo->parent for multiple other things already.

Christian.

Quoted 30 lines

Alex

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
        r = amdgpu_ttm_tt_set_userptr(&bo->tbo, args->addr, args->flags);
        if (r)
                goto release_object;
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -3
index b38788228d0b..eaf02f90fddf 100644
@@ -67,7 +67,6 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
 {
        struct amdgpu_bo *bo = container_of(mni, struct amdgpu_bo, notifier);
        struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-       struct amdgpu_bo *vm_root = bo->vm_bo->vm->root.bo;
        long r;
 
        if (!mmu_notifier_range_blockable(range))
@@ -78,7 +77,7 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
        mmu_interval_set_seq(mni, cur_seq);
 
        amdgpu_vm_bo_invalidate(bo, false);
-       r = dma_resv_wait_timeout(vm_root->tbo.base.resv,
+       r = dma_resv_wait_timeout(bo->parent->tbo.base.resv,
                                  DMA_RESV_USAGE_BOOKKEEP, false,
                                  MAX_SCHEDULE_TIMEOUT);
        mutex_unlock(&adev->notifier_lock);
--

2.43.0

Reviewed-by
#3 lore raw
Quoted 36 lines · Christian König
Quoted 20 lines · Alex Deucher
Quoted 10 lines · Christian König

For a short moment during alloc/free the userptr BO is not part of his VM, so bo->vm_bo can be NULL.

Keep a reference to the VM root PD as parent of the userptr BO so that we can always use that to wait for all submissions of the VM instead of only the one involving the userptr BO.

Fixes 5cd5f99b7b9b ("drm/amdgpu: fix waiting for all submissions for userptrs")
Quoted 5 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data, · line 538

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
index 28f89ae8ca74..686be2bb8c37 100644
@@ -535,6 +535,7 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
        bo = gem_to_amdgpu_bo(gobj);
        bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
        bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT;
+       bo->parent = amdgpu_bo_ref(fpriv->vm.root.bo);

Do you need an unref to match this?

Quoted 1 line

That's in amdgpu_bo_destroy(), we use bo->parent for multiple other things already.

Thanks, might be useful to add a comment to that effect. With the Closes tag, patch is:

Quoted 34 lines

Christian.

Quoted 30 lines

Alex

Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
        r = amdgpu_ttm_tt_set_userptr(&bo->tbo, args->addr, args->flags);
        if (r)
                goto release_object;
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -3
index b38788228d0b..eaf02f90fddf 100644
@@ -67,7 +67,6 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
 {
        struct amdgpu_bo *bo = container_of(mni, struct amdgpu_bo, notifier);
        struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-       struct amdgpu_bo *vm_root = bo->vm_bo->vm->root.bo;
        long r;
 
        if (!mmu_notifier_range_blockable(range))
@@ -78,7 +77,7 @@ static bool amdgpu_hmm_invalidate_gfx(struct mmu_interval_notifier *mni,
        mmu_interval_set_seq(mni, cur_seq);
 
        amdgpu_vm_bo_invalidate(bo, false);
-       r = dma_resv_wait_timeout(vm_root->tbo.base.resv,
+       r = dma_resv_wait_timeout(bo->parent->tbo.base.resv,
                                  DMA_RESV_USAGE_BOOKKEEP, false,
                                  MAX_SCHEDULE_TIMEOUT);
        mutex_unlock(&adev->notifier_lock);
--

2.43.0