Repository navigation
Conversation
f06ae46 to
3fda6b7
Compare
3fda6b7 to
2f1b3b0
Compare
There was a problem hiding this comment.
This is mostly curiosity, but could this have been done by providing extraSrtructuredConfig via kernelPatches rather than overriding the build phase like this?
There was a problem hiding this comment.
It's very unfortunate, and I have tried each and every other option to make this work, but linuxConfig doesn't have a convenient way to pass patches to the kernel config like buildLinux and friends have.
There was a problem hiding this comment.
We might end up needing this for packages that use bpf CO-RE other than systemd, right? Why not make it a top-level attribute?
There was a problem hiding this comment.
The configs selected are systemd-specific. This is also the reason https://github.com/libbpf/vmlinux.h wouldn't work --- it doesn't have enough configs enabled.
Although... I guess it can't really hurt to have one central kitchen sink vmlinux.h in Nixpkgs. What do you think?
There was a problem hiding this comment.
I don't think this would need to happen in this PR? These files are inherently use-case-specific, and unless we want to build one from linuxLates (which we opted against for rebuild reasons), I don't think this makes a lot of sense.
There was a problem hiding this comment.
Although... I guess it can't really hurt to have one central kitchen sink
vmlinux.hin Nixpkgs. What do you think?
I think this would make much more sense.
There was a problem hiding this comment.
Somebody (I think @rnhmjoj?) was already talking on Matrix about having another package that will need something very similar.
There was a problem hiding this comment.
Yes, it's for a personal project and far from ready for now, but I think an easy way to get the vmlinux.h would be useful in general. By the way, eventually I solved this problem with:
vmlinux = pkgs.runCommandLocal "vmlinux.h" {} ''
${pkgs.linux-scripts}/bin/extract-vmlinux ${kernel}/bzImage > $out
'';
I'm not sure if there are disadvantages compared to the method used in this PR, but it seems to work for me.
There was a problem hiding this comment.
@rnhmjoj Hmm, your example raises more questions than it answers:
- Do you need
vmlinux? orvmlinux.h? the two have different usages and it won't make sense to use the same approach for both. If your project depends on the kernel it does not make sense to use a genericvmlinux.h. extract-vmlinuxseems to be a horrible hack for something that we can just use${kernel.dev}/vmlinuxfor. Even if it works you need to un-hardcodebzImagefor other platform's sake
There was a problem hiding this comment.
-
Sorry for the bad naming in the example: it builds the vmlinux ELF. I needed vmlinux to generate vmlinux.h later, with
bpftool. Same as you do, I think. -
Maybe, but at least a user can just supply a kernel binary, rather than the sources to generate this infos. It seems more convenient to me.
There was a problem hiding this comment.
That makes sense. Ideally, we can just have a recent-enough kitchen sink vmlinux.h in Nixpkgs with everything everyone needs enabled, which should work for your case.
There was a problem hiding this comment.
I just checked and this extract-vmlinux script does not work on other platforms, at least on riscv64, but I suspect most archs' boot image formats are incompatible. Therefore extract-vmlinux should not be the default approach in Nixpkgs.
Personally I think extract-vmlinux should just go away entirely but whatever...
2f1b3b0 to
7a8c815
Compare
7a8c815 to
a6ca90b
Compare
|
@emilazy @dramforever is there any more information you could share that might help somebody else carry your systemd change forward? What were the other problems you encountered? Are they blockers for that approach? |
|
(See also #484057) |
|
I decided to give it a go again today and came up with this systemd/systemd@main...dramforever:systemd:no-vmlinux-h I haven't figured out how to properly create a rootfs yet, but with this mountfsd/nsresourced should be working. I was able to start a container while unprivileged. I had to use I'm cautiously confident that this will be accepted upstream. Given that upstream already has a The same, rebased and adjusted on 258.3: systemd/systemd@main...dramforever:systemd:no-vmlinux-h-258.3 This should work on 258.2 too. But I'll probably not keep this branch updated with minor changes. Here's a problem I ran into that I've seemingly solved by doing nothing: Yes, |
|
Great! So what's needed to submit it upstream? mountfsd/nsresourced testing from someone? |
|
I'm currently cleaning up I would still appreciate it if anyone who wanted this feature could give it a test and see if it fixes your use case. |
|
I agree that it is untenable to put a kernel build extremely early (mass rebuild early) in the bootstrap order. Since systemd insists on not providing a modular build (e.g. using Meson subprojects, like Nix does), they are forcing us into this situation. There are only two ways out:
I would be happy with either solution --- 2 also works because then I don't believe However, if upstream doesn't like either (they appear to not like 1, and my understanding is that they have always been against 2), then we should definitely go with 1, because it is a patch small enough that we could just land it ourselves downstream, over their objections, whereas 2 will be effectively impossible to maintain downstream. |
|
@Ericson2314 We have option
I still believe this is not practically worse for compat than using the
One notable example IMHO is perf which switched to doing a |
|
Yeah I would say
are pretty isomorphic options ;) I always would definitely share torvalds/linux@a887466 in the PR thread. IMO in-tree BPF using a subset is a coup de grace. Even the kernel devs think the kernel is too heavy a debt! Even for code which is (effectively, because in tree) versioned the same as the kernel! |
|
Having had some random discussions elsewhere, I'm going to the relevant knowledge that I now know about eBPF CO-RE and At one point in the past, if you wanted to access kernel-internal data structures, you need to use the kernel development headers. No ABI compat whatsoever. That was pretty bad. At present, we have things like However, you still need to declare what types and fields you want to access. This has two possible advantages
Notably, it is not safer for compatibility than defining the types yourself. The same field access checks are done at load time, since it's based on querying the running kernel BTF.
AFAICT some operations on current eBPF compilers are silently CO-RE incompatible. For example, type sizes are not automatically fixed by CO-RE. Field type mismatches are silently ignored. (Field names are checked, at least, and struct names for fields have to be checked, or there's no way to know which struct a field belongs to.) This means that, for example, if an eBPF program is compiled with a struct field with type Since most of the kernel internal types are not stable ABI, they will completely break at some point. Therefore, libbpf provides ways for eBPF C code to query if certain things exist in the kernel. See https://docs.ebpf.io/ebpf-library/libbpf/ebpf/#bpf_core_readh "CO-RE queries". This can be used to match multiple different kernel internal ABIs in the same eBPF code. See loresuso/psc@2ec2889 for a recently written example, where support for old kernel was added. CO-RE queries are necessary if you want the same eBPF ELF to work with kernels with incompatible internal ABIs. Externally, you can also load different eBPF ELFs for different kernel versions, but it would require more integration with libbpf. Some things seem to be only possible to handle externally. For example, if a function to be kprobe'd has its name changed, it doesn't seem to be possible to check for the function name inside of eBPF C code. The calling code would need to do error handling while loading the kprobe. The bottom line though is that if you want compatibility, even if you have In summary, full |
|
Also, here is a branch where I've written up an entire |
I did the same at some point (perhaps even on this PR?) and it worked. For me, this would probably be the favorable way to move forward at the moment. This puts a burden on persons packaging BPF-integrated packages (e.g. systemd, psc), but I think it's the best we can do right now to not put kernel builds in the dependency chain of those packages. P.S.: I agree with your analysis of CO-RE above. |
|
I don't think the systemd team will change their approach at this point, they're aware of the limitations of the vmlinux.h approach, they're aware of the limitations of the CO-RE approach. Can we unblock the current approach and work with that until the first hurdles (similar to the psc ones) happen and at that moment, we can leave it to the systemd team to decide how they want to proceed? |
|
Summarizing a conversation that happened in NixOS systemd on Matrix: systemd upstream will not change their mind as mentioned above. After talking and looking at the options again with those who raised a concern, here are the current conclusions. @emilazy @dramforever @alyssais accepts the compromise of either of these options:
Important notes:
The last solution seems preferred because it save up rebuilds for people who may be doing things with limited resources and pushes the (limited) churn on Hydra except for the fact that there's 100 consumers of systemd in nixpkgs which may just want libsystemd actually. |
|
FWIW I think it's >100 and just GitHub capping the results. I have not verified but believe that After further discussion on Matrix and some thought I believe we should do a treewide to fix all dependencies on This produces the best results for build closures, the Hydra/cache waste is minimal and "honest" with regards to the pitfalls of what upstream is committed to, and will improve the dependencies situation throughout the tree. Caveats:
The only alternative I can see, if I'm not wrong about the rebuild numbers, is to build a kernel from |
|
I haven't been super active on Matrix recently, but if I interpret the recent comments here right, it seems that people on Matrix did (more or less) agree on P.S.:
If this is a statement from the systemd maintainers, the "hand-writing a minimal |
It's ultimately blocked on the libsystemd treewide, yep.
I understood that no one want to take the maintenance churn so we should stick to the original plan except if someone wants to sign up for this (and has a realistic chance to stick to it). |
|
Hey, I've been working on doing the libsystemd treewide in preparation for this. Sorry it's taking me a while. It is my current active project. |
|
@ElvishJerricco did you end up making progress on the libsystemd treewide? |
|
@samiser I took over this work and completed it in my local trees. I'm now smoke testing all the migrations and will send a GH stack for the changes. Closing here. |
Re-target of #404715 against staging.
This adds support for rootless systemd-nspawn containers on NixOS by doing a few things:
linuxManualConfigbuilder by unconditionally emitting avmlinuxELF in thedevoutput, not just whenCONFIG_MODULES=y(also removing an IFD requirement for that).nsresourcedandmountfsd. This is achieved by building a minimal custom kernel, generating avmlinux.hfile from that, and consuming that in systemd. This does not create a strong dependency between the systemd package and a specific kernel version, asthe header file is only used for initial compilation, and BPF symbols are being relocated at runtime later on using BPF CO-RE.
systemd-{nsresourced,mountfsd}binaries in the systemd package. These are passed-through, to be consumed by the NixOS module.Change can be quickly verified by the following pre-change and post-change:
sudo $(nix build .#systemd.out --print-out-paths --no-link)/lib/systemd/systemd-nsresourcedPrior to the change, this will show:
After the change:
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.