linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Jessica Yu <jeyu@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	x86@kernel.org, jbaron@akamai.com, ardb@kernel.org,
	linux-kernel@vger.kernel.org, sumit.garg@linaro.org,
	oliver.sang@intel.com, jarkko@kernel.org
Subject: Re: [PATCH 3/3] static_call: Fix static_call_update() sanity check
Date: Mon, 22 Mar 2021 17:54:00 +0100	[thread overview]
Message-ID: <YFjLqKV9GxGSXcAr@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <YFiuphGw0RKehWsQ@gunter>

On Mon, Mar 22, 2021 at 03:50:14PM +0100, Jessica Yu wrote:

> It should be doable. If you want the exit sections to be treated the same as
> module init, the following patch should stuff any exit sections into the module
> init "region" (completely untested). Hence it should be freed together with the
> init sections and it would identify as init through within_module_init(). Let
> me know if this works for you.

That does indeed seem to DTRT from a quick scan of module.c. Very nice
tidy patch. I was afraid it'd be much worse.

Assuming it actually works; for your Changelog:

"Dynamic code patching (alternatives, jump_label and static_call) can
have sites in __exit code, even it __exit is never executed. Therefore
__exit must be present at runtime, at least for as long as __init code
is.

Additionally, for jump_label and static_call, the __exit sites must also
identify as within_module_init(), such that the infrastructure is aware
to never touch them after module init -- alternatives are only ran once
at init and hence don't have this particular constraint.

By making __exit identify as __init for UNLOAD_MODULE, the above is
satisfied."

Thanks!

> ---
> 
> diff --git a/kernel/module.c b/kernel/module.c
> index 30479355ab85..1c3396a9dd8b 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -2802,7 +2802,11 @@ void * __weak module_alloc(unsigned long size)
> 
>  bool __weak module_init_section(const char *name)
>  {
> -       return strstarts(name, ".init");
> +#ifndef CONFIG_UNLOAD_MODULE
> +       return strstarts(name, ".init") || module_exit_section(name);
> +#else
> +       return strstarts(name, ".init")
> +#endif
>  }
> 
>  bool __weak module_exit_section(const char *name)
> @@ -3116,11 +3120,6 @@ static int rewrite_section_headers(struct load_info *info, int flags)
>                  */
>                 shdr->sh_addr = (size_t)info->hdr + shdr->sh_offset;
> 
> -#ifndef CONFIG_MODULE_UNLOAD
> -               /* Don't load .exit sections */
> -               if (module_exit_section(info->secstrings+shdr->sh_name))
> -                       shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;
> -#endif
>         }
> 
>         /* Track but don't keep modinfo and version sections. */
> 

  reply	other threads:[~2021-03-22 16:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 11:31 [PATCH 0/3] static_call() vs __exit fixes Peter Zijlstra
2021-03-18 11:31 ` [PATCH 1/3] static_call: Fix static_call_set_init() Peter Zijlstra
2021-03-19 12:25   ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra
2021-03-18 11:31 ` [PATCH 2/3] static_call: Align static_call_is_init() patching condition Peter Zijlstra
2021-03-19 12:25   ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra
2021-03-19 13:31   ` [PATCH 2/3] " Rasmus Villemoes
2021-03-19 14:13     ` Peter Zijlstra
2021-03-19 14:40       ` Rasmus Villemoes
2021-03-19 15:44         ` Rasmus Villemoes
2021-03-22 16:59         ` Peter Zijlstra
2021-03-18 11:31 ` [PATCH 3/3] static_call: Fix static_call_update() sanity check Peter Zijlstra
2021-03-18 11:42   ` Peter Zijlstra
2021-03-18 16:13   ` Josh Poimboeuf
2021-03-18 16:58     ` Peter Zijlstra
2021-03-19 12:57       ` Peter Zijlstra
2021-03-19 18:00         ` Steven Rostedt
2021-03-19 19:34           ` Peter Zijlstra
2021-03-19 20:57             ` Steven Rostedt
2021-03-22 14:50               ` Jessica Yu
2021-03-22 16:54                 ` Peter Zijlstra [this message]
2021-03-22 17:36                   ` Jessica Yu
2021-03-22 13:07           ` Jessica Yu
2021-03-22 14:06             ` Peter Zijlstra
2021-03-19 12:25   ` [tip: locking/urgent] " tip-bot2 for Peter Zijlstra
2021-03-18 12:15 ` [PATCH 0/3] static_call() vs __exit fixes Sumit Garg
2021-03-18 19:38 ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YFjLqKV9GxGSXcAr@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ardb@kernel.org \
    --cc=jarkko@kernel.org \
    --cc=jbaron@akamai.com \
    --cc=jeyu@kernel.org \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver.sang@intel.com \
    --cc=rostedt@goodmis.org \
    --cc=sumit.garg@linaro.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).