mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-30 01:20:17 +01:00
panfrost: handle mmap failures
This makes the call-sites to panfrost_bo_mmap check for allocation errors, and try to do the right thing to handle it. Reviewed-by: Eric R. Smith <eric.smith@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32428>
This commit is contained in:
parent
054fbe5e4e
commit
e3f2bc7963
3 changed files with 41 additions and 21 deletions
|
|
@ -409,8 +409,12 @@ panfrost_bo_create(struct panfrost_device *dev, size_t size, uint32_t flags,
|
|||
* never map since we don't care about their contents; they're purely
|
||||
* for GPU-internal use. But we do trace them anyway. */
|
||||
|
||||
if (!(flags & (PAN_BO_INVISIBLE | PAN_BO_DELAY_MMAP)))
|
||||
panfrost_bo_mmap(bo);
|
||||
if (!(flags & (PAN_BO_INVISIBLE | PAN_BO_DELAY_MMAP))) {
|
||||
if (panfrost_bo_mmap(bo)) {
|
||||
panfrost_bo_free(bo);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
p_atomic_set(&bo->refcnt, 1);
|
||||
|
||||
|
|
@ -510,8 +514,8 @@ panfrost_bo_import(struct panfrost_device *dev, int fd)
|
|||
p_atomic_set(&bo->refcnt, 1);
|
||||
|
||||
/* mmap imported BOs when PAN_MESA_DEBUG=dump */
|
||||
if (dev->debug & PAN_DBG_DUMP)
|
||||
panfrost_bo_mmap(bo);
|
||||
if ((dev->debug & PAN_DBG_DUMP) && panfrost_bo_mmap(bo))
|
||||
mesa_loge("failed to mmap");
|
||||
} else {
|
||||
/* bo->refcnt == 0 can happen if the BO
|
||||
* was being released but panfrost_bo_import() acquired the
|
||||
|
|
|
|||
|
|
@ -1308,7 +1308,9 @@ panfrost_map_constant_buffer_cpu(struct panfrost_context *ctx,
|
|||
struct panfrost_resource *rsrc = pan_resource(cb->buffer);
|
||||
|
||||
if (rsrc) {
|
||||
panfrost_bo_mmap(rsrc->bo);
|
||||
if (panfrost_bo_mmap(rsrc->bo))
|
||||
return NULL;
|
||||
|
||||
panfrost_flush_writer(ctx, rsrc, "CPU constant buffer mapping");
|
||||
panfrost_bo_wait(rsrc->bo, INT64_MAX, false);
|
||||
|
||||
|
|
|
|||
|
|
@ -588,10 +588,11 @@ panfrost_resource_setup(struct pipe_screen *screen,
|
|||
assert(valid);
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
panfrost_resource_init_afbc_headers(struct panfrost_resource *pres)
|
||||
{
|
||||
panfrost_bo_mmap(pres->bo);
|
||||
if (panfrost_bo_mmap(pres->bo))
|
||||
return -1;
|
||||
|
||||
unsigned nr_samples = MAX2(pres->base.nr_samples, 1);
|
||||
|
||||
|
|
@ -612,6 +613,7 @@ panfrost_resource_init_afbc_headers(struct panfrost_resource *pres)
|
|||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -842,8 +844,12 @@ panfrost_resource_create_with_modifier(struct pipe_screen *screen,
|
|||
so->constant_stencil = true;
|
||||
}
|
||||
|
||||
if (drm_is_afbc(so->image.layout.modifier))
|
||||
panfrost_resource_init_afbc_headers(so);
|
||||
if (drm_is_afbc(so->image.layout.modifier)) {
|
||||
if (panfrost_resource_init_afbc_headers(so)) {
|
||||
FREE(so);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
panfrost_resource_set_damage_region(screen, &so->base, 0, NULL);
|
||||
|
||||
|
|
@ -1111,16 +1117,19 @@ pan_dump_resource(struct panfrost_context *ctx, struct panfrost_resource *rsc)
|
|||
|
||||
panfrost_flush_writer(ctx, linear, "dump image");
|
||||
panfrost_bo_wait(linear->bo, INT64_MAX, false);
|
||||
panfrost_bo_mmap(linear->bo);
|
||||
|
||||
static unsigned frame_count = 0;
|
||||
frame_count++;
|
||||
snprintf(buffer, sizeof(buffer), "dump_image.%04d", frame_count);
|
||||
if (!panfrost_bo_mmap(linear->bo)) {
|
||||
static unsigned frame_count = 0;
|
||||
frame_count++;
|
||||
snprintf(buffer, sizeof(buffer), "dump_image.%04d", frame_count);
|
||||
|
||||
debug_dump_image(buffer, rsc->base.format, 0 /* UNUSED */, rsc->base.width0,
|
||||
rsc->base.height0,
|
||||
linear->image.layout.slices[0].row_stride,
|
||||
linear->bo->ptr.cpu);
|
||||
debug_dump_image(buffer, rsc->base.format, 0 /* UNUSED */, rsc->base.width0,
|
||||
rsc->base.height0,
|
||||
linear->image.layout.slices[0].row_stride,
|
||||
linear->bo->ptr.cpu);
|
||||
} else {
|
||||
mesa_loge("failed to mmap, not dumping resource");
|
||||
}
|
||||
|
||||
if (plinear)
|
||||
pipe_resource_reference(&plinear, NULL);
|
||||
|
|
@ -1246,14 +1255,17 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource,
|
|||
panfrost_bo_wait(staging->bo, INT64_MAX, false);
|
||||
}
|
||||
|
||||
panfrost_bo_mmap(staging->bo);
|
||||
if (panfrost_bo_mmap(staging->bo))
|
||||
return NULL;
|
||||
|
||||
return staging->bo->ptr.cpu;
|
||||
}
|
||||
|
||||
bool already_mapped = bo->ptr.cpu != NULL;
|
||||
|
||||
/* If we haven't already mmaped, now's the time */
|
||||
panfrost_bo_mmap(bo);
|
||||
if (panfrost_bo_mmap(bo))
|
||||
return NULL;
|
||||
|
||||
if (dev->debug & (PAN_DBG_TRACE | PAN_DBG_SYNC)) {
|
||||
pandecode_inject_mmap(dev->decode_ctx, bo->ptr.gpu, bo->ptr.cpu,
|
||||
|
|
@ -1340,8 +1352,10 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource,
|
|||
rsrc->bo = newbo;
|
||||
rsrc->image.data.base = newbo->ptr.gpu;
|
||||
|
||||
if (!copy_resource && drm_is_afbc(rsrc->image.layout.modifier))
|
||||
panfrost_resource_init_afbc_headers(rsrc);
|
||||
if (!copy_resource && drm_is_afbc(rsrc->image.layout.modifier)) {
|
||||
if (panfrost_resource_init_afbc_headers(rsrc))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bo = newbo;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue