Fix DLSS initialization with staged guest address reservations #2443

Open
github-bot wants to merge 7 commits from github-bot/gh-2443 into main AGit
Owner

@⁠OlaiFG7 on GitHub · 2026-11-20 07:44 UTC · original
OlaiFG7:fix-dlss-guest-reservations → main · +600 −71 · 6 files · 7 commits · open

Continues the work from #2274, preserving its commits and adding hardening for staged guest address reservations. The change delays part of the reservation until after GPU initialization and improves synchronization, host mapping handling, and reservation coverage.

Validation: not run; CMake and project submodules were unavailable in the local environment.

**@⁠OlaiFG7** on GitHub · 2026-11-20 07:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2443) `OlaiFG7:fix-dlss-guest-reservations` → `main` · +600 −71 · 6 files · 7 commits · open Continues the work from #2274, preserving its commits and adding hardening for staged guest address reservations. The change delays part of the reservation until after GPU initialization and improves synchronization, host mapping handling, and reservation coverage. Validation: not run; CMake and project submodules were unavailable in the local environment.
Reserve only fixed system ranges during memory setup, then reserve remaining guest regions after Vulkan/NGX initialization. This avoids host address-space conflicts while ensuring guest mappings are ready before driver startup.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:20:32 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-20 07:55 UTC · original · edited 2026-11-20 08:17 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change reserves available guest address ranges around existing host mappings. It reserves guest region 0 during memory initialization and schedules reservation of regions 1 and 2 after GPU initialization. It adds alignment and reservation tests, checks that an existing Linux mapping remains intact, and checks repeated reservation. Memory ownership checks in the changed operations now run under the shared state lock.

Suggested reviewers: nmzik, nikosszzz

Change: Bug fix

Merge Risk: Minimal · up to 8b362

Guest address space reservation on Linux now retries with a fresh view of host mappings, so a concurrent host mapping no longer ends startup on the first collision. No concrete merge-blocking issue remains. The author reports that no build or test run was done, so a normal CI pass is still worthwhile.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a DLSS initialization fix that relies on staged guest address space reservations. The changeset delays part of the reservation until after GPU initialization (agc.cpp,…
Description check Passed The description states that the change continues work from #2274, adds hardening for staged guest address reservations, delays part of the reservation until after GPU initialization, and improves sync…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a DLSS initialization fix that relies on staged guest address space reservations. The changeset delays part of the reservation until after GPU initialization (agc.cpp, memory.cpp, memoryAddressSpace.inc), which matches the title's subject. The title is specific and concise, and it matches the PR objectives.

Full details: Description check

Explanation

The description states that the change continues work from #2274, adds hardening for staged guest address reservations, delays part of the reservation until after GPU initialization, and improves synchronization and host mapping handling. These points match the changeset. It also notes that validation was not run.

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 949a7d3b28 and 8b362f5c8b.

Files selected for processing: 1

  • src/kernel/memoryAddressSpace.inc

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-20 07:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2443#issuecomment-7033777664) · edited 2026-11-20 08:17 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/2443?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> The change reserves available guest address ranges around existing host mappings. It reserves guest region 0 during memory initialization and schedules reservation of regions 1 and 2 after GPU initialization. It adds alignment and reservation tests, checks that an existing Linux mapping remains intact, and checks repeated reservation. Memory ownership checks in the changed operations now run under the shared state lock. **Suggested reviewers:** `nmzik`, `nikosszzz` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"8b362f5c8b90cd06791e832d076f5ff7a0f5eeb2" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>8b362</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `8b362` --> <!-- final_review_risk_coverage:{"sourceCommitId":"8b362f5c8b90cd06791e832d076f5ff7a0f5eeb2","coveredCommitId":"8b362f5c8b90cd06791e832d076f5ff7a0f5eeb2","kind":"reviewed"} --> Guest address space reservation on Linux now retries with a fresh view of host mappings, so a concurrent host mapping no longer ends startup on the first collision. No concrete merge-blocking issue remains. The author reports that no build or test run was done, so a normal CI pass is still worthwhile. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title names the main change: a DLSS initialization fix that relies on staged guest address space reservations. The changeset delays part of the reservation until after GPU initialization (agc.cpp,… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states that the change continues work from `#2274`, adds hardening for staged guest address reservations, delays part of the reservation until after GPU initialization, and improves sync… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the main change: a DLSS initialization fix that relies on staged guest address space reservations. The changeset delays part of the reservation until after GPU initialization (agc.cpp, memory.cpp, memoryAddressSpace.inc), which matches the title's subject. The title is specific and concise, and it matches the PR objectives. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description states that the change continues work from `#2274`, adds hardening for staged guest address reservations, delays part of the reservation until after GPU initialization, and improves synchronization and host mapping handling. These points match the changeset. It also notes that validation was not run. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2443)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/a1fc5ae438ea343480c9850f585d8c0afed06241/.coderabbit.yaml>) - **Commit**: [a1fc5ae](<https://github.com/KytyPS5/KytyPS5/commit/a1fc5ae438ea343480c9850f585d8c0afed06241>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `cbc52821-ee29-4e6b-9f1f-de96f2b8cb67` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 949a7d3b280163f0c21307cd866e379b623528b2 and 8b362f5c8b90cd06791e832d076f5ff7a0f5eeb2. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 1</strong></summary> <dl> <dd> <br> * `src/kernel/memoryAddressSpace.inc` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
@ -1013,0 +1227,4 @@
segment->segname, errno);
}
AddFreeUnlocked(expected_start, segment->vmsize);
m_owned.emplace_back(expected_start, segment->vmsize);
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-20 07:55 UTC · original · edited 2026-11-20 08:09 UTC

