BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/5] bpf: Allow helper bpf_get_[ns_]current_pid_tgid() for all prog types
@ 2024-03-15 18:48 Yonghong Song
  2024-03-15 18:48 ` [PATCH bpf-next v2 1/5] " Yonghong Song
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Yonghong Song @ 2024-03-15 18:48 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	John Fastabend, kernel-team, Martin KaFai Lau, Yury Namgung

Currently bpf_get_current_pid_tgid() is allowed in tracing, cgroup
and sk_msg progs while bpf_get_ns_current_pid_tgid() is only allowed
in tracing progs.

We have an internal use case where for an application running
in a container (with pid namespace), user wants to get
the pid associated with the pid namespace in a cgroup bpf
program. Besides cgroup, the only prog type, supporting
bpf_get_current_pid_tgid() but not bpf_get_ns_current_pid_tgid(),
is sk_msg.

But actually both bpf_get_current_pid_tgid() and
bpf_get_ns_current_pid_tgid() helpers do not reveal kernel internal
data and there is no reason that they cannot be used in other
program types. This patch just did this and enabled these
two helpers for all program types.

Patch 1 added the kernel support and patches 2-5 added
the test for cgroup and sk_msg.

Change logs:
  v1 -> v2:
    - allow bpf_get_[ns_]current_pid_tgid() for all prog types.
    - for network related selftests, using netns.

Yonghong Song (5):
  bpf: Allow helper bpf_get_[ns_]current_pid_tgid() for all prog types
  selftests/bpf: Replace CHECK with ASSERT_* in ns_current_pid_tgid test
  selftests/bpf: Refactor out some functions in ns_current_pid_tgid test
  selftests/bpf: Add a cgroup prog bpf_get_ns_current_pid_tgid() test
  selftests/bpf: Add a sk_msg prog bpf_get_ns_current_pid_tgid() test

 kernel/bpf/cgroup.c                           |   2 -
 kernel/bpf/helpers.c                          |   4 +
 kernel/trace/bpf_trace.c                      |   4 -
 net/core/filter.c                             |   2 -
 .../bpf/prog_tests/ns_current_pid_tgid.c      | 214 +++++++++++++++---
 .../bpf/progs/test_ns_current_pid_tgid.c      |  31 ++-
 6 files changed, 215 insertions(+), 42 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-03-21 20:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-15 18:48 [PATCH bpf-next v2 0/5] bpf: Allow helper bpf_get_[ns_]current_pid_tgid() for all prog types Yonghong Song
2024-03-15 18:48 ` [PATCH bpf-next v2 1/5] " Yonghong Song
2024-03-18 12:37   ` Jiri Olsa
2024-03-15 18:48 ` [PATCH bpf-next v2 2/5] selftests/bpf: Replace CHECK with ASSERT_* in ns_current_pid_tgid test Yonghong Song
2024-03-18 11:36   ` Jiri Olsa
2024-03-18 15:30     ` Yonghong Song
2024-03-19 21:52       ` Andrii Nakryiko
2024-03-20  0:52         ` Yonghong Song
2024-03-21 20:15         ` Yonghong Song
2024-03-15 18:49 ` [PATCH bpf-next v2 3/5] selftests/bpf: Refactor out some functions " Yonghong Song
2024-03-15 18:49 ` [PATCH bpf-next v2 4/5] selftests/bpf: Add a cgroup prog bpf_get_ns_current_pid_tgid() test Yonghong Song
2024-03-15 18:49 ` [PATCH bpf-next v2 5/5] selftests/bpf: Add a sk_msg " Yonghong Song
2024-03-19 21:50 ` [PATCH bpf-next v2 0/5] bpf: Allow helper bpf_get_[ns_]current_pid_tgid() for all prog types patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox