fix(agc): import guest memory through dma-buf before host pointer when host imports lose write tracking #2434
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2434"
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?
Imported from boykopovar/AnyPS5. Originally posted by 999sian on 2026-10-09T19:59:44Z.
What
On this driver, host-pointer imports of guest memory lose userfaultfd write protection, while dma-buf imports of the same memory keep it. When the startup probe shows that, shared-backed ranges are imported through dma-buf only (except when udmabuf refuses the range before importing anything, which keeps the host-pointer import). Imported storage images over shared-backed direct memory were otherwise compared on every refresh because host-pointer imports dropped write tracking.
VulkanDevice::DmaBufImportSelected()andGraphics::HostImportUsesDmaBuf()are added for the regression test.Regression test
agc_driver_host_import_dma_buf_watch: fails without the change, passes with it.Tested
agc_driver_host_import_dma_buf_watchexecutes (not skipped) and passes on currentmain(2e22b6703), along with the flat/global store and host-import test families (40/40 passed).tools/check_conventions.py --base origin/main,tools/check_test_registration.py, andtools/check_skips.pypass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none added).mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T19:59:54Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T03:38:35Z.
Reopened. Could you rebase this on
mainand drop the fallback to the host pointer after a failed dma-buf import? Pick the import kind once from the probe and throw if that import fails. Fallbacks aren't accepted here (see CONTRIBUTING).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:06:21Z.
Review: CHANGES_REQUESTED
Thanks for the fix. Dean's request above still stands, and there are two more points:
maininlibSceAgcDriver/CMakeLists.txtandGuestBufferMemory.cpp(createImport/importAllocationchanged). Please rebase.GuestBufferMemory.cpp:279: if the dma-buf import fails when it is preferred, the code goes on to the host pointer. As Dean said, pick the import kind once from the probe and throw if that import fails; no fallback (CONTRIBUTING). The same applies to the second block (:284-288): it keeps a host-pointer-then-dma-buf fallback, socreateImportshould take the kind from the probe and use only that one.HostImportDmaBufWatch.cpp:56-59: the test returns "skipped" whenFillBufferfails afterDmaBufImportSupported()was true. Once there is no fallback, that is a failure and should throw, otherwise the test can pass without testing anything.Please also post the
[write-watch]probe lines from your run in the PR so the probe decision (host imports lose tracking, dma-buf keeps it) is visible.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:30:14Z.
Additional platform validation of standalone PR head
b8ba68c62009322640b249ddba9345bf799b7d2e(2026-10-11):Windows: passed with skips — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.2 checks, 0 failures, 1 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
agc_driver_graphics,agc_driver_host_import_dma_buf_watch.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^(agc_driver_host_import_dma_buf_watch|agc_driver_graphics)$".Vulkan: native AMD Radeon RX 6900 XT, driver 32.0.21045.5002.
agc_driver_graphics passed. agc_driver_host_import_dma_buf_watch skipped after its initial memory checks because the Windows Vulkan device does not import guest memory through dma-buf; the Linux dma-buf path was not executed on Windows.
No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Imported from boykopovar/AnyPS5. Originally posted by 999sian on 2026-10-11T11:52:41Z.
Addressed the review requests in cfafe1a7 (rebased onto main at
9a9bd3fb3).Focused Linux validation: CachyOS x86-64, Intel Arc MTL, Release/Ninja, BUILD_TESTING=ON. Built only the two selected test targets and their dependencies (not a full build or full-suite run):
Both checks passed, 0 failures, 0 CTest skips; total 7.52 s. The dma-buf write-watch regression actually executed. The graphics check reported that its guest-arena heap-mirror subcases were not exercised.
Probe output:
No new title/gameplay validation or additional-platform validation was performed for this revision.
Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-11T12:01:03Z.
Another data point for this change, from Stray (PPSA02101 v01.002, UE4) on the same hardware: Intel Arc (Meteor Lake), Mesa 26.2.3 ANV, Fedora 44. Stray runs on
mainf1ae427bwith the set described in #2749.The probe reports
host imports resolve write protection: yes (4 of 4 scratch pages written after a GPU read)anddma-buf imports keep write protection: yes. Yet Stray's direct memory went through the host-pointer path, because that import succeeds on ANV, and every imported range was unwatched. Storage refreshes then byte-compared about 2.8 GB/s of surfaces, render targets up to 3840x2160.With dma-buf imports tried first in that case (the same choice as this PR, written locally before I found it), the calibration screen goes from about 1.0 to 2.07 FPS steady: 434 frames in 240 s instead of 204. I did not test this branch's head itself.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T12:42:11Z.
Review: CHANGES_REQUESTED
Thanks for the rebase and for dropping the fallback. Two points left:
GuestBufferMemory.cpp:736-761:importAllocationnow throws on any host-pointer import failure on every platform (before:state.failed+ copies), and the try/catch inImportMappedRanges(:2013) is gone. That is wider than "throw if the selected dma-buf import fails". Either keep the previous behaviour for the host-pointer kind, or show (test or log) that the throw is the intended outcome there, and cover it with a test.HostImportDmaBufWatch.cpp:44-57:DmaBufImportSupported()only reflects the device capability. If the probe selects the host pointer and/dev/udmabufis not usable,FillBuffer/the watch check fail instead of skipping. Skip on the selected kind (or on a missing shared backing), and keep failing only when dma-buf is the selected import.The red
conventionscheck is not from this PR: checkout fails on main's3rdparty/imguigitlink without a.gitmodulesentry; it will go green once that is fixed on main.Imported from boykopovar/AnyPS5. Originally posted by 999sian on 2026-10-11T16:12:09Z.
Addressed the remaining review points in 9c999b3e.
Validation on Linux, Intel Arc MTL, Release/Ninja, BUILD_TESTING=ON:
Both requested checks passed, 0 CTest skips, total 3.95 s. The supplemental bare recorder run also completed successfully with 'Recorder read tracking and label tests passed'; it reported unavailable-import/not-tested subcases for anonymous memory without shared backing. Graphics also reports its guest-arena heap-mirror subcases were not exercised. This was a focused build, not a full build or full CTest suite.
Skip-path smoke:
APS5_WRITE_WATCH_IMPORTS=unwatch ./build/tests/agc_driver_host_import_dma_buf_watch_testsreported 'skipped, the probe did not select dma-buf as this device's import kind' and exited 77. Default probe selection executed and passed the dma-buf regression, not a skip.Default probe evidence:
Conventions and test-registration checks pass. No new Windows or gameplay validation was performed for this revision.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T16:19:05Z.
Review: CHANGES_REQUESTED
Thanks for the rebase and for dropping the fallback. One blocker left; I built the PR merged onto current
mainand ran ctest (385 tests in thelibSceAgcDriverscope): the new test passes, but 25 fail, among themagc_driver_flat_store,agc_driver_global_atomics*,agc_driver_global_store_addtid,agc_driver_masked_global_store,agc_driver_bda_span_reads,agc_driver_cmask_fast_clear,agc_driver_pixel_interlock. On a device whose probe selects dma-buf (the case this PR targets),agc_driver_flat_storeprints:GuestBufferMemory.cpp:459-474(createImport): when dma-buf is the selected kind and the range has no shared backing (GuestArenaSharedBackingfails, e.g. anonymous memory, as in these tests), the range is now served by copies, so GPU stores through FLAT/GLOBAL addresses never reach it. Onmainthe host-pointer import covers it. This is a regression for every range outside direct memory on dma-buf-selected devices, not only in the tests. Either keep importing those ranges through the host pointer (the probe-selected kind applies to ranges that can be dma-buf-backed), or make the unbacked case a hard failure with a test showing it never happens for ranges the GPU stores to; in both cases the 25 failures above need to pass on a dma-buf-selected device (tryAPS5_WRITE_WATCH_IMPORTSunset on your Arc).GuestBufferMemory.cpp:278: the/dev/udmabufmessage now says only "DMA-BUF imports will fail", but a missing udmabuf no longer breaks the host-pointer path; keep the hint about the ranges being served by copies/FLAT stores or make it match what actually happens.libSceAgcDriverctest scope locally, not just the two targets, since this change affects every import.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T08:12:01Z.
Pre-review found a deterministic regression on Linux/RADV — flagging early since full CI doesn't run automatically on PRs.
Independent pre-review (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV GFX1201):tools/check_conventions.pypasses.The shared error mode is visible in the log and it is exactly this PR's subject:
Negative control: the same tests pass 100% at this branch's own merge base (
9a9bd3fb) on the same machine — the regression is introduced by the branch's changes on this setup, not the base.One data point for interpretation: RADV here exports/imports host-visible memory fine in general, so the failure at shared backing lookup specifically may be a path where the guest allocation wasn't created with an exportable backing at this branch's base. Separately, the branch is ~741 commits behind
mainand needs a rebase regardless. Reproduce with:Happy to provide the full output or probe further if useful.
Imported from boykopovar/AnyPS5. Originally posted by 999sian on 2026-10-12T19:02:26Z.
Addressed the unbacked-range regression in d9af73bcd and rebased onto main at
2a5eca11cd.Validation on Linux/CachyOS x86-64, Intel Arc MTL, Release/Ninja, BUILD_TESTING=ON:
The all-target build succeeded. The complete libSceAgcDriver directory scope ran 448 checks: 445 passed, 3 skipped, 0 failed; 355.11 seconds. Skips: agc_driver_interpolation_f16, agc_driver_oversized_dispatch, agc_driver_shader_clock. This is the full driver scope, not the full repository test suite. The reported flat-memory/storage failures, including flat_store and bda_span_reads, passed.
Standalone flat-store and dma-buf write-watch checks also passed with probe selection enabled; the latter executed rather than skipped. An initial run with a 30-second timeout reported six timeouts. Debugger investigation located the delay in Intel vkCreateComputePipelines after import, and the standalone flat-store check completed in 192.73 seconds. The final full-scope run used a 600-second timeout with no source timeout changes.
No new Windows, RADV, or title/gameplay validation was performed for this revision.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T09:20:24Z.
Review: DISMISSED
Thanks for the fix and for the work on the earlier points. This still conflicts with
main, and the conflict is in logic, not only text:GuestBufferMemory.cpp(4 hunks),GuestBufferMemory.hpp,Texture.cppanddocs/dev/debt/libSceAgcDriver.mdconflict. #3874 (compare an import window's pages when the window closes) changed the same stamping code this PR replaces (WatchedImportsStampPages→HostImportStampsPages,Texture.cpp:1973-1976). After rebasing, check that the per-importstampsPagesstill matches what #3874 decides, and rerunagc_driver_host_import_dma_buf_watchplus the wholelibSceAgcDriverctest scope on the rebased tree.GuestBufferMemory.cpp:146-148: theImportFailuremembers lost their indentation (whitespace-only change); please restore it.Texture.cpp:1973-1976: the comment and indentation of the lines around theelse captureGuestByteschanged without a functional reason; keep that hunk minimal.GuestBufferMemory.cpp:185-187:selectedImportKindonly returnsstate.importKind; use the member directly.We could not build this head locally (build infrastructure failure on our side), so none of the above comes from a test run.
Imported from boykopovar/AnyPS5. Originally posted by 999sian on 2026-10-13T20:59:11Z.
Rebased onto main at
a0f5916a2as a single commit, 7bbaaf7cf. With #3874 the conflict was in logic, so I rebuilt the change against main instead of carrying the old hunks forward.WatchedImportsStampPages, theimportsStampPages/dmaBufImportsStampPagesstate and theTexture.cppbranch that used them; window-close comparison now lives inGuestMemory. The per-importstampsPages,HostImportStampsPagesand theTexture.cpphunk from this PR therefore had nothing left to reconcile and are dropped.Texture.cppis no longer touched.HostImportshas admaBufSelectedmember, set indecideImportWatchwhen host imports drop write tracking and dma-buf imports keep it, and cleared bySetImportWatch. InimportRunAt, a range with a shared backing is imported throughcreateBackingImportonly (insideImportWatched(..., watchedDmaBuf)). A failure throwsDmaBufImportFailure, whichImportMappedRangesrethrows. Every other range keeps main's existing path unchanged, so anonymous/unbacked ranges still get host-pointer imports and FLAT/GLOBAL stores reach them.ImportFailureis untouched (main's indentation);selectedImportKindis gone and the member is used directly. Main's/dev/udmabufmessage is accurate as is (dma-buf is only selected after a successful dma-buf probe), so that hunk is dropped too.Validation on Linux/CachyOS x86-64, Intel Arc MTL (Mesa ANV), Release/Ninja, BUILD_TESTING=ON, on head 7bbaaf7cf:
agc_driver_host_import_dma_buf_watchpassed and executed (not skipped):libSceAgcDriverdirectory scope: 492 tests, 489 passed, 3 skipped, 0 failed, 982.97 s. The 3 skips areagc_driver_interpolation_f16,agc_driver_oversized_dispatchandagc_driver_shader_clock. The--timeout 600is for Intel shader-pipeline compile time (flat_store took ~190 s earlier); no source timeouts were changed.This is not a RADV run. @blawesom, could you rerun the full scope on your RX 9070 XT against 7bbaaf7cf? No Windows or gameplay validation for this revision.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:20:05Z.
This conflicts with
mainagain after #290 (host import windows with least-recent eviction):HostImportsand theimportAllocationcall in the bind path changed inGuestBufferMemory.cpp. Please rebase, and check that a range #290 evicts and imports again keeps its dma-buf kind. Then rerunagc_driver_host_import_dma_buf_watchand the flat/global store tests on a device whose probe picks dma-buf.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T21:33:07Z.
Thanks for the rebase onto #290. The rest of the 10-14 ask is still open: please confirm a range #290 evicts and imports again comes back as dma-buf, and post the
agc_driver_host_import_dma_buf_watchand flat/global store test results on a device whose probe picks dma-buf.Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-16T17:09:24Z.
Rebase + the requested dma-buf checks — rebased onto current
main(143f13055), authorship unchanged; the head moved to554b9a42esince your branch was based on oldermain.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV) — a device whose probe does pick dma-buf (host imports resolve write protection here, dma-buf imports keep it; theagc_driver_host_import_dma_buf_watchrun confirms the selection rather than skipping):agc_driver_host_import_dma_buf_watch— passed (ran, not skipped): the fill reached mapped memory through the dma-buf import and write tracking was keptagc_driver_flat_store,agc_driver_global_store_addtid,agc_driver_masked_global_store— all passedmainregression (agc_driver_tessellationsegfault, #4727); conventions passOn evict-and-reimport keeping the dma-buf kind: the selection is device-level state, not per-import —
decideImportWatchsetsdmaBufSelectedonce from the probe, and everyimportAllocation(including one that re-imports a range #290's LRU just evicted) consults that same state throughdmaBufOnly = state.dmaBufSelected && sharedBacking(...). So an evicted range comes back as dma-buf by construction, and the #290 eviction cycles exercised byagc_driver_host_import_windows(passing here, with dma-buf active on this device) re-import successfully under that selection. If you want it pinned explicitly, a small test assertingHostImportUsesDmaBufafter an over-budget eviction would close it directly.To pick up the rebase:
Head is
554b9a42e.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T09:52:16Z.
@999sian We merged current
maininto this branch for you (2b806712b6; your changes are patch-identical, and the conflicts were only adjacent added functions). It's mergeable again, and full CI is running.We reviewed it on the merged tree, and the mechanism reads right: dma-buf only on Linux devices where the probe shows host imports lose tracking and dma-buf keeps it, only for shared-backed ranges, and evicted ranges come back as dma-buf because
importRunAtrecomputes it each time. adriadam10's 13 Oct points look addressed to us. Three things left, two small:main's settle step for dma-buf imports of 1 MiB and up takes the "falling back to copies" branch when it fails. For ranges this PR selects for dma-buf, it should throw instead, like the rest of the dma-buf path.HostImportUsesDmaBufcallsfindImport(state, address, address + bytes)without thehostImportAlignment/importsStaleguards, andfindImportbumps the LRU. Could it mirrormain's newExistingHostImportForand usepeekImport?[write-watch]lines, the new test passing (not skipped), the flat/global family and the full driver test scope?Thanks!
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-19T10:21:59Z.
@999sian One more, from the full CI run on 2b806712b6: the only failure is Linux
check_skips("agc_driver_host_import_dma_buf_watch skipped"). On lavapipe the new test printsskipped, the probe did not select dma-buf as this device's import kind, andtools/check_skips.pyonly accepts device-limitation skips that match its pattern (for example "the device does not ..." or "the device imports no ..."). Rewording that line to something likeskipped, the device does not select dma-buf for host importsshould make it pass. The test itself is fine.Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-19T10:31:57Z.
@oneandonlydean Native RADV result for the hardware part of your request, on the exact merged head
2b806712b64d63fe619a2aa888d49d8fb8ef3d11.Ubuntu 24.04, Ryzen 9 9950X iGPU (
1002:13c0, gfx1036 / RADV RAPHAEL_MENDOCINO), Mesa 25.2.8, GCC 13.3, Release,BUILD_TESTING=ON. NVIDIA was excluded withVK_ICD_FILENAMES=/usr/share/vulkan/icd.d/radeon_icd.json. All execution fixtures were enabled (ANYPS5_AGC_EXECUTION_TESTSempty) and built, including the separately registered converted lifetime fixture and relinker.The new test executes and passes, rather than skipping. Probe output:
Results on this head:
agc_driver_host_import_dma_buf_watch: passes in the full scope and 3/3 fresh processes after restoring the control below. GPU fill reaches the mapped direct-memory block,HostImportUsesDmaBufis true, and the block remains watched.flat_store, the aperture cases, global atomics,global_store_addtidandmasked_global_store.libSceAgcDriverCTest scope: 785 passed, 6 skipped, 3 failed out of 794,-j4, 21.58 s. Normal cache/journal settings, plusANYPS5_REQUIRE_VULKAN=1; individual tests retain their registered environments.agc_pipeline_cache_file(the cache file lost a pipeline),agc_driver_image_table_vouched_lookups(#7766, zero vouch counters), andagc_driver_guest_memory_lifetime(#7784, CS rejected with -14 thenguest prefix unmap failed). I checked out and rebuilt the exact merged-main parent83bf557dcfe760042fe472151626ee7852f2282band reran those three: all fail there with the same messages. This was a focused parent comparison, not a full parent-scope run.The six skips were
agc_unit_shadow,agc_shadowed_key_stores,agc_driver_unit_shadow,agc_driver_unit_shadow_budget,agc_driver_native_depth_bda_clear, andagc_driver_ngg_vertex_wave_reduction. The dma-buf test is not among them.Local negative control: inside the selected dma-buf branch, replace only
createBackingImport(...selected...)withcreateHostPointerImport(...), leaving the probe selection intact. The new test fails atvkAllocateMemory(-13), rather than skipping or reporting a pass. Restoring the exact source and rebuilding restores 3/3 passes. The clean PR executable and runtime libraries were also frozen separately; a fresh run of that frozen runtime still passes after the main-parent comparison.No experimental source changes remain. This supplies the native selection/flat-global/full-scope evidence; it does not resolve the settle-failure policy, accessor guards/LRU, or the newer lavapipe skip-message review requests. No injected settle-failure, Windows, macOS, title, validation-layer or performance result is claimed.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T04:01:00Z.
@simonbbby thank you, that's exactly the evidence we couldn't produce: the probe selects dma-buf, the new test runs and passes 3/3, the flat/global family is clean, and your negative control (host-pointer import inside the selected branch →
vkAllocateMemory-13) shows the test fails for the right reason. The three failures reproducing on83bf557dcfeputs them outside this PR.@999sian what's left is on the code side:
main.mainhas changedGuestBufferMemory.hpp/.cppagain since our merge (HostImportFornow takes anImportRequester, and the requester block inAcquireRegisteredwas rewritten). This PR wraps that block forDmaBufImportFailure, so it needs your resolution, not a mechanical one.DmaBufImportFailurerather than takemain's "falling back to copies" branch.HostImportUsesDmaBuf: add thehostImportAlignment/importsStaleguards thatExistingHostImportForhas, and usepeekImportso the query doesn't bump the LRU.skipped, the probe did not select dma-buf as this device's import kindfails Linuxcheck_skips.skipped, the device does not select dma-buf for host importsmatches its pattern.Since 1 and 2 touch the import path, once they're pushed we'd ask for one short re-run on the new head on a dma-buf device:
agc_driver_host_import_dma_buf_watchpassing (not skipped) plus the flat/global family. @simonbbby if you can repeat it then, that would close it out.