Repository navigation
rdna2spirv: an out-of-range s_buffer_load reads through the buffer's base (llvmpipe segfault) - #4573
LouisRiverstone wants to merge 2 commits into
Conversation
…base A run-time-bounded s_buffer_load guards each dword with an OpSelectionMerge on the bound and gives 0 outside it. llvmpipe (Mesa 26.0.8, LLVM 21) runs the guarded load anyway: ItsNotRexed#3039's s12 = -4, offset:20 read host memory 4 GB past the buffer and segfaulted vk_compute_test (reduced to 6 lines; in-range offsets run). The guarded load now reads through OpSelect(in range, address, V# base), so a hoisted load reads the base; the OpPhi still gives 0. tests/semantic/test_smem_oob_safe_address.py checks the selected address on the translated SPIR-V and that values are unchanged; ItsNotRexed#3039's cs_w32_late_ext now passes on llvmpipe. docs/design.md row added.
|
Tested What I ran:
Code review:
|
|
Tested head
The |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 76e312e2 on Windows 11, RTX 5070 Ti.
tests/semantic/test_smem_oob_safe_address.py-> 2 tests, OK;git diff --checkclean. The structural check confirms both dwords of a run-time-boundeds_buffer_load_dwordx2now take their pointer fromOpSelect(bound, address, base); the value check runs the six documented offsets and gets the same words as before, constant and run-time sOFF.- GPU,
run_gpu_tests.py --filter smemwith this translator -> 4/4 passed, 4 shadersspirv-valclean:cs_smem_bounds0x0 0x5eed0010 0x5eed000c 0x0 0x5eed000c 0x5eed0010 0x0 0x0,cs_smem_sload_neg,cs_smem_soffset_imm,cs_smem_stride_alignall match their expected words.
The change is in the guarded path only: the out-of-range address becomes dword i of the buffer base (at most 60 bytes on), while the OpPhi still yields 0. I cannot reproduce the llvmpipe hoist on this NVIDIA host, but the selected address is now in-bounds by construction.
|
Apple M2 no-regression check at head 76e312e (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build exit 0).
AI-assisted. |
|
Verified GPU, semantic & negative-control checks (
|
|
Thanks @justr4mzi (RX 6700 XT) and @bobcatchris (Apple M2). The unused pointer is fixed in |
@justr4mzi on ItsNotRexed#4573: the unconditional OpConvertUToPtr of the load address was unused when every dword reads through its own selected pointer. Every dword of one load takes the same path, so the base pointer is now emitted only for the unguarded paths.
|
Verdict: approve-with-nits. The fix is right: the value still comes from Verified: Nits / follow-ups:
AI-assisted review. |
Problem. An out-of-range
s_buffer_loadsegfaults llvmpipe, the CI's GPU. The translated code is correct: ans_buffer_loadwhose bound is only known at run time guards each dword with anOpSelectionMergeonoff + 4·i + 4 <= NUM_RECORDS · strideand 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_exton llvmpipe locally,vk_compute_testcrashes with SIGSEGV (exit 139). Every 32-wide GPU passed it, because their stray read returns garbage that is thrown away. Word 6 iss12 = -4, offset:20: 0xFFFFFFFC + 20 =0x100000010bytes, pastNUM_RECORDS = 0xFFFFFFFF, so it must read 0 (#1948). The guarded load at that address is 4 GB past the buffer.Reduction. Delta debugging brought it down to 6 lines that still crash: that load, a
v_cmpx, ads_mskor_rtn_b32and a store. It doesn't crash withs12 = 12, which is in range. The module passesspirv-val. Two other offsets (-0x100,0x7ffffff0) also crash, but they are in range forNUM_RECORDS = 0xFFFFFFFF, so they are real reads 4 GB away from a small buffer, not a translator issue.Change. In
scalar_load's run-time-bounded path, the guarded load now reads throughOpSelect(in range, address, V# base), converted to a pointer the same way (host_addr).OpPhigives 0 out of range.OpSelectand one pointer per guarded dword. Constant bounds, unguarded loads andbuffer_load*are unchanged.Tests.
tests/semantic/test_smem_oob_safe_address.pychecks that the guarded load's pointer comes from anOpSelecton the bound condition, and that values are unchanged on a grid of in- and out-of-range offsets. It passes 2/2; againstmain'stools/, the structure test fails.test_scalar_mem_smem.py,test_smem_const_offset.pyandtest_global_mem_offset.pypass.runtime/built from this tree,llvm-mc21.1.8):cs_w32_late_extwith this translator passes, with all eight words right (… 0 4008636142); before, it segfaulted.scripts/run_gpu_tests.pygives 139/210 passed, 71 skipped, 0 failed, identical tomain.python -I -m unittest discover -s tests/semanticshows onlymain's known failures (tests/semantic: re-anchor the v_mul_legacy_f32 mutation after the flush change #3883, fix(rdna2spirv): route v_cmp(x)_class_f64 to cmp_class_f64 so malformed forms are rejected #3885/rdna2spirv: reject a modified class mask and a non-EXEC v_cmpx destination (TEST-853) #3948, tests: test_loop_ballot_barrier follows #2089's structured wave64 emulation (main red since 1cc7497b) #3995).docs/design.md: new row after "Scalar/buffer memory".No game files. Claimed on #4421 before starting.
AI-assisted (Claude Code): I reviewed and ran the change and the tests.