All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] jump_label: explicitly annotate inittext labels as init
@ 2022-12-09  6:07 Alexander Gordeev
  2022-12-09  9:41 ` Ard Biesheuvel
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Gordeev @ 2022-12-09  6:07 UTC (permalink / raw)
  To: Ard Biesheuvel, Peter Zijlstra, Josh Poimboeuf, Jason Baron; +Cc: linux-kernel

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")
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
---
 kernel/jump_label.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index 714ac4c3b556..77680665d374 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] jump_label: explicitly annotate inittext labels as init
  2022-12-09  6:07 [PATCH] jump_label: explicitly annotate inittext labels as init Alexander Gordeev
@ 2022-12-09  9:41 ` Ard Biesheuvel
  2022-12-09 12:48   ` Alexander Gordeev
  0 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2022-12-09  9:41 UTC (permalink / raw)
  To: Alexander Gordeev
  Cc: Peter Zijlstra, Josh Poimboeuf, Jason Baron, linux-kernel

On Fri, 9 Dec 2022 at 07:08, Alexander Gordeev <agordeev@linux.ibm.com> wrote:
>
> 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")
> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
> ---
>  kernel/jump_label.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/jump_label.c b/kernel/jump_label.c
> index 714ac4c3b556..77680665d374 100644
> --- a/kernel/jump_label.c
> +++ b/kernel/jump_label.c
> @@ -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);

Isn't it sufficient to only call is_kenel_inittext here?

>                 jump_entry_set_init(iter, in_init);
>
>                 iterk = jump_entry_key(iter);
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] jump_label: explicitly annotate inittext labels as init
  2022-12-09  9:41 ` Ard Biesheuvel
@ 2022-12-09 12:48   ` Alexander Gordeev
  2022-12-09 13:48     ` Ard Biesheuvel
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Gordeev @ 2022-12-09 12:48 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: Peter Zijlstra, Josh Poimboeuf, Jason Baron, linux-kernel

On Fri, Dec 09, 2022 at 10:41:55AM +0100, Ard Biesheuvel wrote:
> > diff --git a/kernel/jump_label.c b/kernel/jump_label.c
> > index 714ac4c3b556..77680665d374 100644
> > --- a/kernel/jump_label.c
> > +++ b/kernel/jump_label.c
> > @@ -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);
> 
> 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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] jump_label: explicitly annotate inittext labels as init
  2022-12-09 12:48   ` Alexander Gordeev
@ 2022-12-09 13:48     ` Ard Biesheuvel
  2022-12-09 14:48       ` Alexander Gordeev
  0 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2022-12-09 13:48 UTC (permalink / raw)
  To: Alexander Gordeev
  Cc: Peter Zijlstra, Josh Poimboeuf, Jason Baron, linux-kernel

On Fri, 9 Dec 2022 at 13:49, Alexander Gordeev <agordeev@linux.ibm.com> wrote:
>
> On Fri, Dec 09, 2022 at 10:41:55AM +0100, Ard Biesheuvel wrote:
> > > diff --git a/kernel/jump_label.c b/kernel/jump_label.c
> > > index 714ac4c3b556..77680665d374 100644
> > > --- a/kernel/jump_label.c
> > > +++ b/kernel/jump_label.c
> > > @@ -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);
> >
> > 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?

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] jump_label: explicitly annotate inittext labels as init
  2022-12-09 13:48     ` Ard Biesheuvel
@ 2022-12-09 14:48       ` Alexander Gordeev
  2022-12-09 14:49         ` Ard Biesheuvel
  0 siblings, 1 reply; 6+ messages in thread
From: Alexander Gordeev @ 2022-12-09 14:48 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: Peter Zijlstra, Josh Poimboeuf, Jason Baron, linux-kernel

On Fri, Dec 09, 2022 at 02:48:49PM +0100, Ard Biesheuvel wrote:
> On Fri, 9 Dec 2022 at 13:49, Alexander Gordeev <agordeev@linux.ibm.com> wrote:
> >
> > On Fri, Dec 09, 2022 at 10:41:55AM +0100, Ard Biesheuvel wrote:
> > > > diff --git a/kernel/jump_label.c b/kernel/jump_label.c
> > > > index 714ac4c3b556..77680665d374 100644
> > > > --- a/kernel/jump_label.c
> > > > +++ b/kernel/jump_label.c
> > > > @@ -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);
> > >
> > > 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?
> 
> 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?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] jump_label: explicitly annotate inittext labels as init
  2022-12-09 14:48       ` Alexander Gordeev
@ 2022-12-09 14:49         ` Ard Biesheuvel
  0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2022-12-09 14:49 UTC (permalink / raw)
  To: Alexander Gordeev
  Cc: Peter Zijlstra, Josh Poimboeuf, Jason Baron, linux-kernel

On Fri, 9 Dec 2022 at 15:48, Alexander Gordeev <agordeev@linux.ibm.com> wrote:
>
> On Fri, Dec 09, 2022 at 02:48:49PM +0100, Ard Biesheuvel wrote:
> > On Fri, 9 Dec 2022 at 13:49, Alexander Gordeev <agordeev@linux.ibm.com> wrote:
> > >
> > > On Fri, Dec 09, 2022 at 10:41:55AM +0100, Ard Biesheuvel wrote:
> > > > > diff --git a/kernel/jump_label.c b/kernel/jump_label.c
> > > > > index 714ac4c3b556..77680665d374 100644
> > > > > --- a/kernel/jump_label.c
> > > > > +++ b/kernel/jump_label.c
> > > > > @@ -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);
> > > >
> > > > 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?
> >
> > 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-09 14:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09  6:07 [PATCH] jump_label: explicitly annotate inittext labels as init Alexander Gordeev
2022-12-09  9:41 ` Ard Biesheuvel
2022-12-09 12:48   ` Alexander Gordeev
2022-12-09 13:48     ` Ard Biesheuvel
2022-12-09 14:48       ` Alexander Gordeev
2022-12-09 14:49         ` Ard Biesheuvel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.