lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZTej8a0ieBAqjbfn@FVFF77S0Q05N>
Date:   Tue, 24 Oct 2023 12:01:05 +0100
From:   Mark Rutland <mark.rutland@....com>
To:     Rong Tao <rtoax@...mail.com>, peterz@...radead.org
Cc:     elver@...gle.com, linux-kernel@...r.kernel.org,
        peterz@...radead.org, rongtao@...tc.cn, tglx@...utronix.de
Subject: Re: [PATCH 2/2] stop_machine: Apply smp_store_release() to
 multi_stop_data::state

On Fri, Oct 20, 2023 at 10:43:34PM +0800, Rong Tao wrote:
> From: Rong Tao <rongtao@...tc.cn>
> 
> Replace smp_wmb()+WRITE_ONCE() with smp_store_release() and add comment.
> 
> Signed-off-by: Rong Tao <rongtao@...tc.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
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