LATX, fix: Restore x87 state across signal handlers - #436
Open
ganjue66da wants to merge 3 commits into
Open
Conversation
FXSAVE and XSAVE restore the architectural x87 control and status words, but LATX continues with the LoongArch FCSR left by the signal handler. A handler that changes rounding or exception state can therefore affect translated x87 instructions after sigreturn. Rebuild the FCSR rounding, exception enable, and exception flag fields from the restored x87 control and status words. Tests: - Verify x87 round-down survives SIGUSR1 in 32-bit and 64-bit hard-float and LATX_SOFTFPU=1/2 modes Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
LATX tracks x87 and MMX execution in the private mode_fpu field, but its saved x87 image does not encode MMX's valid tags and 0xffff exponents. A signal handler can change mode_fpu while the interrupted mode exists only outside the signal frame. In LATX_SOFTFPU=2 mode, subsequent MMX instructions can then read the wrong host register set. Canonicalize MMX state before building the signal frame, recognize its physical-register encoding after restore, and rebuild mode_fpu. Tests: - Verify MMX state survives a SIGUSR1 handler that executes FNINIT in 32-bit and 64-bit hard-float and LATX_SOFTFPU=1/2 modes Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
The 64-bit signal path saves interrupted state with non-destructive FXSAVE or XSAVE, then enters the handler without initializing live x87 state. The handler consequently observes the interrupted x87 stack and control state. Initialize only x87 after successfully building the signal frame. Do not change MXCSR or vector and extended state, and leave the frame unchanged so sigreturn restores the interrupted state. Tests: - Verify a 64-bit SIGUSR1 handler starts with initial x87 state while non-x87 state remains unchanged and sigreturn restores saved state - Verify 32-bit and 64-bit x87 state survives SIGUSR1 in hard-float and LATX_SOFTFPU=1/2 modes 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.
Dependency / 依赖
Depends on #424. Please merge #424 first.
Without #424, the hard-float x87-entry regression reaches the pre-existing
stale LBT TOP issue and exits with status 22 after sigreturn. With #424
applied, all nine targeted signal tests pass.
Summary / 变更说明
words after sigreturn.
reconstruct
mode_fpuafter restore.64-bit handler starts with Linux-compatible initial x87 state while the
interrupted state remains available to sigreturn.
The added work is limited to signal-frame setup and sigreturn; translated
instruction and TB hot paths are unchanged.
Validation / 验证
./latxbuild/build64.sh -clat-x86_64 1.6.5-340-g49a31b8402a1c44b66cb77e63a5c98856164d22b70c196b3cc652dcad3eaa5c8cb3a4d1cbeninja -C build32 latx-i386761a9e0c621aefd0cc589ffe1f155ed0e58e8ed526a557eee1a461334fb9c1c6upstream/masterplus this series:x87-entryexits 22 because LATX, fix: Restore LBT TOP state after longjmp #424 is not present.upstream/masterplus LATX, fix: Restore LBT TOP state after longjmp #424 and this series:hard-float,
LATX_SOFTFPU=1, andLATX_SOFTFPU=2(9/9).Checklist / 检查项
CONTRIBUTING.md. / 我已阅读CONTRIBUTING.md。git commit -s). /每个提交都包含 DCO 签署(
git commit -s)。are not applicable. /
我已提供相关构建或测试结果,或说明了不适用的原因。