-
Notifications
You must be signed in to change notification settings - Fork 721
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
Add Maps to Instruction metadata #567
Conversation
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.
Hi Dylan,
Thanks for the PR! I started the review yesterday, but only managed to finish it today.
- Can you explain what the kernel uses the various bits of information for? I know that SetLine ends up in the verifier log, but what about File, Line, Column?
- How does the library use this information? Seems like we ignore File, Line, Column?
- Is it possible to only pass e.g. Line, but leave other bits empty?
Regarding the metadata, I'd prefer if the setters modified the instruction instead of making a copy, so pointer receivers. Behind the scenes metadata would still be copied. Intuitively I expect a setter to make changes to the object I'm calling it on. Calling the setters also becomes awkward judging from the changes in the PRs.
I also saw that you merged master into your feature branch, maybe that was an accident? Doing that makes merges much messier, please rebase instead.
5323356
to
6baf8b9
Compare
As far as I know, the kernel doesn't use any of the
I used the The Filename and Column information isn't currently used by the library directly. My motivation for adding is was to use them outside of the library in edb where I use the information to display the relevant source file and place the cursor at the correct line within that file.
Yea it should be. If we were to create a |
529db6f
to
c06fd4d
Compare
Got almost everything. The only thing left is to make |
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.
Went through it in detail, great work! This has been on our minds for a few months now and will open some exciting new possibilities.
cd5b9d9
to
c6cd0f7
Compare
c6cd0f7
to
bd4672e
Compare
bd4672e
to
e046535
Compare
f29fc04
to
17f87c4
Compare
@dylandreimerink can you add a |
17f87c4
to
9aa26fe
Compare
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.
Have a few last comments. Looks like the commit title and message of asm,elf_reader: added instruction context
is now outdated.
As discussed offline, let's only merge the Map support here, the .BTF.ext unmarshaler needs a few changes since we're processing LineInfos per section again.
9aa26fe
to
fa83acc
Compare
This commit adds the ability to add a Map pointer to an Instruction. The main reason for doing so is to maintain a reference to a Map while it is being referred to from a ProgramSpec. Before, loading an ELF referring to a pinned map caused the map to be opened and its fd to be included in Instructions. If garbage collection ran between loading the ELF and inserting the program into the kernel, the map's fd may have been closed before the program can be inserted. Resolving Maps into FDs and embedding them into an Instruction has been moved to Instructions.Marshal(). Associating a Map with an Instruction happens with the new `AssociateMap()`, replacing the now-deprecated `RewriteMapPtr()`. Fixes cilium#515
fa83acc
to
9ef93aa
Compare
The LineInfo metadata was split off from this PR as this one already touched several subtle interactions regarding maps between the loader, linker and marshaler. This one is good to go for now. |
This PR improves the existing per-instruction metadata, as discussed in #564 and fixes #515.
This PR moves the existing
Instruction.Reference
andInstruction.Symbol
metadata to a separate struct calledmetadata
.asm.Instruction
now has a pointer to thismetadata
struct. TheInstruction
struct now has exported getters and setters to get and modify this metadata. The design is such that we only assign metadata to instructions if we have to, since most instructions don't have metadata.Copying instructions will not automatically copy the metadata since
Instruction
has a pointer to metadata. Therefor the setters will perform a copy-on-write, so upon the first modification of metadata, the instruction will get a new metadata object which is copied from the existing one and then modified.These setters all have value receivers which return the modified instruction. This choice was made because it makes it easier to use the setters in the DSL, since you can't call functions with pointer receivers on literals. By returning a modified instruction we make method chaining possible, which fits well with the rest of the DSL.
We also added Filename, Line and LineCol to the
metadata
and getters and setters for them toInstruction
. The ELF reader was modified to add looked-upLineInfo
from the .BTF.ext section to the program instructions. This allows us to print the original source code info along with the program instructions when formattingasm.Instructions
.By attaching this info the the instruction makes it relocation-proof. In future PRs we might even be able to marshal blobs to be loaded into the kernel so would guarantee correct BTF line info for relocated programs and BTF line info for programs created via the DSL.
Lastly, this PR adds map references to the per-instruction metadata. This allows us to add references to
ebpf.Map
to the program instructions themselves, specifically during rewriting, which prevents the maps from being garbage collected, thus fixing #515