This is an archive of the discontinued LLVM Phabricator instance.

BPF: make __builtin_btf_type_id() return 64bit int
ClosedPublic

Authored by yonghong-song on Nov 14 2020, 8:06 PM.

Details

Summary

Linux kernel recently added support for kernel modules

https://lore.kernel.org/bpf/20201110011932.3201430-5-andrii@kernel.org/

In such cases, a type id in the kernel needs to be presented
as (btf id for modules, btf type id for this module).
Change __builtin_btf_type_id() to return 64bit value
so libbpf can do the above encoding.

Diff Detail

Event Timeline

yonghong-song created this revision.Nov 14 2020, 8:06 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 14 2020, 8:06 PM
yonghong-song requested review of this revision.Nov 14 2020, 8:06 PM
ast accepted this revision.Nov 15 2020, 10:21 AM
ast added inline comments.
llvm/lib/Target/BPF/BTFDebug.cpp
1230

libbpf would need to support both (ld_imm64 and mov32), right?

This revision is now accepted and ready to land.Nov 15 2020, 10:21 AM
yonghong-song added inline comments.Nov 15 2020, 11:33 AM
llvm/lib/Target/BPF/BTFDebug.cpp
1230

all selftests passed. I suspect libbpf already supports both ld_imm64 and mov32...

anakryiko added inline comments.Nov 15 2020, 1:02 PM
llvm/lib/Target/BPF/BTFDebug.cpp
1230

there is no need to make BTF_TYPE_ID_LOCAL to return u64, but if it helps uniformity, then why not.

libbpf does support ldimm64 in general, but I'll need to extend this specifically for BTF_TYPE_ID_REMOTE to record module BTF ID in upper 32 bits. For now it will be just zeroes, which works fine.

yonghong-song added inline comments.Nov 15 2020, 10:14 PM
llvm/lib/Target/BPF/BTFDebug.cpp
1230

yes, uniformity is why I also return u64 for BTF_TYPE_ID_LOCAL.

fix clang-format warning

This revision was landed with ongoing or failed builds.Nov 16 2020, 7:09 AM
This revision was automatically updated to reflect the committed changes.