Skip to contentSkip to conversation

jump_label: explicitly annotate inittext labels as init

PATCH Superseded Alexander Gordeev 2 participants 6 messages Dec 9, 2022 Static branch/call

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 jump_label: explicitly annotate inittext labels as init

inittext code may be out of [__init_begin, __init_end] range on some architectures. Yet, the jump_label_init() only calls init_section_contains() function to check if a label needs to be annotated as init and inittext code is left behind.

Fixes 19483677684b ("jump_label: Annotate entries that operate on __init code earlier")
---
 kernel/jump_label.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/jump_label.c +4 -1
index 714ac4c3b556..77680665d374 100644
@@ -481,13 +481,16 @@ void __init jump_label_init(void)
 
 	for (iter = iter_start; iter < iter_stop; iter++) {
 		struct static_key *iterk;
+		unsigned long addr;
 		bool in_init;
 
 		/* rewrite NOPs */
 		if (jump_label_type(iter) == JUMP_LABEL_NOP)
 			arch_jump_label_transform_static(iter, JUMP_LABEL_NOP);
 
-		in_init = init_section_contains((void *)jump_entry_code(iter), 1);
+		addr = jump_entry_code(iter);
+		in_init = init_section_contains((void *)addr, 1) ||
+			  is_kernel_inittext(addr);
 		jump_entry_set_init(iter, in_init);
 
 		iterk = jump_entry_key(iter);
Signature · 1 line
2.34.1
#1 lore raw
Quoted 22 lines · Alexander Gordeev

inittext code may be out of [__init_begin, __init_end] range on some architectures. Yet, the jump_label_init() only calls init_section_contains() function to check if a label needs to be annotated as init and inittext code is left behind.

Fixes 19483677684b ("jump_label: Annotate entries that operate on __init code earlier")
---
 kernel/jump_label.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/jump_label.c +1 -0
index 714ac4c3b556..77680665d374 100644
@@ -481,13 +481,16 @@ void __init jump_label_init(void)
 
        for (iter = iter_start; iter < iter_stop; iter++) {
                struct static_key *iterk;
+               unsigned long addr;

kernel/jump_label.c void __init jump_label_init(void) · line 493

Quoted 10 lines
kernel/jump_label.c +3 -1
                bool in_init;
 
                /* rewrite NOPs */
                if (jump_label_type(iter) == JUMP_LABEL_NOP)
                        arch_jump_label_transform_static(iter, JUMP_LABEL_NOP);
 
-               in_init = init_section_contains((void *)jump_entry_code(iter), 1);
+               addr = jump_entry_code(iter);
+               in_init = init_section_contains((void *)addr, 1) ||
+                         is_kernel_inittext(addr);

Isn't it sufficient to only call is_kenel_inittext here?

Quoted 6 lines
kernel/jump_label.c +0 -1
                jump_entry_set_init(iter, in_init);
 
                iterk = jump_entry_key(iter);
--

2.34.1

#2 lore raw
Quoted 15 lines · Ard Biesheuvel
Quoted 15 lines
kernel/jump_label.c +1 -0
index 714ac4c3b556..77680665d374 100644
@@ -481,13 +481,16 @@ void __init jump_label_init(void)
 
        for (iter = iter_start; iter < iter_stop; iter++) {
                struct static_key *iterk;
+               unsigned long addr;
                bool in_init;
 
                /* rewrite NOPs */
                if (jump_label_type(iter) == JUMP_LABEL_NOP)
                        arch_jump_label_transform_static(iter, JUMP_LABEL_NOP);
 
Quoted 6 lines

kernel/jump_label.c void __init jump_label_init(void) · line 493

Quoted 4 lines
kernel/jump_label.c +3 -1
-               in_init = init_section_contains((void *)jump_entry_code(iter), 1);
+               addr = jump_entry_code(iter);
+               in_init = init_section_contains((void *)addr, 1) ||
+                         is_kernel_inittext(addr);

Isn't it sufficient to only call is_kenel_inittext here?

I am not sure every arch out there would stick to putting init code to inittext only.

However, should not is_kernel_exittext() (which does not exist) also get checked here?

#3 lore raw
Quoted 24 lines · Alexander Gordeev
Quoted 15 lines · Ard Biesheuvel
Quoted 15 lines
kernel/jump_label.c +1 -0
index 714ac4c3b556..77680665d374 100644
@@ -481,13 +481,16 @@ void __init jump_label_init(void)
 
        for (iter = iter_start; iter < iter_stop; iter++) {
                struct static_key *iterk;
+               unsigned long addr;
                bool in_init;
 
                /* rewrite NOPs */
                if (jump_label_type(iter) == JUMP_LABEL_NOP)
                        arch_jump_label_transform_static(iter, JUMP_LABEL_NOP);
 
Quoted 6 lines

kernel/jump_label.c void __init jump_label_init(void) · line 493

Quoted 4 lines
kernel/jump_label.c +3 -1
-               in_init = init_section_contains((void *)jump_entry_code(iter), 1);
+               addr = jump_entry_code(iter);
+               in_init = init_section_contains((void *)addr, 1) ||
+                         is_kernel_inittext(addr);

Isn't it sufficient to only call is_kenel_inittext here?

Quoted 5 lines

I am not sure every arch out there would stick to putting init code to inittext only.

However, should not is_kernel_exittext() (which does not exist) also get checked here?

No, exittext either exists or it doesn't, rather than disappearing at runtime like inittext.

#4 lore raw
Quoted 25 lines · Ard Biesheuvel
Quoted 24 lines · Alexander Gordeev
Quoted 21 lines · Ard Biesheuvel
Quoted 9 lines
kernel/jump_label.c +1 -0
index 714ac4c3b556..77680665d374 100644
@@ -481,13 +481,16 @@ void __init jump_label_init(void)
 
        for (iter = iter_start; iter < iter_stop; iter++) {
                struct static_key *iterk;
+               unsigned long addr;

kernel/jump_label.c void __init jump_label_init(void) · line 493

Quoted 10 lines
kernel/jump_label.c +3 -1
                bool in_init;
 
                /* rewrite NOPs */
                if (jump_label_type(iter) == JUMP_LABEL_NOP)
                        arch_jump_label_transform_static(iter, JUMP_LABEL_NOP);
 
-               in_init = init_section_contains((void *)jump_entry_code(iter), 1);
+               addr = jump_entry_code(iter);
+               in_init = init_section_contains((void *)addr, 1) ||
+                         is_kernel_inittext(addr);

Isn't it sufficient to only call is_kenel_inittext here?

Quoted 8 lines
Quoted 5 lines

I am not sure every arch out there would stick to putting init code to inittext only.

However, should not is_kernel_exittext() (which does not exist) also get checked here?

No, exittext either exists or it doesn't, rather than disappearing at runtime like inittext.

May be just swap the order of init_section_contains() and is_kernel_inittext() checks then?

#5 lore raw
Quoted 30 lines · Alexander Gordeev
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Alexander Gordeev
Quoted 15 lines · Ard Biesheuvel
Quoted 15 lines
kernel/jump_label.c +1 -0
index 714ac4c3b556..77680665d374 100644
@@ -481,13 +481,16 @@ void __init jump_label_init(void)
 
        for (iter = iter_start; iter < iter_stop; iter++) {
                struct static_key *iterk;
+               unsigned long addr;
                bool in_init;
 
                /* rewrite NOPs */
                if (jump_label_type(iter) == JUMP_LABEL_NOP)
                        arch_jump_label_transform_static(iter, JUMP_LABEL_NOP);
 
Quoted 6 lines

kernel/jump_label.c void __init jump_label_init(void) · line 493

Quoted 4 lines
kernel/jump_label.c +3 -1
-               in_init = init_section_contains((void *)jump_entry_code(iter), 1);
+               addr = jump_entry_code(iter);
+               in_init = init_section_contains((void *)addr, 1) ||
+                         is_kernel_inittext(addr);

Isn't it sufficient to only call is_kenel_inittext here?

I am not sure every arch out there would stick to putting init code to inittext only.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

However, should not is_kernel_exittext() (which does not exist) also get checked here?

No, exittext either exists or it doesn't, rather than disappearing at runtime like inittext.

May be just swap the order of init_section_contains() and is_kernel_inittext() checks then?

No I don't think we need both.