AGC: SRT walker statically evaluates a scalar load behind a per-lane exec guard and fails on a NULL pointer #479

Closed
opened 2026-10-03 20:10:09 +00:00 by ThisIsAkill · 6 comments
ThisIsAkill commented 2026-10-03 20:10:09 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-03T20:10:09Z.


Summary

A compute shader fails at record time with AGC driver: guest memory is not readable at 0x30 (range 0x30+0x4). The SRT walker statically evaluates a scalar load that sits on a branch it cannot evaluate (a per-lane exec guard), follows a NULL pointer, and throws. On hardware the block would page-fault if it ran, so it is presumably not executed while the pointer is NULL.

Seen with PPSA21567 on Linux (GCC 16.2), main d3ec1f15 plus #285, compute shader at 0x5005f6100 (16x16, wave64).

Pointer chain

0x1f40  v_cmp_* exec, 0, v58          ; per-lane condition
0x1f48  s_cbranch_execz               ; skip block
0x1f5c  s_cbranch_execz               ; skip block
0x1f60  s_load_dwordx2 s[8:9], s[0:1], 0      ; user SGPRs s[0:1] -> table, entry 0 -> P
0x1f6c  s_load_dword   vcc_lo, s[8:9], 0x18   ; P+0x18
0x1f78  s_bitcmp1_b32  vcc_lo, 18 ; s_trap 1 if set
0x1f88  s_load_dwordx2 s[6:7],  s[8:9], 0x58  ; P+0x58
0x1f90  s_load_dwordx2 s[10:11], s[8:9], 0x30 ; P+0x30 -> 0x30 when P = 0

The table that s[0:1] points to is mapped and all zero, so P is NULL.

Why this is not a bounds-check case

s_load_* reads a raw 64-bit address. There is no V#, so no num_records clamp (only s_buffer_load_* is range-checked). If this block ran with P = 0, real hardware would raise a VM fault rather than return 0. The title does not fault on the console, so the block is presumably not executed while P is NULL.

Where the driver fails

SrtDescriptorEvaluation.cpp (EvaluateRuntimeSourcesImpl) marks descriptor sources inactive only on paths whose block condition the clean evaluator can compute from uniform memory. The guard here is exec from a per-lane compare, which it cannot evaluate, so both successors stay active. The load through P is then evaluated when the dispatch is recorded, and GuestMemory::CheckRange throws.

Options (not choosing)

  1. Defer the failure. When a descriptor source on a branch the walker cannot evaluate reads unreadable memory, do not throw at record time. Instead, make the shader report a fault at runtime if it actually reaches that block (the existing FaultBuffer path, or a trap), and throw when the fault is read back. A block that never runs costs nothing; one that does run still fails loudly.
  2. Resolve the load at runtime. Read that source through device addresses (the BDA page table) instead of evaluating it statically.

Assumptions and limits

  • The table and V# contents were read with gdb in separate runs from the shader dump. Addresses are assumed identical across runs; a valid V# at the expected SRT offset in the same run supports this, but it is not proven.
  • Evidence that the table is never written is weak. It is still zero 5 s after the failure with the title's other threads running, but the title may be waiting on this GPU work. None of the buffer V#s in the 14 earlier dumped shaders of the run covers the table. That does not rule out writes by the command processor, flat/BDA stores or graphics outputs.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5693124055 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/479). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-03T20:10:09Z. --- ### Summary A compute shader fails at record time with `AGC driver: guest memory is not readable at 0x30 (range 0x30+0x4)`. The SRT walker statically evaluates a scalar load that sits on a branch it cannot evaluate (a per-lane `exec` guard), follows a NULL pointer, and throws. On hardware the block would page-fault if it ran, so it is presumably not executed while the pointer is NULL. Seen with PPSA21567 on Linux (GCC 16.2), `main` d3ec1f15 plus #285, compute shader at `0x5005f6100` (16x16, wave64). ### Pointer chain ``` 0x1f40 v_cmp_* exec, 0, v58 ; per-lane condition 0x1f48 s_cbranch_execz ; skip block 0x1f5c s_cbranch_execz ; skip block 0x1f60 s_load_dwordx2 s[8:9], s[0:1], 0 ; user SGPRs s[0:1] -> table, entry 0 -> P 0x1f6c s_load_dword vcc_lo, s[8:9], 0x18 ; P+0x18 0x1f78 s_bitcmp1_b32 vcc_lo, 18 ; s_trap 1 if set 0x1f88 s_load_dwordx2 s[6:7], s[8:9], 0x58 ; P+0x58 0x1f90 s_load_dwordx2 s[10:11], s[8:9], 0x30 ; P+0x30 -> 0x30 when P = 0 ``` The table that `s[0:1]` points to is mapped and all zero, so `P` is NULL. ### Why this is not a bounds-check case `s_load_*` reads a raw 64-bit address. There is no V#, so no `num_records` clamp (only `s_buffer_load_*` is range-checked). If this block ran with `P = 0`, real hardware would raise a VM fault rather than return 0. The title does not fault on the console, so the block is presumably not executed while `P` is NULL. ### Where the driver fails `SrtDescriptorEvaluation.cpp` (`EvaluateRuntimeSourcesImpl`) marks descriptor sources inactive only on paths whose block condition the clean evaluator can compute from uniform memory. The guard here is `exec` from a per-lane compare, which it cannot evaluate, so both successors stay active. The load through `P` is then evaluated when the dispatch is recorded, and `GuestMemory::CheckRange` throws. ### Options (not choosing) 1. **Defer the failure.** When a descriptor source on a branch the walker cannot evaluate reads unreadable memory, do not throw at record time. Instead, make the shader report a fault at runtime if it actually reaches that block (the existing `FaultBuffer` path, or a trap), and throw when the fault is read back. A block that never runs costs nothing; one that does run still fails loudly. 2. **Resolve the load at runtime.** Read that source through device addresses (the BDA page table) instead of evaluating it statically. ### Assumptions and limits - The table and V# contents were read with gdb in separate runs from the shader dump. Addresses are assumed identical across runs; a valid V# at the expected SRT offset in the same run supports this, but it is not proven. - Evidence that the table is never written is weak. It is still zero 5 s after the failure with the title's other threads running, but the title may be waiting on this GPU work. None of the buffer V#s in the 14 earlier dumped shaders of the run covers the table. That does not rule out writes by the command processor, flat/BDA stores or graphics outputs. AI-assisted: yes.
