From d0ea44cfdcd63fa8c5a65062bf2e972e70b0b7b6 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Mon, 19 Feb 2024 11:15:01 +0100 Subject: [PATCH] v3d,v3dv: fix BO allocation for shared vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to allocate "shared size" bytes for each workgroup but we were incorrectly multiplying by the number of workgroups in each supergroup instead, which would typically cause us to allocate less memory than actually required. The reason this issue was not visible until now is that the kernel driver is using a large page alignment on all BO allocations and this causes us to "waste" a lot of memory after each allocation. Incidentally, this wasted memory ensured that out of bounds accesses would not cause issues since they would typically land in unused memory regions in between aligned allocations, however, experimenting with reduced memory aligments raised the issue, which manifested with the UE4 Shooter demo as a GPU hang caused by corrupted state from out of bounds memory writes to CS shared memory. Reviewed-by: Alejandro PiƱeiro Cc: mesa-stable Part-of: (cherry picked from commit 1880e7cfed18eecc8acc2c48df86d92e72df9177) --- .pick_status.json | 2 +- src/broadcom/vulkan/v3dv_cmd_buffer.c | 2 +- src/gallium/drivers/v3d/v3dx_draw.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 4cea68fe6f6..d59dab2e7bf 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2034,7 +2034,7 @@ "description": "v3d,v3dv: fix BO allocation for shared vars", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index da4518de100..dda20edc157 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -4327,7 +4327,7 @@ cmd_buffer_create_csd_job(struct v3dv_cmd_buffer *cmd_buffer, if (cs_variant->prog_data.cs->shared_size > 0) { job->csd.shared_memory = v3dv_bo_alloc(cmd_buffer->device, - cs_variant->prog_data.cs->shared_size * wgs_per_sg, + cs_variant->prog_data.cs->shared_size * num_wgs, "shared_vars", true); if (!job->csd.shared_memory) { v3dv_flag_oom(cmd_buffer, NULL); diff --git a/src/gallium/drivers/v3d/v3dx_draw.c b/src/gallium/drivers/v3d/v3dx_draw.c index feba9080ec2..eec3b0b6df8 100644 --- a/src/gallium/drivers/v3d/v3dx_draw.c +++ b/src/gallium/drivers/v3d/v3dx_draw.c @@ -1390,7 +1390,7 @@ v3d_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info) v3d->compute_shared_memory = v3d_bo_alloc(v3d->screen, v3d->prog.compute->prog_data.compute->shared_size * - wgs_per_sg, + num_wgs, "shared_vars"); }