shader: read BDA pages past the page table as missing #2358
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2358
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2358"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@wuboo on GitHub · 2026-11-17 18:40 UTC · original
wuboo:pr/bda-page-guard→main· +113 −5 · 2 files · 1 commits · openProblem
get_bda_pointer(DefineGetBdaPointerinspirvEmitterMemory.cpp) narrows the 64-bit guest page number to 32 bits and uses it, unchecked, to index the BDA page table and the fault bitmap. The table holdsCACHING_NUMPAGES= (2^40 + 512 GiB) >> 14 = 100,663,296 entries. A guest address whose packed page is outside the table causes two problems:robustBufferAccess, which the device always enables, this does not lose the device. But the value read is only guaranteed to be zero withrobustBufferAccess2; core robustness allows any value from inside the buffer, which is a device address of an unrelated page;Cause
page = OpUConvert(u32, packed >> CACHING_PAGEBITS)has no range check, and the fault path records the narrowed page as well.Fix
Compare the 64-bit page with
CACHING_NUMPAGESbefore narrowing it. A page outside the table uses index 0 for the (now in-bounds) table load and goes down the existing "unbacked" path, so it reads as zero. The fault bit is only recorded for in-range pages, so a garbage address never marks page 0 as faulting.Testing
TestNewShaderRecompilerUnbasedFlatUsesBdanow also checks the disassembledget_bda_pointer. The function must compare the page with theCACHING_NUMPAGESconstant (OpULessThan) and have the nested selection that skips the fault record. The SPIR-V still validates.ctestgives the same result set asmain(guest_red_zone_patcheraborted once under-j6and passed 3/3 when rerun alone; it does not touch this code).AI use & testing
I used AI coding assistants to help review the page-table lookup, draft the change and write the unit test check. I reviewed every line of the diff myself and I am responsible for it.
Testing:
TestNewShaderRecompilerUnbasedFlatUsesBda, including a mutation check that fails when the fix is reverted.@coderabbitai[bot] on GitHub · 2026-11-17 18:45 UTC · original · edited 2026-11-24 23:22 UTC
Walkthrough
The generated SPIR-V
get_bda_pointerfunction now checks the 64-bit guest page index againstBufferCache::CACHING_NUMPAGESbefore narrowing it for page-table lookup. Out-of-range indices use index zero for lookup, are treated as unbacked, and return zero without recording a fault. In-range unbacked pages still record a fault and return zero. The shader configuration test checks the generated function for the bound comparison, index selection, and guarded fault-buffer uses.Suggested reviewers:
claxten10,nmzik,senaxxChange: Bug fix
Merge Risk:
Minimal · previous review
222c7This change makes out-of-range guest page lookups read as missing instead of wrapping to a valid lower page or reading past the table. No concrete merge-blocking risk remains; the test could be tightened further but that is optional.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: BDA page lookups past the page table are now treated as missing (unbacked, zero). The raw summary and objectives confirm the change in DefineGetBdaPointer matches this title.
Full details: Description check
Explanation
The description explains the problem (unchecked 64-bit page narrowing indexing the BDA page table and fault bitmap), the cause, the fix (range check against CACHING_NUMPAGES before narrowing, index 0 with unbacked path), and the unit test changes. It is directly related to the changeset.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@coderabbitai[bot] on GitHub · 2026-11-17 18:46 UTC · original · reviewed
61ea1620-2f9b-4e20-b961-b95c929aa73aReviewing files that changed from the base of the PR and between
4da95bd8d0and 4fd0344a1bba92d3280a7425d06ed77d174543bc.src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
@wuboo on GitHub · 2026-11-17 20:46 UTC · original
Re the test nitpick: updated. The test now follows the
OpULessThanresult into theOpSelectthat picks the page table index, into the unbacked condition and into the nested branch. It also checks thatfault_bufferis only accessed in the block that branch guards. A constant-true guard, a missing index select or a reverted emitter each fail it.@coderabbitai[bot] on GitHub · 2026-11-17 20:50 UTC · original · reviewed
872d9a1b-19b2-4d87-80bc-13a09d4abb9dReviewing files that changed from the base of the PR and between 4fd0344a1bba92d3280a7425d06ed77d174543bc and 37c7ab10990d4d38574700a8b094722e9bb7ff56.
tests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-11-24 20:15 UTC · original · reviewed
d3fc48be-623b-48e1-ad4f-df1f65f518a7Reviewing files that changed from the base of the PR and between 2c117b96b8981116405005a0c5e9bd049f3c53ee and 222c73dd4315080105c8a3dd2bb34c2170cd1731.
tests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.