From 2362e02f297d0556fe07b7ae7ee680ca784dfc0c Mon Sep 17 00:00:00 2001 From: Italo Nicola Date: Fri, 17 Mar 2023 15:59:38 -0300 Subject: [PATCH] panfrost: fix strict-aliasing violations when packing fb ptrs Compilers are free to make the assumption that pointers don't violate strict aliasing. If that assumption is incorrect, as it is with the framebuffer pointer packing code here, the job can fail. This depends heavily on the compiler and optimization levels, so it's hard to reproduce, but it did happen for at least two users running with -O2 on gcc. Fixes: 67cbbf941751 ("panfrost: Use framebuffer pointer XML") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8627 Signed-off-by: Italo Nicola Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 6 +++++- src/panfrost/lib/pan_cs.c | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 6ce9398..11da62f 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -4426,10 +4426,14 @@ init_batch(struct panfrost_batch *batch) batch->tls = batch->framebuffer; #if PAN_ARCH == 5 - pan_pack(&batch->tls.gpu, FRAMEBUFFER_POINTER, cfg) { + struct mali_framebuffer_pointer_packed ptr; + + pan_pack(ptr.opaque, FRAMEBUFFER_POINTER, cfg) { cfg.pointer = batch->framebuffer.gpu; cfg.render_target_count = 1; /* a necessary lie */ } + + batch->tls.gpu = ptr.opaque[0]; #endif #endif } diff --git a/src/panfrost/lib/pan_cs.c b/src/panfrost/lib/pan_cs.c index 4e02305..c4bcb6c 100644 --- a/src/panfrost/lib/pan_cs.c +++ b/src/panfrost/lib/pan_cs.c @@ -27,6 +27,8 @@ #include "util/macros.h" +#include "genxml/gen_macros.h" + #include "pan_cs.h" #include "pan_encoder.h" #include "pan_texture.h" @@ -831,12 +833,12 @@ GENX(pan_emit_fbd)(const struct panfrost_device *dev, *(fb->rts[i].crc_valid) = false; } - uint64_t tag = 0; - pan_pack(&tag, FRAMEBUFFER_POINTER, cfg) { + struct mali_framebuffer_pointer_packed tag; + pan_pack(tag.opaque, FRAMEBUFFER_POINTER, cfg) { cfg.zs_crc_extension_present = has_zs_crc_ext; cfg.render_target_count = MAX2(fb->rt_count, 1); } - return tag; + return tag.opaque[0]; } #else /* PAN_ARCH == 4 */ unsigned -- 2.7.4