anv: Add missing error-checking to anv_block_pool_init (v2)
When the memfd_create() and u_vector_init() fail on anv_block_pool_init(), this patch makes to return VK_ERROR_INITIALIZATION_FAILED. All of initialization success on anv_block_pool_init(), it makes to return VK_SUCCESS. CID 1394319 v2: Fixes from Emil's review: a) Add the return type for propagating the return value to caller. b) Changed anv_block_pool_init() to return VK_ERROR_INITIALIZATION_FAILED on failure of initialization. Cc: "13.0" <mesa-stable@lists.freedesktop.org> Signed-off-by: Mun Gwan-gyeong <elongbug@gmail.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:

committed by
Emil Velikov

parent
02bf1bbe6e
commit
ecc618b0d8
@@ -246,10 +246,12 @@ anv_ptr_free_list_push(void **list, void *elem)
|
|||||||
static uint32_t
|
static uint32_t
|
||||||
anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state);
|
anv_block_pool_grow(struct anv_block_pool *pool, struct anv_block_state *state);
|
||||||
|
|
||||||
void
|
VkResult
|
||||||
anv_block_pool_init(struct anv_block_pool *pool,
|
anv_block_pool_init(struct anv_block_pool *pool,
|
||||||
struct anv_device *device, uint32_t block_size)
|
struct anv_device *device, uint32_t block_size)
|
||||||
{
|
{
|
||||||
|
VkResult result;
|
||||||
|
|
||||||
assert(util_is_power_of_two(block_size));
|
assert(util_is_power_of_two(block_size));
|
||||||
|
|
||||||
pool->device = device;
|
pool->device = device;
|
||||||
@@ -260,17 +262,23 @@ anv_block_pool_init(struct anv_block_pool *pool,
|
|||||||
|
|
||||||
pool->fd = memfd_create("block pool", MFD_CLOEXEC);
|
pool->fd = memfd_create("block pool", MFD_CLOEXEC);
|
||||||
if (pool->fd == -1)
|
if (pool->fd == -1)
|
||||||
return;
|
return vk_error(VK_ERROR_INITIALIZATION_FAILED);
|
||||||
|
|
||||||
/* Just make it 2GB up-front. The Linux kernel won't actually back it
|
/* Just make it 2GB up-front. The Linux kernel won't actually back it
|
||||||
* with pages until we either map and fault on one of them or we use
|
* with pages until we either map and fault on one of them or we use
|
||||||
* userptr and send a chunk of it off to the GPU.
|
* userptr and send a chunk of it off to the GPU.
|
||||||
*/
|
*/
|
||||||
if (ftruncate(pool->fd, BLOCK_POOL_MEMFD_SIZE) == -1)
|
if (ftruncate(pool->fd, BLOCK_POOL_MEMFD_SIZE) == -1) {
|
||||||
return;
|
result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
|
||||||
|
goto fail_fd;
|
||||||
|
}
|
||||||
|
|
||||||
u_vector_init(&pool->mmap_cleanups,
|
if (!u_vector_init(&pool->mmap_cleanups,
|
||||||
round_to_power_of_two(sizeof(struct anv_mmap_cleanup)), 128);
|
round_to_power_of_two(sizeof(struct anv_mmap_cleanup)),
|
||||||
|
128)) {
|
||||||
|
result = vk_error(VK_ERROR_INITIALIZATION_FAILED);
|
||||||
|
goto fail_fd;
|
||||||
|
}
|
||||||
|
|
||||||
pool->state.next = 0;
|
pool->state.next = 0;
|
||||||
pool->state.end = 0;
|
pool->state.end = 0;
|
||||||
@@ -279,6 +287,13 @@ anv_block_pool_init(struct anv_block_pool *pool,
|
|||||||
|
|
||||||
/* Immediately grow the pool so we'll have a backing bo. */
|
/* Immediately grow the pool so we'll have a backing bo. */
|
||||||
pool->state.end = anv_block_pool_grow(pool, &pool->state);
|
pool->state.end = anv_block_pool_grow(pool, &pool->state);
|
||||||
|
|
||||||
|
return VK_SUCCESS;
|
||||||
|
|
||||||
|
fail_fd:
|
||||||
|
close(pool->fd);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -433,8 +433,8 @@ anv_state_clflush(struct anv_state state)
|
|||||||
anv_clflush_range(state.map, state.alloc_size);
|
anv_clflush_range(state.map, state.alloc_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void anv_block_pool_init(struct anv_block_pool *pool,
|
VkResult anv_block_pool_init(struct anv_block_pool *pool,
|
||||||
struct anv_device *device, uint32_t block_size);
|
struct anv_device *device, uint32_t block_size);
|
||||||
void anv_block_pool_finish(struct anv_block_pool *pool);
|
void anv_block_pool_finish(struct anv_block_pool *pool);
|
||||||
int32_t anv_block_pool_alloc(struct anv_block_pool *pool);
|
int32_t anv_block_pool_alloc(struct anv_block_pool *pool);
|
||||||
int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool);
|
int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool);
|
||||||
|
Reference in New Issue
Block a user