Skip to content

LATX, fix: Restore LBT TOP state after longjmp - #424

Open
ganjue66da wants to merge 2 commits into
lat-opensource:masterfrom
ganjue66da:codex/lbt-top-longjmp
Open

LATX, fix: Restore LBT TOP state after longjmp#424
ganjue66da wants to merge 2 commits into
lat-opensource:masterfrom
ganjue66da:codex/lbt-top-longjmp

Conversation

@ganjue66da

Copy link
Copy Markdown
Contributor

Motivation

Some translator exits use siglongjmp and bypass the normal generated epilogue. If the saved host FCSR still records LBT TOP mode as active, the next x87 entry can reuse a stale physical-to-logical stack mapping.

Changes

  • Clear stale LBT TOP state after returning to cpu_exec() through siglongjmp.
  • Save FCSR after normal register cleanup on syscall exits so the slow cleanup path is not repeated unnecessarily.

Validation

  • ninja -C build32 latx-i386
  • ninja -C build64 latx-x86_64
  • Native LBT TOP instruction/order checks completed with matching direct and sequential results.
  • Combined with the separate x87 signal-frame PR, LATX_SOFTFPU=2 LATX_SOFTFPU_FAST=0xc00000 passes the signal-stack regression.

Dependency note

The signal restoration regression also requires the separately submitted x87 signal-frame fix. This branch remains based directly on master so the two problems can be reviewed independently.

Some translator exits bypass the generated epilogue, and siglongjmp
can restore a host context with LBT TOP mode still active.  The next
entry then loads physical x87 registers through the stale mapping and
places values in the wrong slots for Minke.MI.Organ.

After siglongjmp returns to cpu_exec(), check the saved FCSR TOP-mode
bit.  Clear both the saved bit and hardware mode only when it is set,
and leave soft-float execution unchanged.

Tests:
- Run 20,000 x87 signal deliveries with no failures
- Verify single, seven-thread, and nonzero-TOP signal restoration

Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
INT and syscall translators saved FCSR before register cleanup disabled
LBT TOP mode.  The longjmp exit therefore saw the saved mode as active
and had to clear it again on every traditional syscall.

Save FCSR after register cleanup on regular INT, traditional syscall
tunnel, and x86-64 SYSCALL exits.  This records the disabled mode,
avoids the longjmp slow path, and removes an unused FCSR save from the
optimized syscall tunnel.

Tests:
- Run 20,000 x87 signal deliveries with no failures
- Run 2,000 Wine/.NET external-GC float round trips

Signed-off-by: Wenqiang Wei <weiwenqiang@mail.ustc.edu.cn>
@ganjue66da
ganjue66da force-pushed the codex/lbt-top-longjmp branch from 097cfe6 to 6932b21 Compare August 25, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant