public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Support storing struct task_struct objects as kptrs
@ 2022-09-30 20:47 David Vernet
  2022-09-30 20:47 ` [PATCH 1/2] bpf: Add kfuncs for storing struct task_struct * as a kptr David Vernet
  2022-09-30 20:47 ` [PATCH 2/2] bpf/selftests: Add selftests for new task kfuncs David Vernet
  0 siblings, 2 replies; 4+ messages in thread
From: David Vernet @ 2022-09-30 20:47 UTC (permalink / raw)
  To: ast, daniel, andrii, martin.lau
  Cc: kernel-team, bpf, linux-kernel, yhs, song, john.fastabend,
	kpsingh, sdf, haoluo, jolsa, tj, memxor

Now that BPF supports adding new kernel functions with kfuncs, and storing
kernel objects in maps with kptrs, we can add a set of kfuncs which allow
struct task_struct objects to be stored in maps as referenced kptrs.

The possible use-cases for doing this are plentiful.  During tracing,
for example, it would be useful to be able to collect some tasks that
performed a certain operation, and then periodically summarize who they
are, which cgroup they're in, how much CPU time they've spent, etc.
Doing this now would require storing the task's pids along with some
relevant data to be exported to user space, and later associating the
pids to tasks in other event handlers where the data is recorded.
Another useful by-product of this is that it allows a program to pin a
task, and by proxy therefore also pin its task local storage.

This patch set adds this aforementioned set of kfuncs, along with a new
selftest suite for validation.

David Vernet (2):
  bpf: Add kfuncs for storing struct task_struct * as a kptr
  bpf/selftests: Add selftests for new task kfuncs

 kernel/bpf/helpers.c                          |  75 ++++++++-
 .../selftests/bpf/prog_tests/task_kfunc.c     | 152 ++++++++++++++++++
 .../selftests/bpf/progs/task_kfunc_common.h   |  82 ++++++++++
 .../selftests/bpf/progs/task_kfunc_failure.c  | 132 +++++++++++++++
 .../selftests/bpf/progs/task_kfunc_success.c  | 111 +++++++++++++
 5 files changed, 551 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/task_kfunc.c
 create mode 100644 tools/testing/selftests/bpf/progs/task_kfunc_common.h
 create mode 100644 tools/testing/selftests/bpf/progs/task_kfunc_failure.c
 create mode 100644 tools/testing/selftests/bpf/progs/task_kfunc_success.c

--
2.37.3


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

end of thread, other threads:[~2022-09-30 23:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-30 20:47 [PATCH 0/2] Support storing struct task_struct objects as kptrs David Vernet
2022-09-30 20:47 ` [PATCH 1/2] bpf: Add kfuncs for storing struct task_struct * as a kptr David Vernet
2022-09-30 23:12   ` kernel test robot
2022-09-30 20:47 ` [PATCH 2/2] bpf/selftests: Add selftests for new task kfuncs David Vernet

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