Skip to content

JIT: add missing endbr #10605

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

Closed
wants to merge 1 commit into from
Closed

JIT: add missing endbr #10605

wants to merge 1 commit into from

Conversation

PeterYang12
Copy link
Contributor

PR #8774 added IBT support for jitted code and passed all built-in tests in "ext/opcache/tests/jit". However, we found several "missing ENDBR" issues recently when running some real world workloads.

Such workloads introduce new code path and thus more "indirect branch target" are in jited code. This fix adds missing endbr correspondingly.

Reviewed-by: chen-hu-97 hu1.chen@intel.com
Reviewed-by: bjzhjing cathy.zhang@intel.com

PR php#8774 added IBT support for jitted code and passed all built-in tests in
"ext/opcache/tests/jit". However, we found several "missing ENDBR" issues
recently when running some real world workloads.

Such workloads introduce new code path and thus more "indirect branch target"
are in jited code. This fix adds missing endbr correspondingly.

Signed-off-by: PeterYang12 <yuhan.yang@intel.com>
Reviewed-by:   chen-hu-97  <hu1.chen@intel.com>
Reviewed-by:   bjzhjing    <cathy.zhang@intel.com>
@mvorisek
Copy link
Contributor

when running some real world workloads

can it be covered with simple unit tests?

@devnexen devnexen requested a review from dstogov February 16, 2023 19:50
@PeterYang12
Copy link
Contributor Author

NO, I only encounter the issue in real world workloads.

}
| ENDBR
Copy link
Member

Choose a reason for hiding this comment

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

I suppose, this ENDBR is used here only to support indirect branches generated by zend_jit_switch(). This should be fixed in different way. In case we have to generate ENDBR we will have to generate additional gates...

.LABEL
    endbr
    jmp trace_exit_N

Copy link
Member

Choose a reason for hiding this comment

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

I mean, this should be fixed in zend_jit_switch()

@@ -3214,6 +3219,7 @@ static int zend_jit_check_exception_undef_result(dasm_State **Dst, const zend_op

static int zend_jit_trace_begin(dasm_State **Dst, uint32_t trace_num, zend_jit_trace_info *parent, uint32_t exit_num)
{
| ENDBR
Copy link
Member

Choose a reason for hiding this comment

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

This is also wrong. ENDBR for "root" traces is generated in zend_jit_prologue(). This ENDBR for "side" traces should be generated only if (parent != NULL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I will add a judgment.

@@ -3126,6 +3130,7 @@ static int zend_jit_set_ip(dasm_State **Dst, const zend_op *opline)

static int zend_jit_set_ip_ex(dasm_State **Dst, const zend_op *opline, bool set_ip_reg)
{
| ENDBR
Copy link
Member

Choose a reason for hiding this comment

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

ENDBR here is definitely wrong. Please identify, the code that causes the problem here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I traced jitted code and found ENDBR missing here. Let me see if I can provide a case to produce the problem. Thank you for your kind advice.

@@ -15026,13 +15032,15 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o
} while (count);
|.code
|3:
| ENDBR
Copy link
Member

Choose a reason for hiding this comment

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

Actually, all the jump table targets should have ENDBR at start. This is going to be not a trivial fix...
We may use gates for side exits, but it's going to be an overhead for jumps to other basic blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. Let me figure out a proper way to do this.

@PeterYang12
Copy link
Contributor Author

Thank you, Dmitry, for your assistance. Our team has estimated that we will submit another patch when we have more availability in the coming quarters. Therefore, I will close this PR for now. Thanks again!

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.

3 participants