[RHEL8,COMMIT] ploop: Acquire mutex in ploop_preresume()

Submitted by Konstantin Khorenko on March 19, 2021, 4:03 p.m.

Details

Message ID 202103191603.12JG3GsA905652@finist-co8.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko March 19, 2021, 4:03 p.m.
The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.9
------>
commit 5bd9d4eeabe2a4b0d1584a1fd652cfa964a71e9d
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Fri Mar 19 19:03:16 2021 +0300

    ploop: Acquire mutex in ploop_preresume()
    
    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;
 }