From: Mark Rutland <mark.rutland@arm.com>
To: Rong Tao <rtoax@foxmail.com>, peterz@infradead.org
Cc: elver@google.com, linux-kernel@vger.kernel.org,
peterz@infradead.org, rongtao@cestc.cn, tglx@linutronix.de
Subject: Re: [PATCH 2/2] stop_machine: Apply smp_store_release() to multi_stop_data::state
Date: Tue, 24 Oct 2023 12:01:05 +0100 [thread overview]
Message-ID: <ZTej8a0ieBAqjbfn@FVFF77S0Q05N> (raw)
In-Reply-To: <tencent_3B1BE2B20183906E56D9E58C4AE4EBC62806@qq.com>
On Fri, Oct 20, 2023 at 10:43:34PM +0800, Rong Tao wrote:
> From: Rong Tao <rongtao@cestc.cn>
>
> Replace smp_wmb()+WRITE_ONCE() with smp_store_release() and add comment.
>
> Signed-off-by: Rong Tao <rongtao@cestc.cn>
> ---
> kernel/stop_machine.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
> index 268c2e581698..cdf4a3fe0348 100644
> --- a/kernel/stop_machine.c
> +++ b/kernel/stop_machine.c
> @@ -183,8 +183,10 @@ static void set_state(struct multi_stop_data *msdata,
> {
> /* Reset ack counter. */
> atomic_set(&msdata->thread_ack, msdata->num_threads);
> - smp_wmb();
> - WRITE_ONCE(msdata->state, newstate);
> + /* This smp_store_release() pair with READ_ONCE() in multi_cpu_stop().
> + * Avoid potential access multi_stop_data::state race behaviour.
> + */
> + smp_store_release(&msdata->state, newstate);
This doesn't match coding style:
/*
* Block comments should look like this, with a leading '/*' line
* before the text and a traling '*/' line afterwards.
*/
See https://www.kernel.org/doc/html/v4.10/process/coding-style.html#commenting
I don't think the "Avoid potential access multi_stop_data::state race
behaviour." text is all that helpful, and I think we can drop that.
In general, it's unusual to pair a smp_store_release() with READ_ONCE(), and
for that to work it relies on dependency ordering and/or hazarding on the
reader side (e.g. the atomic_dec_and_test() is ordered after the READ_ONCE()
since it's an RMW and there's a control dependency, but a plain read could be
reordered w.r.t. the READ_ONCE()). So we probably need to explain that if we're
going to comment on that smp_store_release().
Peter, might it be worth replacing the READ_ONCE() with smp_load_acquire() at
the same time? I know it's not strictly necessary given the ordering we have
today, but it would at least be obvious.
Mark.
> }
>
> /* Last one to ack a state moves to the next state. */
> --
> 2.41.0
>
next prev parent reply other threads:[~2023-10-24 11:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1697811778.git.rongtao@cestc.cn>
2023-10-20 14:43 ` [PATCH 1/2] stop_machine: Use non-atomic read multi_stop_data::state clearly Rong Tao
2023-10-24 10:46 ` Mark Rutland
2023-10-25 0:37 ` Rong Tao
2023-10-27 11:49 ` Rong Tao
2023-10-20 14:43 ` [PATCH 2/2] stop_machine: Apply smp_store_release() to multi_stop_data::state Rong Tao
2023-10-24 11:01 ` Mark Rutland [this message]
2023-10-25 0:59 ` Rong Tao
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=ZTej8a0ieBAqjbfn@FVFF77S0Q05N \
--to=mark.rutland@arm.com \
--cc=elver@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rongtao@cestc.cn \
--cc=rtoax@foxmail.com \
--cc=tglx@linutronix.de \
/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.