From a8c7a25fb135ca9705901bcf2f1a8f0f9f432317 Mon Sep 17 00:00:00 2001 From: Daivik Bhatia Date: Wed, 15 Apr 2026 19:34:10 +0530 Subject: [PATCH] broadcom/compiler: Add explicit NOP instruction at page boundaries The QPU prefetches the next instruction during shader execution. If the shader assembly size perfectly aligns with a page boundary, the prefetching mechanism reads past the compiled boundary, leading to an MMU error. This commit insert an explicit NOP instruction at the end of the shader and increases the qpu_inst_count by one when the instruction count exactly hits a page boundary. This ensures we don't fall off the end of the last executable instruction page and into invalid memory. Reviewed-by: Iago Toral Quiroga Part-of: --- src/broadcom/compiler/vir_to_qpu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/broadcom/compiler/vir_to_qpu.c b/src/broadcom/compiler/vir_to_qpu.c index a4618d94c6e..05b7b896c6e 100644 --- a/src/broadcom/compiler/vir_to_qpu.c +++ b/src/broadcom/compiler/vir_to_qpu.c @@ -479,6 +479,16 @@ v3d_vir_to_qpu(struct v3d_compile *c, struct qpu_reg *temp_registers) v3d_qpu_schedule_instructions(c); + /* If the shader ends exactly on a page boundary, append a trailing + * NOP so the QPU's instruction prefetcher can't read past the last + * real instruction into an unmapped page. + */ + if (c->qpu_inst_count * sizeof(*c->qpu_insts) % c->devinfo->page_size == 0) { + struct qinst *inst = vir_nop(); + list_addtail(&inst->link, &vir_exit_block(c)->instructions); + c->qpu_inst_count++; + } + c->qpu_insts = rzalloc_array(c, uint64_t, c->qpu_inst_count); int i = 0; vir_for_each_inst_inorder(inst, c) {