OSDN Git Service

bpf: Introduce helper bpf_find_vma
authorSong Liu <songliubraving@fb.com>
Fri, 5 Nov 2021 23:23:29 +0000 (16:23 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 7 Nov 2021 19:54:51 +0000 (11:54 -0800)
commit7c7e3d31e7856a8260a254f8c71db416f7f9f5a1
treed2754fa3a377dd507bfa4e6131e554f3d011d844
parent5fd79ed9bed1934de0ba0024e62eacaedb3c4c8a
bpf: Introduce helper bpf_find_vma

In some profiler use cases, it is necessary to map an address to the
backing file, e.g., a shared library. bpf_find_vma helper provides a
flexible way to achieve this. bpf_find_vma maps an address of a task to
the vma (vm_area_struct) for this address, and feed the vma to an callback
BPF function. The callback function is necessary here, as we need to
ensure mmap_sem is unlocked.

It is necessary to lock mmap_sem for find_vma. To lock and unlock mmap_sem
safely when irqs are disable, we use the same mechanism as stackmap with
build_id. Specifically, when irqs are disabled, the unlocked is postponed
in an irq_work. Refactor stackmap.c so that the irq_work is shared among
bpf_find_vma and stackmap helpers.

Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Tested-by: Hengqi Chen <hengqi.chen@gmail.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20211105232330.1936330-2-songliubraving@fb.com
include/linux/bpf.h
include/uapi/linux/bpf.h
kernel/bpf/btf.c
kernel/bpf/mmap_unlock_work.h [new file with mode: 0644]
kernel/bpf/stackmap.c
kernel/bpf/task_iter.c
kernel/bpf/verifier.c
kernel/trace/bpf_trace.c
tools/include/uapi/linux/bpf.h