Re: [PATCH 3/3] static_call: Fix static_call_update() sanity check

From: Jessica Yu
Date: Mon Mar 22 2021 - 10:52:32 EST

+++ Steven Rostedt [19/03/21 16:57 -0400]:
On Fri, 19 Mar 2021 20:34:24 +0100
Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:

On Fri, Mar 19, 2021 at 02:00:05PM -0400, Steven Rostedt wrote:
> Would making __exit code the same as init code work? That is, load it just
> like module init code is loaded, and free it when the init code is freed

As stated, yes. But it must then also identify as init through

I think that's doable. Since the usecases for that appear to be mostly
about "think code may no longer exist after it is used". Thus, having exit
code act just like init code when UNLOAD is not set, appears appropriate.

Jessica, please correct me if I'm wrong.

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.


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");
+ return strstarts(name, ".init") || module_exit_section(name);
+ return strstarts(name, ".init")

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;

- /* Don't load .exit sections */
- if (module_exit_section(info->secstrings+shdr->sh_name))
- shdr->sh_flags &= ~(unsigned long)SHF_ALLOC;

/* Track but don't keep modinfo and version sections. */