Skip to content
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

Fix long-standing PT "taken" bug. #1568

Merged
merged 1 commit into from
Jan 27, 2025
Merged

Fix long-standing PT "taken" bug. #1568

merged 1 commit into from
Jan 27, 2025

Conversation

vext01
Copy link
Contributor

@vext01 vext01 commented Jan 27, 2025

For a while now we've noticed fishy behaviour in the PT decoder, where a compressed return is detected, but the following TNT bit is not one, as it should be.

We also know that carrying on after seeing this causes nonsense traces. For this reason we recently added code to detect the bug and abort tracing.

The reason for the bug is that seek_tnt_or_tip(), whose job it is to read packets until the next control flow event, would return any packet that carries a TIP (target instruction pointer) payload, even if the payload was "out of context" (PT terminology for "unknown TIP").

To follow the CFG properly, some (not all) call-sites to seek_tnt_or_tip() will be uninterested in out of context TIP updates and will want to ignore them.

Critically is_compressed_return() must skip out of context TIPs, since they have no bearing on whether the return is compressed or not. This was the underlying cause of the taken bug.

Rather than forcing call-sites to loop if they get an out of context TIP when they want to skip them, this change adds a skip_ooc flag to seek_tnt_or_tip() which determines whether it will skip OOC TIPs or not.

Adding the flag also forces us to think about whether we should be skipping such packets or not.

[Since compressed returns are currently disabled at tracing time, we should in fact never decode a compressed return. Due to this I've replaced a chunk of compressed return logic with an unreachable!()]

For a while now we've noticed fishy behaviour in the PT decoder, where
a compressed return is detected, but the following TNT bit is not one,
as it should be.

We also know that carrying on after seeing this causes nonsense traces.
For this reason we recently added code to detect the bug and abort
tracing.

The reason for the bug is that `seek_tnt_or_tip()`, whose job it is to
read packets until the next control flow event, would return any packet
that carries a TIP (target instruction pointer) payload, even if the
payload was "out of context" (PT terminology for "unknown TIP").

To follow the CFG properly, some (not all) call-sites to
`seek_tnt_or_tip()` will be uninterested in out of context TIP updates
and will want to ignore them.

Critically `is_compressed_return()` *must* skip out of context TIPs,
since they have no bearing on whether the return is compressed or not.
This was the underlying cause of the taken bug.

Rather than forcing call-sites to loop if they get an out of context TIP
when they want to skip them, this change adds a `skip_ooc` flag to
`seek_tnt_or_tip()` which determines whether it will skip OOC TIPs or
not.

Adding the flag also forces us to think about whether we should be
skipping such packets or not.

[Since compressed returns are currently disabled at tracing time, we
should in fact never decode a compressed return. Due to this I've
replaced a chunk of compressed return logic with an unreachable!()]
@ltratt
Copy link
Contributor

ltratt commented Jan 27, 2025

Excellent!

@ltratt ltratt added this pull request to the merge queue Jan 27, 2025
Merged via the queue into ykjit:master with commit 3dc428a Jan 27, 2025
2 checks passed
@vext01 vext01 deleted the taken-bug branch January 27, 2025 15:36
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