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 issues when porting alloy/pyroscope to android #3582

Merged
merged 2 commits into from
Sep 24, 2024

Conversation

zmj64351508
Copy link
Contributor

I'm porting alloy/pyroscope to the mobile phone running Android 14. And I found some issues:

  1. The config CONFIG_PID_NS is not set in standard Android kernel, which means /proc/self/ns/pid is not exist and alloy will exit with failure. The first commit fixed this issue by ignoring error when /proc/self/ns/pid doesn't exist.

  2. When kernel modules or bpf programs are dynamic loaded from userspace after kernel boot, the address in /proc/kallsyms may be unordered, which causes the origin code find wrong symbol. The second commit fixed this issue by sorting the symbol by address.
    Here's an example for such /proc/kallsyms:

# cat /proc/kallsyms
...
ffffffd6b60e2140 t cleanup_module       [bootprof]
ffffffd6b60e53c0 d __this_module        [bootprof]  
ffffffc0145a52cc t bpf_prog_98e4c662c49a1bca_xdp_drop_ipv4_u    [bpf]
ffffffc0145ad4a8 t bpf_prog_a06399a1ec0a769e_schedcls_tether    [bpf]
ffffffc012b4b218 t bpf_prog_e814348da2c722a4_schedcls_tether    [bpf]
...

@CLAassistant
Copy link

CLAassistant commented Sep 23, 2024

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


mingjun.zhou seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

ebpf/session.go Outdated
if err != nil {
return fmt.Errorf("pyrobpf rewrite constants %w", err)
// if the file does not exist, CONFIG_PID_NS is not supported, so we just ignore the error
if os.IsExist(err) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something looks off here. I would expect this condition to be true if error is ErrExist and I do not expect this error to be returned during pid ns check ( we do not create any files/objects).
The next error check looks suspicious as well. It looks like we rewrite global_config constant here only in case if ErrExist and err==nil which looks impossible to my brain
Did you test this change with PD_NS configured and inside a pid namespace ( a docker container for example)?

We need to change something here.
Let me know if I am missing/misunderstanding something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR Updated. I'm new to golang and it's my misunderstanding of os.IsExist. It's now replaced by !os.IsNotExist().

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 tested the new patch on WSL and Android Phone, both work fine.

@@ -94,5 +95,9 @@ func NewKallsymsFromData(kallsyms []byte) (*SymbolTab, error) {
if allZeros {
return NewSymbolTab(nil), nil
}
// kallsyms maybe unsorted when bpf/modules are loaded from userspace after kernel boot.
sort.Slice(syms, func(i, j int) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: It would be nice to add a test, but it is is not required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR Updated. I add 2 unordered symbols in testdata. I tested it and it will fail without this patch and success with this patch.

@korniltsev
Copy link
Collaborator

Thank you for the contribution. I left some comments.

@korniltsev
Copy link
Collaborator

Thank you for the contribution!
I've created an issue to add an integration tests for these cases. Feel free to submit a PR if you want to
#3588

@zmj64351508 zmj64351508 deleted the android branch September 24, 2024 11:19
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