If dm_get_live_table() returned NULL, dm_put_live_table() was never
called.  Also, if md->zone_revalidate_map is set, check that
dm_blk_report_zones() is being called from the process that set it in
__bind(). Otherwise the zone resources could change while accessing
them. Finally, it is possible that md->zone_revalidate_map will change
while calling this function. Only read it once, so that we are always
using the same value. Otherwise we might miss a call to
dm_put_live_table().

Signed-off-by: Benjamin Marzinski <bmarz...@redhat.com>
---
 drivers/md/dm-core.h |  1 +
 drivers/md/dm-zone.c | 23 +++++++++++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h
index 3637761f3585..f3a3f2ef6322 100644
--- a/drivers/md/dm-core.h
+++ b/drivers/md/dm-core.h
@@ -141,6 +141,7 @@ struct mapped_device {
 #ifdef CONFIG_BLK_DEV_ZONED
        unsigned int nr_zones;
        void *zone_revalidate_map;
+       struct task_struct *revalidate_map_task;
 #endif
 
 #ifdef CONFIG_IMA
diff --git a/drivers/md/dm-zone.c b/drivers/md/dm-zone.c
index 681058feb63b..11e19281bb64 100644
--- a/drivers/md/dm-zone.c
+++ b/drivers/md/dm-zone.c
@@ -56,24 +56,29 @@ int dm_blk_report_zones(struct gendisk *disk, sector_t 
sector,
 {
        struct mapped_device *md = disk->private_data;
        struct dm_table *map;
-       int srcu_idx, ret;
+       struct dm_table *zone_revalidate_map = md->zone_revalidate_map;
+       int srcu_idx, ret = -EIO;
 
-       if (!md->zone_revalidate_map) {
-               /* Regular user context */
+       if (!zone_revalidate_map || md->revalidate_map_task != current) {
+               /*
+                * Regular user context or
+                * Zone revalidation during __bind() is in progress, but this
+                * call is from a different process
+                */
                if (dm_suspended_md(md))
                        return -EAGAIN;
 
                map = dm_get_live_table(md, &srcu_idx);
-               if (!map)
-                       return -EIO;
        } else {
                /* Zone revalidation during __bind() */
-               map = md->zone_revalidate_map;
+               map = zone_revalidate_map;
        }
 
-       ret = dm_blk_do_report_zones(md, map, sector, nr_zones, cb, data);
+       if (map)
+               ret = dm_blk_do_report_zones(md, map, sector, nr_zones, cb,
+                                            data);
 
-       if (!md->zone_revalidate_map)
+       if (!zone_revalidate_map)
                dm_put_live_table(md, srcu_idx);
 
        return ret;
@@ -175,7 +180,9 @@ int dm_revalidate_zones(struct dm_table *t, struct 
request_queue *q)
         * our table for dm_blk_report_zones() to use directly.
         */
        md->zone_revalidate_map = t;
+       md->revalidate_map_task = current;
        ret = blk_revalidate_disk_zones(disk);
+       md->revalidate_map_task = NULL;
        md->zone_revalidate_map = NULL;
 
        if (ret) {
-- 
2.48.1


Reply via email to