Re: [PATCH bpf-next v2 5/8] libbpf, xsk: select AF_XDP BPF program based on kernel version
From: Björn Töpel <hidden>
Date: 2021-01-20 18:34:24
Also in:
bpf
On 2021-01-20 19:25, Alexei Starovoitov wrote:
On Wed, Jan 20, 2021 at 7:27 AM Björn Töpel [off-list ref] wrote:quoted
quoted
quoted
Would it make sense with some kind of BPF-specific "supported features" mechanism? Something else with a bigger scope (whole kernel)?Heh, in my opinion, yeah. Seems like we'll finally get it for XDP, but for BPF in general the approach has always been probing AFAICT. For the particular case of arguments to helpers, I suppose the verifier could technically validate value ranges for flags arguments, say. That would be nice as an early reject anyway, but I'm not sure if it is possible to add after-the-fact without breaking existing programs because the verifier can't prove the argument is within the valid range. And of course it doesn't help you with compatibility with already-released kernels.Hmm, think I have a way forward. I'll use BPF_PROG_TEST_RUN. If the load fail for the new helper, fallback to bpf_redirect_map(). Use BPF_PROG_TEST_RUN to make sure that "action via flags" passes.+1 to Toke's point. No version checks please. One way to detect is to try prog_load. Search for FEAT_* in libbpf. Another approach is to scan vmlinux BTF for necessary helpers. Currently libbpf is relying on the former. I think going forward would be good to detect features via BTF. It's going to be much faster and won't create noise for audit that could be looking at prog_load calls.
Thanks Alexei. I'll explore both options for the next spin! Björn