GPU: keep a title guard page inside a range; change guards in runs #68
No reviewers
Labels
No labels
accessibility
already-solved
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
merged
needs-decision
needs-game-run
needs-rebase
not-merged
nvidia
obsolete
question
security
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/avatarmanz--VIctory-7900XTX!68
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-68"
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?
@zocram4cc on GitHub · 2026-11-26 01:28 UTC · original
zocram4cc:up/guard-runs→main· +585 −49 · 3 files · 2 commits · openPromised to @itsonewi on #14 (review of "copies of title memory"): a separate PR for this bug, with its own test. It does not depend on #14: this branch is cut from
avatarmanz/VIctory-7900XTXmainand contains none of #14's code.Bug: a title guard page inside a protected block loses its guard
protect_here(a range) andprotect_alias(another view of a guarded page) madePAGE_READONLYover a whole 64 KiB block, or over a whole range, after looking at the first page's old protection only. A page the title guards itself (PAGE_GUARD) further on in that block lost its guard: nothing faulted and nothing was seen written, so the title's own guard never fired.Now a change of protection covers only blocks that Windows says are alike (committed, one region, read-only or read-write throughout). A block that is not gets no call and stays as it is, with
VICTORY_GUARD_RUNSon or off.Tests (the two bug tests run with the switch off and on):
watch::tests::a_page_the_title_guards_inside_a_range_keeps_its_guard: on v7900/main the guarded page readsPAGE_READONLY(left: 2) instead ofPAGE_READWRITE | PAGE_GUARD(right: 260).watch::tests::a_page_the_title_guards_in_another_view_keeps_its_guard:left: 2,right: 260before theprotect_aliascheck; green with it.Change guards in runs (
VICTORY_GUARD_RUNS, on by default)Each change of protection is a kernel call; under Wine it is an
mprotectand a flush of every processor's address cache. The guards changed protection one block at a call, after asking for a whole range first where it could be refused across views. With the switch on:With
VICTORY_GUARD_RUNS=0a range is asked for whole only when it is one alike region; otherwise each block gets its own call. The refused call across views is no longer made:runs_of_guarded_blocks_are_cut_where_views_meetexpects 6 calls there, not 7.In-game counter (Proton Experimental, v7900 base, one scripted run)
Frame-line counter (diagnostics builds), two steady windows, per frame:
VICTORY_GUARD_RUNS=0.No frame-time change measured. The only two frame-time runs (98.0 ms/frame median in an earlier run without the bug fix or the runs, 100.9 ms in the run with both) are not an A/B: they differ in more than this change. I make no frame-time claim either way.
Credits
VirtualProtectper run of guarded pages, the idea behind the runs.As we read their code, their runs ignore view boundaries and the call's result, so it does not fit this tree; this is a new implementation.
Testing
cargo xwin build --profile diag -p victory --features diagnostics --target x86_64-pc-windows-msvcpasses.-D warnings(cargo xwin clippy -p victory-gpu --all-targets, default and--all-features): every diagnostic it reports is on a line this PR does not change.other_memory_inside_a_run_keeps_its_protectionpasses there too, since the old code already kept other memory's protection. The other-view test fails on the port before theprotect_aliascheck and passes after it.watch::module under Proton: the same three tests fail on the unchanged base and here (holes_are_known_until_the_runtime_tells,no_mapping_is_lost_between_askers,what_is_left_alone_is_no_known_hole). No new failures.AI-assisted: yes. Drafted with an AI coding assistant; the tests were run under Proton; the counter numbers come from the in-game run above.
protect_here and protect_alias made PAGE_READONLY over a whole 64 KiB block, or over a whole range, after looking at the first page's old protection only. A PAGE_GUARD page the title set further on in that block lost its guard with no fault and no write seen. Now a change of protection covers only blocks that Windows says are alike (committed, one region, read-only or read-write throughout). A block that is not gets no call and stays as it is, with VICTORY_GUARD_RUNS on or off. Runs (VICTORY_GUARD_RUNS, on; =0 keeps one call per block where a range is not one alike region): - unguard: blocks that follow one another in one view are opened with one call. - protect_here: one call per run of alike blocks within each view the runtime told of. A call across two views is refused, so runs are cut there. - cover: the other views of a run of guarded pages are made read-only with one call per run (protect_alias_runs); protect_alias takes what is left. With =0 a range is asked for whole only when it is one alike region, so the call across views that was refused is no longer made. Counter on victory_gpu::host (diagnostics builds), on the 5 s lines: calls and blocks per frame for giving write access back and for making read-only, and the refused ones ("the guards' changes of protection per frame"). Tests (watch::tests): a_write_over_guarded_blocks_opens_them_with_one_call, a_write_inside_guarded_blocks_opens_its_own_and_no_others, runs_of_guarded_blocks_are_cut_where_views_meet, other_memory_inside_a_run_keeps_its_protection, the_other_views_of_a_guarded_run_are_guarded_with_one_call, a_page_the_title_guards_inside_a_range_keeps_its_guard, a_page_the_title_guards_in_another_view_keeps_its_guard. Credits: Marvisak/VIctory PR #2849 (Therecalloftheonion) for the idea of one change of protection per run of guarded pages; PR #2848 item 6 (pes7) for giving guarded pages back in runs. As we read them, their runs ignore view boundaries and the call's result, so their code does not fit this tree; this is a new implementation for it.@avatarmanz on GitHub · 2026-11-26 07:33 UTC · original
Left open: conflicts with main (host.rs), and VICTORY_GUARD_RUNS is on by default; needs a rebase and an in-game check.
8b8da9b06ftoc56e299e23@zocram4cc on GitHub · 2026-11-26 08:12 UTC · original
Rebased onto current
main(the 5 s lines moved intometer_lines; the guard counter line is called there now) andVICTORY_GUARD_RUNSis off by default now (=1turns the batching on). The guard-page fix does not depend on the switch: with it off, a range is asked for whole only when it is one alike region, and a block that is not alike is left as it is.In-game check on
main+ this branch (Proton, RX 6900 XT) follows; I will post the numbers here.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.