-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix invalid target opline with jit->reuse_ip active #16440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When the JIT jumps out of tracing while reuse_ip is set, it will jump directly to the reused pointer, which might be e.g. EX(call) instead of EX(opline). Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
9d07f5a
to
098e22d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recently saw and fix the same problem, but I thought it's related to my new changes in #16365 (it's not merged yet).
I think your fix is right (it needs few minor tweaks).
It would be very useful to see the TRACE where the "invalid" zend_jit_trace_return()
occurs.
@@ -16811,6 +16811,9 @@ static int zend_jit_trace_end_loop(zend_jit_ctx *jit, int loop_ref, const void * | |||
|
|||
static int zend_jit_trace_return(zend_jit_ctx *jit, bool original_handler, const zend_op *opline) | |||
{ | |||
if (!original_handler && jit->reuse_ip) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the check for original_handler
is useless, but the check for jit->reuse_ip
may be not enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wanted to leave minimal impact on codepaths, but maybe it's useless. I don't understand the code well enough.
} | ||
} else if (p->stop == ZEND_JIT_TRACE_STOP_RETURN) { | ||
zend_jit_trace_return(&ctx, 0, NULL); | ||
zend_jit_trace_return(&ctx, 0, p->opline); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so, but wasn't sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#16365 fixed the similar problem by adding the following code at the end of zend_jit_init_method_call()
+ if (trace
+ && trace->op == ZEND_JIT_TRACE_END
+ && trace->stop >= ZEND_JIT_TRACE_STOP_INTERPRETER) {
+ if (!zend_jit_set_ip(jit, opline + 1)) {
+ return 0;
+ }
+ }
And I also have a self-contained reproducer now:
with
|
Right, this is the reason I liked to see the test case. |
Unfortunately the fix for this problem becomes more complex than I thought. Probably, I'll have to extend the solution from #16365 Anyway, I would prefer to merge it first. |
I see. It was fine for fixing my issue, but probably not in the general case then. |
This is an alternative for php#16440
This is an alternative for #16440
Closing as fixed by #16457. |
When the JIT jumps out of tracing while reuse_ip is set, it will jump directly to the reused pointer, which might be e.g. EX(call) instead of EX(opline).
I honestly don't know how to properly give an isolated reproducer, but the gist is that the tracing JIT was bailing out on a DO_UCALL opcode...
I'm not sure whether that fix is correct, but at least I could no longer reproduce it later.