Skip to content

LATX, fix: Handle guest return addresses in JRRA stack returns - #479

Open
yzewei wants to merge 1 commit into
lat-opensource:masterfrom
yzewei:fix-latx-jrra-signal-restorer
Open

LATX, fix: Handle guest return addresses in JRRA stack returns#479
yzewei wants to merge 1 commit into
lat-opensource:masterfrom
yzewei:fix-latx-jrra-signal-restorer

Conversation

@yzewei

@yzewei yzewei commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

When the JRRA stack return optimization is enabled, return addresses are treated by default as addresses of translated LoongArch code, allowing for a direct jump.

However, certain guest control-flow paths still store x86 guest addresses—such as the pretcode found in Linux user-mode signal frames. Upon return, JRRA mistakenly treats such an address as a LoongArch address and attempts to execute it, triggering a SIGBUS.

This fix uses reserved_va to distinguish between the two types of return addresses:

  • Guest addresses fall back to the original translate_ret() and TB lookup paths;
  • Host-translated addresses continue to use the JRRA direct-jump path.

The JRRA fast-return behavior for standard host-translated code remains unchanged.

JRRA stack returns assume that the address popped from the guest stack is already a LoongArch translated-code address and jump to it directly.

Some guest control-flow paths still store x86 guest addresses, such as the pretcode saved in a Linux user-mode signal frame. JRRA could mistake such an address for a host translated address and execute it as LoongArch code, causing SIGBUS.

Use reserved_va to distinguish the two kinds of return addresses in the JRRA stack-return path:

- fall back to the normal translate_ret() and TB lookup path for guest addresses;
- retain the direct JRRA return fast path for host translated addresses.

This preserves the optimized return path for translated code while preventing guest addresses from being executed directly as LoongArch code.

Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
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