]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amdgpu: Test for imported buffers with drm_gem_is_imported()
authorThomas Zimmermann <tzimmermann@suse.de>
Wed, 25 Jun 2025 08:42:17 +0000 (10:42 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 30 Jun 2025 15:54:59 +0000 (11:54 -0400)
Instead of testing import_attach for imported GEM buffers, invoke
drm_gem_is_imported() to do the test.

v2:
- keep amdgpu_bo_print_info() as-is (Christian)

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

index 35c778426a7c704f37dfdc8533dc61d79e3bf9e3..9e463d3ee92779a8ece4836ee682b44b4a0d312e 100644 (file)
@@ -1317,7 +1317,7 @@ amdgpu_display_user_framebuffer_create(struct drm_device *dev,
        /* Handle is imported dma-buf, so cannot be migrated to VRAM for scanout */
        bo = gem_to_amdgpu_bo(obj);
        domains = amdgpu_display_supported_domains(drm_to_adev(dev), bo->flags);
-       if (obj->import_attach && !(domains & AMDGPU_GEM_DOMAIN_GTT)) {
+       if (drm_gem_is_imported(obj) && !(domains & AMDGPU_GEM_DOMAIN_GTT)) {
                drm_dbg_kms(dev, "Cannot create framebuffer from imported dma_buf\n");
                drm_gem_object_put(obj);
                return ERR_PTR(-EINVAL);
index 44e120f9f76497dd6045e6dea0cda8a03e6ec087..5743ebb2f1b7cf54b1ae21ce3b9acdf63469819b 100644 (file)
@@ -513,7 +513,7 @@ bool amdgpu_dmabuf_is_xgmi_accessible(struct amdgpu_device *adev,
        if (!adev)
                return false;
 
-       if (obj->import_attach) {
+       if (drm_gem_is_imported(obj)) {
                struct dma_buf *dma_buf = obj->import_attach->dmabuf;
 
                if (dma_buf->ops != &amdgpu_dmabuf_ops)
index 0ecc88df72088ca496662cc96217e2ffd628673d..d1edfead3068246f15bbf0573edcb9f0ebf33702 100644 (file)
@@ -317,7 +317,7 @@ static int amdgpu_gem_object_open(struct drm_gem_object *obj,
         */
        if (!vm->is_compute_context || !vm->process_info)
                return 0;
-       if (!obj->import_attach ||
+       if (!drm_gem_is_imported(obj) ||
            !dma_buf_is_dynamic(obj->import_attach->dmabuf))
                return 0;
        mutex_lock_nested(&vm->process_info->lock, 1);
@@ -1024,7 +1024,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
                break;
        }
        case AMDGPU_GEM_OP_SET_PLACEMENT:
-               if (robj->tbo.base.import_attach &&
+               if (drm_gem_is_imported(&robj->tbo.base) &&
                    args->value & AMDGPU_GEM_DOMAIN_VRAM) {
                        r = -EINVAL;
                        amdgpu_bo_unreserve(robj);
index a0fc4bec5746dd2c4687d3aa3aea6f8a4f21894e..c5fda18967c8d859526aeabd280c97f10c65886d 100644 (file)
@@ -63,7 +63,7 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
 
        amdgpu_bo_kunmap(bo);
 
-       if (bo->tbo.base.import_attach)
+       if (drm_gem_is_imported(&bo->tbo.base))
                drm_prime_gem_destroy(&bo->tbo.base, bo->tbo.sg);
        drm_gem_object_release(&bo->tbo.base);
        amdgpu_bo_unref(&bo->parent);
@@ -940,7 +940,7 @@ int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain)
                domain = bo->preferred_domains & domain;
 
        /* A shared bo cannot be migrated to VRAM */
-       if (bo->tbo.base.import_attach) {
+       if (drm_gem_is_imported(&bo->tbo.base)) {
                if (domain & AMDGPU_GEM_DOMAIN_GTT)
                        domain = AMDGPU_GEM_DOMAIN_GTT;
                else
@@ -968,7 +968,7 @@ int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain)
         */
        domain = amdgpu_bo_get_preferred_domain(adev, domain);
 
-       if (bo->tbo.base.import_attach)
+       if (drm_gem_is_imported(&bo->tbo.base))
                dma_buf_pin(bo->tbo.base.import_attach);
 
        /* force to pin into visible video ram */
@@ -1019,7 +1019,7 @@ void amdgpu_bo_unpin(struct amdgpu_bo *bo)
        if (bo->tbo.pin_count)
                return;
 
-       if (bo->tbo.base.import_attach)
+       if (drm_gem_is_imported(&bo->tbo.base))
                dma_buf_unpin(bo->tbo.base.import_attach);
 
        if (bo->tbo.resource->mem_type == TTM_PL_VRAM) {
@@ -1264,7 +1264,7 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
 
        amdgpu_bo_kunmap(abo);
 
-       if (abo->tbo.base.dma_buf && !abo->tbo.base.import_attach &&
+       if (abo->tbo.base.dma_buf && !drm_gem_is_imported(&abo->tbo.base) &&
            old_mem && old_mem->mem_type != TTM_PL_SYSTEM)
                dma_buf_move_notify(abo->tbo.base.dma_buf);
 
index 80a5fc375da3257a26f66b9673e93fd686585683..27ab4e754b2a9f431d7a5269ebf7f711ed3c06c8 100644 (file)
@@ -1061,7 +1061,7 @@ static void amdgpu_ttm_backend_unbind(struct ttm_device *bdev,
        /* if the pages have userptr pinning then clear that first */
        if (gtt->userptr) {
                amdgpu_ttm_tt_unpin_userptr(bdev, ttm);
-       } else if (ttm->sg && gtt->gobj->import_attach) {
+       } else if (ttm->sg && drm_gem_is_imported(gtt->gobj)) {
                struct dma_buf_attachment *attach;
 
                attach = gtt->gobj->import_attach;
index 20ad57f7815d1fd00b4ec7640359c6827ccdf6d0..51022c9f9b23754b710fc08d81580a437e8a3a37 100644 (file)
@@ -1271,7 +1271,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
        } else {
                struct drm_gem_object *obj = &bo->tbo.base;
 
-               if (obj->import_attach && bo_va->is_xgmi) {
+               if (drm_gem_is_imported(obj) && bo_va->is_xgmi) {
                        struct dma_buf *dma_buf = obj->import_attach->dmabuf;
                        struct drm_gem_object *gobj = dma_buf->priv;
                        struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);
@@ -1631,7 +1631,7 @@ int amdgpu_vm_handle_moved(struct amdgpu_device *adev,
                 * validation
                 */
                if (vm->is_compute_context &&
-                   bo_va->base.bo->tbo.base.import_attach &&
+                   drm_gem_is_imported(&bo_va->base.bo->tbo.base) &&
                    (!bo_va->base.bo->tbo.resource ||
                     bo_va->base.bo->tbo.resource->mem_type == TTM_PL_SYSTEM))
                        amdgpu_vm_bo_evicted_user(&bo_va->base);