From: Stanislav Fomichev <sdf@google.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org
Subject: [PATCH bpf-next v2 0/3] bpf: expose bpf_{g,s}et_retval to more cgroup hooks
Date: Tue, 16 Aug 2022 13:12:11 -0700 [thread overview]
Message-ID: <20220816201214.2489910-1-sdf@google.com> (raw)
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.
v2:
- move everything into kernel/bpf/cgroup.c instead (Martin)
- use cgroup_common_func_proto in lsm (Martin)
Stanislav Fomichev (3):
bpf: Introduce cgroup_{common,current}_func_proto
bpf: Use cgroup_{common,current}_func_proto in more hooks
selftests/bpf: Make sure bpf_{g,s}et_retval is exposed everywhere
include/linux/bpf.h | 18 +-
kernel/bpf/bpf_lsm.c | 19 +-
kernel/bpf/cgroup.c | 333 +++++++++++++++++-
kernel/bpf/helpers.c | 205 +----------
net/core/filter.c | 92 ++---
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 +
9 files changed, 466 insertions(+), 291 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
--
2.37.1.595.g718a3a8f04-goog
next reply other threads:[~2022-08-16 20:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 20:12 Stanislav Fomichev [this message]
2022-08-16 20:12 ` [PATCH bpf-next v2 1/3] bpf: Introduce cgroup_{common,current}_func_proto Stanislav Fomichev
2022-08-17 19:22 ` Martin KaFai Lau
2022-08-17 22:41 ` Stanislav Fomichev
2022-08-16 20:12 ` [PATCH bpf-next v2 2/3] bpf: Use cgroup_{common,current}_func_proto in more hooks Stanislav Fomichev
2022-08-16 20:12 ` [PATCH bpf-next v2 3/3] selftests/bpf: Make sure bpf_{g,s}et_retval is exposed everywhere Stanislav Fomichev
2022-08-17 19:07 ` [PATCH bpf-next v2 0/3] bpf: expose bpf_{g,s}et_retval to more cgroup hooks Martin KaFai Lau
2022-08-17 22:41 ` Stanislav Fomichev
2022-08-17 23:27 ` Martin KaFai Lau
2022-08-17 23:59 ` Stanislav Fomichev
2022-08-18 0:21 ` Martin KaFai Lau
2022-08-18 3:42 ` Stanislav Fomichev
2022-08-18 18:15 ` Martin KaFai Lau
2022-08-18 18:30 ` Stanislav Fomichev
2022-08-18 19:54 ` Martin KaFai Lau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220816201214.2489910-1-sdf@google.com \
--to=sdf@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=song@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox