]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
kallsyms: Add helper kallsyms_on_each_match_symbol()
authorZhen Lei <thunder.leizhen@huawei.com>
Wed, 2 Nov 2022 08:49:17 +0000 (16:49 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 Oct 2023 10:03:16 +0000 (12:03 +0200)
commite9b4b7256736e92bb0f66be0594a021a8b98c861
tree5323418ac6a8a307cd137c7b342b813224e110d5
parentda359f699f5942ca383f528d144fc17c7c95e78a
kallsyms: Add helper kallsyms_on_each_match_symbol()

[ Upstream commit 4dc533e0f2c04174e1ae4aa98e7cffc1c04b9998 ]

Function kallsyms_on_each_symbol() traverses all symbols and submits each
symbol to the hook 'fn' for judgment and processing. For some cases, the
hook actually only handles the matched symbol, such as livepatch.

Because all symbols are currently sorted by name, all the symbols with the
same name are clustered together. Function kallsyms_lookup_names() gets
the start and end positions of the set corresponding to the specified
name. So we can easily and quickly traverse all the matches.

The test results are as follows (twice): (x86)
kallsyms_on_each_match_symbol:     7454,     7984
kallsyms_on_each_symbol      : 1173380911785803

kallsyms_on_each_match_symbol() consumes only 0.066% of
kallsyms_on_each_symbol()'s time. In other words, 1523x better
performance.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Stable-dep-of: b022f0c7e404 ("tracing/kprobes: Return EADDRNOTAVAIL when func matches several symbols")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/kallsyms.h
kernel/kallsyms.c