KEMBAR78
Allow profiling kprobes/uprobes with --fdtransfer by apangin · Pull Request #1300 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

apangin
Copy link
Member

@apangin apangin commented May 19, 2025

Description

Extend fdtransfer protocol to pass probe name in perf_event requests.

Motivation and context

Async-profiler can profile kprobes and uprobes, e.g. asprof -e kprobe:fd_install. However, this does not work with --fdtransfer option. The reason is, perf_event_attr structure contains a pointer to kprobe/uprobe name, but when perf_event_attr is passed to another process (fdtransfer server), this pointer becomes invalid, since the address belongs to a different process.

The proposed solution extends perf_fd_request structure with a new field that contains a name of kprobe/uprobe. For events other than kprobe/uprobe, this field contains an empty string. When fdtransfer server receives non-empty probe name, it adjusts pointer in perf_event_attr.

How has this been tested?

Added KernelTests.kprobe test, which failed before the fix, but passes now.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.


#define RESTARTABLE(call) ({ ssize_t ret; while ((ret = call) < 0 && errno == EINTR); ret; })

#define MAX_PROBE_LEN 256
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could be documented for users?

Copy link
Member Author

Choose a reason for hiding this comment

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

This will be superfluous, IMO. I can't imagine a reasonable function name with more than 256 characters. The only thing we must ensure is that async-profiler does not crash due to out-of-bounds access.

@fandreuz
Copy link
Contributor

Looks good to me

@apangin apangin merged commit 3a9252c into master May 19, 2025
39 of 49 checks passed
@apangin apangin deleted the kprobe-transfer branch May 21, 2025 12:29
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.

2 participants