From ad62911683793f5b93e1f1f8698e1f38cf4f2a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Wed, 1 Oct 2025 11:03:02 -0700 Subject: [PATCH] anv/allocator: Change some parameters and variables from 32bit to 64bits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit struct anv_state::offset and struct anv_block_pool::max_size are 64bits so these parameters should also be 64bit or risk overflow. Cc: mesa-stable Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/vulkan/anv_allocator.c | 21 +++++++++++++-------- src/intel/vulkan/anv_private.h | 3 +-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 375791c490a..2ca656aa8b4 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -465,12 +465,17 @@ anv_block_pool_expand_range(struct anv_block_pool *pool, uint32_t size) * The returned pointer points to the map for the memory at the specified * offset. The offset parameter is relative to the "center" of the block pool * rather than the start of the block pool BO map. + * + * offset parameter here is a offset from the beginning of block_pool. */ -void* -anv_block_pool_map(struct anv_block_pool *pool, int32_t offset, uint32_t size) +void * +anv_block_pool_map(struct anv_block_pool *pool, int64_t offset, uint32_t size) { struct anv_bo *bo = NULL; - int32_t bo_offset = 0; + int64_t bo_offset = 0; + + assert(offset + size <= pool->max_size); + anv_block_pool_foreach_bo(iter_bo, pool) { if (offset < bo_offset + iter_bo->size) { bo = iter_bo; @@ -774,7 +779,7 @@ anv_state_pool_get_bucket_size(uint32_t bucket) */ static void anv_state_pool_return_blocks(struct anv_state_pool *pool, - uint32_t chunk_offset, uint32_t count, + uint64_t chunk_offset, uint32_t count, uint32_t block_size) { /* Disallow returning 0 chunks */ @@ -818,7 +823,7 @@ anv_state_pool_return_blocks(struct anv_state_pool *pool, */ static void anv_state_pool_return_chunk(struct anv_state_pool *pool, - uint32_t chunk_offset, uint32_t chunk_size, + uint64_t chunk_offset, uint32_t chunk_size, uint32_t small_size) { uint32_t divisor = pool->block_size; @@ -831,7 +836,7 @@ anv_state_pool_return_chunk(struct anv_state_pool *pool, * aligned to divisor. Also anv_state_pool_return_blocks() only accepts * aligned chunks. */ - uint32_t offset = chunk_offset + rest; + uint64_t offset = chunk_offset + rest; anv_state_pool_return_blocks(pool, offset, nblocks, divisor); } @@ -884,7 +889,7 @@ anv_state_pool_alloc_no_vg(struct anv_state_pool *pool, state = anv_free_list_pop(&pool->buckets[b].free_list, &pool->table); if (state) { unsigned chunk_size = anv_state_pool_get_bucket_size(b); - int32_t chunk_offset = state->offset; + int64_t chunk_offset = state->offset; /* First lets update the state we got to its new size. offset and map * remain the same. @@ -950,7 +955,7 @@ anv_state_pool_alloc_no_vg(struct anv_state_pool *pool, state->map = anv_block_pool_map(&pool->block_pool, offset, alloc_size); if (padding > 0) { - uint32_t return_offset = offset - padding; + uint64_t return_offset = offset - padding; anv_state_pool_return_chunk(pool, return_offset, padding, 0); } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 3d493c0c840..ea187bfe312 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -878,8 +878,7 @@ VkResult anv_block_pool_alloc(struct anv_block_pool *pool, uint32_t block_size, int64_t *offset, uint32_t *padding); -void* anv_block_pool_map(struct anv_block_pool *pool, int32_t offset, uint32_t -size); +void *anv_block_pool_map(struct anv_block_pool *pool, int64_t offset, uint32_t size); struct anv_state_pool_params { const char *name;