Re: Headers for whitelisted kernel functions available to BPF programs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jun 9, 2021 at 2:42 AM Yonghong Song <yhs@xxxxxx> wrote:
> So your intention is to call functions in
> drivers/gpu/drm/drm_gem_ttm_helper.c, right? How do you get function
> parameters? What kinds of programs you intend to call
> this functions?
ok... sounds like my use case was not concret enough.  Perhaps I can
elaborate further with the following examples:

In the GPU scheduler, there's a trace point
"trace_drm_run_job(sched_job, entity)":

https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/scheduler/sched_main.c#L813

If I want to analyze the jobs being scheduled, I can potentially
attach a bpf prog with this tracepoint.  Each driver has its own
run_job and sched_job implementation so I was thinking the drivers can
provide a bpf helper function to resolve this.  Alternatively, there
could be tracepoint in the driver implementation that one can attach
bpf to, but tracepoints are not universally put in place (have trace:
https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c#L221;
not have trace:
https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/etnaviv/etnaviv_sched.c#L72
.)  So in cases without tracepoint, I guess I would be using kprobe or
fentry?

Note that all of these are in kernel modules.  My understanding is
that BTF will work but having helper functions from the kernel modules
are not yet available?  So let say I want to whitelist and call "
amdgpu_device_gpu_recover"
(https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c#L4521)
from inside a bpf prog, or whitelist and call
"drm_sched_increase_karma"
https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/scheduler/sched_main.c#L362,
I wouldn't be able to do so?  Are there any criteria in terms of what
kernel function should or should not be whitelisted (separate from the
kernel module support question)?  For example, would
amdgpu_device_gpu_recover be not "whitelist-able" because of the hw
interaction or complexity or likelihood to crash the kernel while
drm_sched_increase_karma is ok because it's more or less manipulation
of some data structure?

A quick side question, does container_of work inside a bpf prog?

> kprobe probably won't work as kernel does not capture
> traced function types. fentry program might be a good
> choice.
Thanks for the pointer.  I am not familiar with fentry but I will look
into it.  By function type, what do you mean by that?



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux