Skip to content

fix(kernel,agc): honor GPU-only memory protection bits - #23770

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
birdmarty:fix/kernel-agc-gpu-only-protection
Nov 20, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
birdmarty:fix/kernel-agc-gpu-only-protection

Conversation

@birdmarty

@birdmarty birdmarty commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Far Cry 6 (PPSA01870 01.000.013) draws no text on its splash screen and main menu: the buttons are there, empty. The title maps the memory its UI text is drawn into (a 16 MiB block at 0x23f300000) with protection 0x30, GPU read and write without CPU read or write, and fills it from a compute shader through storage images.

LinuxProtFromSce already commits such memory read/write on the host (0x10 gives read, 0x20 read and write). GuestAllocations registered it with readable = false and writable = false, though, and the AGC driver only takes readable ranges into its leases. So GPU-only memory was missing from the leases, the BDA table, host imports and RegisteredReadableCovers, and storage-image results stored there were dropped as "memory no longer registered".

A registered range now keeps the GPU write bit (gpuWritable), and the driver asks two questions instead of the CPU bits:

  • HostReadable() = readable || gpu
  • HostWritable() = writable || gpuWritable

These are exactly the host protections LinuxProtFromSce gives the pages, so the driver reads and writes only pages the host lets it.

What stays the same:

  • CPU-side checks keep the CPU bits. sceKernelSyncOnAddressWait32 on GPU-only memory still returns EFAULT (new case), and sceKernelVirtualQuery reports the same protection as before.
  • The existing 5-argument Add and Protect set gpuWritable = gpu && writable, so HostWritable() equals writable for every caller that does not pass the new argument. HostReadable() differs from readable only for ranges with GPU access and no CPU read, which only libkernel's mappings and sceKernelMprotect create; they now pass the GPU write bit.
  • Adjacent ranges still join into one run (host import runs, GuestAllocationsAcquireMapped) when their CPU bits, GPU bit and host writability match, so every run that joins on main still joins. They split only where host writability differs, for example 0x11 next to 0x31.
  • A protection change gives the range a new backing serial, as before, so cached views and dispatches see a change of the GPU write bit.
  • Frame capture still skips ranges the CPU cannot read, as on main; the debt fragment records it.

Changes

  • libc/include/GuestAllocations.hpp, libc/src/GuestAllocations.cpp:
    • adds Range::gpuWritable, HostReadable() and HostWritable();
    • adds GuestAllocationsAddGpu_nid_no_patch and GuestAllocationsProtectGpu_nid_no_patch behind 6-argument Mutation::Add and Mutation::Protect. The 5-argument forms forward to them;
    • gpuWritable requires gpu, and survives Find, splits and unmaps;
    • GuestAllocationsEnd's GPU mapping notice and GuestAllocationsAcquire, AcquireMapped and AcquireRegistered take HostReadable() ranges.
  • libkernel/DirectMemory/DirectMemory.cpp: sceKernelMapDirectMemory, flexible mappings, fixed remaps and sceKernelMprotect pass prot & 0x20 as the GPU write bit.
  • libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp, Execution/src/ShaderMemory.cpp: the lease, import, mirror, BDA and registration checks use HostReadable() and HostWritable().
  • Tests:
    • Three existing cases registered ranges with GPU access to stand for unreadable memory: registeredReadableCoverTests, leaseSnapshotTests and CheckMappedLeasesPreserveReadableRuns. Those inputs now drop the GPU bit, and each test gained the GPU-only variant.
    • 0x30 and 0x10 through sceKernelMapDirectMemory, sceKernelMprotect and sceKernelMapNamedFlexibleMemory.
    • EFAULT from sceKernelSyncOnAddressWait32 on GPU-only memory.
    • BDA table entries and write permission for GPU-only ranges, copied and imported.
    • Run joining by host writability.
    • agc_storage_gpu_only_writeback: a storage image in 0x30 memory is cleared on the GPU and written back, with and without a host import.
  • docs/dev/debt/changes/fix-kernel-agc-gpu-only-protection.md: frame capture does not record GPU-only memory.

Tested

Windows 11 Pro (build 26300), MinGW-w64 GCC 15.3.0, Release build with tests, AMD Radeon RX 6800.

