LATX, fix: Preserve 16K permission checks with a cached fast path - #425
Open
ganjue66da wants to merge 8 commits into
Open
LATX, fix: Preserve 16K permission checks with a cached fast path#425ganjue66da wants to merge 8 commits into
ganjue66da wants to merge 8 commits into
Conversation
The LATX_MT compatibility path walks the page-flags interval tree for every instrumented memory access. That is too expensive for applications which need exact guest 4K write checks on a 16K host. Allocate compact byte tables for guest 4K writability and mixed host 16K pages only after LATX_MT is enabled. Generated stores normally need one table lookup and consult the exact 4K entry only for mixed host pages. Disabled configurations retain no large tables or CPU state pointers and emit no additional guest memory checks. Do not enable LATX_MT automatically. Default translations remain uninstrumented, while affected applications can opt in explicitly. Tests: - default and LATX_MT=1 atomic-lock-stress-test - LATX_MT=1 Minke.MI.Organ.exe reached the rendered login window Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
Minke.MI.Organ.exe uses a fixed Wine helper and small generated code mappings whose stores may cross guest 4K permission boundaries on a 16K host. Without precise checks, a write can miss the fault needed to create a shadow page and the application fails during startup. Add the explicit LATX_MINKE_16K_PAGE_CHECK option. On a 16K host it is accepted only for Minke.MI.Organ.exe, allocates the application TB map, and instruments the fixed helper page and small executable mappings recorded by mmap and mprotect. Other applications and disabled configurations remain on the normal uninstrumented path. This avoids the global LATX_MT cost while retaining the precise write fault where the application requires it. Tests: - 16K host: selective checks reached the rendered login window with LATX_MT=0 - 4K host: default and explicit-option atomic-lock-stress-test Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
ganjue66da
force-pushed
the
codex/minke-16k-write-checks
branch
from
August 25, 2026 03:55
9159bd7 to
2ee0fee
Compare
The global memory-check option skipped every read in the 32-bit 16K path. A readable guest page could therefore expose a neighboring PROT_NONE page through the merged host mapping. Cache guest permission bits and record mixed permissions separately for each access type. Check reads in global mode while retaining the write-only scope of the Minke-specific instrumentation. Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
Define LATX_MT=1 as sparse mixed-page checks and LATX_MT=2 as direct guest-page checks. Both policies use the permission cache on 16K hosts. Restrict the option to the documented range and expose the available policies in command-line help. Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
Checking only the starting address misses accesses that cross from a permitted guest 4K page into a protected page within one host mapping. Pass access widths from scalar, vector and atomic memory emitters. Check the final byte as well as the first before emitting the access in the 32-bit 16K cached path. Add a focused i386 regression for mixed read permissions and a vector write across a guest-page boundary. Tests: - Static i386 fixture built on x86 and run on the 16K LoongArch host: protected read and crossing write returned SIGSEGV in MT modes 1/2. Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
The push/pop recovery walk assumes a fixed alignment expansion. Permission instrumentation uses four-instruction alignment, so the walk can miscount host instructions and run past the regenerated IR2 list while delivering a guest fault. Calculate padding from the alignment operand and current host offset, including prior pseudo instructions and stack optimizations. Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
The final-page permission check leaves the access endpoint in the address used to report a guest fault. A 16-byte store starting four bytes before a protected page reports that page plus eleven bytes. Report the final guest page's start on that failure path. Retain the original address when the initial-page check fails. Extend the i386 regression to check signal code, fault address, EIP and ESP, including crossing reads, writes, a pushed stack and valid accesses. Tests: - Native i386 fixture on x86: all six cases passed. - 16K LoongArch host: all six cases passed with LATX_MT=1 and =2. Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
Accept LATX_16K_PERMISSION_FIXTURE for an executable built on an x86 host. Otherwise check for clang and ld.lld before compilation, and propagate compilation failures instead of converting them to skips. Tests: - 58: Meson permission regression passed with the prebuilt fixture; no tests skipped. - Injected compiler failure propagated status 42. - Invalid prebuilt fixture failed with status 1. Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary / 变更说明
Preserve the cached permission-check fast path needed by
Minke.MI.Organ.exeon 16K LoongArch hosts while enforcing guest 4Kpermissions for instrumented accesses.
A readable/writable guest page can share a host page with a protected
guest page. The merged host mapping alone cannot enforce that boundary.
Global checks now cover reads as well as writes, and the 32-bit cached
path checks both the first and final guest page of each instrumented
access. A crossing fault reports the first inaccessible byte rather than
the access endpoint.
LATX_MT=1: consult exact guest-page flags when the host page has mixedpermissions for the requested access type.
LATX_MT=2: always consult cached guest-page flags on the 32-bit 16K path.LATX_MT=0: leave global instrumentation disabled. The existing explicitLATX_MINKE_16K_PAGE_CHECKoption retains selective Minke write checks.on the 32-bit 16K path.
by the permission instrumentation's generated code.
pointer and stack pointer. The runner accepts a prebuilt fixture through
LATX_16K_PERMISSION_FIXTURE; actual compilation failures are errors.The series separates the original fast-path/application changes, read
permission restoration, policy selection, crossing checks, fault recovery,
fault address correction and test-runner correction into focused commits.
Validation / 验证
Final patched
latx-i386built on host 58 (16K LoongArch pages).Binary SHA-256:
63b71760c2a771e56a94199832a213f5f09c6df8de4f29a90fc6bfac01b96a06.passed natively.
LATX_MT=1andLATX_MT=2:protected read, crossing vector write, protected write at a nonzero page
offset, crossing read, valid access, and a fault after pushes.
fault address. Earlier control runs with
LATX_MT=0allowed the protectedread and crossing write to proceed.
1 passed, 0 failed, 0 skipped.
mprotect-4k-testandlock-cmpxchg8b-on-page-no-write-unalignpassed in both enabled modes.prebuilt fixture failed with status 1.
Remaining validation: the final revision has not rerun the medical
application GUI/startup timing comparison or the full build matrix. A broad
test rebuild on 58 encountered pre-existing unused-variable/function errors
in
tests/unit/test-x11-async-handler.cunder-Werror; the translator wasbuilt separately and the targeted integration test used
--no-rebuild.Earlier login-window and full-matrix results apply to the original PR
revision, not to this final revision.
Checklist / 检查项
CONTRIBUTING.md.