Repository navigation
LATX, fix: Translate 64-bit XSAVE and XRSTOR variants - #528
Merged
Merged
Conversation
Translate XSAVE64, XSAVEOPT64, and XRSTOR64 with the existing XSAVE/XRSTOR wrappers, matching the FXSAVE64/FXRSTOR64 handling. Wine's x86-64 syscall dispatcher uses xsave64 to preserve the non-volatile XMM6-XMM15 registers across win32u calls. The missing translation left those registers zeroed, so notepad's About and Find dialogs were created with zero size and appeared as invisible 1x1 modal windows. Add an x86-64 integration regression that round-trips XMM6/XMM7 through xsave64/xrstor64 in JIT, cold AOT, and hot AOT paths. Update the SHBR inventory, implicit-semantics model, and audit expectations for the new 64-bit XSAVE variants so translator coverage stays consistent. Classify the 64-bit XSAVE variants as required softfpu regions so LATX_SOFTFPU=2 saves and restores XMM and high GPR state around the helpers. Fixes Wine notepad Help->About and Ctrl+F on LoongArch hosts. Signed-off-by: Leslie Zhai <xiangzhai83@gmail.com>
Contributor
Author
|
Thanks! |
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 / 变更说明
由分析 #523 复现 issue: 在 AOSC 16K、4K页内核运行 /usr/lib/wine/x86_64-windows/notepad.exe 点击菜单:帮助 -> 关于记事本,均100%复现阻塞。
修复 Wine x86-64
notepad.exe在“帮助 → 关于记事本”以及Ctrl+F打开对话框时主窗口阻塞、对话框不可见的问题。
根因是 LATX 没有翻译 x86-64 的 64 位 XSAVE/XRSTOR 变体。Wine 的 syscall
dispatcher 在进入 win32u 系统调用前用
xsave64保存 XMM6–XMM15,返回时从syscall frame 恢复;LATX 只登记了
XSAVE、XSAVEOPT、XRSTOR,没有XSAVE64、XSAVEOPT64、XRSTOR64。因此保存没有发生,dispatcher 返回时把XMM6–XMM15 恢复成 frame 中的零值。
在
user32!DIALOG_CreateIndirect中,对话框尺寸在ClientToScreen调用期间保存在 XMM6 中。XMM6 被清零后,
CreateWindowExW收到 0×0 尺寸,X11 创建出1×1 的模态窗口,主窗口因此表现为阻塞。该问题不限于“关于记事本”:
Ctrl+F“查找”对话框同样为 1×1。
本 PR 的变更:
target/i386/latx/translator/translate.c:将XSAVE64、XSAVEOPT64、XRSTOR64映射到已有的 32 位变体 wrapper,与现有FXSAVE64/FXRSTOR64的处理方式一致。tests/integration/xsave64-roundtrip.S:新增 x86-64 回归测试,设置XMM6/XMM7,执行
xsave64检查保存区,再设置新值并执行xrstor64检查恢复。
tests/integration/registrations/avx/meson.build:注册test-xsave64-roundtrip,由test-avx-regressions.py在 JIT、cold AOT、hot AOT 三种路径运行。
target/i386/latx/optimization/hbr.c、hbr-xmm-semantics.json、hbr-xmm-semantics.inc及 HBR audit/metrics 测试:将三个新指令纳入 SHBR语义清单,保持 translator mnemonic 审计和覆盖率统计一致。
XSAVEC64/XSAVES64/XRSTORS64没有对应的 QEMU helper,本次不映射。实测 Wine 的
user_shared_data中XState.CompactionEnabled未启用,dispatcher 走
xsave64分支而不是xsavec64,因此不影响本 issue;若以后启用 compaction,需要作为独立工作处理。
Why HBR is updated / 为什么需要修改 HBR
translate.c只决定指令“能不能执行”;HBR/SHBR 还需要知道它对 XMM/YMM状态的数据流语义,才能安全地做高 128 位相关的优化和状态复用。因此新增
XSAVE64/XSAVEOPT64/XRSTOR64后,HBR 侧必须同步:审计门禁要求同步
scripts/latx_hbr_audit.py会解析translate.c中的TRANS_FUNC_GEN(...),对 translator mnemonic 集合计算 SHA-256,并与hbr-xmm-semantics.json的期望值比较;同时检查计数、inventory 覆盖和生成的规则表。新增三个 mnemonic 后,完整性检查报:
直接导致
test-latx-hbr-audit和test-latx-hbr-metrics失败。HBR 优化需要正确的隐式 XMM 语义
这三个指令会读写全部 XMM 状态:
XSAVE64/XSAVEOPT64:隐式读取全部 XMM(保存状态);XRSTOR64:隐式读写全部 XMM(恢复状态)。如果 HBR 不把它们标记为 implicit-all-XMM,优化器可能错误地认为 XMM
高 128 位在指令前后保持不变,进而做出不安全的消除或复用。它们必须与
已有的 32 位
XSAVE/XSAVEOPT/XRSTOR使用相同策略。具体同步内容:
hbr-xmm-semantics.json:将三个指令加入 legacy inventory,配置implicit-read-all/implicit-read-write-all,并更新计数与 mnemonic哈希;
hbr.c:在apply_implicit_semantic()和has_implicit_semantic()中加入对应 case,使运行时真正采用这些语义;hbr-xmm-semantics.inc:由 JSON 重新生成规则表;test_latx_hbr_audit.py/test_latx_hbr_metrics.py:更新审计和覆盖率期望值(translator_supported 1098→1101、相关计数 774→777、生成规则
519→522)。
简言之:
translate.c让新指令“能跑”,HBR 相关修改让它们“被正确分析和优化”,并让项目强制的语义审计保持通过;这不是单纯为了更新哈希。
Validation / 验证
Root cause evidence / 根因证据
Wine trace 中对话框模板和
AdjustWindowRectEx输入都是正确的,但CreateWindowExW收到 0×0 尺寸:user32!DIALOG_CreateIndirect在AdjustWindowRectEx后用psubd把尺寸放入XMM6,随后调用
ClientToScreen;Wine x86-64 dispatcher 的__wine_syscall_dispatcher使用xsave64保存 XMM6–XMM15,并用movaps 0x1c0(%rcx),%xmm6 ... 0x250(%rcx),%xmm15恢复。freestanding x86-64 指令测试(不经过 Wine)复现了 LATX 的缺口:
xsave/xrstor(无 REX.W)xsave64/xrstor64(REX.W)xsaveopt64fxsave64/fxrstor64编码差异仅为 REX.W:
修复前用户可见结果为 1×1 的
关于 记事本窗口;修复后为正常尺寸并完整绘制控件。
Regression tests / 回归测试
新增测试在修复前为 RED,修复后为 GREEN:
Semantics / 语义验证
xsave64/xrstor64现在与xsave/xrstor一样能正确保存和恢复XMM6/XMM7;
xsaveopt64同样正常;fxsave64原有行为不变。GetDesktopWindow、ClientToScreen、GetSystemMetrics,调用前后XMM6/XMM7 均保持测试模式值;修复前这些调用会把它们清零。
563×399,内部
AdjustWindowRectEx后窗口尺寸 569×431),控件和 Wine开发者列表均正常绘制;关闭后主窗口恢复响应。
Ctrl+F“查找”对话框显示为 552×132。
Full suites / 完整套件
使用全新的 Meson 构建目录(x86_64 + i386,
--enable-tests,--enable-latx-avx-opt,--optimize-O1)运行;.asmAVX fixture 使用本地构建的 nasm 2.16.03 加入
PATH。test-xsave64-roundtrip在 JIT、cold AOT、hot AOT 三种路径均通过。latx-integration的 8 个失败均为既有环境/工具链问题,不是本变更引入:test-rip-relative-cache-*:测试注册把LATX_AVX_PREBUILT设为空字符串,runner 的
argparse将Path('')变成.,误走 prebuilt路径;不设置该环境变量直接运行同一 fixture 可以通过。
test-avx-single-instruction:clang 22 无法汇编其中的avx-regression-vround-boundaries.S(“cannot use more than one symbolin memory operand”);同一组其余 13 个 fixture 均通过。
test-prctl-x86-privileged:clang 22 的 freestanding 链接缺少memset符号。test-prctl-x86-semantics:p用例返回 52;用修复前的备份二进制运行结果相同,属于既有环境行为。
22 个 SKIP 是需要额外权限、namespace 或内核特性的测试(exit 77),属于
环境跳过的预期结果。
Checklist / 检查项
CONTRIBUTING.md. / 我已阅读CONTRIBUTING.md。git commit -s). /每个提交都包含 DCO 签署(
git commit -s)。are not applicable. /
我已提供相关构建或测试结果,或说明了不适用的原因。