mesa/src/asahi/lib
Alyssa Rosenzweig 3eb7575679
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run
asahi: do not use "Null" layout
This is the most serious bug we've had in a long time due to a fundamental
misunderstanding of the hardware (due to incomplete reverse-engineering). It
caught me off guard.

The texture descriptor has "mode" bits which configure two aspects of how the
address pointer is interpreted:

* whether it is indirected, pointing to a secondary page table for sparse
* whether it writes texture access counters (for Metal's idea of sparse).

...Neither of these is a "null texture" mode.

So why did I see Apple's blob using a non-normal mode for null textures, and why
did I copy those settings?

1. Because the hardware texture access counters provide a cheap way to detect
   null texture accesses after the fact, which I think their GPU debug tools
   use. I'm not sure why release builds of the driver do/did that, but whatever.

2. Because I assumed Cupertino knew best and I didn't bother looking too close.

We can't use them here (without doing extra memory allocations), since then
the GPU will increment access counters. And since our null texture address used
to just be a pointer in the command buffer, that mean the GPU will trash
whatever memory happened to be 0x400 bytes after the start of the null texture
descriptor. The symptom being random faults.

This bug was caught when trying to use the zero-page instead, which raised a
permission fault when the GPU tried to write counts. Then I remembered the
sparse mechanism and had a bit of a eureka moment. Immediately followed by an
"oh, f#$&" moment as I realized how many random bugs could potentially be root
caused to this.

The fix is two-fold:

1. Use normal layout instead.
2. Set the address to the zero-page (which is a fixed VA) and detect null
   textures by checking the address, instead of the mode.

The latter is a good idea anyway, but both parts needs to be done atomically to
maintain bisectability.

Backport-to: 25.1
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34703>
2025-04-24 19:05:07 +00:00
..
tests asahi: add missing tib alignment check 2024-01-10 08:44:38 -04:00
agx_abi.h asahi: do not use "Null" layout 2025-04-24 19:05:07 +00:00
agx_bg_eot.c asahi: port to common stats framework 2025-03-05 20:50:17 +00:00
agx_bg_eot.h asahi,vtn: precompile kernels 2024-11-28 17:34:12 +00:00
agx_bo.c asahi: port to stable uAPI 2025-04-09 20:25:49 +00:00
agx_bo.h asahi: port to stable uAPI 2025-04-09 20:25:49 +00:00
agx_border.c ail: swallow up formats 2024-09-02 23:27:14 +00:00
agx_device.c asahi: fix zero bo leak 2025-04-11 20:16:01 +00:00
agx_device.h asahi: fix zero bo leak 2025-04-11 20:16:01 +00:00
agx_device_virtio.c asahi: port to stable uAPI 2025-04-09 20:25:49 +00:00
agx_device_virtio.h asahi: add broken bits of unstable Linux UAPI 2024-06-14 15:44:30 +00:00
agx_helpers.h asahi: do not use "Null" layout 2025-04-24 19:05:07 +00:00
agx_linker.c asahi,hk: mmap BO on first use 2024-12-02 19:26:46 +00:00
agx_linker.h asahi,hk: disentangle logicop_enable 2025-04-08 19:04:47 +00:00
agx_nir_format_helpers.h asahi/lib: use #pragma once 2024-02-14 21:02:32 +00:00
agx_nir_lower_gs.c agx/nir_lower_gs: bound static topologies 2025-04-23 16:20:59 +00:00
agx_nir_lower_gs.h agx/nir_lower_gs: bound static topologies 2025-04-23 16:20:59 +00:00
agx_nir_lower_ia.c hk,libagx: handle adjacency without a GS 2024-12-21 01:50:32 +00:00
agx_nir_lower_msaa.c asahi/lib: Move alpha_to_one and alpha_to_coverage lowering to common code. 2025-04-23 09:03:41 +00:00
agx_nir_lower_sample_intrinsics.c asahi: clang-format 2025-04-23 16:20:59 +00:00
agx_nir_lower_tess.c agx/nir_lower_tess: drop dead todo 2025-04-22 12:47:54 +00:00
agx_nir_lower_tilebuffer.c asahi: switch tib lower to intrinsic pass 2025-02-22 02:24:28 +00:00
agx_nir_lower_uvs.c treewide: use nir_metadata_control_flow 2024-06-17 16:28:14 -04:00
agx_nir_lower_vbo.c asahi: optimize !robustness with soft fault 2024-10-05 18:30:13 +00:00
agx_nir_lower_vbo.h asahi: implement rba2 semantics for vbo 2024-06-16 12:15:22 -04:00
agx_nir_prolog_epilog.c agx: plumb vertex_id_zero_base 2025-04-23 16:20:59 +00:00
agx_ppp.h asahi: split frag shader words 2024-05-16 13:25:56 -04:00
agx_scratch.c asahi,hk: mmap BO on first use 2024-12-02 19:26:46 +00:00
agx_scratch.h asahi,vtn: precompile kernels 2024-11-28 17:34:12 +00:00
agx_tilebuffer.c asahi: add tib sample setter helper 2024-10-05 18:30:10 +00:00
agx_tilebuffer.h asahi/lib: Move alpha_to_one and alpha_to_coverage lowering to common code. 2025-04-23 09:03:41 +00:00
agx_usc.h asahi,vtn: precompile kernels 2024-11-28 17:34:12 +00:00
agx_uvs.h asahi: extend varying linking for tri fan weirdness 2024-05-14 04:57:27 +00:00
agx_va.c asahi: port to stable uAPI 2025-04-09 20:25:49 +00:00
asahi_proto.h asahi: port to stable uAPI 2025-04-09 20:25:49 +00:00
decode.c asahi: port to stable uAPI 2025-04-09 20:25:49 +00:00
decode.h asahi: port to stable uAPI 2025-04-09 20:25:49 +00:00
dyld_interpose.h asahi: Clang-format the subtree 2022-12-27 22:46:29 +00:00
meson.build asahi/lib: Move alpha_to_one and alpha_to_coverage lowering to common code. 2025-04-23 09:03:41 +00:00
pool.c asahi,hk: mmap BO on first use 2024-12-02 19:26:46 +00:00
pool.h asahi: label individual pools 2024-12-02 19:26:46 +00:00
wrap.c asahi: fix libwrap.dylib 2025-02-22 02:24:28 +00:00