Linux RAID subsystem development
 help / color / mirror / Atom feed
From: Zizhi Wo <wozizhi@huawei.com>
To: <song@kernel.org>, <yukuai@fygo.io>, <magiclinan@didiglobal.com>,
	<xiao@kernel.org>, <linux-raid@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <yangerkun@huawei.com>,
	<chengzhihao1@huawei.com>, <wozizhi@huawei.com>
Subject: [PATCH V2 1/2] md/raid10: annotate lockless access to array_freeze_pending
Date: Mon, 17 Aug 2026 11:33:39 +0800	[thread overview]
Message-ID: <20260817033340.418119-2-wozizhi@huawei.com> (raw)
In-Reply-To: <20260817033340.418119-1-wozizhi@huawei.com>

conf->array_freeze_pending is updated under conf->resync_lock in
freeze_array(), but read locklessly in allow_barrier(). Annotate these
accesses with READ_ONCE()/WRITE_ONCE() to document the intentional lockless
access and to prevent load/store tearing or fusing by the compiler. No
functional change.

Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
---
 drivers/md/raid10.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 0a3cfdd3f5df..dc40110a6736 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1031,11 +1031,11 @@ static bool wait_barrier(struct r10conf *conf, bool nowait)
 }
 
 static void allow_barrier(struct r10conf *conf)
 {
 	if ((atomic_dec_and_test(&conf->nr_pending)) ||
-			(conf->array_freeze_pending))
+	    READ_ONCE(conf->array_freeze_pending))
 		wake_up_barrier(conf);
 }
 
 static void freeze_array(struct r10conf *conf, int extra)
 {
@@ -1050,16 +1050,16 @@ static void freeze_array(struct r10conf *conf, int extra)
 	 * Thus the number queued (nr_queued) plus this request (extra)
 	 * must match the number of pending IOs (nr_pending) before
 	 * we continue.
 	 */
 	write_seqlock_irq(&conf->resync_lock);
-	conf->array_freeze_pending++;
+	WRITE_ONCE(conf->array_freeze_pending, conf->array_freeze_pending + 1);
 	WRITE_ONCE(conf->barrier, conf->barrier + 1);
 	conf->nr_waiting++;
 	wait_event_barrier_cmd(conf, atomic_read(&conf->nr_pending) ==
 			conf->nr_queued + extra, flush_pending_writes(conf));
-	conf->array_freeze_pending--;
+	WRITE_ONCE(conf->array_freeze_pending, conf->array_freeze_pending - 1);
 	write_sequnlock_irq(&conf->resync_lock);
 }
 
 static void unfreeze_array(struct r10conf *conf)
 {
-- 
2.52.0


  reply	other threads:[~2026-08-17  3:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17  3:33 [PATCH V2 0/2] md/raid10: annotate lockless access and fix hungtask Zizhi Wo
2026-08-17  3:33 ` Zizhi Wo [this message]
2026-08-17  3:33 ` [PATCH V2 2/2] md/raid10: fix missing wakeup in wait_barrier_nolock Zizhi Wo
2026-08-17 10:53   ` Abd-Alrhman Masalkhi

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=20260817033340.418119-2-wozizhi@huawei.com \
    --to=wozizhi@huawei.com \
    --cc=chengzhihao1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=song@kernel.org \
    --cc=xiao@kernel.org \
    --cc=yangerkun@huawei.com \
    --cc=yukuai@fygo.io \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox