Skip to content

Commit 16245bd

Browse files
nomuraneckergon
authored andcommitted
dm: do not replace bioset for request based dm
This patch fixes a regression introduced in v3.8, which causes oops like this when dm-multipath is used: general protection fault: 0000 [#1] SMP RIP: 0010:[<ffffffff810fe754>] [<ffffffff810fe754>] mempool_free+0x24/0xb0 Call Trace: <IRQ> [<ffffffff81187417>] bio_put+0x97/0xc0 [<ffffffffa02247a5>] end_clone_bio+0x35/0x90 [dm_mod] [<ffffffff81185efd>] bio_endio+0x1d/0x30 [<ffffffff811f03a3>] req_bio_endio.isra.51+0xa3/0xe0 [<ffffffff811f2f68>] blk_update_request+0x118/0x520 [<ffffffff811f3397>] blk_update_bidi_request+0x27/0xa0 [<ffffffff811f343c>] blk_end_bidi_request+0x2c/0x80 [<ffffffff811f34d0>] blk_end_request+0x10/0x20 [<ffffffffa000b32b>] scsi_io_completion+0xfb/0x6c0 [scsi_mod] [<ffffffffa000107d>] scsi_finish_command+0xbd/0x120 [scsi_mod] [<ffffffffa000b12f>] scsi_softirq_done+0x13f/0x160 [scsi_mod] [<ffffffff811f9fd0>] blk_done_softirq+0x80/0xa0 [<ffffffff81044551>] __do_softirq+0xf1/0x250 [<ffffffff8142ee8c>] call_softirq+0x1c/0x30 [<ffffffff8100420d>] do_softirq+0x8d/0xc0 [<ffffffff81044885>] irq_exit+0xd5/0xe0 [<ffffffff8142f3e3>] do_IRQ+0x63/0xe0 [<ffffffff814257af>] common_interrupt+0x6f/0x6f <EOI> [<ffffffffa021737c>] srp_queuecommand+0x8c/0xcb0 [ib_srp] [<ffffffffa0002f18>] scsi_dispatch_cmd+0x148/0x310 [scsi_mod] [<ffffffffa000a38e>] scsi_request_fn+0x31e/0x520 [scsi_mod] [<ffffffff811f1e57>] __blk_run_queue+0x37/0x50 [<ffffffff811f1f69>] blk_delay_work+0x29/0x40 [<ffffffff81059003>] process_one_work+0x1c3/0x5c0 [<ffffffff8105b22e>] worker_thread+0x15e/0x440 [<ffffffff8106164b>] kthread+0xdb/0xe0 [<ffffffff8142db9c>] ret_from_fork+0x7c/0xb0 The regression was introduced by the change c0820cf "dm: introduce per_bio_data", where dm started to replace bioset during table replacement. For bio-based dm, it is good because clone bios do not exist during the table replacement. For request-based dm, however, (not-yet-mapped) clone bios may stay in request queue and survive during the table replacement. So freeing the old bioset could cause the oops in bio_put(). Since the size of front_pad may change only with bio-based dm, it is not necessary to replace bioset for request-based dm. Reported-by: Bart Van Assche <[email protected]> Tested-by: Bart Van Assche <[email protected]> Signed-off-by: Jun'ichi Nomura <[email protected]> Acked-by: Mikulas Patocka <[email protected]> Acked-by: Mike Snitzer <[email protected]> Cc: <[email protected]> Signed-off-by: Alasdair G Kergon <[email protected]>
1 parent b666973 commit 16245bd

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

drivers/md/dm.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,15 +1947,27 @@ static void __bind_mempools(struct mapped_device *md, struct dm_table *t)
19471947
{
19481948
struct dm_md_mempools *p = dm_table_get_md_mempools(t);
19491949

1950-
if (md->io_pool && (md->tio_pool || dm_table_get_type(t) == DM_TYPE_BIO_BASED) && md->bs) {
1951-
/*
1952-
* The md already has necessary mempools. Reload just the
1953-
* bioset because front_pad may have changed because
1954-
* a different table was loaded.
1955-
*/
1956-
bioset_free(md->bs);
1957-
md->bs = p->bs;
1958-
p->bs = NULL;
1950+
if (md->io_pool && md->bs) {
1951+
/* The md already has necessary mempools. */
1952+
if (dm_table_get_type(t) == DM_TYPE_BIO_BASED) {
1953+
/*
1954+
* Reload bioset because front_pad may have changed
1955+
* because a different table was loaded.
1956+
*/
1957+
bioset_free(md->bs);
1958+
md->bs = p->bs;
1959+
p->bs = NULL;
1960+
} else if (dm_table_get_type(t) == DM_TYPE_REQUEST_BASED) {
1961+
BUG_ON(!md->tio_pool);
1962+
/*
1963+
* There's no need to reload with request-based dm
1964+
* because the size of front_pad doesn't change.
1965+
* Note for future: If you are to reload bioset,
1966+
* prep-ed requests in the queue may refer
1967+
* to bio from the old bioset, so you must walk
1968+
* through the queue to unprep.
1969+
*/
1970+
}
19591971
goto out;
19601972
}
19611973

0 commit comments

Comments
 (0)