Skip to content

fix(agc): skip Linux host imports of ranges not mapped read-write - #1051

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
fisherjoey:fix/linux-unwritable-host-import
Oct 8, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
fisherjoey:fix/linux-unwritable-host-import

Conversation

@fisherjoey

Copy link
Copy Markdown
Contributor

What

On Linux, importAllocation now checks that a range is mapped read-write (GuestMemory::Accessible(base, bytes, true)) before offering it to VK_EXT_external_memory_host. Ranges that fail the check are copied, as any refused import already is. This matches what the Windows branch does for read-only memory. A TechnicalDebt line records the driver behaviour.

The NVIDIA driver refuses imports of mappings it cannot pin writable with VK_ERROR_OUT_OF_DEVICE_MEMORY, and after that every vkAllocateMemory on the device fails the same way, including plain device-local allocations. On main, the read-only sections of the relinked image are offered for import, so the first refusal ends the title on its next texture or buffer allocation:

[gpu] host import of 0x55c1fbb94000+0x1e79000 failed at vkAllocateMemory (-2); falling back to copies
...
[videoout] presentation failed: compute shader 0x248898d00: AGC graphics: vkAllocateMemory texture: Vulkan result -2

Standalone repro (no AnyPS5): import one 1 MiB mapping, then allocate 16 MiB of device-local memory.

mapping import 16 MiB device-local alloc after it
anonymous MAP_PRIVATE rw 0 0
file MAP_PRIVATE rw 0 0
memfd MAP_SHARED rw 0 0
anonymous MAP_SHARED rw 0 0
anonymous, mprotect to r or rx -2 -2
file MAP_PRIVATE r or rx -2 -2
regular file MAP_SHARED rw -2 -2

Direct memory (memfd MAP_SHARED) is unaffected. Linux write watch uses userfaultfd write protection, so watched pages still read as rw in the mapping and stay importable.

Fixes #1022.

Tested

Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti, driver 595.91.07.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#1065 docs/dev/TechnicalDebt.md L255
#1072 docs/dev/TechnicalDebt.md L255
#1073 docs/dev/TechnicalDebt.md L255
#1237 docs/dev/TechnicalDebt.md L255

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the Accessible(base, bytes, true) check against /proc/self/maps permissions (same rule as the Windows branch for read-only memory), rebased on current main: build and ctest 415/415, CI green. The NVIDIA behaviour and the Demon's Souls run are taken from your repro and Dean's review (we can't run either here).

Added one commit: the TechnicalDebt line now says shared mappings of regular files, which the driver also refuses, are not checked for. Merging.

@adriadam10
adriadam10 force-pushed the fix/linux-unwritable-host-import branch from 4324cc1 to ecfaef0 Compare October 8, 2026 05:48
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
fisherjoey and others added 2 commits October 8, 2026 09:37
NVIDIA (595.91.07) refuses VK_EXT_external_memory_host imports of
read-only or executable mappings with VK_ERROR_OUT_OF_DEVICE_MEMORY and
then fails every later vkAllocateMemory on the device. Check the range
is mapped read-write before importing on Linux, as the Windows path
already does for read-only memory, and copy it otherwise.

Refs boykopovar#1022
…e mappings

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

Rebased again on current main (only a TechnicalDebt.md adjacency conflict with the CMASK line; both lines kept, no logic change). Build and ctest 423/423 pass. The Accessible(base, bytes, true) check matches the Windows branch for read-only memory, and the TechnicalDebt line says shared file mappings, which the driver also refuses, are not checked for. The NVIDIA behaviour and the Demon's Souls run are taken from the repro and Dean's review (not reproducible here). Merging once CI is green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux/NVIDIA: a refused host import of a read-only range makes every later vkAllocateMemory fail

2 participants