Skip to content

Commit 9571f82

Browse files
author
Mike Snitzer
committed
dm table: fix dm_table_supports_poll to return false if no data devices
It was reported that the "generic/250" test in xfstests (which uses the dm-error target) demonstrates a regression where the kernel crashes in bioset_exit(). Since commit cfc97ab ("dm: conditionally enable BIOSET_PERCPU_CACHE for dm_io bioset") the bioset_init() for the dm_io bioset will setup the bioset's per-cpu alloc cache if all devices have QUEUE_FLAG_POLL set. But there was an bug where a target that doesn't have any data devices (and that doesn't even set the .iterate_devices dm target callback) will incorrectly return true from dm_table_supports_poll(). Fix this by updating dm_table_supports_poll() to follow dm-table.c's well-worn pattern for testing that _all_ targets in a DM table do in fact have underlying devices that set QUEUE_FLAG_POLL. NOTE: An additional block fix is still needed so that bio_alloc_cache_destroy() clears the bioset's ->cache member. Otherwise, a DM device's table reload that transitions the DM device's bioset from using a per-cpu alloc cache to _not_ using one will result in bioset_exit() crashing in bio_alloc_cache_destroy() because dm's dm_io bioset ("io_bs") was left with a stale ->cache member. Fixes: cfc97ab ("dm: conditionally enable BIOSET_PERCPU_CACHE for dm_io bioset") Reported-by: Matthew Wilcox <[email protected]> Reported-by: Dave Chinner <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent ca52248 commit 9571f82

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/md/dm-table.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ bool dm_table_request_based(struct dm_table *t)
10051005
return __table_type_request_based(dm_table_get_type(t));
10061006
}
10071007

1008-
static int dm_table_supports_poll(struct dm_table *t);
1008+
static bool dm_table_supports_poll(struct dm_table *t);
10091009

10101010
static int dm_table_alloc_md_mempools(struct dm_table *t, struct mapped_device *md)
10111011
{
@@ -1027,7 +1027,7 @@ static int dm_table_alloc_md_mempools(struct dm_table *t, struct mapped_device *
10271027
per_io_data_size = max(per_io_data_size, ti->per_io_data_size);
10281028
min_pool_size = max(min_pool_size, ti->num_flush_bios);
10291029
}
1030-
poll_supported = !!dm_table_supports_poll(t);
1030+
poll_supported = dm_table_supports_poll(t);
10311031
}
10321032

10331033
t->mempools = dm_alloc_md_mempools(md, type, per_io_data_size, min_pool_size,
@@ -1547,9 +1547,20 @@ static int count_device(struct dm_target *ti, struct dm_dev *dev,
15471547
return 0;
15481548
}
15491549

1550-
static int dm_table_supports_poll(struct dm_table *t)
1550+
static bool dm_table_supports_poll(struct dm_table *t)
15511551
{
1552-
return !dm_table_any_dev_attr(t, device_not_poll_capable, NULL);
1552+
struct dm_target *ti;
1553+
unsigned i = 0;
1554+
1555+
while (i < dm_table_get_num_targets(t)) {
1556+
ti = dm_table_get_target(t, i++);
1557+
1558+
if (!ti->type->iterate_devices ||
1559+
ti->type->iterate_devices(ti, device_not_poll_capable, NULL))
1560+
return false;
1561+
}
1562+
1563+
return true;
15531564
}
15541565

15551566
/*

0 commit comments

Comments
 (0)