Skip to content

LATX, fix: Fix incorrect exception PC backtrace caused by div-related instptn handling - #297

Open
rmjskhy wants to merge 12 commits into
lat-opensource:masterfrom
rmjskhy:temp1
Open

LATX, fix: Fix incorrect exception PC backtrace caused by div-related instptn handling#297
rmjskhy wants to merge 12 commits into
lat-opensource:masterfrom
rmjskhy:temp1

Conversation

@rmjskhy

@rmjskhy rmjskhy commented May 25, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread linux-user/syscall.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

信号发送范围太大,当前实现会打到所有线程,不只是 vCPU 线程。

Comment thread linux-user/signal.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 我希望我们在编码时可以注意语义边界的问题,比如这里的“ SIGRTMIN + 1”替换成宏定一个内部常量,如LAT_FORK_UNLINK_SIG 或其它什么你喜欢的名字。
  2. 整体来看信号是一个我们不想牺牲热路径性能的 tradeoff 的方案,但不 100% 安全,我建议加一个开关吧。

@LaurenIsACoder LaurenIsACoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 该方案是 tradeoff,并不 100% 对 guest 安全,建议给 signal unlink 增加动态开关;
  2. 发送信号只给 vcpu 即可,管理线程不必。

… instptn handling

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
@rmjskhy
rmjskhy force-pushed the temp1 branch 2 times, most recently from 3ebec1f to a8c6a8f Compare June 25, 2026 04:00
@rmjskhy
rmjskhy force-pushed the temp1 branch 2 times, most recently from 4b2a398 to 3ff1b15 Compare July 29, 2026 07:03
rmjskhy added 11 commits July 29, 2026 16:18
… all worker threads to force them out of infinite TB loops.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
translate_invalid() only saved the lower eight guest general-purpose
registers before raising EXCP06_ILLOP. The upper registers r8-r15 were
left stale in CPUX86State.

This corrupted the signal context when handling HotSpot deoptimization
traps. In particular, HotSpot uses r15 as the JavaThread pointer, so an
invalid r15 caused crashes in DeoptimizationBlob or left virtual threads
stuck during deoptimization.

Save r8-r15 and xmm8-xmm15 before raising #UD on x86-64. Reuse this
complete exception path for UD2 translation.

This fixes the OpenJDK virtual-thread deoptimization test in both
slowdebug and release builds.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
The fast jump cache was freed before the exiting CPU was removed from
the global CPU list. Concurrent TB invalidation could still access the
freed cache and cause a SIGSEGV.

Allocate the cache together with an RCU head and defer its release until
after the CPU is unrealized and an RCU grace period has elapsed. Remove
unsafe cache cleanup from exit_group and fatal signal paths, where the
process address space will be reclaimed by the kernel.

This also preserves cache reclamation for workloads that create and
destroy large numbers of threads.

Tested with compiler/unsafe/OpaqueAccesses.java.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
The fork-unlink notification used to be broadcast before fork_start() entered start_exclusive(). A notified vCPU could leave cpu_exec() and re-enter it before start_exclusive() marked it as a waiter. The subsequent qemu_cpu_kick() only set exit_request, which a vCPU blocked in a host futex could not observe, leaving start_exclusive() waiting forever.

Send the internal signal from qemu_cpu_kick() only after start_exclusive() has marked the vCPU as a waiter. The signal handler marks a signal pending so an interrupted safe syscall returns instead of re-entering the same futex, then exits the translated TB through the normal TU-aware path.

This removes the timing-dependent fork deadlock seen when Java ProcessBuilder starts jstack.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
The setsockopt translator did not handle IP_MULTICAST_ALL and returned ENOPROTOOPT even when the host kernel supported the option. The JDK treats that error as an old-kernel compatibility case, leaving multicast sockets in promiscuous mode and allowing a socket joined to one group to receive packets for another group.

Forward IP_MULTICAST_ALL through the existing SOL_IP integer-option path so the host kernel receives the requested setting.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
The setsockopt translator returned ENOPROTOOPT for IPPROTO_SCTP options before passing them to the host. The JDK initializes every SCTP channel by subscribing to SCTP_EVENTS, so socket creation failed even though the host SCTP protocol was available.

Translate only the legacy eight-byte SCTP_EVENTS subscription used by the x86 JDK. Copy its common fields into the host structure and clear newer host-only event bits, leaving all other SCTP options unsupported until their ABI conversions are defined.

Tested with java/net/SctpSanity.java.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
The setsockopt translator returned ENOPROTOOPT for IPv6 source-filtering options before invoking the host. DatagramChannel source filtering therefore reported UnsupportedOperationException after joining an IPv6 multicast group.

Copy the x86 group_source_req into a host request and forward MCAST_JOIN_SOURCE_GROUP, MCAST_LEAVE_SOURCE_GROUP, MCAST_BLOCK_SOURCE, and MCAST_UNBLOCK_SOURCE at SOL_IPV6.

Tested with java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
A forked child can inherit util/path.c path-cache mutex while another host thread holds it. That thread does not exist in the child, so the first path lookup before exec waits forever in pthread_mutex_lock and concurrent Java ProcessBuilder launches hang.

Include the cache lock in the linux-user fork barrier. The parent unlocks it after fork; the child reinitializes it before it handles more guest system calls.

Tested with tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/util/CommandOutputControlTest.java and a 100-process concurrent fork stress harness.

Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
LATX kept the host ucontext after the signal handler returned. A later state restoration could then read the expired signal-stack pointer and corrupt guest registers after JFR sampling signals.

Keep the context only while SIGSEGV/SIGBUS use cpu_signal_handler or SIGFPE/SIGTRAP restore state through tlb_fill. Clear it on every return path from CPU state restoration.

Signed-off-by: liuchaoyi <liuchaoyi@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.

2 participants