Skip to content

bpf: expose bpf_{g,s}et_retval to more cgroup hooks

Stanislav Fomichev bpf 5 versions – 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 · linked by author and title

  1. v5 Latest5 patches 1 replyApplied 5/5
  2. v45 patches 3 repliesSuperseded
  3. v35 patches 6 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches11 repliesSuperseded
v13 patches4 repliesSuperseded

Changes in v5 from the cover letter

- remove net/cls_cgroup.h include from patch 1/5 (Martin)
- move endif changes from patch 1/5 to 3/5 (Martin)
- don't define __weak protos, the ones in core.c suffice (Martin)

Patches in v5 All 5 applied

#Subject and filesSizeRepliesApplied
1/5bpf: Introduce cgroup_{common,current}_func_protoinclude/linux/bpf-cgroup.h kernel/bpf/cgroup.c kernel/bpf/helpers.c+115 -531 replyApplied
2/5bpf: Use cgroup_{common,current}_func_proto in more hooksinclude/linux/bpf.h kernel/bpf/bpf_lsm.c kernel/bpf/cgroup.c +1 more+80 -580 repliesApplied
3/5bpf: expose bpf_strtol and bpf_strtoul to all program typeskernel/bpf/cgroup.c kernel/bpf/helpers.c+5 -50 repliesApplied
4/5bpf: update bpf_{g,s}et_retval documentationinclude/uapi/linux/bpf.h tools/include/uapi/linux/bpf.h+34 -100 repliesApplied
5/5selftests/bpf: Make sure bpf_{g,s}et_retval is exposed everywheretools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/cgroup_getset_retval_hooks.h tools/testing/selftests/bpf/prog_tests/cgroup_getset_retval.c +1 more+90 -00 repliesApplied

Reviews trailers per patch

All 5 patches have a Reviewed-by or Acked-by.

PatchMartin KaFai Lau
1/5A-b
2/5A-b
3/5A-b
4/5A-b
5/5A-b

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

Read the v5 thread

Cover letter [PATCH bpf-next v5 0/5] bpf: expose bpf_{g,s}et_retval to more cgroup hooks

Apparently, only a small subset of cgroup hooks actually falls back to cgroup_base_func_proto. This leads to unexpected result where not all cgroup helpers have bpf_{g,s}et_retval.

It's getting harder and harder to manage which helpers are exported to which hooks. We now have the following call chains:

- cg_skb_func_proto
- sk_filter_func_proto
- bpf_sk_base_func_proto
- bpf_base_func_proto

So by looking at cg_skb_func_proto it's pretty hard to understand what's going on.

For cgroup helpers, I'm proposing we do the following instead:

  func_proto = cgroup_common_func_proto();
  if (func_proto) return func_proto;

  /* optional, if hook has 'current' */
  func_proto = cgroup_current_func_proto();
  if (func_proto) return func_proto;

...

  switch (func_id) {
  /* hook specific helpers */
  case BPF_FUNC_hook_specific_helper:
    return &xyz;
  default:
    /* always fall back to plain bpf_base_func_proto */
    bpf_base_func_proto(func_id);
  }

If this turns out more workable, we can follow up with converting the rest to the same pattern.

v5:
- remove net/cls_cgroup.h include from patch 1/5 (Martin)
- move endif changes from patch 1/5 to 3/5 (Martin)
- don't define __weak protos, the ones in core.c suffice (Martin)

v4:
- don't touch existing helper.c helpers (Martin)
- drop unneeded CONFIG_CGROUP_BPF in bpf_lsm_func_proto (Martin)

v3:
- expose strtol/strtoul everywhere (Martin)
- move helpers declarations from bpf.h to bpf-cgroup.h (Martin)
- revise bpf_{g,s}et_retval documentation (Martin)
- don't expose bpf_{g,s}et_retval to cg_skb hooks (Martin)

v2:
- move everything into kernel/bpf/cgroup.c instead (Martin)
- use cgroup_common_func_proto in lsm (Martin)

Stanislav Fomichev (5):
bpf: Introduce cgroup_{common,current}_func_proto
bpf: Use cgroup_{common,current}_func_proto in more hooks
bpf: expose bpf_strtol and bpf_strtoul to all program types
bpf: update bpf_{g,s}et_retval documentation selftests/bpf: Make sure bpf_{g,s}et_retval is exposed everywhere

 include/linux/bpf-cgroup.h                    |  17 ++
 include/linux/bpf.h                           |   1 +
 include/uapi/linux/bpf.h                      |  22 ++-
 kernel/bpf/bpf_lsm.c                          |  17 +-
 kernel/bpf/cgroup.c                           | 157 +++++++++++++++---
 kernel/bpf/helpers.c                          |  40 +----
 net/core/filter.c                             |  80 ++++-----
 tools/include/uapi/linux/bpf.h                |  22 ++-
 tools/testing/selftests/bpf/Makefile          |   1 +
 .../bpf/cgroup_getset_retval_hooks.h          |  25 +++
 .../bpf/prog_tests/cgroup_getset_retval.c     |  48 ++++++
 .../bpf/progs/cgroup_getset_retval_hooks.c    |  16 ++
 12 files changed, 322 insertions(+), 124 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/cgroup_getset_retval_hooks.h
 create mode 100644 tools/testing/selftests/bpf/progs/cgroup_getset_retval_hooks.c
Signature · 1 line
2.37.1.595.g718a3a8f04-goog