Skip to content

feat(memory): back GPU-visible guest memory with shareable memory behind a flag - #580

Open
RINNECODER wants to merge 7 commits into
mainfrom
team/gpuproc-p0
Open

RINNECODER wants to merge 7 commits into
mainfrom
team/gpuproc-p0

Conversation

@RINNECODER

Copy link
Copy Markdown
Owner

What

P0 of the GPU-process plan (anyps5-ops/notes/perf/gpu-process-study-2026-10-14/MEMO.md): a native
arm64 process has to be able to map the guest memory the AGC driver reads and writes at the addresses
the x86_64 engine already uses. macOS refuses fixed mappings in [64 GiB, 512 GiB), and a probe on
this Mac shows a native arm64 process refuses 6–256 GiB outright, so the guest arena's raw
[8, 1008) GiB cannot be mapped natively at all.

Everything is behind ANYPS5_GPU_SHARED_MEMORY=1 and the default path is unchanged.

  • GuestLayout.hpp (the slide the native AOT lane defined, byte-identical so the two tracks merge):
    with the flag on, the Darwin guest arena takes the 512 GiB slide, so the application area is
    [520 GiB, 1520 GiB).
  • A fixed guest request in the raw application area is moved by the same slide and returned through
    addr, like the pre-existing 448 GiB hole relocation, so guest and server agree on every address
    and the driver's borrowed ranges stay identity.
  • One sparse shm object backs the whole arena (/aps5-gpu-<pid>-arena, 1000 GiB, created on the first
    commit), so the libc GPU heap, GPU-flagged anonymous maps and the driver's command staging are all
    shareable through the one GuestArenaCommit path. Direct memory keeps its shm_open object open
    under the flag instead of unlinking it immediately.
  • GpuSharedMemory records each range with the object and offset backing it and writes them to
    ANYPS5_GPU_SHARED_MEMORY_MANIFEST.

