Skip to contentSkip to conversation

dm: Refuse to load an sq table on an mq device

PATCH In review Bart Van Assche 2 participants 6 messages Dec 8, 2016 – Dec 9, 2016 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: Refuse to load an sq table on an mq device

This patch avoids that the following call trace can be triggered:

------------[ cut here ]------------
WARNING: CPU: 10 PID: 19102 at drivers/md/dm-mpath.c:543 __multipath_map.isra.17+0x23a/0x370 [dm_multipath]
CPU: 10 PID: 19102 Comm: mkfs.ext4 Not tainted 4.9.0-rc8-dbg+ #4
Call Trace:
 [<ffffffff81329cd5>] dump_stack+0x68/0x93
 [<ffffffff810650e6>] __warn+0xc6/0xe0
 [<ffffffff810651b8>] warn_slowpath_null+0x18/0x20
 [<ffffffffa004603a>] __multipath_map.isra.17+0x23a/0x370 [dm_multipath]
 [<ffffffffa0046188>] multipath_clone_and_map+0x18/0x20 [dm_multipath]
 [<ffffffffa002a54d>] map_request+0xed/0x300 [dm_mod]
 [<ffffffffa002a807>] dm_mq_queue_rq+0x77/0x110 [dm_mod]
 [<ffffffff81310fbf>] blk_mq_process_rq_list+0x23f/0x340
 [<ffffffff813111e2>] __blk_mq_run_hw_queue+0x122/0x1c0
 [<ffffffff81310d5f>] blk_mq_run_hw_queue+0x9f/0xc0
 [<ffffffff81311ef5>] blk_mq_insert_requests+0x245/0x320
 [<ffffffff813133f5>] blk_mq_flush_plug_list+0x125/0x140
 [<ffffffff81306b12>] blk_flush_plug_list+0xa2/0x210
 [<ffffffff81307157>] blk_finish_plug+0x27/0x40
 [<ffffffff8116c119>] __do_page_cache_readahead+0x279/0x2f0
 [<ffffffff8116c728>] force_page_cache_readahead+0xa8/0x100
 [<ffffffff8116c7b9>] page_cache_sync_readahead+0x39/0x40
 [<ffffffff8115c964>] generic_file_read_iter+0x234/0x780
 [<ffffffff8121f8e0>] blkdev_read_iter+0x30/0x40
 [<ffffffff811dd2db>] __vfs_read+0xbb/0x130
 [<ffffffff811de341>] vfs_read+0x91/0x130
 [<ffffffff811df6e4>] SyS_read+0x44/0xa0
 [<ffffffff816401aa>] entry_SYSCALL_64_fastpath+0x18/0xad
---[ end trace c5c6591c32eae6dd ]---

after having inserted the following code in __multipath_map():

	WARN_ON_ONCE(clone && q->mq_ops);
	WARN_ON_ONCE(!clone && !q->mq_ops);
---
 drivers/md/dm-ioctl.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/md/dm-ioctl.c +5 -0
index c72a77048b73..918e8b363015 100644
@@ -1322,6 +1322,11 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
 		DMWARN("can't change device type after initial table load.");
 		r = -EINVAL;
 		goto err_unlock_md_type;
+	} else if (dm_get_md_type(md) == DM_TYPE_MQ_REQUEST_BASED &&
+		   !dm_table_all_blk_mq_devices(t)) {
+		DMWARN("can't load a sq table on a blk-mq dm device.");
+		r = -EINVAL;
+		goto err_unlock_md_type;
 	}
 
 	dm_unlock_md_type(md);
Signature · 1 line
2.11.0
#1 lore raw
Quoted 48 lines · Bart Van Assche

This patch avoids that the following call trace can be triggered:

------------[ cut here ]------------
WARNING: CPU: 10 PID: 19102 at drivers/md/dm-mpath.c:543 __multipath_map.isra.17+0x23a/0x370 [dm_multipath]
CPU: 10 PID: 19102 Comm: mkfs.ext4 Not tainted 4.9.0-rc8-dbg+ #4
Call Trace:
 [<ffffffff81329cd5>] dump_stack+0x68/0x93
 [<ffffffff810650e6>] __warn+0xc6/0xe0
 [<ffffffff810651b8>] warn_slowpath_null+0x18/0x20
 [<ffffffffa004603a>] __multipath_map.isra.17+0x23a/0x370 [dm_multipath]
 [<ffffffffa0046188>] multipath_clone_and_map+0x18/0x20 [dm_multipath]
 [<ffffffffa002a54d>] map_request+0xed/0x300 [dm_mod]
 [<ffffffffa002a807>] dm_mq_queue_rq+0x77/0x110 [dm_mod]
 [<ffffffff81310fbf>] blk_mq_process_rq_list+0x23f/0x340
 [<ffffffff813111e2>] __blk_mq_run_hw_queue+0x122/0x1c0
 [<ffffffff81310d5f>] blk_mq_run_hw_queue+0x9f/0xc0
 [<ffffffff81311ef5>] blk_mq_insert_requests+0x245/0x320
 [<ffffffff813133f5>] blk_mq_flush_plug_list+0x125/0x140
 [<ffffffff81306b12>] blk_flush_plug_list+0xa2/0x210
 [<ffffffff81307157>] blk_finish_plug+0x27/0x40
 [<ffffffff8116c119>] __do_page_cache_readahead+0x279/0x2f0
 [<ffffffff8116c728>] force_page_cache_readahead+0xa8/0x100
 [<ffffffff8116c7b9>] page_cache_sync_readahead+0x39/0x40
 [<ffffffff8115c964>] generic_file_read_iter+0x234/0x780
 [<ffffffff8121f8e0>] blkdev_read_iter+0x30/0x40
 [<ffffffff811dd2db>] __vfs_read+0xbb/0x130
 [<ffffffff811de341>] vfs_read+0x91/0x130
 [<ffffffff811df6e4>] SyS_read+0x44/0xa0
 [<ffffffff816401aa>] entry_SYSCALL_64_fastpath+0x18/0xad
---[ end trace c5c6591c32eae6dd ]---

after having inserted the following code in __multipath_map():

	WARN_ON_ONCE(clone && q->mq_ops);
	WARN_ON_ONCE(!clone && !q->mq_ops);
---
 drivers/md/dm-ioctl.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/md/dm-ioctl.c +0 -0
index c72a77048b73..918e8b363015 100644
@@ -1322,6 +1322,11 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
 		DMWARN("can't change device type after initial table load.");

drivers/md/dm-ioctl.c static int table_load(struct dm_ioctl *param, size_t param_size) · line 1332

Quoted 10 lines
drivers/md/dm-ioctl.c +5 -0
 		r = -EINVAL;
 		goto err_unlock_md_type;
+	} else if (dm_get_md_type(md) == DM_TYPE_MQ_REQUEST_BASED &&
+		   !dm_table_all_blk_mq_devices(t)) {
+		DMWARN("can't load a sq table on a blk-mq dm device.");
+		r = -EINVAL;
+		goto err_unlock_md_type;
 	}
 
 	dm_unlock_md_type(md);

Hi Bart,

Thanks for catching this lack of table type verification.

I'm not a fan of a patch header including a stack trace for debugging was temporarily introduced loclaly for debugging purposes; especially not for a patch that will cc stable. As such I'll be re-writing the patch header.

Also, I prefer the following variant of your fix (results in failing the table load a bit sooner and doesn't allow a table->type inconsistency to escape dm_table_determine_type()).

Should I still attribute authorship of this change to you? Or would you prefer I switch to you being the Reporter (via Reported-by)?

drivers/md/dm-table.c +5 -0
index 8ce81d0..0a427de 100644
@@ -976,6 +976,11 @@ static int dm_table_determine_type(struct dm_table *t)
 	}
 	t->all_blk_mq = mq_count > 0;
 
+	if (t->type == DM_TYPE_MQ_REQUEST_BASED && !t->all_blk_mq) {
+		DMERR("table load rejected: all devices are not blk-mq request-stackable");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
#2 lore raw
Quoted 2 lines · Mike Snitzer

Should I still attribute authorship of this change to you? Or would you prefer I switch to you being the Reporter (via Reported-by)?

Hello Mike,

I'm fine with a Reported-by tag.

Thanks,

Bart.

#3 lore raw
Quoted 7 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

Should I still attribute authorship of this change to you? Or would you prefer I switch to you being the Reporter (via Reported-by)?

Hello Mike,

I'm fine with a Reported-by tag.

Thinking about rebasing this fix to come before this cleanup (so that backporting to stable@ is easier):
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.10&id=db1c06dc2edd242146e25d38b1af61b681d49253

And then still attributing this fix to you. I'll let you know what I come up with later today.

Mike

#4 lore raw
Quoted 9 lines · Mike Snitzer
Quoted 6 lines · Bart Van Assche
Quoted 2 lines · Mike Snitzer

Should I still attribute authorship of this change to you? Or would you prefer I switch to you being the Reporter (via Reported-by)?

Hello Mike,

Quoted 8 lines
Quoted 1 line

I'm fine with a Reported-by tag.

Thinking about rebasing this fix to come before this cleanup (so that backporting to stable@ is easier):
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.10&id=db1c06dc2edd242146e25d38b1af61b681d49253

And then still attributing this fix to you. I'll let you know what I come up with later today.

Done, please see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.10&id=301fc3f5efb98633115bd887655b19f42c6dfaa8

#5 lore raw
Quoted 11 lines · Mike Snitzer
Quoted 6 lines · Mike Snitzer

Thinking about rebasing this fix to come before this cleanup (so that backporting to stable@ is easier):
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.10&id=db1c06dc2edd242146e25d38b1af61b681d49253

And then still attributing this fix to you. I'll let you know what I come up with later today.

Done, please see:
https://git.kernel.org/cgit/linux/kernel/git/device-mapper/linux-dm.git/commit/?h=dm-4.10&id=301fc3f5efb98633115bd887655b19f42c6dfaa8

That patch works fine on my test setup.

Thanks,

Bart.