Skip to content

Zend: Check vm_interrupt with relaxed load before atomic exchange - #480

Closed
iliaal wants to merge 6 commits into
masterfrom
opt/vm-interrupt-relaxed-load
Closed

iliaal wants to merge 6 commits into
masterfrom
opt/vm-interrupt-relaxed-load

Conversation

@iliaal

@iliaal iliaal commented Nov 27, 2026

Copy link
Copy Markdown
Owner

zend_call_function() executes an unconditional atomic_exchange() on EG(vm_interrupt) after every internal-to-PHP callback return even when no interrupt is pending, forcing an exclusive cache-line read-modify-write.

Guard the exchange with a relaxed atomic load of EG(vm_interrupt), matching zend_interrupt_helper_SPEC().

On ARM64 (Neoverse-N1, GCC 13.3 -O2 NTS), array_map() callbacks improve by 6.07% (-4.74% cycles) and usort() callbacks by 3.98% (-2.55% cycles), with untouched control flat (-0.35%).

jorgsowa and others added 6 commits November 30, 2026 20:57
With session.serialize_handler=php_serialize, stored data whose top-level value isn't an array (i:1;, s:3:"abc";, b:1;, N;, an object) was accepted and became $_SESSION as that type. Decoding reported success, and writes were then silently skipped, so the bad record stayed in storage.

That data now takes the same path as data that can't be unserialized: $_SESSION is reset to an empty array, decoding fails with "Failed to decode session object. Session has been destroyed", and the session is destroyed. This matches the php and php_binary handlers, which can only ever produce an array. Valid sessions are unaffected, including a reference-wrapped array.
zend_handle_delayed_oom() always reset EG(opline_before_exception) to NULL,
even when called from zend_call_function() in the middle of an opcode. The
JIT exception handler stubs then dereferenced it. Only the VM and JIT
interrupt handlers run between two opcodes, so they now clear it instead.

Fix phpGH-25304
Close phpGH-25408
* PHP-8.4:
  Zend: delayed OOM clears the opline of a frame mid-op.
* PHP-8.5:
  Zend: delayed OOM clears the opline of a frame mid-op.
* PHP-8.6:
  Zend: delayed OOM clears the opline of a frame mid-op.
zend_call_function() executed an atomic_exchange() on EG(vm_interrupt) on
every internal-to-PHP callback return, an exclusive cache-line
read-modify-write even when no interrupt is pending. Load the flag first and
exchange only when it is set, as ZEND_VM_FCALL_INTERRUPT_CHECK() does. A
relaxed load suffices: a stale false only defers handling to the next VM
interrupt check, and the exchange stays the synchronizing operation.
@iliaal
iliaal force-pushed the opt/vm-interrupt-relaxed-load branch from 624554d to da5982c Compare November 30, 2026 20:51
@iliaal

iliaal commented Nov 30, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php/php-src phpGH-25976.

@iliaal iliaal closed this Nov 30, 2026
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.

3 participants