Skip to content

Commit 4ed7bdc

Browse files
committed
Merge tag 'for-4.21/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper updates from Mike Snitzer: - Eliminate a couple indirect calls from bio-based DM core. - Fix DM to allow reads that exceed readahead limits by setting io_pages in the backing_dev_info. - A couple code cleanups in request-based DM. - Fix various DM targets to check for device sector overflow if CONFIG_LBDAF is not set. - Use u64 instead of sector_t to store iv_offset in DM crypt; sector_t isn't large enough on 32bit when CONFIG_LBDAF is not set. - Performance fixes to DM's kcopyd and the snapshot target focused on limiting memory use and workqueue stalls. - Fix typos in the integrity and writecache targets. - Log which algorithm is used for dm-crypt's encryption and dm-integrity's hashing. - Fix false -EBUSY errors in DM raid target's handling of check/repair messages. - Fix DM flakey target's corrupt_bio_byte feature to reliably corrupt the Nth byte in a bio's payload. * tag 'for-4.21/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm: do not allow readahead to limit IO size dm raid: fix false -EBUSY when handling check/repair message dm rq: cleanup leftover code from recently removed q->mq_ops branching dm verity: log the hash algorithm implementation dm crypt: log the encryption algorithm implementation dm integrity: fix spelling mistake in workqueue name dm flakey: Properly corrupt multi-page bios. dm: Check for device sector overflow if CONFIG_LBDAF is not set dm crypt: use u64 instead of sector_t to store iv_offset dm kcopyd: Fix bug causing workqueue stalls dm snapshot: Fix excessive memory usage and workqueue stalls dm bufio: update comment in dm-bufio.c dm writecache: fix typo in error msg for creating writecache_flush_thread dm: remove indirect calls from __send_changing_extent_only() dm mpath: only flush workqueue when needed dm rq: remove unused arguments from rq_completed() dm: avoid indirect call in __dm_make_request
2 parents 5d24ae6 + c6d6e9b commit 4ed7bdc

17 files changed

Lines changed: 121 additions & 82 deletions

‎drivers/md/dm-bufio.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
/*
6767
* Linking of buffers:
68-
* All buffers are linked to cache_hash with their hash_list field.
68+
* All buffers are linked to buffer_tree with their node field.
6969
*
7070
* Clean buffers that are not being written (B_WRITING not set)
7171
* are linked to lru[LIST_CLEAN] with their lru_list field.
@@ -457,7 +457,7 @@ static void free_buffer(struct dm_buffer *b)
457457
}
458458

459459
/*
460-
* Link buffer to the hash list and clean or dirty queue.
460+
* Link buffer to the buffer tree and clean or dirty queue.
461461
*/
462462
static void __link_buffer(struct dm_buffer *b, sector_t block, int dirty)
463463
{
@@ -472,7 +472,7 @@ static void __link_buffer(struct dm_buffer *b, sector_t block, int dirty)
472472
}
473473

