All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org, jpoimboe@redhat.com, jbaron@akamai.com,
	rostedt@goodmis.org, ardb@kernel.org,
	linux-kernel@vger.kernel.org, sumit.garg@linaro.org,
	oliver.sang@intel.com, jarkko@kernel.org
Subject: Re: [PATCH 2/3] static_call: Align static_call_is_init() patching condition
Date: Fri, 19 Mar 2021 16:44:36 +0100	[thread overview]
Message-ID: <34ceee59-4276-90b5-871b-cda303901ce3@rasmusvillemoes.dk> (raw)
In-Reply-To: <c4e9dfdf-c83a-3314-8c55-5b2371a56ec8@rasmusvillemoes.dk>

On 19/03/2021 15.40, Rasmus Villemoes wrote:
> On 19/03/2021 15.13, Peter Zijlstra wrote:
> 
>>> Dunno, probably overkill, but perhaps we could have an atomic_t (or
>>> refcount, whatever) init_ref inited to 1, with init_ref_get() doing an
>>> inc_unless_zero, and iff you get a ref, you're free to call (/patch)
>>> __init functions and access __initdata, but must do init_ref_put(), with
>>> PID1 dropping its initial ref and waiting for it to drop to 0 before
>>> doing the *free_initmem() calls.
>>
>> I'd as soon simply add another SYSTEM state. That way we don't have to
>> worry about who else looks at RUNNING for what etc..
> 
> I don't understand. How would that solve the
> 
> PID1                           PIDX
>                                ok = system_state < INIT_MEM_GONE;
> system_state = INIT_MEM_GONE;
> free_initmem();
> system_state = RUNNING;
>                                if (ok)
>                                    poke init mem
> 
> race? I really don't see any way arbitrary threads can reliably check
> how far PID1 has progressed at one point in time and use that
> information (a few lines) later to access init memory without
> synchronizing with PID1.
> 
> AFAICT, having an atomic_t object representing the init memory 

something like

--- a/init/main.c
+++ b/init/main.c
@@ -1417,6 +1417,18 @@ void __weak free_initmem(void)
        free_initmem_default(POISON_FREE_INITMEM);
 }

+static atomic_t init_mem_ref = ATOMIC_INIT(1);
+static DECLARE_COMPLETION(init_mem_may_go);
+bool init_mem_get(void)
+{
+       return atomic_inc_not_zero(&init_mem_ref);
+}
+void init_mem_put(void)
+{
+       if (atomic_dec_and_test(&init_mem_ref))
+               complete(&init_mem_may_go);
+}
+
 static int __ref kernel_init(void *unused)
 {
        int ret;
@@ -1424,6 +1436,8 @@ static int __ref kernel_init(void *unused)
        kernel_init_freeable();
        /* need to finish all async __init code before freeing the memory */
        async_synchronize_full();
+       init_mem_put();
+       wait_for_completion(&init_mem_may_go);
        kprobe_free_init_mem();
        ftrace_free_init_mem();
        kgdb_free_init_mem();


  reply	other threads:[~2021-03-19 15:45 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 [this message]
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
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=34ceee59-4276-90b5-871b-cda303901ce3@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=ardb@kernel.org \
    --cc=jarkko@kernel.org \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oliver.sang@intel.com \
    --cc=peterz@infradead.org \
    --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 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.