Centos-kernel-stream-9/kernel/bpf
Jiri Benc ffd8cd8977 bpf: tcp: Allow bpf-tcp-cc to call bpf_(get|set)sockopt
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071618

Conflicts:
- [minor] context difference in bpf_tcp_ca_get_func_proto due to out of
  order backport of 5e0bc3082e2e "bpf: Forbid bpf_ktime_get_coarse_ns and
  bpf_timer_* in tracing progs"

commit eb18b49ea758ec052ac2a12c6bb204e1e877ec31
Author: Martin KaFai Lau <kafai@fb.com>
Date:   Tue Aug 24 10:30:07 2021 -0700

    bpf: tcp: Allow bpf-tcp-cc to call bpf_(get|set)sockopt

    This patch allows the bpf-tcp-cc to call bpf_setsockopt.  One use
    case is to allow a bpf-tcp-cc switching to another cc during init().
    For example, when the tcp flow is not ecn ready, the bpf_dctcp
    can switch to another cc by calling setsockopt(TCP_CONGESTION).

    During setsockopt(TCP_CONGESTION), the new tcp-cc's init() will be
    called and this could cause a recursion but it is stopped by the
    current trampoline's logic (in the prog->active counter).

    While retiring a bpf-tcp-cc (e.g. in tcp_v[46]_destroy_sock()),
    the tcp stack calls bpf-tcp-cc's release().  To avoid the retiring
    bpf-tcp-cc making further changes to the sk, bpf_setsockopt is not
    available to the bpf-tcp-cc's release().  This will avoid release()
    making setsockopt() call that will potentially allocate new resources.

    Although the bpf-tcp-cc already has a more powerful way to read tcp_sock
    from the PTR_TO_BTF_ID, it is usually expected that bpf_getsockopt and
    bpf_setsockopt are available together.  Thus, bpf_getsockopt() is also
    added to all tcp_congestion_ops except release().

    When the old bpf-tcp-cc is calling setsockopt(TCP_CONGESTION)
    to switch to a new cc, the old bpf-tcp-cc will be released by
    bpf_struct_ops_put().  Thus, this patch also puts the bpf_struct_ops_map
    after a rcu grace period because the trampoline's image cannot be freed
    while the old bpf-tcp-cc is still running.

    bpf-tcp-cc can only access icsk_ca_priv as SCALAR.  All kernel's
    tcp-cc is also accessing the icsk_ca_priv as SCALAR.   The size
    of icsk_ca_priv has already been raised a few times to avoid
    extra kmalloc and memory referencing.  The only exception is the
    kernel's tcp_cdg.c that stores a kmalloc()-ed pointer in icsk_ca_priv.
    To avoid the old bpf-tcp-cc accidentally overriding this tcp_cdg's pointer
    value stored in icsk_ca_priv after switching and without over-complicating
    the bpf's verifier for this one exception in tcp_cdg, this patch does not
    allow switching to tcp_cdg.  If there is a need, bpf_tcp_cdg can be
    implemented and then use the bpf_sk_storage as the extended storage.

    bpf_sk_setsockopt proto has only been recently added and used
    in bpf-sockopt and bpf-iter-tcp, so impose the tcp_cdg limitation in the
    same proto instead of adding a new proto specifically for bpf-tcp-cc.

    Signed-off-by: Martin KaFai Lau <kafai@fb.com>
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20210824173007.3976921-1-kafai@fb.com

Signed-off-by: Jiri Benc <jbenc@redhat.com>
2022-05-12 17:29:46 +02:00
..
preload libbpf: Move BPF_SEQ_PRINTF and BPF_SNPRINTF to bpf_helpers.h 2021-05-26 10:45:41 -07:00
Kconfig sock_map: Relax config dependency to CONFIG_NET 2022-05-12 17:29:43 +02:00
Makefile bpf: Enable task local storage for tracing programs 2021-02-26 11:51:47 -08:00
arraymap.c bpf: Fix potential race in tail call compatibility check 2022-04-29 18:17:15 +02:00
bpf_inode_storage.c bpf: Fix spelling mistakes 2021-05-24 21:13:05 -07:00
bpf_iter.c bpf: tcp: Support bpf_(get|set)sockopt in bpf tcp iter 2022-05-12 17:29:46 +02:00
bpf_local_storage.c bpf: Prevent deadlock from recursive bpf_task_storage_[get|delete] 2021-02-26 11:51:48 -08:00
bpf_lru_list.c bpf_lru_list: Read double-checked variable once without lock 2021-02-10 15:54:26 -08:00
bpf_lru_list.h
bpf_lsm.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2021-06-17 11:54:56 -07:00
bpf_struct_ops.c bpf: tcp: Allow bpf-tcp-cc to call bpf_(get|set)sockopt 2022-05-12 17:29:46 +02:00
bpf_struct_ops_types.h
bpf_task_storage.c bpf: Consolidate task_struct BTF_ID declarations 2022-04-29 18:14:47 +02:00
btf.c bpf: Fix bpf-next builds without CONFIG_BPF_EVENTS 2022-04-29 18:17:12 +02:00
cgroup.c bpf: Add support for {set|get} socket options from setsockopt BPF 2022-05-12 17:29:46 +02:00
core.c bpf: Change value of MAX_TAIL_CALL_CNT from 32 to 33 2022-04-29 18:17:17 +02:00
cpumap.c bpf: cpumap: Implement generic cpumap 2022-04-29 18:14:30 +02:00
devmap.c bpf: devmap: Implement devmap prog execution for generic XDP 2022-04-29 18:14:30 +02:00
disasm.c bpf: Relicense disassembler as GPL-2.0-only OR BSD-2-Clause 2022-04-29 18:17:12 +02:00
disasm.h bpf: Relicense disassembler as GPL-2.0-only OR BSD-2-Clause 2022-04-29 18:17:12 +02:00
dispatcher.c
hashtab.c bpf: Add map side support for bpf timers. 2022-04-29 18:14:31 +02:00
helpers.c bpf: Forbid bpf_ktime_get_coarse_ns and bpf_timer_* in tracing progs 2022-04-29 18:17:16 +02:00
inode.c bpf: Fix regression on BPF_OBJ_GET with non-O_RDWR flags 2021-06-22 14:57:43 +02:00
local_storage.c bpf: Increase supported cgroup storage value size 2022-04-29 18:14:36 +02:00
lpm_trie.c bpf: Allow RCU-protected lookups to happen from bh context 2021-06-24 19:41:15 +02:00
map_in_map.c bpf: Remember BTF of inner maps. 2022-04-29 18:14:31 +02:00
map_in_map.h
map_iter.c
net_namespace.c
offload.c
percpu_freelist.c
percpu_freelist.h
prog_iter.c
queue_stack_maps.c
reuseport_array.c bpf: Fix spelling mistakes 2021-05-24 21:13:05 -07:00
ringbuf.c bpf: Fix false positive kmemleak report in bpf_ringbuf_area_alloc() 2021-06-28 15:57:46 +02:00
stackmap.c bpf: Consolidate task_struct BTF_ID declarations 2022-04-29 18:14:47 +02:00
syscall.c bpf: Fix potential race in tail call compatibility check 2022-04-29 18:17:15 +02:00
sysfs_btf.c
task_iter.c bpf: Consolidate task_struct BTF_ID declarations 2022-04-29 18:14:47 +02:00
tnum.c bpf, tnums: Provably sound, faster, and more precise algorithm for tnum_mul 2021-06-01 13:34:15 +02:00
trampoline.c bpf: Refactor BPF_PROG_RUN into a function 2022-04-29 18:14:40 +02:00
verifier.c bpf: Fix verifier support for validation of async callbacks 2022-04-29 18:17:16 +02:00