Skip to content

Commit 071c95c

Browse files
BenjaminGrayNp1mpe
authored andcommitted
powerpc/code-patching: Use WARN_ON and fix check in poking_init
BUG_ON() when failing to initialise the code patching window is unnecessary, and use of BUG_ON is discouraged. We don't set poking_init_done in this case, so failure to init the boot CPU will result in a strict RWX error when a following patch_instruction uses raw_patch_instruction. If it only fails for later CPUs, they won't be onlined in the first place. The return value of cpuhp_setup_state() is also >= 0 on success, so check for < 0. Signed-off-by: Benjamin Gray <[email protected]> Reviewed-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3671f4e commit 071c95c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

arch/powerpc/lib/code-patching.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ static int text_area_cpu_down(unsigned int cpu)
8181

8282
static __ro_after_init DEFINE_STATIC_KEY_FALSE(poking_init_done);
8383

84-
/*
85-
* Although BUG_ON() is rude, in this case it should only happen if ENOMEM, and
86-
* we judge it as being preferable to a kernel that will crash later when
87-
* someone tries to use patch_instruction().
88-
*/
8984
void __init poking_init(void)
9085
{
91-
BUG_ON(!cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
92-
"powerpc/text_poke:online", text_area_cpu_up,
93-
text_area_cpu_down));
86+
int ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
87+
"powerpc/text_poke:online",
88+
text_area_cpu_up,
89+
text_area_cpu_down);
90+
91+
/* cpuhp_setup_state returns >= 0 on success */
92+
if (WARN_ON(ret < 0))
93+
return;
94+
9495
static_branch_enable(&poking_init_done);
9596
}
9697

0 commit comments

Comments
 (0)