mm/bpf: Add bpf_get_kmem_cache() kfunc
authorNamhyung Kim <namhyung@kernel.org>
Thu, 10 Oct 2024 23:25:04 +0000 (16:25 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 16 Oct 2024 16:21:03 +0000 (09:21 -0700)
commita992d7a3979120fbd7c13435d27b3da8d9ed095a
treeac4a2fe921d176f96bc30919136ae1f00b7be387
parent4971266e1595f76be3f844c834c1f9357a97dbde
mm/bpf: Add bpf_get_kmem_cache() kfunc

The bpf_get_kmem_cache() is to get a slab cache information from a
virtual address like virt_to_cache().  If the address is a pointer
to a slab object, it'd return a valid kmem_cache pointer, otherwise
NULL is returned.

It doesn't grab a reference count of the kmem_cache so the caller is
responsible to manage the access.  The returned point is marked as
PTR_UNTRUSTED.

The intended use case for now is to symbolize locks in slab objects
from the lock contention tracepoints.

Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev> (mm/*)
Acked-by: Vlastimil Babka <vbabka@suse.cz> #mm/slab
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20241010232505.1339892-3-namhyung@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/helpers.c
kernel/bpf/verifier.c
mm/slab_common.c