From 28cf5de6146bdaf24246658c9840cf4fbb562dbc Mon Sep 17 00:00:00 2001 From: LinQuickDev Date: Fri, 21 Aug 2026 23:20:29 +0800 Subject: [PATCH 1/4] fix: preserve SSE state in x86_64 bthread context switch --- src/bthread/context.cpp | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/bthread/context.cpp b/src/bthread/context.cpp index 7f913adfc1..8f94cfdb85 100644 --- a/src/bthread/context.cpp +++ b/src/bthread/context.cpp @@ -347,20 +347,40 @@ __asm ( " pushq %r14 \n" " pushq %r13 \n" " pushq %r12 \n" -" leaq -0x8(%rsp), %rsp\n" +" leaq -0xa8(%rsp), %rsp\n" +" movups %xmm6, 0x00(%rsp)\n" +" movups %xmm7, 0x10(%rsp)\n" +" movups %xmm8, 0x20(%rsp)\n" +" movups %xmm9, 0x30(%rsp)\n" +" movups %xmm10, 0x40(%rsp)\n" +" movups %xmm11, 0x50(%rsp)\n" +" movups %xmm12, 0x60(%rsp)\n" +" movups %xmm13, 0x70(%rsp)\n" +" movups %xmm14, 0x80(%rsp)\n" +" movups %xmm15, 0x90(%rsp)\n" " cmp $0, %rcx\n" " je 1f\n" -" stmxcsr (%rsp)\n" -" fnstcw 0x4(%rsp)\n" +" stmxcsr 0xa0(%rsp)\n" +" fnstcw 0xa4(%rsp)\n" "1:\n" " movq %rsp, (%rdi)\n" " movq %rsi, %rsp\n" +" movups 0x00(%rsp), %xmm6\n" +" movups 0x10(%rsp), %xmm7\n" +" movups 0x20(%rsp), %xmm8\n" +" movups 0x30(%rsp), %xmm9\n" +" movups 0x40(%rsp), %xmm10\n" +" movups 0x50(%rsp), %xmm11\n" +" movups 0x60(%rsp), %xmm12\n" +" movups 0x70(%rsp), %xmm13\n" +" movups 0x80(%rsp), %xmm14\n" +" movups 0x90(%rsp), %xmm15\n" " cmp $0, %rcx\n" " je 2f\n" -" ldmxcsr (%rsp)\n" -" fldcw 0x4(%rsp)\n" +" ldmxcsr 0xa0(%rsp)\n" +" fldcw 0xa4(%rsp)\n" "2:\n" -" leaq 0x8(%rsp), %rsp\n" +" leaq 0xa8(%rsp), %rsp\n" " popq %r12 \n" " popq %r13 \n" " popq %r14 \n" @@ -387,12 +407,12 @@ __asm ( "bthread_make_fcontext:\n" " movq %rdi, %rax\n" " andq $-16, %rax\n" -" leaq -0x48(%rax), %rax\n" -" movq %rdx, 0x38(%rax)\n" +" leaq -0xe8(%rax), %rax\n" +" movq %rdx, 0xd8(%rax)\n" " stmxcsr (%rax)\n" " fnstcw 0x4(%rax)\n" " leaq finish(%rip), %rcx\n" -" movq %rcx, 0x40(%rax)\n" +" movq %rcx, 0xe0(%rax)\n" " ret \n" "finish:\n" " xorq %rdi, %rdi\n" From 3a4464030cd323141e2027a4a3a89d87cd4565ce Mon Sep 17 00:00:00 2001 From: LinQuickDev Date: Sat, 22 Aug 2026 12:54:06 +0800 Subject: [PATCH 2/4] fix: initialize control words at updated context offsets --- src/bthread/context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bthread/context.cpp b/src/bthread/context.cpp index 8f94cfdb85..467445c964 100644 --- a/src/bthread/context.cpp +++ b/src/bthread/context.cpp @@ -409,8 +409,8 @@ __asm ( " andq $-16, %rax\n" " leaq -0xe8(%rax), %rax\n" " movq %rdx, 0xd8(%rax)\n" -" stmxcsr (%rax)\n" -" fnstcw 0x4(%rax)\n" +" stmxcsr 0xa0(%rax)\n" +" fnstcw 0xa4(%rax)\n" " leaq finish(%rip), %rcx\n" " movq %rcx, 0xe0(%rax)\n" " ret \n" From dd16341592c8615f02066cb4a7ddd5dbf59315ba Mon Sep 17 00:00:00 2001 From: LinQuickDev Date: Sat, 22 Aug 2026 22:37:50 +0800 Subject: [PATCH 3/4] fix: update task tracer for expanded context frame --- src/bthread/task_tracer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bthread/task_tracer.cpp b/src/bthread/task_tracer.cpp index 1cc5c05a2e..a9e4910e0f 100644 --- a/src/bthread/task_tracer.cpp +++ b/src/bthread/task_tracer.cpp @@ -280,16 +280,16 @@ unw_cursor_t TaskTracer::MakeCursor(bthread_fcontext_t fcontext) { // Only need RBP, RIP, RSP on x86_64. // The base pointer (RBP). - if (unw_set_reg(&cursor, UNW_X86_64_RBP, regs[6]) != 0) { + if (unw_set_reg(&cursor, UNW_X86_64_RBP, regs[26]) != 0) { LOG(ERROR) << "Fail to set RBP"; } // The instruction pointer (RIP). - if (unw_set_reg(&cursor, UNW_REG_IP, regs[7]) != 0) { + if (unw_set_reg(&cursor, UNW_REG_IP, regs[27]) != 0) { LOG(ERROR) << "Fail to set RIP"; } #if UNW_VERSION_MAJOR >= 1 && UNW_VERSION_MINOR >= 7 // The stack pointer (RSP). - if (unw_set_reg(&cursor, UNW_REG_SP, regs[8]) != 0) { + if (unw_set_reg(&cursor, UNW_REG_SP, regs[28]) != 0) { LOG(ERROR) << "Fail to set RSP"; } #endif From 755d48aa939e30a4709d447253a8b4595dfe54e5 Mon Sep 17 00:00:00 2001 From: Spicy-cream <2667314914@qq.com> Date: Tue, 25 Aug 2026 05:51:26 -0700 Subject: [PATCH 4/4] ci: add timeout diagnostics for ASan tests --- test/run_tests.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/run_tests.sh b/test/run_tests.sh index dd80afd94f..c255de116f 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -30,11 +30,16 @@ for test_bin in $test_bins; do # A passing death test may leave a core behind. Keep only cores from the # binary about to run so a later failure is symbolized against its core. rm -f core.* - ./$test_bin + echo "[runtest] START $test_bin $(date -Iseconds)" + timeout --signal=KILL 20m ./$test_bin + rc=$? + echo "[runtest] END $test_bin rc=$rc $(date -Iseconds)" + if [ $rc -eq 124 ] || [ $rc -eq 137 ]; then + >&2 echo "[runtest] TIMEOUT $test_bin" + fi # If ASan abort without detailed call stack of new/delete, # try to disable fast_unwind_on_malloc, which would be a performance killer. # ASAN_OPTIONS="fast_unwind_on_malloc=0:detect_leaks=0" ./$test_bin - rc=$? if [ $rc -ne 0 ]; then failed_test="$test_bin" break;