Skip to content

Commit 6e95ef0

Browse files
committed
Merge tag 'bpf-next-6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Pull bpf updates from Alexei Starovoitov: - Add BPF uprobe session support (Jiri Olsa) - Optimize uprobe performance (Andrii Nakryiko) - Add bpf_fastcall support to helpers and kfuncs (Eduard Zingerman) - Avoid calling free_htab_elem() under hash map bucket lock (Hou Tao) - Prevent tailcall infinite loop caused by freplace (Leon Hwang) - Mark raw_tracepoint arguments as nullable (Kumar Kartikeya Dwivedi) - Introduce uptr support in the task local storage map (Martin KaFai Lau) - Stringify errno log messages in libbpf (Mykyta Yatsenko) - Add kmem_cache BPF iterator for perf's lock profiling (Namhyung Kim) - Support BPF objects of either endianness in libbpf (Tony Ambardar) - Add ksym to struct_ops trampoline to fix stack trace (Xu Kuohai) - Introduce private stack for eligible BPF programs (Yonghong Song) - Migrate samples/bpf tests to selftests/bpf test_progs (Daniel T. Lee) - Migrate test_sock to selftests/bpf test_progs (Jordan Rife) * tag 'bpf-next-6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (152 commits) libbpf: Change hash_combine parameters from long to unsigned long selftests/bpf: Fix build error with llvm 19 libbpf: Fix memory leak in bpf_program__attach_uprobe_multi bpf: use common instruction history across all states bpf: Add necessary migrate_disable to range_tree. bpf: Do not alloc arena on unsupported arches selftests/bpf: Set test path for token/obj_priv_implicit_token_envvar selftests/bpf: Add a test for arena range tree algorithm bpf: Introduce range_tree data structure and use it in bpf arena samples/bpf: Remove unused variable in xdp2skb_meta_kern.c samples/bpf: Remove unused variables in tc_l2_redirect_kern.c bpftool: Cast variable `var` to long long bpf, x86: Propagate tailcall info only for subprogs bpf: Add kernel symbol for struct_ops trampoline bpf: Use function pointers count as struct_ops links count bpf: Remove unused member rcu from bpf_struct_ops_map selftests/bpf: Add struct_ops prog private stack tests bpf: Support private stack for struct_ops progs selftests/bpf: Add tracing prog private stack tests bpf, x86: Support private stack in jit ...
2 parents 43fb83c + 2c8b09a commit 6e95ef0

File tree

211 files changed

+6961
-3473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+6961
-3473
lines changed

Documentation/bpf/btf.rst

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ section named by ``btf_ext_info_sec->sec_name_off``.
835835
See :ref:`Documentation/bpf/llvm_reloc.rst <btf-co-re-relocations>`
836836
for more information on CO-RE relocations.
837837

838-
4.2 .BTF_ids section
838+
4.3 .BTF_ids section
839839
--------------------
840840

841841
The .BTF_ids section encodes BTF ID values that are used within the kernel.
@@ -896,6 +896,81 @@ and is used as a filter when resolving the BTF ID value.
896896
All the BTF ID lists and sets are compiled in the .BTF_ids section and
897897
resolved during the linking phase of kernel build by ``resolve_btfids`` tool.
898898

