[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231229070500.3602712-1-lilingfeng@huaweicloud.com>
Date: Fri, 29 Dec 2023 15:05:00 +0800
From: Li Lingfeng <lilingfeng@...weicloud.com>
To: song@...nel.org
Cc: linux-raid@...r.kernel.org,
linux-kernel@...r.kernel.org,
yukuai3@...wei.com,
linan122@...wei.com,
yi.zhang@...wei.com,
yangerkun@...wei.com,
lilingfeng@...weicloud.com,
lilingfeng3@...wei.com
Subject: [PATCH] md: get rdev->mddev with READ_ONCE()
From: Li Lingfeng <lilingfeng3@...wei.com>
Users may get rdev->mddev by sysfs while rdev is releasing.
So use both READ_ONCE() and WRITE_ONCE() to prevent load/store tearing
and to read/write mddev atomically.
Signed-off-by: Li Lingfeng <lilingfeng3@...wei.com>
---
drivers/md/md.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 9bdd57324c37..3b38a565bffa 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2562,7 +2562,7 @@ static void md_kick_rdev_from_array(struct md_rdev *rdev)
list_del_rcu(&rdev->same_set);
pr_debug("md: unbind<%pg>\n", rdev->bdev);
mddev_destroy_serial_pool(rdev->mddev, rdev);
- rdev->mddev = NULL;
+ WRITE_ONCE(rdev->mddev, NULL);
sysfs_remove_link(&rdev->kobj, "block");
sysfs_put(rdev->sysfs_state);
sysfs_put(rdev->sysfs_unack_badblocks);
@@ -3646,7 +3646,7 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr,
struct kernfs_node *kn = NULL;
bool suspend = false;
ssize_t rv;
- struct mddev *mddev = rdev->mddev;
+ struct mddev *mddev = READ_ONCE(rdev->mddev);
if (!entry->store)
return -EIO;
--
2.39.2
Powered by blists - more mailing lists