[PATCH 2/2] stop_machine: Apply smp_store_release() to multi_stop_data::state

From: Rong Tao
Date: Fri Oct 20 2023 - 10:57:16 EST


From: Rong Tao <rongtao@xxxxxxxx>

Replace smp_wmb()+WRITE_ONCE() with smp_store_release() and add comment.

Signed-off-by: Rong Tao <rongtao@xxxxxxxx>
---
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);
}

/* Last one to ack a state moves to the next state. */
--
2.41.0