Pass the fd of a btf from the userspace to the bpf() syscall, and then convert the fd into a btf. The btf is generated from the module that defines the target BPF struct_ops type. In order to inform the kernel about the module that defines the target struct_ops type, the userspace program needs to provide a btf fd for the respective module's btf. This btf contains essential information on the types defined within the module, including the target struct_ops type. A btf fd must be provided to the kernel for struct_ops maps and for the bpf programs attached to those maps. In the case of the bpf programs, the attach_btf_obj_fd parameter is passed as part of the bpf_attr and is converted into a btf. This btf is then stored in the prog->aux->attach_btf field. Here, it just let the verifier access attach_btf directly. In the case of struct_ops maps, a btf fd is passed as value_type_btf_obj_fd of bpf_attr. The bpf_struct_ops_map_alloc() function converts the fd to a btf and stores it as st_map->btf. A flag BPF_F_VTYPE_BTF_OBJ_FD is added for map_flags to indicate that the value of value_type_btf_obj_fd is set.
Showing the changes to tools/include/uapi/linux (1 of 5 files). Show all
Unified · Split
| @@ -1330,6 +1330,9 @@ enum { · 1329 unmodified lines | |||
| 1330 | 1330 | ||
| 1331 | /* Get path from provided FD in BPF_OBJ_PIN/BPF_OBJ_GET commands */ | 1331 | /* Get path from provided FD in BPF_OBJ_PIN/BPF_OBJ_GET commands */ |
| 1332 | BPF_F_PATH_FD = (1U << 14), | 1332 | BPF_F_PATH_FD = (1U << 14), |
| 1333 | |||
| 1334 | /* Flag for value_type_btf_obj_fd, the fd is available */ | ||
| 1335 | BPF_F_VTYPE_BTF_OBJ_FD = (1U << 15), | ||
| 1333 | }; | 1336 | }; |
| 1334 | 1337 | ||
| 1335 | /* Flags for BPF_PROG_QUERY. */ | 1338 | /* Flags for BPF_PROG_QUERY. */ |
| @@ -1403,6 +1406,11 @@ union bpf_attr { · 67 unmodified lines | |||
| 1403 | * to using 5 hash functions). | 1406 | * to using 5 hash functions). |
| 1404 | */ | 1407 | */ |
| 1405 | __u64 map_extra; | 1408 | __u64 map_extra; |
| 1409 | |||
| 1410 | __s32 value_type_btf_obj_fd; /* fd pointing to a BTF | ||
| 1411 | * type data for | ||
| 1412 | * btf_vmlinux_value_type_id. | ||
| 1413 | */ | ||
| 1406 | }; | 1414 | }; |
| 1407 | 1415 | ||
| 1408 | struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ | 1416 | struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ |