Skip to content

bpf: Remove recursion check for struct_ops prog

Martin KaFai Lau bpf netdev 1 version Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 Latest5 patches 1 replyApplied 5/5

Changes in v3 from the cover letter

- Clear the bpf_chg_cc_inprogress from the newly cloned tcp_sock in tcp_create_openreq_child() because the listen sk can be cloned without lock being held. (Eric Dumazet)

Patches in v3 All 5 applied

#Subject and filesSizeRepliesApplied
1/5bpf: Add __bpf_prog_{enter,exit}_struct_ops for struct_ops trampolinearch/x86/net/bpf_jit_comp.c include/linux/bpf.h kernel/bpf/trampoline.c+30 -00 repliesApplied
2/5bpf: Move the "cdg" tcp-cc check to the common sol_tcp_sockopt()net/core/filter.c+7 -60 repliesApplied
3/5bpf: Refactor bpf_setsockopt(TCP_CONGESTION) handling into another functionnet/core/filter.c+28 -170 repliesApplied
4/5bpf: tcp: Stop bpf_setsockopt(TCP_CONGESTION) in init ops to recur itselfinclude/linux/tcp.h net/core/filter.c net/ipv4/tcp_minisocks.c+34 -11 replyApplied
5/5selftests/bpf: Check -EBUSY for the recurred bpf_setsockopt(TCP_CONGESTION)tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c tools/testing/selftests/bpf/progs/bpf_dctcp.c+21 -80 repliesApplied

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by.

PatchEric Dumazet
1/5
2/5
3/5
4/5R-b
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 bpf-next 0/5] bpf: Remove recursion check for struct_ops prog

From: Martin KaFai Lau <[email protected]>

The struct_ops is sharing the tracing-trampoline's enter/exit function which tracks prog->active to avoid recursion. It turns out the struct_ops bpf prog will hit this prog->active and unnecessarily skipped running the struct_ops prog. eg. The '.ssthresh' may run in_task() and then interrupted by softirq that runs the same '.ssthresh'.

The kernel does not call the tcp-cc's ops in a recursive way, so this set is to remove the recursion check for struct_ops prog.

v3:
- Clear the bpf_chg_cc_inprogress from the newly cloned tcp_sock in tcp_create_openreq_child() because the listen sk can be cloned without lock being held. (Eric Dumazet)

v2:
- v1 [0] turned into a long discussion on a few cases and also whether it needs to follow the bpf_run_ctx chain if there is tracing bpf_run_ctx (kprobe/trace/trampoline) running in between.

It is a good signal that it is not obvious enough to reason about it and needs a tradeoff for a more straight forward approach.

This revision uses one bit out of an existing 1 byte hole in the tcp_sock. It is in Patch 4.

[0]: https://lore.kernel.org/bpf/[email protected]/T/#md98d40ac5ec295fdadef476c227a3401b2b6b911

Martin KaFai Lau (5):
bpf: Add __bpf_prog_{enter,exit}_struct_ops for struct_ops trampoline
bpf: Move the "cdg" tcp-cc check to the common sol_tcp_sockopt()
bpf: Refactor bpf_setsockopt(TCP_CONGESTION) handling into another
function
bpf: tcp: Stop bpf_setsockopt(TCP_CONGESTION) in init ops to recur
itself
selftests/bpf: Check -EBUSY for the recurred
bpf_setsockopt(TCP_CONGESTION)

 arch/x86/net/bpf_jit_comp.c                   |  3 +
 include/linux/bpf.h                           |  4 ++
 include/linux/tcp.h                           |  6 ++
 kernel/bpf/trampoline.c                       | 23 ++++++
 net/core/filter.c                             | 70 ++++++++++++++-----
 net/ipv4/tcp_minisocks.c                      |  1 +
 .../selftests/bpf/prog_tests/bpf_tcp_ca.c     |  4 ++
 tools/testing/selftests/bpf/progs/bpf_dctcp.c | 25 ++++---
 8 files changed, 112 insertions(+), 24 deletions(-)
Signature · 1 line
2.30.2