ThisIsAkill commented 2026-10-03 20:12:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-03T20:12:54Z.


Note for option 1: IrResourcePlan::controlFlow (the ResourceBlock list that EvaluateRuntimeSourcesImpl uses to mark sources inactive) is never populated outside a test (libSceAgcDriver/tests/ShaderMemory.cpp). ExtractPlan copies it from the program's plan, and nothing in the recompiler fills it. So today the walker evaluates every descriptor source unconditionally, including sources on branches with a uniform, evaluable condition. Deferring only sources "on a branch the walker cannot evaluate" would first need the analysis that produces these blocks (sources per block, branch condition, successors).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5973056529 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/479#issuecomment-5973056529). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-03T20:12:54Z. --- Note for option 1: `IrResourcePlan::controlFlow` (the `ResourceBlock` list that `EvaluateRuntimeSourcesImpl` uses to mark sources inactive) is never populated outside a test (`libSceAgcDriver/tests/ShaderMemory.cpp`). `ExtractPlan` copies it from the program's plan, and nothing in the recompiler fills it. So today the walker evaluates every descriptor source unconditionally, including sources on branches with a uniform, evaluable condition. Deferring only sources "on a branch the walker cannot evaluate" would first need the analysis that produces these blocks (sources per block, branch condition, successors).
ThisIsAkill commented 2026-10-03 20:34:33 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ThisIsAkill on 2026-10-03T20:34:33Z.


Local experiment for option 1 (not proposed as code). PPSA21567, Linux, main d3ec1f15 with #285 and #290 applied:

  • During capture, an unreadable word is recorded and returns 0. Every flattened-SRT slot whose evaluation touches a recorded address is marked poisoned, and the mark is part of the variant specialization and disk key. The variant is compiled with a fault buffer, and each ReadConst of a poisoned slot records a BdaAbi Unmapped fault in its original block (the slot read is emitted where the original s_load was).
  • Hits: 5 captures across 4 shaders (0x5005f6100 twice, plus 0x50064fc00, 0x5006b0300, 0x500715700), each with the same 5 reads: P+0x18, P+0x30, P+0x34, P+0x58, P+0x5c.
  • The fault store was emitted for all 5 poisoned slots in each of the 4 compiled variants (none removed as dead code).
  • 4 fault-buffer checks followed those dispatches, all empty. The title then runs on to presentation (stopped by an unrelated windowing issue on this machine).

So the guarded block did not execute in these dispatches while P was invalid. P was NULL in most runs and 0x3f800000 in one, which looks like non-pointer data in that table entry.

Limits: there is no positive control showing this fault path fires when such a block does run (it reuses RecordBdaFault). The mapping of the 4 checks to the 4 variants is inferred from ordering. Without #290 the same dispatch failed earlier with vkAllocateMemory -2, so the result depends on that PR as well.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5973238708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/479#issuecomment-5973238708). Originally posted by [ThisIsAkill](https://github.com/ThisIsAkill) on 2026-10-03T20:34:33Z. --- Local experiment for option 1 (not proposed as code). PPSA21567, Linux, `main` d3ec1f15 with #285 and #290 applied: - During capture, an unreadable word is recorded and returns 0. Every flattened-SRT slot whose evaluation touches a recorded address is marked poisoned, and the mark is part of the variant specialization and disk key. The variant is compiled with a fault buffer, and each `ReadConst` of a poisoned slot records a `BdaAbi` `Unmapped` fault in its original block (the slot read is emitted where the original `s_load` was). - Hits: 5 captures across 4 shaders (`0x5005f6100` twice, plus `0x50064fc00`, `0x5006b0300`, `0x500715700`), each with the same 5 reads: P+0x18, P+0x30, P+0x34, P+0x58, P+0x5c. - The fault store was emitted for all 5 poisoned slots in each of the 4 compiled variants (none removed as dead code). - 4 fault-buffer checks followed those dispatches, all empty. The title then runs on to presentation (stopped by an unrelated windowing issue on this machine). So the guarded block did not execute in these dispatches while P was invalid. P was NULL in most runs and `0x3f800000` in one, which looks like non-pointer data in that table entry. Limits: there is no positive control showing this fault path fires when such a block does run (it reuses `RecordBdaFault`). The mapping of the 4 checks to the 4 variants is inferred from ordering. Without #290 the same dispatch failed earlier with `vkAllocateMemory` -2, so the result depends on that PR as well.
oneandonlydean commented 2026-10-06 05:25:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:25:26Z.


For whoever follows this: #759 (Celegans12, stacked on #757 and #758, open) implements option 1 from this issue. In the flat SRT walk, a read whose base comes from memory and whose dword isn't accessible is not made. The slot reads 0 and is recorded, the record becomes part of the variant and disk-cache key, and each ReadConst of a recorded slot raises a BDA Unmapped fault through the fault buffer at the original pc. A guarded block that never runs costs nothing, and one that does run still fails loudly. It also fills the gap noted in the first comment, since it doesn't rely on IrResourcePlan::controlFlow.

One thing to check against this shader: #759 still throws when a branch condition needs such a value. Here P+0x18 feeds s_bitcmp1_b32 vcc_lo, 18 and then s_trap. @ThisIsAkill, if you have time, a run of #759 on PPSA21567 (0x5005f6100, plus 0x50064fc00, 0x5006b0300 and 0x500715700) would show whether that path is covered, and the result would help the review there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6009969386 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/479#issuecomment-6009969386). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T05:25:26Z. --- For whoever follows this: #759 (Celegans12, stacked on #757 and #758, open) implements option 1 from this issue. In the flat SRT walk, a read whose base comes from memory and whose dword isn't accessible is not made. The slot reads 0 and is recorded, the record becomes part of the variant and disk-cache key, and each `ReadConst` of a recorded slot raises a BDA `Unmapped` fault through the fault buffer at the original pc. A guarded block that never runs costs nothing, and one that does run still fails loudly. It also fills the gap noted in the first comment, since it doesn't rely on `IrResourcePlan::controlFlow`. One thing to check against this shader: #759 still throws when a branch condition needs such a value. Here P+0x18 feeds `s_bitcmp1_b32 vcc_lo, 18` and then `s_trap`. @ThisIsAkill, if you have time, a run of #759 on PPSA21567 (`0x5005f6100`, plus `0x50064fc00`, `0x5006b0300` and `0x500715700`) would show whether that path is covered, and the result would help the review there.
oneandonlydean commented 2026-10-09 20:26:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:26:39Z.


#759 is on main now: a read through a null SRT pointer on a branch that doesn't run no longer throws at capture, and faults at run time if it does run. Branch conditions that need such a value still throw, which may cover the P+0x18 s_bitcmp1/s_trap here. Does 0x5005f6100 still fail on current main?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088688691 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/479#issuecomment-6088688691). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:26:39Z. --- #759 is on main now: a read through a null SRT pointer on a branch that doesn't run no longer throws at capture, and faults at run time if it does run. Branch conditions that need such a value still throw, which may cover the P+0x18 `s_bitcmp1`/`s_trap` here. Does `0x5005f6100` still fail on current main?
adriadam10 commented 2026-10-10 08:45:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:45:56Z.


Partly addressed by #759: a read through a NULL/unmapped SRT pointer no longer throws at capture and raises a deferred Unmapped fault at the original pc if the guarded block runs (covered by GuardedNullPointer), on top of #285 (driver-owned global data share); still open: branch conditions that need such a value (the P+0x18 s_bitcmp1/s_trap here) still throw, and nobody has confirmed 0x5005f6100 on current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095808376 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/479#issuecomment-6095808376). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T08:45:56Z. --- Partly addressed by #759: a read through a NULL/unmapped SRT pointer no longer throws at capture and raises a deferred `Unmapped` fault at the original pc if the guarded block runs (covered by `GuardedNullPointer`), on top of #285 (driver-owned global data share); still open: branch conditions that need such a value (the `P+0x18` `s_bitcmp1`/`s_trap` here) still throw, and nobody has confirmed `0x5005f6100` on current main.
oneandonlydean commented 2026-10-13 02:08:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:08:40Z.


Closing: no answer on whether 0x5005f6100 still fails since #759. Reopen with the log line from current main if it does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6136632500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/479#issuecomment-6136632500). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T02:08:40Z. --- Closing: no answer on whether `0x5005f6100` still fails since #759. Reopen with the log line from current main if it does.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#479
No description provided.