-
Notifications
You must be signed in to change notification settings - Fork 681
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
Map file descriptor is closed after RewriteMaps
#515
Comments
You're right, this is most likely the GC freeing the map since it's not referenced by the Go program anymore. Thanks for providing a reproducer, I'll take a look. |
Here is a snippet from your reproducer:
You can observe a similar behaviour by removing the CO-RE relocation and inserting This is a problem in the API, since it doesn't enforce that the map is kept alive until the map isn't necessary anymore. Fixing this might be complicated however. The most "correct" solution would be to add a pointer to |
I think What about deprecating it (or rather, making it unexported) in favor of passing a |
That might also work. I think the API came about due to @arthurfabre could you make P.S.: I think the API would have to be |
This commit fixes issue cilium#515, which is a bug where `ebpf.Map` objects would be garbage collected and their FDs closed after a call to `CollectionSpec.RewriteMaps`. Root cause of the issue that we delete references to the map after extracting the file descriptor. This commit, utilizes the new per-instruction metadata to attach a reference to the `ebpf.Map` object when rewriting instructions with the map FDs. This commit deprecates `Instructions.RewriteMapPtr` and `Instruction.RewriteMapPtr` in favor of the `RewriteMap` functions. Which add the object reference to the metadata.
Modified the collection for RewriteMaps to test for regession on the fix for issue cilium#515. Added tests to validate the copy-on-write behavour of per-instruction metadata and how per-instruction metadata is compared.
This commit fixes issue cilium#515, which is a bug where `ebpf.Map` objects would be garbage collected and their FDs closed after a call to `CollectionSpec.RewriteMaps`. Root cause of the issue that we delete references to the map after extracting the file descriptor. This commit, utilizes the new per-instruction metadata to attach a reference to the `ebpf.Map` object when rewriting instructions with the map FDs. This commit deprecates `Instructions.RewriteMapPtr` and `Instruction.RewriteMapPtr` in favor of the `RewriteMap` functions. Which add the object reference to the metadata.
Modified the collection for RewriteMaps to test for regession on the fix for issue cilium#515. Added tests to validate the copy-on-write behavour of per-instruction metadata and how per-instruction metadata is compared.
This commit fixes issue cilium#515, which is a bug where `ebpf.Map` objects would be garbage collected and their FDs closed after a call to `CollectionSpec.RewriteMaps`. Root cause of the issue that we delete references to the map after extracting the file descriptor. This commit, utilizes the new per-instruction metadata to attach a reference to the `ebpf.Map` object when rewriting instructions with the map FDs. This commit deprecates `Instructions.RewriteMapPtr` and `Instruction.RewriteMapPtr` in favor of the `RewriteMap` functions. Which add the object reference to the metadata.
Modified the collection for RewriteMaps to test for regession on the fix for issue cilium#515. Added tests to validate the copy-on-write behavour of per-instruction metadata and how per-instruction metadata is compared.
This commit fixes issue cilium#515, which is a bug where `ebpf.Map` objects would be garbage collected and their FDs closed after a call to `CollectionSpec.RewriteMaps`. Root cause of the issue that we delete references to the map after extracting the file descriptor. This commit, utilizes the new per-instruction metadata to attach a reference to the `ebpf.Map` object when rewriting instructions with the map FDs. This commit deprecates `Instructions.RewriteMapPtr` and `Instruction.RewriteMapPtr` in favor of the `RewriteMap` functions. Which add the object reference to the metadata.
Modified the collection for RewriteMaps to test for regession on the fix for issue cilium#515. Added tests to validate the copy-on-write behavour of per-instruction metadata and how per-instruction metadata is compared.
This commit adds the ability to add a pointer to a map to an instruction. The main reason for doing so is to keep a reference to maps after link them, since before we took the FD of the map but no reference which caused maps to be GC'ed since nobody would hold a reference to them(cilium#515). Rewriting of the instructions has been moved and now happens when instructions are marshalled, to avoid maintaining dubble state(fd and reference). Associating a map with a instruction happens with the new `AssociateMap`, which replaces the new deprecated `RewriteMapPtr` func.
This commit adds the ability to add a pointer to a map to an instruction. The main reason for doing so is to keep a reference to maps after link them, since before we took the FD of the map but no reference which caused maps to be GC'ed since nobody would hold a reference to them(cilium#515). Rewriting of the instructions has been moved and now happens when instructions are marshalled, to avoid maintaining dubble state(fd and reference). Associating a map with a instruction happens with the new `AssociateMap`, which replaces the new deprecated `RewriteMapPtr` func.
This commit adds the ability to add a pointer to a map to an instruction. The main reason for doing so is to keep a reference to maps after link them, since before we took the FD of the map but no reference which caused maps to be GC'ed since nobody would hold a reference to them. Rewriting of the instructions has been moved and now happens when instructions are marshalled, to avoid maintaining dubble state(fd and reference). Associating a map with a instruction happens with the new `AssociateMap`, which replaces the new deprecated `RewriteMapPtr` func. Any users whom are unable to switch can still write a int fd value by defining an type which wraps a int and implements FDer as a workaround. Fixes cilium#515
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
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
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 #515
Describe the bug
The file descriptor of an eBPF map uses in
RewriteMaps
is closed before loading the program, causing a failure when loading the program.To Reproduce
I prepared a repository with the reproducer of this problem -> https://github.com/mauriciovasquezbernal/ebpfissue.
I see the problem is that the file descriptor of the map is being closed before loading the program:
It's somehow related to the garbage collection, if I comment out the following line it works fine:
ebpf/internal/sys/fd.go
Line 21 in f40ce35
Two additional details:
My environment is:
I hope I gave enough information to track this down.
/cc @alban
The text was updated successfully, but these errors were encountered: