Skip to content

JIT: Fix state left by killed processes - #25842

Open
dunglas wants to merge 3 commits into
php:PHP-8.4from
dunglas:fix/opcache-kill-safety-2
Open

dunglas wants to merge 3 commits into
php:PHP-8.4from
dunglas:fix/opcache-kill-safety-2

Conversation

@dunglas

@dunglas dunglas commented Nov 27, 2026

Copy link
Copy Markdown
Member

In #25785 (review), @arnaud-lb pointed out some more places where a process killed in the middle of an update leaves the shm of OPcache half updated.

This PR fixes them, and one more in the tracing JIT.
Two other cases are handled by #25258 #25509.

Problems have been reproduced using GDB (breaking and sending the signal) with FPM, and fixes work as expected.

This is part of the reliability work to remove Zend Signals: #25627

This needs a careful review because I'm not familiar with this part of the code base and this is tricky to get right.

When the JIT runs out of root traces, zend_jit_stop_counter_handlers()
restores the original VM handlers of every cached script. It set
jit_counters_stopped before doing so. If the process was killed in the
loop, by SIGKILL or the OOM killer, later calls returned early and the
remaining counting handlers stayed until the next restart: each hot
loop or function still entered the tracer once before being
blacklisted, and the cold ones kept paying for the counters.

Set the flag after the loop, which can safely run again.

Reported by Arnaud Le Blanc in php#25785.
With opcache.jit triggers that compile functions at run time (first
execution, profiling or hot counters), zend_jit_collect_calls() builds
the call graph of the function in its func_info in shared memory, from
process-local arena memory, and zend_jit_cleanup_func_info() clears it
once the function is compiled. If the process was killed in between, by
SIGKILL or the OOM killer, the func_info kept pointers into the arena of
the dead process. Compiling a caller of that function then followed them
from zend_jit_cleanup_func_info() and crashed, and type inference read
the stale return info of the callee.

Reset the func_info of the function before analyzing it, and those of
its direct callees once its call graph is built, as the compilation
reads no other. Keep ZEND_FUNC_JITED when resetting: the cleanup cleared
it on every callee, so a worker waiting to compile a callee that was
compiled meanwhile compiled it again.

Reported by Arnaud Le Blanc in php#25785.
While compiling a trace, the tracing JIT builds the SSA, call graph and
return info of every function the trace goes through in the func_info
of the function in shared memory, from process-local arena memory, and
clears them at the end. If the process was killed in between, by
SIGKILL or the OOM killer, these func_infos kept pointers into the arena
of the dead process. The next trace entering one of these functions
took its SSA as already built and used it, and other compilations read
its stale return info, until the server was restarted.

Record each func_info in a list in shared memory before writing to it,
and reset the listed ones at the start of the next compilation.

Same problem as the function JIT one reported by Arnaud Le Blanc in
php#25785.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant