Skip to content

JIT: Fix state left by killed processes - #25842

Merged
arnaud-lb merged 2 commits into
php:PHP-8.4from
dunglas:fix/opcache-kill-safety-2
Dec 1, 2026
Merged

arnaud-lb merged 2 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.
Comment thread ext/opcache/jit/zend_jit_trace.c Resolved
Comment thread ext/opcache/jit/zend_jit.c Resolved
Comment thread ext/opcache/jit/zend_jit.c Resolved
Comment thread ext/opcache/jit/zend_jit_trace.c Resolved
Comment thread ext/opcache/jit/zend_jit_trace.c Resolved
Comment thread ext/opcache/jit/zend_jit_trace.c Resolved
@dunglas
dunglas force-pushed the fix/opcache-kill-safety-2 branch from 281e1a2 to 677d089 Compare November 27, 2026 22:13

@arnaud-lb arnaud-lb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One last nit, but looks good to me otherwise!

Comment thread ext/opcache/ZendAccelerator.h Resolved
The JIT builds the SSA, call graph and return info of the functions it
compiles in their func_info in shared memory, from process-local arena
memory, and clears them once done. The function JIT does so with the
triggers that compile at run time (first execution, profiling or hot
counters), the tracing JIT for every function a trace goes through. 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 until the
server was restarted. Compiling a caller of such a function crashed, a
trace entering it took its SSA as already built, and type inference
read its stale return info.

Record each func_info in a list in shared memory before writing to it,
and reset the listed ones at the start and at the end of every
compilation, in all JIT modes. With ZEND_CALL_TREE, the function JIT
writes only to the func_info of the function it compiles, so its
cleanup no longer walks the callees. That walk also cleared
ZEND_FUNC_JITED on every callee, so a worker that waited for the lock
compiled again a callee compiled meanwhile.

Reported by Arnaud Le Blanc in php#25785.
@dunglas
dunglas force-pushed the fix/opcache-kill-safety-2 branch from 677d089 to 7684399 Compare November 30, 2026 17:09
@arnaud-lb
arnaud-lb merged commit b42ebd7 into php:PHP-8.4 Dec 1, 2026
18 checks passed
arnaud-lb added a commit that referenced this pull request Dec 1, 2026
* PHP-8.6:
  JIT: Fix state left by killed processes (#25842)
@arnaud-lb

Copy link
Copy Markdown
Member

Thank you!

arnaud-lb added a commit to morrisonlevi/php-src that referenced this pull request Dec 1, 2026
* PHP-8.4: (190 commits)
  JIT: Fix state left by killed processes (php#25842)
  ext/xmlwriter: report the right argument number for an invalid name in method calls
  ext/soap: fix DTD node being matched as an element
  Zend: delayed OOM clears the opline of a frame mid-op.
  Fix fd leak in compress.zlib:// when gzdopen() fails (php#25794)
  Fix NULL dereference in php_init_config() for unresolvable search path ini (phpGH-25882)
  Fix missing \ in .github/actions/test-linux/action.yml. Sorry...
  Remove idleCpu config from CI
  ext/sockets: Fix socket_close_stream_resource.phpt on Windows (phpGH-25946)
  Add missing feedback changes for phpGH-25747
  Fix phpGH-25809: SQLite3::backup() returns true when the backup fails (php#25810)
  Fix race in GHSA-r6x9-5r99-36j7 tests
  ext/curl: Fix intermittent curl test failures on FreeBSD (phpGH-25911)
  ext/intl: Fix UAF in UConverter::convert() on re-entrant encoding change
  ext/bz2: Reset input position after a decompression error
  ext/sockets: Fix leak of the stream resource in socket_close()
  ext/soap: Fix SOAP error handler dropping a custom HTTP status line
  ext/phar: Read all four bytes of tar signature flags
  Fix hostname resolution after DNS test resolver setup (php#25905)
  Fix use-after-free when proc_open() pipe is closed from its user filter
  ...
arnaud-lb added a commit that referenced this pull request Dec 1, 2026
* PHP-8.6:
  [ci skip] NEWS for GH-25842
adapik pushed a commit to adapik/php-src that referenced this pull request Dec 1, 2026
* PHP-8.4:
  JIT: Fix state left by killed processes (php#25842)
adapik pushed a commit to adapik/php-src that referenced this pull request Dec 1, 2026
* PHP-8.5:
  JIT: Fix state left by killed processes (php#25842)
jorgsowa added a commit to jorgsowa/php-src that referenced this pull request Dec 1, 2026
Covers the first-exec, hot counter, profiling, root trace and side trace
compiles fixed in phpGH-25842.
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.

2 participants