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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:   Fri, 27 Oct 2023 19:44:20 +0800
From:   Rong Tao <rtoax@...mail.com>
To:     mark.rutland@....com, elver@...gle.com,
        linux-kernel@...r.kernel.org, peterz@...radead.org
Cc:     rongtao@...tc.cn, rtoax@...mail.com, tglx@...utronix.de
Subject: [PATCH v4] stop_machine: pass curstate to ack_state()

From: Rong Tao <rongtao@...tc.cn>

The multi_cpu_stop() state machine uses multi_stop_data::state to hold
the current state, and this is read and written atomically except in
ack_state(), which performs a non-atomic read.

As ack_state() only performs this non-atomic read when there is a single
writer, this is benign, but it makes reasoning about the state machine a
little harder.

Remove the non-atomic read and pass the (atomically read) curstate in
instead. This makes it clear that we do not expect any racy writes, and
avoids a redundant load.

Acked-by: Mark Rutland <mark.rutland@....com>
Signed-off-by: Rong Tao <rongtao@...tc.cn>
---
v4: This patch, modify comment words according to [0].
    [0] https://lore.kernel.org/lkml/ZTegiFbGQUAp1l0p@FVFF77S0Q05N/
v3: Only pass curstate to ack_state(), it's one of patchset([1/2])
    https://lore.kernel.org/lkml/tencent_49AFDBA31F885906234219591097D42ABE08@qq.com/
v2: Pass curstate to ack_state() and apply smp_store_release()
    https://lore.kernel.org/lkml/tencent_4CD220721A6C0B39670D5D52AAE4BD2A8F0A@qq.com/
v1: Just add READ_ONCE()
    https://lore.kernel.org/lkml/tencent_705C16DF25978ACAEBD1E83E228881901006@qq.com/
---
 kernel/stop_machine.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index cedb17ba158a..268c2e581698 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -188,10 +188,11 @@ static void set_state(struct multi_stop_data *msdata,
 }
 
 /* Last one to ack a state moves to the next state. */
-static void ack_state(struct multi_stop_data *msdata)
+static void ack_state(struct multi_stop_data *msdata,
+		      enum multi_stop_state curstate)
 {
 	if (atomic_dec_and_test(&msdata->thread_ack))
-		set_state(msdata, msdata->state + 1);
+		set_state(msdata, curstate + 1);
 }
 
 notrace void __weak stop_machine_yield(const struct cpumask *cpumask)
@@ -242,7 +243,7 @@ static int multi_cpu_stop(void *data)
 			default:
 				break;
 			}
-			ack_state(msdata);
+			ack_state(msdata, curstate);
 		} else if (curstate > MULTI_STOP_PREPARE) {
 			/*
 			 * At this stage all other CPUs we depend on must spin
-- 
2.42.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