474474
/*
475-
* Unlink buffer from the hash list and dirty or clean queue.
475+
* Unlink buffer from the buffer tree and dirty or clean queue.
476476
*/
477477
static void __unlink_buffer(struct dm_buffer *b)
478478
{
@@ -993,7 +993,7 @@ static struct dm_buffer *__bufio_new(struct dm_bufio_client *c, sector_t block,
993993

994994
/*
995995
* We've had a period where the mutex was unlocked, so need to
996-
* recheck the hash table.
996+
* recheck the buffer tree.
997997
*/
998998
b = __find(c, block);
999999
if (b) {
@@ -1327,7 +1327,7 @@ int dm_bufio_write_dirty_buffers(struct dm_bufio_client *c)
13271327
EXPORT_SYMBOL_GPL(dm_bufio_write_dirty_buffers);
13281328

13291329
/*
1330-
* Use dm-io to send and empty barrier flush the device.
1330+
* Use dm-io to send an empty barrier to flush the device.
13311331
*/
13321332
int dm_bufio_issue_flush(struct dm_bufio_client *c)
13331333
{
@@ -1356,7 +1356,7 @@ EXPORT_SYMBOL_GPL(dm_bufio_issue_flush);
13561356
* Then, we write the buffer to the original location if it was dirty.
13571357
*
13581358
* Then, if we are the only one who is holding the buffer, relink the buffer
1359-
* in the hash queue for the new location.
1359+
* in the buffer tree for the new location.
13601360
*
13611361
* If there was someone else holding the buffer, we write it to the new
13621362
* location but not relink it, because that other user needs to have the buffer

‎drivers/md/dm-crypt.c‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct convert_context {
4949
struct bio *bio_out;
5050
struct bvec_iter iter_in;
5151
struct bvec_iter iter_out;
52-
sector_t cc_sector;
52+
u64 cc_sector;
5353
atomic_t cc_pending;
5454
union {
5555
struct skcipher_request *req;
@@ -81,7 +81,7 @@ struct dm_crypt_request {
8181
struct convert_context *ctx;
8282
struct scatterlist sg_in[4];
8383
struct scatterlist sg_out[4];
84-
sector_t iv_sector;
84+
u64 iv_sector;
8585
};
8686

8787
struct crypt_config;
@@ -160,7 +160,7 @@ struct crypt_config {
160160
struct iv_lmk_private lmk;
161161
struct iv_tcw_private tcw;
162162
} iv_gen_private;
163-
sector_t iv_offset;
163+
u64 iv_offset;
164164
unsigned int iv_size;
165165
unsigned short int sector_size;
166166
unsigned char sector_shift;
@@ -1885,6 +1885,13 @@ static int crypt_alloc_tfms_skcipher(struct crypt_config *cc, char *ciphermode)
18851885
}
18861886
}
18871887

1888+
/*
1889+
* dm-crypt performance can vary greatly depending on which crypto
1890+
* algorithm implementation is used. Help people debug performance
1891+
* problems by logging the ->cra_driver_name.
1892+
*/
1893+
DMINFO("%s using implementation \"%s\"", ciphermode,
1894+
crypto_skcipher_alg(any_tfm(cc))->base.cra_driver_name);
18881895
return 0;
18891896
}
18901897

@@ -1903,6 +1910,8 @@ static int crypt_alloc_tfms_aead(struct crypt_config *cc, char *ciphermode)
19031910
return err;
19041911
}
19051912

1913+
DMINFO("%s using implementation \"%s\"", ciphermode,
1914+
crypto_aead_alg(any_tfm_aead(cc))->base.cra_driver_name);
19061915
return 0;
19071916
}
19081917

@@ -2781,7 +2790,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
27812790
}
27822791

27832792
ret = -EINVAL;
2784-
if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1) {
2793+
if (sscanf(argv[4], "%llu%c", &tmpll, &dummy) != 1 || tmpll != (sector_t)tmpll) {
27852794
ti->error = "Invalid device sector";
27862795
goto bad;
27872796
}

‎drivers/md/dm-delay.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static int delay_class_ctr(struct dm_target *ti, struct delay_class *c, char **a
141141
unsigned long long tmpll;
142142
char dummy;
143143

144-
if (sscanf(argv[1], "%llu%c", &tmpll, &dummy) != 1) {
144+
if (sscanf(argv[1], "%llu%c", &tmpll, &dummy) != 1 || tmpll != (sector_t)tmpll) {
145145
ti->error = "Invalid device sector";
146146
return -EINVAL;
147147
}

‎drivers/md/dm-flakey.c‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int flakey_ctr(struct dm_target *ti, unsigned int argc, char **argv)
213213
devname = dm_shift_arg(&as);
214214

215215
r = -EINVAL;
216-
if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1) {
216+
if (sscanf(dm_shift_arg(&as), "%llu%c", &tmpll, &dummy) != 1 || tmpll != (sector_t)tmpll) {
217217
ti->error = "Invalid device sector";
218218
goto bad;
219219
}
@@ -287,20 +287,31 @@ static void flakey_map_bio(struct dm_target *ti, struct bio *bio)
287287

288288
static void corrupt_bio_data(struct bio *bio, struct flakey_c *fc)
289289
{
290-
unsigned bio_bytes = bio_cur_bytes(bio);
291-
char *data = bio_data(bio);
290+
unsigned int corrupt_bio_byte = fc->corrupt_bio_byte - 1;
291+
292+
struct bvec_iter iter;
293+
struct bio_vec bvec;
294+
295+
if (!bio_has_data(bio))
296+
return;
292297

293298
/*
294-
* Overwrite the Nth byte of the data returned.
299+
* Overwrite the Nth byte of the bio's data, on whichever page
300+
* it falls.
295301
*/
296-
if (data && bio_bytes >= fc->corrupt_bio_byte) {
297-
data[fc->corrupt_bio_byte - 1] = fc->corrupt_bio_value;
298-
299-
DMDEBUG("Corrupting data bio=%p by writing %u to byte %u "
300-
"(rw=%c bi_opf=%u bi_sector=%llu cur_bytes=%u)\n",
301-
bio, fc->corrupt_bio_value, fc->corrupt_bio_byte,
302-
(bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf,
303-
(unsigned long long)bio->bi_iter.bi_sector, bio_bytes);
302+
bio_for_each_segment(bvec, bio, iter) {
303+
if (bio_iter_len(bio, iter) > corrupt_bio_byte) {
304+
char *segment = (page_address(bio_iter_page(bio, iter))
305+
+ bio_iter_offset(bio, iter));
306+
segment[corrupt_bio_byte] = fc->corrupt_bio_value;
307+
DMDEBUG("Corrupting data bio=%p by writing %u to byte %u "
308+
"(rw=%c bi_opf=%u bi_sector=%llu size=%u)\n",
309+
bio, fc->corrupt_bio_value, fc->corrupt_bio_byte,
310+
(bio_data_dir(bio) == WRITE) ? 'w' : 'r', bio->bi_opf,
311+
(unsigned long long)bio->bi_iter.bi_sector, bio->bi_iter.bi_size);
312+
break;
313+
}
314+
corrupt_bio_byte -= bio_iter_len(bio, iter);
304315
}
305316
}
306317

‎drivers/md/dm-integrity.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3460,7 +3460,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
34603460
ti->error = "Recalculate is only valid with internal hash";
34613461
goto bad;
34623462
}
3463-
ic->recalc_wq = alloc_workqueue("dm-intergrity-recalc", WQ_MEM_RECLAIM, 1);
3463+
ic->recalc_wq = alloc_workqueue("dm-integrity-recalc", WQ_MEM_RECLAIM, 1);
34643464
if (!ic->recalc_wq ) {
34653465
ti->error = "Cannot allocate workqueue";
34663466
r = -ENOMEM;

‎drivers/md/dm-kcopyd.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ struct dm_kcopyd_client {
5656
atomic_t nr_jobs;
5757

5858
/*
59-
* We maintain three lists of jobs:
59+
* We maintain four lists of jobs:
6060
*
6161
* i) jobs waiting for pages
6262
* ii) jobs that have pages, and are waiting for the io to be issued.
63-
* iii) jobs that have completed.
63+
* iii) jobs that don't need to do any IO and just run a callback
64+
* iv) jobs that have completed.
6465
*
65-
* All three of these are protected by job_lock.
66+
* All four of these are protected by job_lock.
6667
*/
6768
spinlock_t job_lock;
69+
struct list_head callback_jobs;
6870
struct list_head complete_jobs;
6971
struct list_head io_jobs;
7072
struct list_head pages_jobs;
@@ -625,6 +627,7 @@ static void do_work(struct work_struct *work)
625627
struct dm_kcopyd_client *kc = container_of(work,
626628
struct dm_kcopyd_client, kcopyd_work);
627629
struct blk_plug plug;
630+
unsigned long flags;
628631

629632
/*
630633
* The order that these are called is *very* important.
@@ -633,6 +636,10 @@ static void do_work(struct work_struct *work)
633636
* list. io jobs call wake when they complete and it all
634637
* starts again.
635638
*/
639+
spin_lock_irqsave(&kc->job_lock, flags);
640+
list_splice_tail_init(&kc->callback_jobs, &kc->complete_jobs);
641+
spin_unlock_irqrestore(&kc->job_lock, flags);
642+
636643
blk_start_plug(&plug);
637644
process_jobs(&kc->complete_jobs, kc, run_complete_job);
638645
process_jobs(&kc->pages_jobs, kc, run_pages_job);
@@ -650,7 +657,7 @@ static void dispatch_job(struct kcopyd_job *job)
650657
struct dm_kcopyd_client *kc = job->kc;
651658
atomic_inc(&kc->nr_jobs);
652659
if (unlikely(!job->source.count))
653-
push(&kc->complete_jobs, job);
660+
push(&kc->callback_jobs, job);
654661
else if (job->pages == &zero_page_list)
655662
push(&kc->io_jobs, job);
656663
else
@@ -858,7 +865,7 @@ void dm_kcopyd_do_callback(void *j, int read_err, unsigned long write_err)
858865
job->read_err = read_err;
859866
job->write_err = write_err;
860867

861-
push(&kc->complete_jobs, job);
868+
push(&kc->callback_jobs, job);
862869
wake(kc);
863870
}
864871
EXPORT_SYMBOL(dm_kcopyd_do_callback);
@@ -888,6 +895,7 @@ struct dm_kcopyd_client *dm_kcopyd_client_create(struct dm_kcopyd_throttle *thro
888895
return ERR_PTR(-ENOMEM);
889896

890897
spin_lock_init(&kc->job_lock);
898+
INIT_LIST_HEAD(&kc->callback_jobs);
891899
INIT_LIST_HEAD(&kc->complete_jobs);
892900
INIT_LIST_HEAD(&kc->io_jobs);
893901
INIT_LIST_HEAD(&kc->pages_jobs);
@@ -939,6 +947,7 @@ void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc)
939947
/* Wait for completion of all jobs submitted by this client. */
940948
wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs));
941949

950+
BUG_ON(!list_empty(&kc->callback_jobs));
942951
BUG_ON(!list_empty(&kc->complete_jobs));
943952
BUG_ON(!list_empty(&kc->io_jobs));
944953
BUG_ON(!list_empty(&kc->pages_jobs));

‎drivers/md/dm-linear.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv)
4545
}
4646

4747
ret = -EINVAL;
48-
if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1) {
48+
if (sscanf(argv[1], "%llu%c", &tmp, &dummy) != 1 || tmp != (sector_t)tmp) {
4949
ti->error = "Invalid device sector";
5050
goto bad;
5151
}

‎drivers/md/dm-mpath.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,14 +1211,16 @@ static void flush_multipath_work(struct multipath *m)
12111211
set_bit(MPATHF_PG_INIT_DISABLED, &m->flags);
12121212
smp_mb__after_atomic();
12131213

1214-
flush_workqueue(kmpath_handlerd);
1214+
if (atomic_read(&m->pg_init_in_progress))
1215+
flush_workqueue(kmpath_handlerd);
12151216
multipath_wait_for_pg_init_completion(m);
12161217

12171218
clear_bit(MPATHF_PG_INIT_DISABLED, &m->flags);
12181219
smp_mb__after_atomic();
12191220
}
12201221

