Re: [PATCH ipsec-next v1 6/7] bpf: selftests: test_tunnel: Disable CO-RE relocations

From: Eduard Zingerman
Date: Mon Nov 27 2023 - 16:32:45 EST


On Mon, 2023-11-27 at 14:45 -0600, Daniel Xu wrote:
[...]
> IIUC uapi structs look the same in BTF as any other struct.

Yes, and all share preserve_access_index attribute because of the way
attribute push/pop directives are generated in vmlinux.h.

> Just wondering, though: will bpftool be able to generate the appropriate
> annotations for uapi structs?

The problem is that there is no easy way to identify if structure is
uapi in DWARF (from which BTF is generated).
One way to do this:
- modify pahole to check DW_AT_decl_file for each struct DWARF entry
and generate some special decl tag in BTF;
- modify bpftool to interpret this tag as a marker to not generate
preserve_access_index for a structure.

The drawback is that such behavior hardcodes some kernel specific
assumptions both in pahole and in bpftool. It also remains to be seen
if DW_AT_decl_file tags are consistent.

It might be the case that allowing excessive CO-RE relocations is a
better option. (And maybe tweak something about bitfield access
generation to avoid such issues as in this thread).

Thanks,
Eduard