panfrost: fix strict-aliasing violations when packing fb ptrs
authorItalo Nicola <italonicola@collabora.com>
Fri, 17 Mar 2023 18:59:38 +0000 (15:59 -0300)
committerMarge Bot <emma+marge@anholt.net>
Wed, 22 Mar 2023 11:50:36 +0000 (11:50 +0000)
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 <italonicola@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21991>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/panfrost/lib/pan_cs.c

index 6ce9398..11da62f 100644 (file)
@@ -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
 }
index 4e02305..c4bcb6c 100644 (file)
@@ -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