-
Notifications
You must be signed in to change notification settings - Fork 478
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
dynamic: x86_64: Optimize runtime dynamic patching #1747
Open
clementguidi
wants to merge
10
commits into
namhyung:master
Choose a base branch
from
clementguidi:runtime-dynamic-patch-x86_64-optimize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
dynamic: x86_64: Optimize runtime dynamic patching #1747
clementguidi
wants to merge
10
commits into
namhyung:master
from
clementguidi:runtime-dynamic-patch-x86_64-optimize
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Glibc < 2.30 doen't provide wrappers for 'gettid()' and 'tgkill()' so we define them. Signed-off-by: Clément Guidi <cguidi@ciena.com>
Functions to setup real-time signals and broadcast signals to all threads in an application. Useful for runtime synchronization mechanisms. Co-authored-by: Gabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com> Signed-off-by: Clément Guidi <cguidi@ciena.com>
Skip the functions where uftrace already injected a call to a trampoline. Signed-off-by: Clément Guidi <cguidi@ciena.com>
Refactor for more clarity. Signed-off-by: Clément Guidi <cguidi@ciena.com>
Refactor 'patch_code' so it can later be used at runtime. Co-authored-by: Gabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com> Signed-off-by: Clément Guidi <cguidi@ciena.com>
Check if instruction at a given address is ENDBR64. Signed-off-by: Clément Guidi <cguidi@ciena.com>
When patching a function at runtime, first insert an int3 trap so any incoming thread is diverted from the patching region, to avoid executing partially modified code. The trap handler emulates a call to the trampoline, thus enabling the instrumentation. The trap is eventually removed in subsequent commits. Co-authored-by: Gabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com> Signed-off-by: Clément Guidi <cguidi@ciena.com>
When cross-modifying code, the software needs to ensure that all cores will execute valid instructions at any time. When modifications are not atomic, we issue a specific memory barrier (or execute a serializing instruction on Linux < 4.16) to serialize the execution across all cores. This flushes the different caches, especially the processor pipelines that may have partially fetched straddling instructions. Co-authored-by: Gabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com> Signed-off-by: Clément Guidi <cguidi@ciena.com>
When patching at runtime, no thread can enter the patching region due to the trap that is inserted at the start of it. But threads that entered the region before the trap is installed can still be executing instructions in the region. We broadcast a real-time signal instruction all threads to check their instruction pointer, and execute out-of-line if they are in the patching region. Co-authored-by: Gabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com> Signed-off-by: Clément Guidi <cguidi@ciena.com>
Synchronization requires sending signals to threads inside the process. This is performed for every symbols, which means a lot of signal can be sent. This has a major performance impact. This commit batches the initial and final steps of the patching process so we only need to send one signal per thread for every batch. Co-authored-by: Gabriel-Andrew Pollo-Guilbert <gabrielpolloguilbert@gmail.com> Signed-off-by: Clément Guidi <cguidi@ciena.com>
This was referenced Jul 7, 2023
namhyung
reviewed
Jul 11, 2023
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.
Right, I expect you do this kind of work. :) Will take a look later..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the sixth PR in a series of patches intended to bring runtime dynamic tracing on x86_64 to uftrace.
We optimize the runtime dynamic patching strategy, by batching the cross-modifications, and using as few a 1 or 2 signals per batch.
Related: #1698