Tests ran on main 77d2c4ae60 and on this change, same machine and GPU. The set is 49 test programs: the four that hold the changed tests (guest_memory_tests, guest_sync_on_address_tests, agc_driver_graphics_tests, agc_driver_recorder_tests) and every other guest memory, host import, mirror, storage image, write tracking and BDA test program.

  • main: 368 tests, 364 passed, 4 skipped.

  • This change: 369 tests (the new agc_storage_gpu_only_writeback included), 365 passed, 4 skipped. The same four skip on both sides:

    • agc_host_import_sparse;
    • agc_driver_copied_writer_label_order;
    • agc_driver_copied_writer_label_order_drain;
    • agc_driver_partially_committed_volume_page_samples.
  • The same set again with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Vulkan SDK 1.4.363.0), VK_LOADER_DEBUG=layer and ctest -V: the same results on both sides.

    • Both logs show Insert instance layer "VK_LAYER_KHRONOS_validation": 232 times on main, 233 with this change (one more test).
    • Neither shows was not found but was requested by env var VK_INSTANCE_LAYERS.
    • Neither has a VUID- line.
  • With this change's HostReadable() and HostWritable() reduced to the CPU bits, which is what main checks:

    • agc_storage_gpu_only_writeback fails the way the title does:
      [gpu] storage image 0x200000000+0x40000: memory no longer registered; 1 pending ranges dropped
      AGC graphics: gpu-only storage write-back dropped or corrupted texels at +0
      
    • guest_memory and agc_driver_graphics fail on the new GPU-only cases.
    • guest_sync_on_address passes either way, since the CPU result does not change.
  • The run-joining case fails if adjacent ranges must match in the GPU write bit itself rather than in host writability.

  • public_headers (65 tests, GuestAllocations.hpp changed): passed.

  • agc_shader_memory_tests does not link with this toolchain, on main or with this change (ld: .rsrc merge failure: multiple non-default manifests), so its tests are not in the counts.

  • tools/check_conventions.py --base origin/main and tools/debt_fold.py --check: passed.

  • tools/pr_overlap.py: two open pull requests change the same lines. Neither needs this change, nor this change them.

    76 pull requests that conflict with main share files and could not be compared.

Far Cry 6 (PPSA01870 01.000.013): with this change the splash screen and the main menu draw their text. Taken on an earlier main (d31916ed37) with #21241; the after build also had #16053 reverted, which #20827 has since replaced on main.

Far Cry 6 main menu before and after this change

Far Cry 6 options menu after this change

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA01870 Far Cry 6 (PPSA01870) #21239
  • GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer on main and this change, no new VUIDs
  • AI-assisted: yes

🤖 Generated with Claude Code

birdmarty and others added 2 commits November 19, 2026 17:27
Adjacent registered ranges that differ only in the GPU write bit while
the CPU can write both stay one run, as on main. Ranges whose host
writability differs are split. Record that frame capture still skips
GPU-only memory.

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

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — no blocking findings

The inspected changes consistently track GPU write access separately from CPU permissions, and I found no concrete defect in the reviewed paths.

What I ran

Inspected the prepared diff for head 69dc84cb083fb980ad295d38a6b9f9af28e20620 and targeted source context through repo_read.py. No commands or tests were run.

Results

Check Result Note
Diff and targeted source review passed No concrete defect found in inspected paths.
Tests and build not run No execution environment was available.

Findings

Blocking

None.

Non-blocking

None.

Not verified

Tests and builds were not run; author-reported results in the PR description were not independently confirmed. Full file text was not inspected for the oversized changed files core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cpp, core/libs/prx/libSceAgcDriver/tests/Graphics.cpp, and core/libs/prx/libSceAgcDriver/tests/Recorder.cpp; their changed regions were inspected. The remaining unchanged portions of other changed files were not reviewed.

To get this to a good state

Nothing is required.

@domx4q

domx4q commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

NVIDIA Linux run with the Khronos validation layer of the current head 69dc84cb08; the run in Tested is AMD on Windows.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head 69dc84cb08 merged onto main abc3e4a692 with --no-ff (clean, as c0a0de81e5). Main baseline is a Release build of abc3e4a692 on the same machine.

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R '^(agc_graphics_profile_draw|agc_driver_graphics_maps_fallback|guest_memory|guest_sync_on_address)$|^agc_storage_|host_import|^agc_driver_bda' -V
main abc3e4a692 this PR
Result 46 of 46 passed (42 run, 4 skipped) 47 of 47 passed (43 run, 4 skipped)
Insert instance layer "VK_LAYER_KHRONOS_validation" 43 44
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

