panfrost: Handle gracefully resource BO alloc failures

This makes panfrost_bo_alloc not assert anymore and propagate the
failure again.

Signed-off-by: Mary Guillemard <mary.guillemard@collabora.com>
Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30150>
This commit is contained in:
Mary Guillemard 2024-07-08 14:17:58 +02:00 committed by Marge Bot
parent 71a24a0c5e
commit 32a4596d17
5 changed files with 33 additions and 8 deletions

View file

@ -80,7 +80,9 @@ panfrost_bo_alloc(struct panfrost_device *dev, size_t size, uint32_t flags,
kmod_bo = pan_kmod_bo_alloc(dev->kmod.dev, exclusive_vm, size,
to_kmod_bo_flags(flags));
assert(kmod_bo);
if (kmod_bo == NULL)
goto err_alloc;
bo = pan_lookup_bo(dev, kmod_bo->handle);
assert(!memcmp(bo, &((struct panfrost_bo){0}), sizeof(*bo)));
@ -100,15 +102,23 @@ panfrost_bo_alloc(struct panfrost_device *dev, size_t size, uint32_t flags,
},
};
ASSERTED int ret =
int ret =
pan_kmod_vm_bind(dev->kmod.vm, PAN_KMOD_VM_OP_MODE_IMMEDIATE, &vm_op, 1);
assert(!ret);
if (ret)
goto err_bind;
bo->ptr.gpu = vm_op.va.start;
bo->flags = flags;
bo->dev = dev;
bo->label = label;
return bo;
err_bind:
pan_kmod_bo_put(kmod_bo);
/* BO will be freed with the sparse array, but zero to indicate free */
memset(bo, 0, sizeof(*bo));
err_alloc:
return NULL;
}
static void
@ -383,10 +393,8 @@ panfrost_bo_create(struct panfrost_device *dev, size_t size, uint32_t flags,
bo = panfrost_bo_alloc(dev, size, flags, label);
}
if (!bo) {
unreachable("BO creation failed. We don't handle that yet.");
if (!bo)
return NULL;
}
/* Only mmap now if we know we need to. For CPU-invisible buffers, we
* never map since we don't care about their contents; they're purely

View file

@ -127,6 +127,7 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
if (dev->arch < 10) {
dev->tiler_heap = panfrost_bo_create(
dev, 128 * 1024 * 1024, PAN_BO_INVISIBLE | PAN_BO_GROWABLE, "Tiler heap");
assert(dev->tiler_heap);
}
pthread_mutex_init(&dev->submit_lock, NULL);
@ -134,6 +135,8 @@ panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev)
/* Done once on init */
dev->sample_positions = panfrost_bo_create(
dev, panfrost_sample_positions_buffer_size(), 0, "Sample positions");
assert(dev->sample_positions);
panfrost_upload_sample_positions(dev->sample_positions->ptr.cpu);
return;

View file

@ -399,6 +399,7 @@ panfrost_batch_create_bo(struct panfrost_batch *batch, size_t size,
bo = panfrost_bo_create(pan_device(batch->ctx->base.screen), size,
create_flags, label);
assert(bo);
panfrost_batch_add_bo(batch, bo, stage);
/* panfrost_batch_add_bo() has retained a reference and

View file

@ -54,6 +54,7 @@ panfrost_pool_alloc_backing(struct panfrost_pool *pool, size_t bo_sz)
*/
struct panfrost_bo *bo =
panfrost_bo_create(pool->dev, bo_sz, pool->create_flags, pool->label);
assert(bo);
if (pool->owned)
util_dynarray_append(&pool->bos, struct panfrost_bo *, bo);

View file

@ -714,6 +714,10 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen,
struct panfrost_device *dev = pan_device(screen);
struct panfrost_resource *so = CALLOC_STRUCT(panfrost_resource);
if (!so)
return NULL;
so->base = *template;
so->base.screen = screen;
@ -802,7 +806,7 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen,
if (!so->scanout) {
fprintf(stderr, "Failed to create scanout resource\n");
free(so);
FREE(so);
return NULL;
}
assert(handle.type == WINSYS_HANDLE_TYPE_FD);
@ -810,7 +814,7 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen,
close(handle.handle);
if (!so->bo) {
free(so);
FREE(so);
return NULL;
}
@ -826,6 +830,12 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen,
so->bo =
panfrost_bo_create(dev, so->image.layout.data_size, flags, label);
if (!so->bo) {
FREE(so);
return NULL;
}
so->image.data.base = so->bo->ptr.gpu;
so->constant_stencil = true;
@ -1562,6 +1572,7 @@ panfrost_get_afbc_superblock_sizes(struct panfrost_context *ctx,
panfrost_flush_batches_accessing_rsrc(ctx, rsrc, "AFBC before size flush");
batch = panfrost_get_fresh_batch_for_fbo(ctx, "AFBC superblock sizes");
bo = panfrost_bo_create(dev, metadata_size, 0, "AFBC superblock sizes");
assert(bo);
for (int level = first_level; level <= last_level; ++level) {
unsigned offset = out_offsets[level - first_level];
@ -1658,6 +1669,7 @@ panfrost_pack_afbc(struct panfrost_context *ctx,
struct panfrost_bo *dst =
panfrost_bo_create(dev, new_size, 0, "AFBC compact texture");
assert(dst);
struct panfrost_batch *batch =
panfrost_get_fresh_batch_for_fbo(ctx, "AFBC compaction");