rdna2spirv: an out-of-range s_buffer_load reads through the buffer's base (llvmpipe segfault) #184

Closed
github-bot wants to merge 6 commits from gh-pr/184/head into gh-pr/184/base
Owner

@⁠Andretuta on GitHub · 2026-11-24 02:37 UTC · original
ubiquitarianism:old-pr/9916 → main · +313 −28 · 8 files · 6 commits · closed without merging

Carried over from old PR 9916 by LouisRiverstone in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9916, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
LouisRiverstone: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Problem. An out-of-range s_buffer_load segfaults llvmpipe, the CI's GPU. The translated code is correct: an s_buffer_load whose bound is only known at run time guards each dword with an OpSelectionMerge on off + 4·i + 4 <= NUM_RECORDS · stride and gives 0 outside it. llvmpipe (Mesa 26.0.8, LLVM 21.1.8) executes the guarded load anyway.

Found on #3039. Running its fixture cs_w32_late_ext on llvmpipe locally, vk_compute_test crashes with SIGSEGV (exit 139). Every 32-wide GPU passed it, because their stray read returns garbage that is thrown away. Word 6 is s12 = -4, offset:20: 0xFFFFFFFC + 20 = 0x100000010 bytes, past NUM_RECORDS = 0xFFFFFFFF, so it must read 0 (#1948). The guarded load at that address is 4 GB past the buffer.

Re-submission of #4573. #4573 was closed unmerged during the 2026-11-23 22:45 UTC cleanup, along with the other open PRs. This is the same branch, now merged with current main.

Checked on #4573 by: SweatierKey (Linux), kapitche (WSL2 Ubuntu), TreXito (Linux 6.18), cxchhh (Tesla V100-SXM2-32GB), Ayinaki (RTX 5070), tunczzz (RTX 5070 Ti), searyecheesepeaceful (610M), KkelebekK (780M), MatyEjsr (NVIDIA GeForce RTX 3090), lunarminus (760M), sovljanskii (Apple M4), Mortify7612 (AMD Radeon RX 9060 XT) and 3 more.

No game files.

AI-assisted (Claude Code): I reviewed the change and re-ran its tests on the merge with main.

**@⁠Andretuta** on GitHub · 2026-11-24 02:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/184) `ubiquitarianism:old-pr/9916` → `main` · +313 −28 · 8 files · 6 commits · closed without merging > Carried over from **old PR 9916** by `LouisRiverstone` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9916`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `LouisRiverstone`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): **Problem.** An out-of-range `s_buffer_load` segfaults llvmpipe, the CI's GPU. The translated code is correct: an `s_buffer_load` whose bound is only known at run time guards each dword with an `OpSelectionMerge` on `off + 4·i + 4 <= NUM_RECORDS · stride` and gives 0 outside it. llvmpipe (Mesa 26.0.8, LLVM 21.1.8) executes the guarded load anyway. **Found on `#3039`.** Running its fixture `cs_w32_late_ext` on llvmpipe locally, `vk_compute_test` crashes with SIGSEGV (exit 139). Every 32-wide GPU passed it, because their stray read returns garbage that is thrown away. Word 6 is `s12 = -4, offset:20`: 0xFFFFFFFC + 20 = `0x100000010` bytes, past `NUM_RECORDS = 0xFFFFFFFF`, so it must read 0 (`#1948`). The guarded load at that address is 4 GB past the buffer. Re-submission of `#4573`. `#4573` was closed unmerged during the 2026-11-23 22:45 UTC cleanup, along with the other open PRs. This is the same branch, now merged with current `main`. Checked on `#4573` by: SweatierKey (Linux), kapitche (WSL2 Ubuntu), TreXito (Linux 6.18), cxchhh (Tesla V100-SXM2-32GB), Ayinaki (RTX 5070), tunczzz (RTX 5070 Ti), searyecheesepeaceful (610M), KkelebekK (780M), MatyEjsr (NVIDIA GeForce RTX 3090), lunarminus (760M), sovljanskii (Apple M4), Mortify7612 (AMD Radeon RX 9060 XT) and 3 more. No game files. AI-assisted (Claude Code): I reviewed the change and re-ran its tests on the merge with `main`.
Rebuilt on main, which replaced one selection per dword with one per load (to
cut the blocks of the cascade-shadow CS). That still segfaults llvmpipe (Mesa
26.0.8, LLVM 21) on #3039's s12 = -4, offset:20 and on cs_smem_oob_far: the
load inside the selection is hoisted and reads 4 GB past the buffer.

The loads now have no branch: they read through OpSelect(dword 0 in range,
the address, the V#'s base), at index i when in range and 0 otherwise (main's
indexing), and each value is OpSelect(dword i in range, loaded, 0). Out of
range they read the buffer's first dword and the values are discarded; no
extra blocks at all.

- test_scalar_mem_smem.py's evaluator models OpSelect %uint and keeps loads
  through the out-of-range side of an address select out of reads.
- tests/semantic/test_smem_oob_safe_address.py: the no-branch shape (one
  selected pointer on dword 0's bound, a value select per dword), discarded
  reads only at the V# base's first dword, values unchanged, the fixture on
  the CPU.
- runtime/test/shaders/cs_smem_oob_far.asm: passes on llvmpipe with this rule,
  segfaults vk_compute_test with main's translator.
- docs/design.md row added.
@memorypressure on #4573: with no readable bytes (dword 0 out of range,
num_records 0 included) main read nothing, while the branchless form read the
V# base, which such a descriptor may leave anywhere. The fallback is now Xbox
VA 0: the start of the host buffer the runtime maps the GPU window into
(host_addr), so always readable. The earlier claim that 'the heap base is 0 in
vk_compute_test' was wrong (its output buffer is the heap); the heap-base
variant had segfaulted because it still selected the address inside the
branch.

- test_smem_oob_safe_address.py: discarded reads at VA 0, and a zero-size
  descriptor with a far base (num_records 0) reads only VA 0 and gives 0.
- cs_smem_oob_far: word 4 is now that zero-size far-base case; header refreshed
  for the branchless form. Passes on llvmpipe with LLVM 21 and 23.
- docs/design.md row corrected.
# Conflicts:
#	docs/design.md
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/semantic/regen_fixtures.py
#	tests/semantic/test_scalar_mem_smem.py
# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/semantic/regen_fixtures.py
# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/semantic/regen_fixtures.py
# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:47:58 +00:00
github-bot closed this pull request 2026-11-26 08:47:58 +00:00
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:19 UTC · original

This carry-over of old upstream PR 9916 has been taken over in #650, so I'm closing this draft as #17 describes. The branch old-pr/9916 stays.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-24 19:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/184#issuecomment-7141918439) This carry-over of old upstream PR 9916 has been taken over in #650, so I'm closing this draft as #17 describes. The branch `old-pr/9916` stays. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.