Let a shadow write-back clear the write watch's protection of its range in one call on Linux (shadow_bulk_write = 1).

On Linux the write watch protects pages, so a write-back from shadow storage into guest memory took a fault
at the first store into every page. plat_mem_prepare_write clears the protection of a range with one
UFFDIO_WRITEPROTECT call; the pages count as written, as they would after the faults. Off by default;
Windows has nothing to clear.

Pull request #327 by theurbanninja1993-sketch (a draft on GitHub). The platform function and its Linux
test are taken as they are. The call moved: the write-back it was written for is now shadow_write_back in
runtime/vk_memory.c (a file other sessions are changing), where it covers the runs of pages a submission
changed, and the setting is registered in cfg.c and described in nx2navi.ini.example, which also says
that the lazy write-back stays off with shadow storage.

The Windows files compile; the Linux code and its test are not compiled or run here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 06:31:27 -05:00
parent 3134f52475
commit 4d12238e69
7 changed files with 72 additions and 3 deletions

View File

@@ -254,6 +254,10 @@ int plat_mem_census(uint64_t *priv, uint64_t *wc, uint64_t *wc_allocs);
// The pages of a watched reservation written since the last reset, up to max page addresses into pages, in address
// order; reset: those reported start over as unwritten. UINT64_MAX when writes to the range are not tracked.
uint64_t plat_mem_written(uint64_t addr, uint64_t n, uint64_t *pages, uint64_t max, int reset);
// Before the host itself writes [addr, addr+n) of a watched reservation: clears the write watch's protection of those
// pages in one call, where the watch works by protecting pages (Linux), so the stores do not fault page by page. The
// pages count as written. Returns 0 when there is nothing to clear or it cannot be done; the write is valid either way.
int plat_mem_prepare_write(uint64_t addr, uint64_t n);
// A write that faulted on a read-only page at addr goes to fn first; fn returns 1 when it made the page writable and
// the write should run again, 0 to let the fault go on (to the crash handler). One hook per process.
void plat_mem_fault_hook(int (*fn)(uint64_t addr));