Re: Headers for whitelisted kernel functions available to BPF programs

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

 





On 6/15/21 12:34 PM, Kenny Ho wrote:
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?

Yes, either kprobe or fentry should work.


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 "

We could you have some kernel helpers interacts with kernel subsystems.
For example, ipv6 could be a module, some kernel helpers actually works
fine with ipv6 module, you need have some configure time checking as well as some runtime checking.


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?

To determine whether a function can be used in what context indeed a very tricky question. The function amdgpu_device_gpu_recover is very
complex and has a lot of side effect. Maybe it can still be used,
but need to tag the function with some conditions and unless these
conditions are verified by verifier, the function cannot be used
in bpf program.

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

Yes, the macro is defined in bpf_helpers.h.


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?

Sorry, probably typing too fast. "function type" here I actually
mean "btf type". To call kernel function inside the bpf program,
we need btf type to verify kernel function signature, precondition
etc. kprobe uses pt_regs and all types are lost.





[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