The pattern covers the four test programs this PR changes (agc_graphics_profile_draw and agc_driver_graphics_maps_fallback run agc_driver_graphics_tests, which holds the BDA, guest allocation and registered-cover cases; guest_memory; guest_sync_on_address), plus every agc_storage_*, host import and BDA test, since HostReadable()/HostWritable() now decide imports and write-back. agc_driver_graphics_tests runs against a mock device and loads no layer; the layer counts come from the storage, import and BDA tests.

  • main: 46 tests, 42 run and pass, 4 skip. This PR: 47 tests (the new agc_storage_gpu_only_writeback, absent on main), 43 run and pass, the same 4 skip.
  • The skips are device conditions: agc_driver_host_import_dma_buf_watch (the device does not select dma-buf for host imports), agc_driver_bda_reads_shadowed_results and _per_build (the device reports watched host memory written when it imports or reads it), agc_host_import_sparse (udmabuf size_limit_mb is above 1024).

Negative control: this PR's tests with Execution/src/ShaderMemory.cpp and Graphics/src/GuestBufferMemory.cpp from main (libc, libkernel and the tests kept from this PR) fail both:

agc_graphics_profile_draw:
AGC graphics: a gpu-rw allocation without cpu access must be covered as writable
agc_storage_gpu_only_writeback:
[gpu] storage image 0x7f700e270000+0x40000: memory no longer registered; 1 pending ranges dropped
AGC graphics: gpu-only storage write-back dropped or corrupted texels at +0

No new VUID- errors; all focused tests pass on Ada, and the new GPU-only write-back case fails without the libSceAgcDriver part of the change.

AI-assisted: yes (Claude Code)

@Colewiz7

Copy link
Copy Markdown
Contributor

Head 69dc84cb08 merged onto main 23786c4e4f as b72179ba77, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6300 on the 7900 XT, the 2029 GPU ones on the iGPU), new failures vs main none none
-R '^agc' (1961 tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the set of distinct validation messages matches main.

AI-assisted: yes

@4le22io

4le22io commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Tested on NVIDIA, to add a second vendor to the AMD run. There are no regressions, and the new test passes.

System: Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 4060 (10de:2882), driver 621.01, Intel Core i5-12400F, WinLibs GCC 15.2.0 r7 (UCRT), Release, BUILD_TESTING=ON.

Trees: main 9d5f50b, and the same commit with head 69dc84c merged with git merge --no-ff (clean merge, 13 files). Each tree had a full build.

Run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer (Vulkan SDK 1.4.363.1), ctest -R 'memory|sync_on_address|host_import|import_|mirror|storage|write_track|watch|bda|lease|readable|gpu_only' -j 8 -V:

  | main | this PR -- | -- | -- tests | 324 | 325 (+ agc_storage_gpu_only_writeback) passed | 317 | 318 failed | 2 | the same 2 skipped | 5 | the same 5 Insert instance layer "VK_LAYER_KHRONOS_validation" | 177 | 178 was not found but was requested | 0 | 0 VUID- lines | 0 | 0

One addition to your run: with WinLibs GCC 15.2.0 r7, agc_shader_memory_tests links. agc_shader_memory and agc_shader_memory_coherent_atomic_loads pass with this PR, so the ShaderMemory.cpp change is exercised here.

Not tested: Far Cry 6 (I don't have the title), Linux, and the "HostReadable/HostWritable reduced to the CPU bits" counter-check.

AI-assisted: yes (Claude Code). It merged the PR, ran both builds and test sets, and drafted this comment.

@github-actions github-actions Bot added the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 19, 2026
@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 20, 2026
@oneandonlydean
oneandonlydean merged commit 8363b41 into boykopovar:main Nov 20, 2026
22 of 24 checks passed
oneandonlydean pushed a commit that referenced this pull request Nov 23, 2026
Planet Zoo (PPSA18026) marks a 32 GiB range at 0xd000000000 as PRT with
the AMM, so its unbacked pages are zero pages with GPU read protection
(0x10). Since the AGC driver takes GPU-only memory into its leases
(#23770), every address-based build took that range in. It could neither
import it (over the host import budget) nor mirror it, so it counted it
as a copy and aborted: "an address-based build copies 32761 MiB of 3
registered ranges, past 64 MiB (APS5_ADDRESS_COPY_MAX_MIB)".

Zero pages now keep their GPU read protection (sceKernelVirtualQuery is
unchanged) but are registered without the GPU bits, so the driver leaves
them out of its leases and host imports, as it left all GPU-only memory
before #23770. Pages the AMM maps into the range keep their protection's
bits. Outside Windows, DoMapZero now passes the zero flag to
MapAnonymous instead of calling DoMapAnon; the mapping itself is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs libc libkernel unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants