Skip to content

Commit 698bace

Browse files
author
Peter Zijlstra
committed
static_call: Align static_call_is_init() patching condition
The intent is to avoid writing init code after init (because the text might have been freed). The code is needlessly different between jump_label and static_call and not obviously correct. The existing code relies on the fact that the module loader clears the init layout, such that within_module_init() always fails, while jump_label relies on the module state which is more obvious and matches the kernel logic. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Jarkko Sakkinen <[email protected]> Tested-by: Sumit Garg <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 68b1edd commit 698bace

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

kernel/static_call.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
149149
};
150150

151151
for (site_mod = &first; site_mod; site_mod = site_mod->next) {
152+
bool init = system_state < SYSTEM_RUNNING;
152153
struct module *mod = site_mod->mod;
153154

154155
if (!site_mod->sites) {
@@ -168,23 +169,16 @@ void __static_call_update(struct static_call_key *key, void *tramp, void *func)
168169
if (mod) {
169170
stop = mod->static_call_sites +
170171
mod->num_static_call_sites;
172+
init = mod->state == MODULE_STATE_COMING;
171173
}
172174
#endif
173175

174176
for (site = site_mod->sites;
175177
site < stop && static_call_key(site) == key; site++) {
176178
void *site_addr = static_call_addr(site);
177179

178-
if (static_call_is_init(site)) {
179-
/*
180-
* Don't write to call sites which were in
181-
* initmem and have since been freed.
182-
*/
183-
if (!mod && system_state >= SYSTEM_RUNNING)
184-
continue;
185-
if (mod && !within_module_init((unsigned long)site_addr, mod))
186-
continue;
187-
}
180+
if (!init && static_call_is_init(site))
181+
continue;
188182

189183
if (!kernel_text_address((unsigned long)site_addr)) {
190184
WARN_ONCE(1, "can't patch static call site at %pS",

0 commit comments

Comments
 (0)