899+
4.4 .BTF.base section
900+
---------------------
901+
Split BTF - where the .BTF section only contains types not in the associated
902+
base .BTF section - is an extremely efficient way to encode type information
903+
for kernel modules, since they generally consist of a few module-specific
904+
types along with a large set of shared kernel types. The former are encoded
905+
in split BTF, while the latter are encoded in base BTF, resulting in more
906+
compact representations. A type in split BTF that refers to a type in
907+
base BTF refers to it using its base BTF ID, and split BTF IDs start
908+
at last_base_BTF_ID + 1.
909+
910+
The downside of this approach however is that this makes the split BTF
911+
somewhat brittle - when the base BTF changes, base BTF ID references are
912+
no longer valid and the split BTF itself becomes useless. The role of the
913+
.BTF.base section is to make split BTF more resilient for cases where
914+
the base BTF may change, as is the case for kernel modules not built every
915+
time the kernel is for example. .BTF.base contains named base types; INTs,
916+
FLOATs, STRUCTs, UNIONs, ENUM[64]s and FWDs. INTs and FLOATs are fully
917+
described in .BTF.base sections, while composite types like structs
918+
and unions are not fully defined - the .BTF.base type simply serves as
919+
a description of the type the split BTF referred to, so structs/unions
920+
have 0 members in the .BTF.base section. ENUM[64]s are similarly recorded
921+
with 0 members. Any other types are added to the split BTF. This
922+
distillation process then leaves us with a .BTF.base section with
923+
such minimal descriptions of base types and .BTF split section which refers
924+
to those base types. Later, we can relocate the split BTF using both the
925+
information stored in the .BTF.base section and the new .BTF base; the type
926+
information in the .BTF.base section allows us to update the split BTF
927+
references to point at the corresponding new base BTF IDs.
928+
929+
BTF relocation happens on kernel module load when a kernel module has a
930+
.BTF.base section, and libbpf also provides a btf__relocate() API to
931+
accomplish this.
932+
933+
As an example consider the following base BTF::
934+
935+
[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
936+
[2] STRUCT 'foo' size=8 vlen=2
937+
'f1' type_id=1 bits_offset=0
938+
'f2' type_id=1 bits_offset=32
939+
940+
...and associated split BTF::
941+
942+
[3] PTR '(anon)' type_id=2
943+
944+
i.e. split BTF describes a pointer to struct foo { int f1; int f2 };
945+
946+
.BTF.base will consist of::
947+
948+
[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
949+
[2] STRUCT 'foo' size=8 vlen=0
950+
951+
If we relocate the split BTF later using the following new base BTF::
952+
953+
[1] INT 'long unsigned int' size=8 bits_offset=0 nr_bits=64 encoding=(none)
954+
[2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
955+
[3] STRUCT 'foo' size=8 vlen=2
956+
'f1' type_id=2 bits_offset=0
957+
'f2' type_id=2 bits_offset=32
958+
959+
...we can use our .BTF.base description to know that the split BTF reference
960+
is to struct foo, and relocation results in new split BTF::
961+
962+
[4] PTR '(anon)' type_id=3
963+
964+
Note that we had to update BTF ID and start BTF ID for the split BTF.
965+
966+
So we see how .BTF.base plays the role of facilitating later relocation,
967+
leading to more resilient split BTF.
968+
969+
.BTF.base sections will be generated automatically for out-of-tree kernel module
970+
builds - i.e. where KBUILD_EXTMOD is set (as it would be for "make M=path/2/mod"
971+
cases). .BTF.base generation requires pahole support for the "distilled_base"
972+
BTF feature; this is available in pahole v1.28 and later.
973+
899974
5. Using BTF
900975
============
901976

Documentation/bpf/verifier.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ Notes:
507507
from the parent state to the current state.
508508

509509
* Details about REG_LIVE_READ32 are omitted.
510-
510+
511511
* Function ``propagate_liveness()`` (see section :ref:`read_marks_for_cache_hits`)
512512
might override the first parent link. Please refer to the comments in the
513513
``propagate_liveness()`` and ``mark_reg_read()`` source code for further
@@ -571,7 +571,7 @@ works::
571571
are considered equivalent.
572572

573573
.. _read_marks_for_cache_hits:
574-
574+
575575
Read marks propagation for cache hits
576576
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
577577

arch/arm64/net/bpf_jit_comp.c

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,6 +2094,12 @@ static void restore_args(struct jit_ctx *ctx, int args_off, int nregs)
20942094
}
20952095
}
20962096

2097+
static bool is_struct_ops_tramp(const struct bpf_tramp_links *fentry_links)
2098+
{
2099+
return fentry_links->nr_links == 1 &&
2100+
fentry_links->links[0]->link.type == BPF_LINK_TYPE_STRUCT_OPS;
2101+
}
2102+
20972103
/* Based on the x86's implementation of arch_prepare_bpf_trampoline().
20982104
*
20992105
* bpf prog and function entry before bpf trampoline hooked:
@@ -2123,6 +2129,7 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
21232129
struct bpf_tramp_links *fmod_ret = &tlinks[BPF_TRAMP_MODIFY_RETURN];
21242130
bool save_ret;
21252131
__le32 **branches = NULL;
2132+
bool is_struct_ops = is_struct_ops_tramp(fentry);
21262133

21272134
/* trampoline stack layout:
21282135
* [ parent ip ]
@@ -2191,11 +2198,14 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
21912198
*/
21922199
emit_bti(A64_BTI_JC, ctx);
21932200

2194-
/* frame for parent function */
2195-
emit(A64_PUSH(A64_FP, A64_R(9), A64_SP), ctx);
2196-
emit(A64_MOV(1, A64_FP, A64_SP), ctx);
2201+
/* x9 is not set for struct_ops */
2202+
if (!is_struct_ops) {
2203+
/* frame for parent function */
2204+
emit(A64_PUSH(A64_FP, A64_R(9), A64_SP), ctx);
2205+
emit(A64_MOV(1, A64_FP, A64_SP), ctx);
2206+
}
21972207

2198-
/* frame for patched function */
2208+
/* frame for patched function for tracing, or caller for struct_ops */
21992209
emit(A64_PUSH(A64_FP, A64_LR, A64_SP), ctx);
22002210
emit(A64_MOV(1, A64_FP, A64_SP), ctx);
22012211

@@ -2289,19 +2299,24 @@ static int prepare_trampoline(struct jit_ctx *ctx, struct bpf_tramp_image *im,
22892299
/* reset SP */
22902300
emit(A64_MOV(1, A64_SP, A64_FP), ctx);
22912301

2292-
/* pop frames */
2293-
emit(A64_POP(A64_FP, A64_LR, A64_SP), ctx);
2294-
emit(A64_POP(A64_FP, A64_R(9), A64_SP), ctx);
2295-
2296-
if (flags & BPF_TRAMP_F_SKIP_FRAME) {
2297-
/* skip patched function, return to parent */
2298-
emit(A64_MOV(1, A64_LR, A64_R(9)), ctx);
2299-
emit(A64_RET(A64_R(9)), ctx);
2302+
if (is_struct_ops) {
2303+
emit(A64_POP(A64_FP, A64_LR, A64_SP), ctx);
2304+
emit(A64_RET(A64_LR), ctx);
23002305
} else {
2301-
/* return to patched function */
2302-
emit(A64_MOV(1, A64_R(10), A64_LR), ctx);
2303-
emit(A64_MOV(1, A64_LR, A64_R(9)), ctx);
2304-
emit(A64_RET(A64_R(10)), ctx);
2306+
/* pop frames */
2307+
emit(A64_POP(A64_FP, A64_LR, A64_SP), ctx);
2308+
emit(A64_POP(A64_FP, A64_R(9), A64_SP), ctx);
2309+
2310+
if (flags & BPF_TRAMP_F_SKIP_FRAME) {
2311+
/* skip patched function, return to parent */
2312+
emit(A64_MOV(1, A64_LR, A64_R(9)), ctx);
2313+
emit(A64_RET(A64_R(9)), ctx);
2314+
} else {
2315+
/* return to patched function */
2316+
emit(A64_MOV(1, A64_R(10), A64_LR), ctx);
2317+
emit(A64_MOV(1, A64_LR, A64_R(9)), ctx);
2318+
emit(A64_RET(A64_R(10)), ctx);
2319+
}
23052320
}
23062321

23072322
kfree(branches);

0 commit comments

Comments
 (0)