From: Alexei Starovoitov Date: Tue, 21 Apr 2026 00:52:49 +0000 (-0700) Subject: Merge branch 'bpf-extend-btf-uapi-vlen-kinds-to-use-unused-bits' X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=552ad802cad94bd759f85c170d07cc53f7d5deb9;p=thirdparty%2Fkernel%2Flinux.git Merge branch 'bpf-extend-btf-uapi-vlen-kinds-to-use-unused-bits' Alan Maguire says: ==================== bpf: Extend BTF UAPI vlen, kinds to use unused bits Currently BTF types can have a maximum of 65535 vlen-specified objects. While this limit has not yet been surpassed for existing cases (struct/union fields, enum values, function arguments and datasec), upcoming BTF location information - specifically inline sites - will hit that limit. Utilize unused BTF info bits in struct btf_type to increase limit to 24-bits (over 16 million). This is more than an order of magnitude greater than inline site counts for the kernel (~400,000) so should be enough for the near future at least. Similarly, struct btf_type uses 5 bits for BTF kind values; currently we use 20 kinds, but BTF location information will take another 3, and conceivably providing better support for Rust types in BTF (now that modules can be built using Rust) could push us close to the max of 31. Use 2 unused bits to provide a max possible kind of 127. Patch 1 handles UAPI and kernel-related changes. Patch 2 updates libbpf to have btf_vlen() return a __u32 instead of __u16 and updates consumers in libbpf accordingly. Also adds bounds checking for max vlen. Patch 3 cleans up __u16 vlen usage in bpftool. Patch 4 fixes up a test that relies on BTF info overflowing maximum kind value; fix up the expected error to be an invalid kind rather than (now impossible) invalid btf_info. Patch 5 fixes up __u16 vlen usage in selftests/bpf. Patch 6 syncs BTF documentation with UAPI changes. Changes since v2 [1]: - dropped backwards-compatibility macros (Alexei, patch 1) - added additional vlen bounds check in btf__add_field() (sashiko, bpf bot, patch 2) - dropped sanitization check in libbpf as older kernels will reject BTF with extended vlen/kinds using BTF info mask (Alexei) - fix more vlen assumptions in prog_test/ctx_rewrite.c (sashiko, patch 5) Changes since v1 [2]: - added redundant macros to UAPI in case enum switch for BTF_MAX* values causes problems (sashiko, patch 1) - updated feature test to use BTF loading rather than vmlinux BTF lookup, in line with other BTF feature tests (sashiko, patch 3) - fixed up a few more kernel, libbpf, bpftool instances of __u16 usage (bpf bot, sashiko, patches 1, 2, 4) - fixed up sanitize selftest cleanup (Mykyta, patch 5) - used unlikely-to-be-used kind (sashiko, patch 6) - fixed a few lingering selftests uses of __u16 for kind (patch 7) - update btf.rst with new vlen, kind sizes (patch 8) [1] https://lore.kernel.org/bpf/20260416143904.1220662-1-alan.maguire@oracle.com/ [2] https://lore.kernel.org/bpf/20260414195019.684531-1-alan.maguire@oracle.com/ ==================== Link: https://patch.msgid.link/20260417143023.1551481-1-alan.maguire@oracle.com Signed-off-by: Alexei Starovoitov --- 552ad802cad94bd759f85c170d07cc53f7d5deb9