Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.