From 5984ca8417455a4923f74584bc68fcca5f913118 Mon Sep 17 00:00:00 2001 From: Aksel Hjerpbakk Date: Mon, 21 Jul 2025 12:13:26 +0000 Subject: [PATCH] panvk: avoid cs jump block with no allocator Also initialize allocator to NULL for tiler OOM handler and assert if capacity is sufficient in the event that allocator is NULL Reviewed-by: Lars-Ivar Hesselberg Simonsen Part-of: --- src/panfrost/genxml/cs_builder.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/panfrost/genxml/cs_builder.h b/src/panfrost/genxml/cs_builder.h index e177e72c912..2a591396d6e 100644 --- a/src/panfrost/genxml/cs_builder.h +++ b/src/panfrost/genxml/cs_builder.h @@ -513,6 +513,17 @@ cs_reserve_instrs(struct cs_builder *b, uint32_t num_instrs) if (unlikely(!cs_is_valid(b))) return false; + /* Make sure we have sufficient capacity if we wont allocate more */ + if (b->conf.alloc_buffer == NULL) { + if (unlikely(b->cur_chunk.size + num_instrs > b->cur_chunk.buffer.capacity)) { + assert(!"Out of CS space"); + b->invalid = true; + return false; + } + + return true; + } + /* Lazy root chunk allocation. */ if (unlikely(!b->root_chunk.buffer.cpu)) { b->root_chunk.buffer = b->conf.alloc_buffer(b->conf.cookie); @@ -530,8 +541,10 @@ cs_reserve_instrs(struct cs_builder *b, uint32_t num_instrs) * We actually do this a few instructions before running out, because the * sequence to jump to a new queue takes multiple instructions. */ - if (unlikely((b->cur_chunk.size + num_instrs + JUMP_SEQ_INSTR_COUNT) > - b->cur_chunk.buffer.capacity)) { + bool jump_to_next_chunk = + (b->cur_chunk.size + num_instrs + JUMP_SEQ_INSTR_COUNT) > + b->cur_chunk.buffer.capacity; + if (unlikely(jump_to_next_chunk)) { /* Now, allocate a new chunk */ struct cs_buffer newbuf = b->conf.alloc_buffer(b->conf.cookie);