Skip to content

Commit 9cb3735

Browse files
Zhen Leimcgrof
Zhen Lei
authored andcommitted
livepatch: Use kallsyms_on_each_match_symbol() to improve performance
Based on the test results of kallsyms_on_each_match_symbol() and kallsyms_on_each_symbol(), the average performance can be improved by more than 1500 times. Signed-off-by: Zhen Lei <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]>
1 parent 4dc533e commit 9cb3735

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

kernel/livepatch/core.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,24 @@ static int klp_find_callback(void *data, const char *name,
153153
return 0;
154154
}
155155

156+
static int klp_match_callback(void *data, unsigned long addr)
157+
{
158+
struct klp_find_arg *args = data;
159+
160+
args->addr = addr;
161+
args->count++;
162+
163+
/*
164+
* Finish the search when the symbol is found for the desired position
165+
* or the position is not defined for a non-unique symbol.
166+
*/
167+
if ((args->pos && (args->count == args->pos)) ||
168+
(!args->pos && (args->count > 1)))
169+
return 1;
170+
171+
return 0;
172+
}
173+
156174
static int klp_find_object_symbol(const char *objname, const char *name,
157175
unsigned long sympos, unsigned long *addr)
158176
{
@@ -167,7 +185,7 @@ static int klp_find_object_symbol(const char *objname, const char *name,
167185
if (objname)
168186
module_kallsyms_on_each_symbol(klp_find_callback, &args);
169187
else
170-
kallsyms_on_each_symbol(klp_find_callback, &args);
188+
kallsyms_on_each_match_symbol(klp_match_callback, name, &args);
171189

172190
/*
173191
* Ensure an address was found. If sympos is 0, ensure symbol is unique;

0 commit comments

Comments
 (0)