1221-
flush_workqueue(kmultipathd);
1222+
if (m->queue_mode == DM_TYPE_BIO_BASED)
1223+
flush_work(&m->process_queued_bios);
12221224
flush_work(&m->trigger_event);
12231225
}
12241226

‎drivers/md/dm-raid.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,8 +3690,7 @@ static int raid_message(struct dm_target *ti, unsigned int argc, char **argv,
36903690
set_bit(MD_RECOVERY_INTR, &mddev->recovery);
36913691
md_reap_sync_thread(mddev);
36923692
}
3693-
} else if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
3694-
test_bit(MD_RECOVERY_NEEDED, &mddev->recovery))
3693+
} else if (decipher_sync_action(mddev, mddev->recovery) != st_idle)
36953694
return -EBUSY;
36963695
else if (!strcasecmp(argv[0], "resync"))
36973696
; /* MD_RECOVERY_NEEDED set below */

‎drivers/md/dm-raid1.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
943943
char dummy;
944944
int ret;
945945

946-
if (sscanf(argv[1], "%llu%c", &offset, &dummy) != 1) {
946+
if (sscanf(argv[1], "%llu%c", &offset, &dummy) != 1 ||
947+
offset != (sector_t)offset) {
947948
ti->error = "Invalid offset";
948949
return -EINVAL;
949950
}

0 commit comments

Comments
 (0)