[RH8,1/2] ploop: Acquire mutex in ploop_preresume()

Submitted by Kirill Tkhai on March 19, 2021, 3:50 p.m.

Details

Message ID 161616903724.244960.11166233773731259958.stgit@localhost.localdomain
State New
Series "Series without cover letter"
Headers show

Commit Message

Kirill Tkhai March 19, 2021, 3:50 p.m.
Close race between "set noresume" and resume.
Also, add READ_ONCE() in ploop_status to underline
we read unlocked.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/md/dm-ploop-target.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 591f583bc324..5ae0c624c8fb 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -265,7 +265,7 @@  static void ploop_status(struct dm_target *ti, status_type_t type,
 	read_lock_irq(&ploop->bat_rwlock);
 	if (ploop->tracking_bitmap)
 		p += sprintf(p, "t");
-	if (ploop->noresume)
+	if (READ_ONCE(ploop->noresume))
 		p += sprintf(p, "n");
 	if (ploop->pb) {
 		if (ploop->pb->alive)
@@ -286,8 +286,10 @@  static int ploop_preresume(struct dm_target *ti)
 	struct ploop *ploop = ti->private;
 	int ret = 0;
 
-	if (READ_ONCE(ploop->noresume))
+	down_read(&ploop->ctl_rwsem);
+	if (ploop->noresume)
 		ret = -EAGAIN;
+	up_read(&ploop->ctl_rwsem);
 	return ret;
 }