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: 67cbbf9417 ("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>
This commit is contained in:
Italo Nicola
2023-03-17 15:59:38 -03:00
committed by Marge Bot
parent b6d5cb0d39
commit 2362e02f29
2 changed files with 10 additions and 4 deletions

View 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
}

View 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