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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230402091236.976723-4-yukuai1@huaweicloud.com>
Date:   Sun,  2 Apr 2023 17:12:34 +0800
From:   Yu Kuai <yukuai1@...weicloud.com>
To:     logang@...tatee.com, song@...nel.org
Cc:     linux-kernel@...r.kernel.org, linux-raid@...r.kernel.org,
        yukuai3@...wei.com, yukuai1@...weicloud.com, yi.zhang@...wei.com,
        yangerkun@...wei.com
Subject: [PATCH v4 3/5] md: add a helper to access md_thread() directly

From: Yu Kuai <yukuai3@...wei.com>

In some context it's safe to access md_thread directly without
protection, this patch add a helper to do that. There are no functional
changes, prepare to protect md_thread with rcu.

Signed-off-by: Yu Kuai <yukuai3@...wei.com>
---
 drivers/md/md-bitmap.c   | 7 ++++---
 drivers/md/md.c          | 4 +++-
 drivers/md/md.h          | 6 ++++++
 drivers/md/raid10.c      | 2 +-
 drivers/md/raid5-cache.c | 7 ++++---
 5 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index e7cc6ba1b657..f670c72d97be 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -1246,7 +1246,7 @@ void md_bitmap_daemon_work(struct mddev *mddev)
 
 	bitmap->daemon_lastrun = jiffies;
 	if (bitmap->allclean) {
-		mddev->thread->timeout = MAX_SCHEDULE_TIMEOUT;
+		get_md_thread(mddev->thread)->timeout = MAX_SCHEDULE_TIMEOUT;
 		goto done;
 	}
 	bitmap->allclean = 1;
@@ -1343,7 +1343,7 @@ void md_bitmap_daemon_work(struct mddev *mddev)
 
  done:
 	if (bitmap->allclean == 0)
-		mddev->thread->timeout =
+		get_md_thread(mddev->thread)->timeout =
 			mddev->bitmap_info.daemon_sleep;
 	mutex_unlock(&mddev->bitmap_info.mutex);
 }
@@ -1941,7 +1941,8 @@ int md_bitmap_load(struct mddev *mddev)
 	/* Kick recovery in case any bits were set */
 	set_bit(MD_RECOVERY_NEEDED, &bitmap->mddev->recovery);
 
-	mddev->thread->timeout = mddev->bitmap_info.daemon_sleep;
+	get_md_thread(mddev->thread)->timeout =
+				mddev->bitmap_info.daemon_sleep;
 	md_wakeup_thread(mddev->thread);
 
 	md_bitmap_update_sb(bitmap);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 139c7b0202e3..d5a29ccb24ec 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -458,7 +458,9 @@ static void md_submit_bio(struct bio *bio)
  */
 void mddev_suspend(struct mddev *mddev)
 {
-	WARN_ON_ONCE(mddev->thread && current == mddev->thread->tsk);
+	struct md_thread *thread = get_md_thread(mddev->thread);
+
+	WARN_ON_ONCE(thread && current == thread->tsk);
 	lockdep_assert_held(&mddev->reconfig_mutex);
 	if (mddev->suspended++)
 		return;
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 344e055e4d0f..5acdd704a922 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -718,6 +718,12 @@ struct md_io_acct {
 
 #define THREAD_WAKEUP  0
 
+/* caller need to make sured returned md_thread won't be freed */
+static inline struct md_thread *get_md_thread(struct md_thread *t)
+{
+	return t;
+}
+
 static inline void safe_put_page(struct page *p)
 {
 	if (p) put_page(p);
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 0171ba4f19b0..fc8d07fb1c7d 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -996,7 +996,7 @@ static bool stop_waiting_barrier(struct r10conf *conf)
 		return true;
 
 	/* move on if recovery thread is blocked by us */
-	if (conf->mddev->thread->tsk == current &&
+	if (get_md_thread(conf->mddev->thread)->tsk == current &&
 	    test_bit(MD_RECOVERY_RUNNING, &conf->mddev->recovery) &&
 	    conf->nr_queued > 0)
 		return true;
diff --git a/drivers/md/raid5-cache.c b/drivers/md/raid5-cache.c
index 0464d4d551fc..7e45df3e093f 100644
--- a/drivers/md/raid5-cache.c
+++ b/drivers/md/raid5-cache.c
@@ -1582,11 +1582,11 @@ void r5l_quiesce(struct r5l_log *log, int quiesce)
 		/* make sure r5l_write_super_and_discard_space exits */
 		mddev = log->rdev->mddev;
 		wake_up(&mddev->sb_wait);
-		kthread_park(log->reclaim_thread->tsk);
+		kthread_park(get_md_thread(log->reclaim_thread)->tsk);
 		r5l_wake_reclaim(log, MaxSector);
 		r5l_do_reclaim(log);
 	} else
-		kthread_unpark(log->reclaim_thread->tsk);
+		kthread_unpark(get_md_thread(log->reclaim_thread)->tsk);
 }
 
 bool r5l_log_disk_error(struct r5conf *conf)
@@ -3124,7 +3124,8 @@ int r5l_init_log(struct r5conf *conf, struct md_rdev *rdev)
 	if (md_register_thread(&log->reclaim_thread, r5l_reclaim_thread,
 			       log->rdev->mddev, "reclaim"))
 		goto reclaim_thread;
-	log->reclaim_thread->timeout = R5C_RECLAIM_WAKEUP_INTERVAL;
+	get_md_thread(log->reclaim_thread)->timeout =
+				R5C_RECLAIM_WAKEUP_INTERVAL;
 
 	init_waitqueue_head(&log->iounit_wait);
 
-- 
2.39.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