Minor · Functional Correctness · Quick win

Keep linked-segment ownership consistent with merged free ranges.

On linked macOS builds, SYSTEM_MANAGED and SYSTEM_RESERVED are adjacent. AddFreeUnlocked merges their free ranges, but this insertion leaves separate ownership entries.

A two-page allocation across HOST_SYSTEM_MANAGED_MAX + 1 can therefore succeed in Commit and then fail KernelMprotect or fixed replacement. Owns requires the entire span to fit in one entry. Coalesce adjacent owned intervals, or make Owns check contiguous coverage.

✅ Addressed in commit 8b362f5

**@⁠coderabbitai[bot]** on GitHub · 2026-11-20 07:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2443#discussion_r4639877545) · edited 2026-11-20 08:09 UTC <!-- coderabbit-ai-generated:v1 --> **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Functional Correctness** · **Quick win** **Keep linked-segment ownership consistent with merged free ranges.** On linked macOS builds, `SYSTEM_MANAGED` and `SYSTEM_RESERVED` are adjacent. `AddFreeUnlocked` merges their free ranges, but this insertion leaves separate ownership entries. A two-page allocation across `HOST_SYSTEM_MANAGED_MAX + 1` can therefore succeed in `Commit` and then fail `KernelMprotect` or fixed replacement. `Owns` requires the entire span to fit in one entry. Coalesce adjacent owned intervals, or make `Owns` check contiguous coverage. <!-- fingerprinting:phantom:medusa:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d73d924dbe4aa6614e97a75f --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit 8b362f5
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-20 07:55 UTC · original · reviewed

Actionable comments posted: 1

Minor comments: 1

src/kernel/memoryAddressSpace.inc: 1

1127-1127: Minor · Stability & Availability · Low value

Retry Linux reservation when a host mapping appears in a free gap.

The Linux branch takes one /proc/self/maps snapshot (lines 1081–1090). It then requests each aligned free gap with MAP_FIXED_NOREPLACE (lines 1125–1127). A region with no mappings at scan time has one gap: the whole region. If a host thread maps memory inside that region after the scan, the request fails with EEXIST and no bytes are recorded for the region. The check at lines 1129–1135 then ends startup, although the rest of the region may still be free.

A region with existing mappings keeps its other gaps. Startup ends only when every gap for that region fails.

When a gap request fails, re-read /proc/self/maps and recompute the free gaps for that region. Keep the ranges already reserved. The new snapshot lists them as occupied, so they are not requested again. Use a fixed attempt limit, and end startup only after the last attempt fails. The macOS branch uses the same re-query and retry approach.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a1fc5ae438 and 949a7d3b28.

Files selected for processing: 6

  • src/emulator.cpp
  • src/kernel/memory.cpp
  • src/kernel/memory.h
  • src/kernel/memoryAddressSpace.inc
  • src/libs/agc.cpp
  • tests/VirtualMemoryAllocationTests.cpp

Included 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-20 07:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2443#pullrequestreview-5989256761) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor comments: 1</summary><blockquote> <dl> <dd> <br> <details> <summary>src/kernel/memoryAddressSpace.inc: 1</summary><blockquote> <dl> <dd> <br> `1127-1127`: **<picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor** · **Stability & Availability** · **Low value** **Retry Linux reservation when a host mapping appears in a free gap.** The Linux branch takes one `/proc/self/maps` snapshot (lines 1081–1090). It then requests each aligned free gap with `MAP_FIXED_NOREPLACE` (lines 1125–1127). A region with no mappings at scan time has one gap: the whole region. If a host thread maps memory inside that region after the scan, the request fails with `EEXIST` and no bytes are recorded for the region. The check at lines 1129–1135 then ends startup, although the rest of the region may still be free. A region with existing mappings keeps its other gaps. Startup ends only when every gap for that region fails. When a gap request fails, re-read `/proc/self/maps` and recompute the free gaps for that region. Keep the ranges already reserved. The new snapshot lists them as occupied, so they are not requested again. Use a fixed attempt limit, and end startup only after the last attempt fails. The macOS branch uses the same re-query and retry approach. <!-- cr-comment:v1:0c7a214b94b952e9d893682e --> </dd> </dl> </blockquote></details> </dd> </dl> </blockquote></details> <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/a1fc5ae438ea343480c9850f585d8c0afed06241/.coderabbit.yaml>) - **Commit**: [a1fc5ae](<https://github.com/KytyPS5/KytyPS5/commit/a1fc5ae438ea343480c9850f585d8c0afed06241>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `7eb686be-104a-4a4d-b60e-efa6565e18f1` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between a1fc5ae438ea343480c9850f585d8c0afed06241 and 949a7d3b280163f0c21307cd866e379b623528b2. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 6</summary> <dl> <dd> <br> * `src/emulator.cpp` * `src/kernel/memory.cpp` * `src/kernel/memory.h` * `src/kernel/memoryAddressSpace.inc` * `src/libs/agc.cpp` * `tests/VirtualMemoryAllocationTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=85285946-61b2-4f49-9370-6c9602784e83 attempt=49582bc0-7768-494a-89c4-6a70ef9d2d3f batch=1/1 -->
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2443/head:github-bot/gh-2443'
git switch 'github-bot/gh-2443'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2443'
git switch 'github-bot/gh-2443'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2443'
git switch 'github-bot/gh-2443'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2443'
git switch 'main'
git merge --squash 'github-bot/gh-2443'
git switch 'main'
git merge --ff-only 'github-bot/gh-2443'
git switch 'main'
git merge 'github-bot/gh-2443'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.