Tested

  • core/libs/tests/gpu_shared_memory (ctest gpu_shared_memory_proof): an x86_64 process runs the
    engine's own memory code with the flag on and a native arm64 program opens the published objects,
    maps each range at the recorded address, checks the bytes the x86_64 process wrote and writes a
    counter-pattern the x86_64 process re-checks. Passes.
  • Rosetta ctest 26/26, Metal ctest 63/63, check_conventions.py --base origin/main clean.
  • AGC replay gates with the flag off and on: agc-map --expect-hash 51a268f2e73efb9c matches both;
    agc-live-map 79 px / 75 px and agc-menu 91 px / 61 px against replay-ref-v3.png (limit 200).
  • Boot smoke with the flag on is unverified: the title aborts 0.5 s in with the known
    main-808f8f3ec boot regression (Thread destructor callback is already registered, PR fix(relinker): stop running a guest module's preinit array from the startup stubs #579's
    root cause), before any GPU or arena work; Steam came up during the run and the rules forbid a game
    run while it is running, so the control and the bootfix-assisted rerun did not happen.

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 (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: none
  • GPUs tested: Apple M5 Pro (AGX G17S), macOS 27, Metal 382.5.3, x86_64 under Rosetta and native arm64
  • AI-assisted: yes

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9fd71e3-10a0-4a46-b3c6-31c3869cbc80
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T14:54:48.927419Z 8ec2c32 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57b38032e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +187 to +189
std::erase_if(shared.regions, [address, end](const Region& region) {
return region.address < end && address < region.address + region.bytes;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve unaffected registry fragments on overlap

When a registered mapping is only partially remapped or unmapped, this erases the entire overlapping Region; for example, replacing 16 KiB inside a 64 KiB arena allocation removes the manifest entry for the untouched 48 KiB even though those pages remain GPU-visible. Subsequent publication therefore leaves the native process unable to map valid surrounding memory, so registration and unregistration need to retain the non-overlapping fragments with adjusted object offsets.

Useful? React with 👍 / 👎.

Comment on lines +225 to +226
writeManifest();
return true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Report manifest write failures from publish

When the configured manifest directory is missing, unwritable, full, or the final rename fails, writeManifest() silently returns without publishing but this function still reports success. Callers such as the proof writer consequently proceed as though the native process received a current manifest; make the write/flush/close/rename path return a status and propagate it here.

Useful? React with 👍 / 👎.

Comment on lines 363 to 365
if (shared) GpuSharedMemory::GpuSharedMemoryAdoptObject_nid_postfix(name.c_str());
const int created = shm_open(name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
if (created < 0) throw std::system_error(errno, std::generic_category(), "create direct memory backing");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove stale direct-memory objects before exclusive creation

With shared memory enabled, an abnormal engine termination bypasses the atexit unlink and leaves /aps5-dmem-<pid> named indefinitely. Once macOS reuses that PID, this O_EXCL open fails with EEXIST, causing direct-memory initialization for the new run to throw; clear the per-PID stale name before creation as the new arena-object creation path already does.

Useful? React with 👍 / 👎.

@RINNECODER

Copy link
Copy Markdown
Owner Author

P1 and both P2s fixed in df77780: partial remap/unmap now keeps the surrounding fragments with adjusted object offsets (ctest gpu_shared_memory_registry covers both cases), GpuSharedMemoryPublish propagates a manifest write/flush/close/rename failure, and the direct-memory object is unlinked before its exclusive create so a stale per-pid name cannot fail the next run. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df77780d4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

#else
if (::mmap(reinterpret_cast<void*>(address), bytes, protection, MAP_SHARED | MAP_FIXED, file, static_cast<off_t>(fileOffset + offset)) == MAP_FAILED) throw std::system_error(errno, std::generic_category(), "map direct memory backing");
#if defined(__APPLE__)
GpuSharedMemory::GpuSharedMemoryRegister_nid_postfix(address, bytes, PhysicalObjectName().c_str(), fileOffset + offset);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Exclude out-of-arena mappings from the manifest

When shared memory is enabled and a fixed direct-memory request lies outside the raw application area, DarwinRelocateFixed and MapPlaced intentionally leave it at its host address, but this unconditional registration still publishes that address. A native consumer maps manifest regions with MAP_FIXED, so an out-of-arena mapping—such as one overlapping the relinked image range—can replace the native process's own mappings and crash it; only mappings placed in the shared/slid address space should be registered.

Useful? React with 👍 / 👎.

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@RINNECODER

Copy link
Copy Markdown
Owner Author

P1 fixed in ce01d40: PhysicalBacking::Map registers a range only when the guest arena contains it, so a fixed mapping that stayed outside the slid address space is no longer published. The proof writer now maps direct memory at 6 GiB, below the application area, and asserts the manifest does not mention it — the assertion fails without the guard. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce01d408a2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +113 to +117
if (fixedAnonymous && !GuestArena::GuestArenaContains_nid_postfix(address, rounded)) {
auto slid = start;
if (!GuestArena::GuestArenaSlideAddress_nid_postfix(&slid, rounded)) return failed(GuestInvalid);
start = slid;
address = reinterpret_cast<void*>(slid);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Slide fixed anonymous mappings only once

When mmap_nid_postfix receives a fixed anonymous raw address below 496 GiB, this block adds the 512 GiB slide and then passes the resulting address to DoMapAnon; on Darwin, DoMapAnon calls DarwinRelocateFixed, whose range check still treats that once-slid address as belonging to the raw application area and adds the slide again. The mapping is consequently returned 512 GiB above the compiler/runtime address, and ReleaseFlexibleMappingRange also releases the once-slid range rather than the actual mapping. Let the lower mapping layer perform the slide, or make it recognize addresses already inside the slid arena.

Useful? React with 👍 / 👎.

}
state.applied = ranges;
state.configured = true;
GpuSharedMemory::GpuSharedMemoryPublish_nid_postfix();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Publish the manifest after later range changes

This is the only production call to GpuSharedMemoryPublish_nid_postfix, so it publishes only during initial driver configuration. When GPU allocations change afterward, DirectDriver() takes the ReplaceBorrowedRanges branch at lines 388–390 without rewriting the manifest; the registry is updated by the mapping code, but the native process keeps the initial snapshot and cannot map newly allocated or remapped GPU memory. Republish when the applied range set changes, not only on first configuration.

Useful? React with 👍 / 👎.

@RINNECODER

Copy link
Copy Markdown
Owner Author

Both P1s fixed in 8f690ec: (1) mmap's fixed anonymous path no longer pre-slides — the validation only refuses a request no slide can move into the arena, DoMapAnon performs the single slide, and the flexible-memory release uses the returned address; the proof writer now maps a fixed anonymous range at 128 GiB and asserts it comes back exactly 512 GiB higher. (2) the manifest is republished whenever the applied range set changes (DirectDriver's ReplaceBorrowedRanges branch), gated on a registry version so an unchanged set costs nothing — measured 0.19 ms for a 250-region manifest, the only case where it writes. The registry test covers publish-after-change, the no-op publish and the retry after a failed publish. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f690ec907

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
}
#endif
return PlaceAt(pointer, bytes, protection);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fail instead of falling back to private arena memory

When ANYPS5_GPU_SHARED_MEMORY=1 and either the arena shm object cannot be created or its MAP_SHARED mapping fails, this fallback silently commits the range as private anonymous memory. The guest allocation is still treated as GPU-visible, but no registry entry gives the native process access to its contents, so submissions using the range can read stale or unmapped data; propagate the shared-backing failure rather than continuing with PlaceAt.

Useful? React with 👍 / 👎.

std::fprintf(file, "region 0x%llx 0x%llx %s 0x%llx\n", static_cast<unsigned long long>(region.address),
static_cast<unsigned long long>(region.bytes), region.object.c_str(), static_cast<unsigned long long>(region.offset));
}
if (std::fflush(file) != 0 || std::fclose(file) != 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Close the manifest file after a flush failure

When fflush fails, such as after the manifest filesystem becomes full, the short-circuiting || skips fclose(file). Every subsequent failed publication can therefore leak another descriptor until the process reaches its descriptor limit, at which point unrelated file and shared-memory operations also fail; call fclose regardless of the flush result and combine the recorded statuses afterward.

Useful? React with 👍 / 👎.

@RINNECODER

Copy link
Copy Markdown
Owner Author

In 9f0d0c0: the arena commit path now throws when the shared object cannot be created or its MAP_SHARED mapping fails, instead of silently committing private anonymous memory a server would read as stale; and a failed fflush no longer skips fclose. The "publish after later range changes" finding was already fixed in 8f690ec (DirectDriver() publishes in the ReplaceBorrowedRanges branch, gated on the registry version) — the code at that line now calls GpuSharedMemoryPublish_nid_postfix() right after state.applied = ranges. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 27c9284441

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
state.applied = ranges;
state.configured = true;
GpuSharedMemory::GpuSharedMemoryPublish_nid_postfix();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move the AGC driver memory into shared space

With ANYPS5_GPU_SHARED_MEMORY=1, this publishes only ranges registered with GpuSharedMemory, but MapDriverMemory() in Execution/src/Driver/Lifecycle.cpp still creates its GPU-visible 2 MiB block as a private anonymous mapping at raw address 0xfe0000000 and merely adds it to GuestAllocations. Consequently the native process receives borrowed ranges that reference the FS table and routine block but no manifest entry or shared object from which to map them; this block must also be slid and shared, including its embedded fixed addresses, before the manifest is published.

Useful? React with 👍 / 👎.

@RINNECODER

Copy link
Copy Markdown
Owner Author

In c4329aa: the driver's own 2 MiB GPU-visible FS-table block now slides with the arena and is committed from the arena's shared object, with the routine-table, routine and FS-slot addresses all derived from the mapped base, so the native process has a manifest entry and a shared object for it. The other two findings on 27c9284 were already fixed in 8f690ec and 27c9284 (the ReplaceBorrowedRanges branch publishes, and the arena commit throws instead of falling back to private memory). Rosetta ctest 27/27, Metal ctest 63/63, conventions clean. The flag-on replay gate still cannot be repeated: Steam is running.

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4329aab87

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

void* mapped = nullptr;
#if defined(__APPLE__)
if (GpuSharedMemory::GpuSharedMemoryEnabled_nid_postfix() && GuestArena::GuestArenaAvailable_nid_postfix()) {
GuestArena::GuestArenaCommit_nid_postfix(reinterpret_cast<void*>(base), DriverMemoryBytes, 0x04, DriverMemoryBytes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move driver memory outside the reserved arena interval

When ANYPS5_GPU_SHARED_MEMORY=1, this slides DriverMemoryAddress from 0xfe0000000 to 0x8fe0000000, but the raw address lies inside [GuestLayout::SystemReservedStart, GuestLayout::SystemReservedEnd). SeedDarwinUsedRanges() has already inserted that entire slid interval into the arena's _used map, so this commit calls MarkUsedForCommit() and throws an "overlaps a used range" exception whenever the AGC driver is initialized. Fresh evidence after the earlier driver-memory finding is this new shared commit path, which now prevents initialization rather than leaving the block private; place the internal block in an allocatable arena range or explicitly carve it out of the reservation.

Useful? React with 👍 / 👎.

}
state.applied = ranges;
state.configured = true;
GpuSharedMemory::GpuSharedMemoryPublish_nid_postfix();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle failed initial manifest publication

When shared memory is enabled but the configured manifest path is temporarily missing, unwritable, or full, GpuSharedMemoryPublish_nid_postfix() now correctly returns false, but this call discards it after marking the driver configured. If the borrowed ranges remain unchanged, DirectDriver() never calls publish again, so the native process receives no initial mapping manifest even after the filesystem problem is fixed; propagate the failure or leave publication pending for retry. The later replacement call at line 391 has the same unchecked failure behavior.

Useful? React with 👍 / 👎.

@RINNECODER

Copy link
Copy Markdown
Owner Author

In 38cbe1a: the driver block is now allocated from the slid arena rather than slid by 512 GiB — its raw address sits inside the PS5 system reservation, whose slid image [544 GiB, 576 GiB) the arena reserves, so the slid address collided and the commit threw. The arena allocator cannot hand out the reserved interval, and the block's table, routine and slot addresses still derive from the mapped base. Also added: the manifest publication failures at Configure and at ReplaceBorrowedRanges are reported on stderr instead of dropped. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@RINNECODER

Copy link
Copy Markdown
Owner Author

Correction: the commit in my previous comment is 4daa44cca (I mistyped the short sha). The Codex connector has now hit its review usage limit, so no review of 4daa44cca has run. Summary of the review round on c4329aab8 and its fixes: (1) the driver FS-table block is allocated from the slid arena instead of slid into the reserved [544 GiB, 576 GiB) interval; (2) a failed manifest publication at Configure and at ReplaceBorrowedRanges is reported on stderr; (3) "publish after later range changes" and "fail instead of falling back to private arena memory" were already fixed in 8f690ec90 and 27c928444. Local gates on 4daa44cca: Rosetta ctest 27/27, Metal ctest 63/63, check_conventions.py clean.

@RINNECODER

Copy link
Copy Markdown
Owner Author

Rebased onto current main (6c6d32dcd, #581) — new head f77c1457b; the only conflict was the appended entry in docs/dev/debt/libSceAgcDriver.md (both entries kept). Gates on the rebased head: Metal ctest 63/63, check_conventions.py --base origin/main clean, Rosetta ctest 26/27. The one failure, rosetta_image_cache, is pre-existing on main: #581 made GuestImageCache::Insert call texture->Descriptor() / CanShareBackingIgnoringDcc, which the rosetta_direct_graphics fakes do not provide, so rosetta_image_cache_tests does not even compile on a clean main checkout; with a local 4-line fixture shim it compiles and then fails on two #581 behaviour assertions ("an overlapping insert replaces the older surface", "only the newest of overlapping surfaces stays"). None of my commits touch the image cache; another worktree is already carrying that fixture fix. The full suite was 27/27 on the previous base 808f8f3ec.

…ind a flag

P0 of the GPU-process plan: a native arm64 process has to be able to map the
guest memory the AGC driver reads and writes at the addresses the x86_64
engine already uses, and macOS refuses fixed mappings in [64 GiB, 512 GiB).

ANYPS5_GPU_SHARED_MEMORY=1 slides the Darwin guest arena by 512 GiB (the
GuestLayout slide the native AOT lane uses), so the application area is at
[520 GiB, 1520 GiB), moves a fixed guest request in the raw application area
by the same amount, and backs every arena commit with one sparse shm object
covering the arena. Direct memory keeps its shm object open under the flag,
and the driver's command staging comes from the arena, so the staged words
are shared too. GpuSharedMemory records each range with the object and offset
backing it and writes them to ANYPS5_GPU_SHARED_MEMORY_MANIFEST.

The flag defaults off and nothing changes without it: the slide is zero, the
Darwin arena stays unavailable and its commits stay anonymous.

Tested: core/libs/tests/gpu_shared_memory runs the engine's own memory code as
an x86_64 process and a small arm64 program that maps the published objects at
the registered addresses, reads the bytes the x86_64 process wrote and writes
them back. Rosetta ctest 26/26, Metal ctest 63/63, check_conventions clean.
Review follow-ups on the shared-memory registry:

- a partial remap or unmap now keeps the parts of a registered range around
  it, with the object offset advanced by the bytes kept, instead of dropping
  the whole range (a 16 KiB remap inside a 64 KiB arena allocation used to
  lose the manifest entry for the other 48 KiB);
- GpuSharedMemoryPublish reports a manifest write, flush, close or rename
  failure instead of reporting success;
- the direct memory object is unlinked before its exclusive create, so a
  name left behind by an earlier run that died before its exit handler does
  not make the next run with the same pid throw.

Tested: ctest gpu_shared_memory_registry checks both fragment cases and the
unwritable manifest path; Rosetta ctest 27/27, Metal ctest 63/63,
check_conventions clean.
A fixed direct-memory request outside the raw PS5 application area keeps its
host address, so publishing it would tell a native process to map that address
with MAP_FIXED, over its own mappings (the relinked image range, for example).
Register only ranges the guest arena contains, which is exactly the slid
address space the server can map.

Tested: the proof writer maps direct memory at 6 GiB, below the application
area, and asserts the manifest does not mention it; the check fails without
the guard. Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.
…hanges

Two review follow-ups:

- mmap's fixed anonymous path slid the address and then let DoMapAnon slide
  it again, so a raw address below 496 GiB was mapped 512 GiB too high and
  the flexible-memory release used the wrong address. The validation now only
  refuses a fixed request no slide can move into the arena, the mapping layer
  does the single slide, and the release uses the returned address;
- the manifest was published only when the driver was first configured, so a
  later GPU allocation or remap left the native process with the initial
  snapshot. It is now published whenever the applied range set changes, and
  only when the registry version changed (0.19 ms for 250 regions, so an
  unchanged set costs nothing).

Tested: the proof writer maps a fixed anonymous range at 128 GiB and checks
it comes back exactly 512 GiB higher; the registry test covers publishing
after a change, the no-op publish, and the retry after a failed publish.
Rosetta ctest 27/27, Metal ctest 63/63, conventions clean.
…fest file

Review follow-ups:

- the arena commit path fell back to private anonymous memory when the shared
  object could not be created or its MAP_SHARED mapping failed, which leaves a
  GPU-visible range the native process cannot map and would read as stale; it
  now throws instead;
- a failed fflush no longer short-circuits past fclose, so repeated failed
  publications cannot leak descriptors.

Tested: Rosetta ctest 27/27 (including the shared-memory registry and the
cross-architecture proof), Metal ctest 63/63, check_conventions clean.
The driver's own 2 MiB GPU-visible block (the FS table and its routine
record block) was a private anonymous mapping at a fixed raw address and only
appeared in the guest allocations, so a native process got borrowed ranges
for it with no shared object to map. Under ANYPS5_GPU_SHARED_MEMORY it now
moves with the arena slide and is committed from the arena's shared object,
and every address written into the block (the routine table and routine
entries, and the FS table slot) follows the mapped base.

Tested: Rosetta ctest 27/27, Metal ctest 63/63 (including
anyps5_metal_agc_fs_table_calls, which maps its own block at the raw address),
check_conventions clean. The flag-on replay gate could not be repeated: Steam
is running.
The driver block's raw address is inside the PS5 system reservation, whose
slid image ([544 GiB, 576 GiB)) the arena reserves too, so sliding it put it
inside a reserved interval and the commit threw. Under the flag it is now
allocated from the slid arena, which cannot hand out the reserved interval,
and the manifest publication failures at driver configuration and range
replacement are reported instead of being dropped.

Tested: Rosetta ctest 27/27, Metal ctest 63/63, check_conventions clean.
@RINNECODER

Copy link
Copy Markdown
Owner Author

Rebased onto current main (4800a06a, #579/#581/#582) — head 8ec2c32e1.

Gameplay gate with ANYPS5_GPU_SHARED_MEMORY=1: PASS, all six checks (tools/release/gameplay_smoke.sh --build build-rosetta --title-dir <mounted title> --seconds 360 --min-gameplay 60): 3D map at 193.3 s, gameplay 109.9 s after it, 95 captured frames after the map, 173 presented events, nonblack min 0.93 / mean 0.959, 0 black-region frames, clean guest exit (0, reached the 360 s wall limit). The flag-on boot blocker is gone with #579.

Frame rate on the map: 489 presented frames over the gate's 109.9 s = 4.45 fps average (≈225 ms/frame), steady across 30 s slices (4.34 / 4.01 / 4.80 fps), computed from the frames_presented cumulative count / since_ms windows in run.log; the whole run is 3400 frames over 279.3 s = 12.17 fps including the fast menu and loading screens.

map.png: ~/Documents/ChatGPT/metal/anyps5-ops/scratch/team-1018/gpuproc/gameplay/map.png (with map-best.png, run.log, frames.csv, summary.txt). Checked quantitatively and structurally rather than visually (no image input in this session): 2018 distinct colours in the gate's 64x36 sample against 2036 for the known live-map capture captures/agc-live-map/game-0.png and 1273 for the last loading frame of the same run (documented bands: 1080-1290 loading, 1600-2200 map); it is the first frame of the five-frame animating window that triggered map detection; post-map frames keep changing; the left 15% and top 5% strips carry 3.8% and 2.6% high-contrast thin-stroke pixels (text/icons) against 0.46% and 0.32% on the loading frame; the coarse colour map shows a central landmass with dark unexplored borders and flat grey panels anchored to the left and bottom edges.

Rosetta ctest 26/27 and Metal ctest 63/63 on this head; check_conventions.py clean. The single failure, rosetta_image_cache, is pre-existing on main — compiling ImageCacheTest.cpp against origin/main's own GuestImageCache.hpp alone reproduces the same two failures, which are #581's behaviour change left un-updated in the fixture; nothing here touches the image cache.

@RINNECODER

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ec2c32e14

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +63 to +65
if (GpuSharedMemory::GpuSharedMemoryEnabled_nid_postfix() && GuestArena::GuestArenaAvailable_nid_postfix()) {
base = reinterpret_cast<std::uint64_t>(GuestArena::GuestArenaAllocate_nid_postfix(DriverMemoryBytes, 0x1000));
GuestArena::GuestArenaCommit_nid_postfix(reinterpret_cast<void*>(base), DriverMemoryBytes, 0x04, DriverMemoryBytes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the FS table at its fixed guest address

When ANYPS5_GPU_SHARED_MEMORY=1, allocating this block at the arena's next free address moves the FS table away from 0xfe0040000, but table-call shaders still embed that address unchanged: ReadTableCallees() dereferences the shader's constant pointer, and ComputeFsTableCalls.cpp explicitly verifies the table at 0xfe0040000. Such shaders will therefore fault while reading the descriptor instead of reaching the initialized table. Back the fixed address with shareable memory, or add a consistent relocation for every reference to it, rather than assigning an arbitrary arena address.

Useful? React with 👍 / 👎.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant