Skip to content

Commit 90add6d

Browse files
committed
Merge tag 'for-5.19/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper fixes from Mike Snitzer: - Fix DM core's bioset initialization so that blk integrity pool is properly setup. Remove now unused bioset_init_from_src. - Fix DM zoned hang from locking imbalance due to needless check in clone_endio(). * tag 'for-5.19/dm-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm: fix zoned locking imbalance due to needless check in clone_endio block: remove bioset_init_from_src dm: fix bio_set allocation
2 parents 045fb9c + dddf305 commit 90add6d

File tree

7 files changed

+46
-111
lines changed

7 files changed

+46
-111
lines changed

block/bio.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,26 +1747,6 @@ int bioset_init(struct bio_set *bs,
17471747
}
17481748
EXPORT_SYMBOL(bioset_init);
17491749

1750-
/*
1751-
* Initialize and setup a new bio_set, based on the settings from
1752-
* another bio_set.
1753-
*/
1754-
int bioset_init_from_src(struct bio_set *bs, struct bio_set *src)
1755-
{
1756-
int flags;
1757-
1758-
flags = 0;
1759-
if (src->bvec_pool.min_nr)
1760-
flags |= BIOSET_NEED_BVECS;
1761-
if (src->rescue_workqueue)
1762-
flags |= BIOSET_NEED_RESCUER;
1763-
if (src->cache)
1764-
flags |= BIOSET_PERCPU_CACHE;
1765-
1766-
return bioset_init(bs, src->bio_pool.min_nr, src->front_pad, flags);
1767-
}
1768-
EXPORT_SYMBOL(bioset_init_from_src);
1769-
17701750
static int __init init_bio(void)
17711751
{
17721752
int i;

drivers/md/dm-core.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ struct dm_kobject_holder {
3333
* access their members!
3434
*/
3535

36+
/*
37+
* For mempools pre-allocation at the table loading time.
38+
*/
39+
struct dm_md_mempools {
40+
struct bio_set bs;
41+
struct bio_set io_bs;
42+
};
43+
3644
struct mapped_device {
3745
struct mutex suspend_lock;
3846

@@ -110,8 +118,7 @@ struct mapped_device {
110118
/*
111119
* io objects are allocated from here.
112120
*/
113-
struct bio_set io_bs;
114-
struct bio_set bs;
121+
struct dm_md_mempools *mempools;
115122

116123
/* kobject and completion */
117124
struct dm_kobject_holder kobj_holder;

drivers/md/dm-rq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static int setup_clone(struct request *clone, struct request *rq,
319319
{
320320
int r;
321321

322-
r = blk_rq_prep_clone(clone, rq, &tio->md->bs, gfp_mask,
322+
r = blk_rq_prep_clone(clone, rq, &tio->md->mempools->bs, gfp_mask,
323323
dm_rq_bio_constructor, tio);
324324
if (r)
325325
return r;

drivers/md/dm-table.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,17 +1038,6 @@ static int dm_table_alloc_md_mempools(struct dm_table *t, struct mapped_device *
10381038
return 0;
10391039
}
10401040

1041-
void dm_table_free_md_mempools(struct dm_table *t)
1042-
{
1043-
dm_free_md_mempools(t->mempools);
1044-
t->mempools = NULL;
1045-
}
1046-
1047-
struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t)
1048-
{
1049-
return t->mempools;
1050-
}
1051-
10521041
static int setup_indexes(struct dm_table *t)
10531042
{
10541043
int i;

drivers/md/dm.c

Lines changed: 36 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ static int get_swap_bios(void)
136136
return latch;
137137
}
138138

139-
/*
140-
* For mempools pre-allocation at the table loading time.
141-
*/
142-
struct dm_md_mempools {
143-
struct bio_set bs;
144-
struct bio_set io_bs;
145-
};
146-
147139
struct table_device {
148140
struct list_head list;
149141
refcount_t count;
@@ -581,7 +573,7 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
581573
struct dm_target_io *tio;
582574
struct bio *clone;
583575

584-
clone = bio_alloc_clone(NULL, bio, GFP_NOIO, &md->io_bs);
576+
clone = bio_alloc_clone(NULL, bio, GFP_NOIO, &md->mempools->io_bs);
585577
/* Set default bdev, but target must bio_set_dev() before issuing IO */
586578
clone->bi_bdev = md->disk->part0;
587579

@@ -628,7 +620,8 @@ static struct bio *alloc_tio(struct clone_info *ci, struct dm_target *ti,
628620
} else {
629621
struct mapped_device *md = ci->io->md;
630622

631-
clone = bio_alloc_clone(NULL, ci->bio, gfp_mask, &md->bs);
623+
clone = bio_alloc_clone(NULL, ci->bio, gfp_mask,
624+
&md->mempools->bs);
632625
if (!clone)
633626
return NULL;
634627
/* Set default bdev, but target must bio_set_dev() before issuing IO */
@@ -1023,23 +1016,19 @@ static void clone_endio(struct bio *bio)
10231016
struct dm_io *io = tio->io;
10241017
struct mapped_device *md = io->md;
10251018

1026-
if (likely(bio->bi_bdev != md->disk->part0)) {
1027-
struct request_queue *q = bdev_get_queue(bio->bi_bdev);
1028-
1029-
if (unlikely(error == BLK_STS_TARGET)) {
1030-
if (bio_op(bio) == REQ_OP_DISCARD &&
1031-
!bdev_max_discard_sectors(bio->bi_bdev))
1032-
disable_discard(md);
1033-
else if (bio_op(bio) == REQ_OP_WRITE_ZEROES &&
1034-
!q->limits.max_write_zeroes_sectors)
1035-
disable_write_zeroes(md);
1036-
}
1037-
1038-
if (static_branch_unlikely(&zoned_enabled) &&
1039-
unlikely(blk_queue_is_zoned(q)))
1040-
dm_zone_endio(io, bio);
1019+
if (unlikely(error == BLK_STS_TARGET)) {
1020+
if (bio_op(bio) == REQ_OP_DISCARD &&
1021+
!bdev_max_discard_sectors(bio->bi_bdev))
1022+
disable_discard(md);
1023+
else if (bio_op(bio) == REQ_OP_WRITE_ZEROES &&
1024+
!bdev_write_zeroes_sectors(bio->bi_bdev))
1025+
disable_write_zeroes(md);
10411026
}
10421027

1028+
if (static_branch_unlikely(&zoned_enabled) &&
1029+
unlikely(blk_queue_is_zoned(bdev_get_queue(bio->bi_bdev))))
1030+
dm_zone_endio(io, bio);
1031+
10431032
if (endio) {
10441033
int r = endio(ti, bio, &error);
10451034
switch (r) {
@@ -1876,8 +1865,7 @@ static void cleanup_mapped_device(struct mapped_device *md)
18761865
{
18771866
if (md->wq)
18781867
destroy_workqueue(md->wq);
1879-
bioset_exit(&md->bs);
1880-
bioset_exit(&md->io_bs);
1868+
dm_free_md_mempools(md->mempools);
18811869

18821870
if (md->dax_dev) {
18831871
dax_remove_host(md->disk);
@@ -2049,48 +2037,6 @@ static void free_dev(struct mapped_device *md)
20492037
kvfree(md);
20502038
}
20512039

2052-
static int __bind_mempools(struct mapped_device *md, struct dm_table *t)
2053-
{
2054-
struct dm_md_mempools *p = dm_table_get_md_mempools(t);
2055-
int ret = 0;
2056-
2057-
if (dm_table_bio_based(t)) {
2058-
/*
2059-
* The md may already have mempools that need changing.
2060-
* If so, reload bioset because front_pad may have changed
2061-
* because a different table was loaded.
2062-
*/
2063-
bioset_exit(&md->bs);
2064-
bioset_exit(&md->io_bs);
2065-
2066-
} else if (bioset_initialized(&md->bs)) {
2067-
/*
2068-
* There's no need to reload with request-based dm
2069-
* because the size of front_pad doesn't change.
2070-
* Note for future: If you are to reload bioset,
2071-
* prep-ed requests in the queue may refer
2072-
* to bio from the old bioset, so you must walk
2073-
* through the queue to unprep.
2074-
*/
2075-
goto out;
2076-
}
2077-
2078-
BUG_ON(!p ||
2079-
bioset_initialized(&md->bs) ||
2080-
bioset_initialized(&md->io_bs));
2081-
2082-
ret = bioset_init_from_src(&md->bs, &p->bs);
2083-
if (ret)
2084-
goto out;
2085-
ret = bioset_init_from_src(&md->io_bs, &p->io_bs);
2086-
if (ret)
2087-
bioset_exit(&md->bs);
2088-
out:
2089-
/* mempool bind completed, no longer need any mempools in the table */
2090-
dm_table_free_md_mempools(t);
2091-
return ret;
2092-
}
2093-
20942040
/*
20952041
* Bind a table to the device.
20962042
*/
@@ -2144,12 +2090,28 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t,
21442090
* immutable singletons - used to optimize dm_mq_queue_rq.
21452091
*/
21462092
md->immutable_target = dm_table_get_immutable_target(t);
2147-
}
21482093

2149-
ret = __bind_mempools(md, t);
2150-
if (ret) {
2151-
old_map = ERR_PTR(ret);
2152-
goto out;
2094+
/*
2095+
* There is no need to reload with request-based dm because the
2096+
* size of front_pad doesn't change.
2097+
*
2098+
* Note for future: If you are to reload bioset, prep-ed
2099+
* requests in the queue may refer to bio from the old bioset,
2100+
* so you must walk through the queue to unprep.
2101+
*/
2102+
if (!md->mempools) {
2103+
md->mempools = t->mempools;
2104+
t->mempools = NULL;
2105+
}
2106+
} else {
2107+
/*
2108+
* The md may already have mempools that need changing.
2109+
* If so, reload bioset because front_pad may have changed
2110+
* because a different table was loaded.
2111+
*/
2112+
dm_free_md_mempools(md->mempools);
2113+
md->mempools = t->mempools;
2114+
t->mempools = NULL;
21532115
}
21542116

21552117
ret = dm_table_set_restrictions(t, md->queue, limits);

drivers/md/dm.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ struct dm_target *dm_table_get_immutable_target(struct dm_table *t);
7171
struct dm_target *dm_table_get_wildcard_target(struct dm_table *t);
7272
bool dm_table_bio_based(struct dm_table *t);
7373
bool dm_table_request_based(struct dm_table *t);
74-
void dm_table_free_md_mempools(struct dm_table *t);
75-
struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);
7674

7775
void dm_lock_md_type(struct mapped_device *md);
7876
void dm_unlock_md_type(struct mapped_device *md);

include/linux/bio.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ enum {
403403
extern int bioset_init(struct bio_set *, unsigned int, unsigned int, int flags);
404404
extern void bioset_exit(struct bio_set *);
405405
extern int biovec_init_pool(mempool_t *pool, int pool_entries);
406-
extern int bioset_init_from_src(struct bio_set *bs, struct bio_set *src);
407406

408407
struct bio *bio_alloc_bioset(struct block_device *bdev, unsigned short nr_vecs,
409408
unsigned int opf, gfp_t gfp_mask,

0 commit comments

Comments
 (0)