mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 20:38:06 +02:00
asahi: Make BO import path failures more robust
These operations can fail for complex reasons through no fault of mesa, so we should have proper runtime checks for them even in release builds. Signed-off-by: Asahi Lina <lina@asahilina.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22353>
This commit is contained in:
parent
fcf594d00b
commit
883ba4b161
1 changed files with 25 additions and 5 deletions
|
|
@ -148,7 +148,11 @@ agx_bo_import(struct agx_device *dev, int fd)
|
|||
pthread_mutex_lock(&dev->bo_map_lock);
|
||||
|
||||
ret = drmPrimeFDToHandle(dev->fd, fd, &gem_handle);
|
||||
assert(!ret);
|
||||
if (ret) {
|
||||
fprintf(stderr, "import failed: Could not map fd %d to handle\n", fd);
|
||||
pthread_mutex_unlock(&dev->bo_map_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bo = agx_lookup_bo(dev, gem_handle);
|
||||
dev->max_handle = MAX2(dev->max_handle, gem_handle);
|
||||
|
|
@ -170,9 +174,9 @@ agx_bo_import(struct agx_device *dev, int fd)
|
|||
stderr,
|
||||
"import failed: BO is not a multiple of the page size (0x%llx bytes)\n",
|
||||
(long long)bo->size);
|
||||
pthread_mutex_unlock(&dev->bo_map_lock);
|
||||
return NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
bo->flags = AGX_BO_SHARED | AGX_BO_SHAREABLE;
|
||||
bo->handle = gem_handle;
|
||||
bo->prime_fd = dup(fd);
|
||||
|
|
@ -186,10 +190,21 @@ agx_bo_import(struct agx_device *dev, int fd)
|
|||
&dev->main_heap, bo->size + dev->guard_size, dev->params.vm_page_size);
|
||||
simple_mtx_unlock(&dev->vma_lock);
|
||||
|
||||
if (!bo->ptr.gpu) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"import failed: Could not allocate from VMA heap (0x%llx bytes)\n",
|
||||
(long long)bo->size);
|
||||
abort();
|
||||
}
|
||||
|
||||
ret =
|
||||
agx_bo_bind(dev, bo, bo->ptr.gpu, ASAHI_BIND_READ | ASAHI_BIND_WRITE);
|
||||
assert(!ret);
|
||||
|
||||
if (ret) {
|
||||
fprintf(stderr, "import failed: Could not bind BO at 0x%llx\n",
|
||||
(long long)bo->ptr.gpu);
|
||||
abort();
|
||||
}
|
||||
} else {
|
||||
/* bo->refcnt == 0 can happen if the BO
|
||||
* was being released but agx_bo_import() acquired the
|
||||
|
|
@ -209,6 +224,11 @@ agx_bo_import(struct agx_device *dev, int fd)
|
|||
pthread_mutex_unlock(&dev->bo_map_lock);
|
||||
|
||||
return bo;
|
||||
|
||||
error:
|
||||
memset(bo, 0, sizeof(*bo));
|
||||
pthread_mutex_unlock(&dev->bo_map_lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue