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

program: retrieve xlated Instructions from Program #538

Merged
merged 3 commits into from
Jan 17, 2022

Conversation

ti-mo
Copy link
Collaborator

@ti-mo ti-mo commented Dec 27, 2021

Allow introspecting instructions after they have been translated by and loaded into the kernel.

Just putting this up here for discussion, I remember there being some prior discussion around this a while back.


There's also the following cosmetic bug:

tail_main:
	0: LoadMapPtr dst: r2 fd: 226

226 is the map's BPF ID, not its fd. Not sure if this needs to be taken into account.

@ti-mo ti-mo requested a review from lmb December 27, 2021 21:22
prog.go Outdated Show resolved Hide resolved
Move things around so other similar info can be retrieved later.
Adding xlated instructions in a follow-up commit.

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo marked this pull request as ready for review January 17, 2022 12:34
asm/instruction.go Show resolved Hide resolved
info.go Outdated Show resolved Hide resolved
info.go Outdated Show resolved Hide resolved
prog_test.go Outdated Show resolved Hide resolved
Add Instructions.Unmarshal() to unmarshal a binary instruction stream
into an Instructions.

Signed-off-by: Timo Beckers <timo@isovalent.com>
Allow introspecting instructions after they have been translated by and
loaded into the kernel.

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo merged commit 4eed175 into cilium:master Jan 17, 2022
@ti-mo ti-mo deleted the tb/xlated-prog-insns branch January 17, 2022 15:12
@klueska
Copy link

klueska commented Jan 21, 2022

I see the comment that the instructions read out cannot be written back in. My original use case from #444 was to do exactly this (i.e. read out, prepend to, write back).

Is there someway to retrieve the original stream of instructions to accomplish what I need from what’s been added here?

@ti-mo
Copy link
Collaborator Author

ti-mo commented Jan 21, 2022

@klueska I think this implementation does what you asked for, at least it provides the API for you to build your use case on top of.

xlated instructions have BPF map IDs where map FDs used to be during load time. Walking the insns, calling NewMapFromID on all map IDs you encounter (maybe taking care you don't open the same map ID more than once) and rewriting those map IDs with the newly-opened FDs should work. There might be some other differences that I'm not aware of, but this should you most of the way there. 🙂

At least now, you can also diff your ProgramSpec insns with the loaded Program insns and see what changed. Good luck!

@klueska
Copy link

klueska commented Jan 22, 2022

I have verified that moving from my custom code to this implementation works identically.

The diff is fairly small: https://gitlab.com/nvidia/container-toolkit/libnvidia-container/-/merge_requests/127/diffs?commit_id=d21ac33cb0459e9277f61622ef99fc8d8fa91ca5

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.

None yet

3 participants