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

Custom labels 2 #4

Merged
merged 8 commits into from
Aug 7, 2024
Merged

Custom labels 2 #4

merged 8 commits into from
Aug 7, 2024

Conversation

umanwizard
Copy link
Collaborator

Attempt 2 at custom labels PR.

This is broken up into individual PRs which should hopefully be independently digestible

This is necessary in some cases when we need the verifier to _not_ be
able to predict the bounds of a variable, which can cause an explosion
in the amount of state it needs to consider and prevent verification
in under 1M instructions.

See the comment for fuller details.

This also requires setting the Clang target to `bpf` and passing the
arm64/x86 defines manually (rather than relying on `-target` to set
them), because otherwise the inline eBPF assembly doesn't work.
This commit is dead code until the user-mode code adds to cause it to
be invoked.

It expects to be passed a `GoCustomLabelsOffset` object in the
`go_procs` map, which controls how it finds the custom labels map for
a given PID.
If the `CollectCustomLabels` config flag is turned on,
this parses Go binaries to determine their version number, then uses a
hardcoded map of offsets by version to populate the `go_procs` map and
instruct the unwinder to collect custom labels.

In the future, we can automate updating this map, and also fall back
to finding the labels via disassembly when a given version doesn't
have them available. Those features are not yet present in this
commit, however.
@brancz
Copy link
Member

brancz commented Aug 5, 2024

Which kernels does this verify on, and how many instructions is it?

@umanwizard
Copy link
Collaborator Author

It's still failing on 4.19 and 5.4 which I am investigating now.

@umanwizard
Copy link
Collaborator Author

This now verifies on all tested kernels except 4.19.x.

Total instructions: 28892

@gnurizen
Copy link
Collaborator

gnurizen commented Aug 6, 2024

So the issue is that 4.19 has a 4k instruction count limit right? I think it's fine to ignore 4.19.

// We need to write this in assembly because the verifier doesn't understand
// that val_len has already been bounds-checked above, apparently
// because clang has spilled it to the stack rather than
// keeping it in a register.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious if you tried putting the "register" keyword on val_len?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't try, but I looked into it and apparently modern compilers simply ignore the register keyword: https://stackoverflow.com/questions/10675072/is-the-register-keyword-still-used

Copy link
Collaborator

@gnurizen gnurizen left a comment

Choose a reason for hiding this comment

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

LGTM!

@umanwizard umanwizard merged commit 7794483 into parca-dev:main Aug 7, 2024
10 of 11 checks passed
umanwizard added a commit that referenced this pull request Aug 28, 2024
Originally PR #4.
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