Skip to content

Commit 9629d83

Browse files
committed
Merge tag 'for-6.14/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper updates from Mikulas Patocka: - fix a spelling error in dm-raid - change kzalloc to kcalloc - remove useless test in alloc_multiple_bios - disable REQ_NOWAIT for flushes - dm-transaction-manager: use red-black trees instead of linear lists - atomic writes support for dm-linear, dm-stripe and dm-mirror - dm-crypt: code cleanups and two bugfixes * tag 'for-6.14/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm-crypt: track tag_offset in convert_context dm-crypt: don't initialize cc_sector again dm-crypt: don't update io->sector after kcryptd_crypt_write_io_submit() dm-crypt: use bi_sector in bio when initialize integrity seed dm-crypt: fully initialize clone->bi_iter in crypt_alloc_buffer() dm-crypt: set atomic as false when calling crypt_convert() in kworker dm-mirror: Support atomic writes dm-io: Warn on creating multiple atomic write bios for a region dm-stripe: Enable atomic writes dm-linear: Enable atomic writes dm: Ensure cloned bio is same length for atomic write dm-table: atomic writes support dm-transaction-manager: use red-black trees instead of linear lists dm: disable REQ_NOWAIT for flushes dm: remove useless test in alloc_multiple_bios dm: change kzalloc to kcalloc dm raid: fix spelling errors in raid_ctr()
2 parents 13845bd + 8b8f803 commit 9629d83

File tree

12 files changed

+120
-63
lines changed

12 files changed

+120
-63
lines changed

drivers/md/dm-crypt.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct convert_context {
5959
struct bio *bio_out;
6060
struct bvec_iter iter_out;
6161
atomic_t cc_pending;
62+
unsigned int tag_offset;
6263
u64 cc_sector;
6364
union {
6465
struct skcipher_request *req;
@@ -1187,7 +1188,7 @@ static int dm_crypt_integrity_io_alloc(struct dm_crypt_io *io, struct bio *bio)
11871188

11881189
tag_len = io->cc->tuple_size * (bio_sectors(bio) >> io->cc->sector_shift);
11891190

1190-
bip->bip_iter.bi_sector = io->cc->start + io->sector;
1191+
bip->bip_iter.bi_sector = bio->bi_iter.bi_sector;
11911192

11921193
ret = bio_integrity_add_page(bio, virt_to_page(io->integrity_metadata),
11931194
tag_len, offset_in_page(io->integrity_metadata));
@@ -1256,6 +1257,7 @@ static void crypt_convert_init(struct crypt_config *cc,
12561257
if (bio_out)
12571258
ctx->iter_out = bio_out->bi_iter;
12581259
ctx->cc_sector = sector + cc->iv_offset;
1260+
ctx->tag_offset = 0;
12591261
init_completion(&ctx->restart);
12601262
}
12611263

@@ -1588,7 +1590,6 @@ static void crypt_free_req(struct crypt_config *cc, void *req, struct bio *base_
15881590
static blk_status_t crypt_convert(struct crypt_config *cc,
15891591
struct convert_context *ctx, bool atomic, bool reset_pending)
15901592
{
1591-
unsigned int tag_offset = 0;
15921593
unsigned int sector_step = cc->sector_size >> SECTOR_SHIFT;
15931594
int r;
15941595

@@ -1611,9 +1612,9 @@ static blk_status_t crypt_convert(struct crypt_config *cc,
16111612
atomic_inc(&ctx->cc_pending);
16121613

16131614
if (crypt_integrity_aead(cc))
1614-
r = crypt_convert_block_aead(cc, ctx, ctx->r.req_aead, tag_offset);
1615+
r = crypt_convert_block_aead(cc, ctx, ctx->r.req_aead, ctx->tag_offset);
16151616
else
1616-
r = crypt_convert_block_skcipher(cc, ctx, ctx->r.req, tag_offset);
1617+
r = crypt_convert_block_skcipher(cc, ctx, ctx->r.req, ctx->tag_offset);
16171618

16181619
switch (r) {
16191620
/*
@@ -1633,8 +1634,8 @@ static blk_status_t crypt_convert(struct crypt_config *cc,
16331634
* exit and continue processing in a workqueue
16341635
*/
16351636
ctx->r.req = NULL;
1637+
ctx->tag_offset++;
16361638
ctx->cc_sector += sector_step;
1637-
tag_offset++;
16381639
return BLK_STS_DEV_RESOURCE;
16391640
}
16401641
} else {
@@ -1648,16 +1649,16 @@ static blk_status_t crypt_convert(struct crypt_config *cc,
16481649
*/
16491650
case -EINPROGRESS:
16501651
ctx->r.req = NULL;
1652+
ctx->tag_offset++;
16511653
ctx->cc_sector += sector_step;
1652-
tag_offset++;
16531654
continue;
16541655
/*
16551656
* The request was already processed (synchronously).
16561657
*/
16571658
case 0:
16581659
atomic_dec(&ctx->cc_pending);
16591660
ctx->cc_sector += sector_step;
1660-
tag_offset++;
1661+
ctx->tag_offset++;
16611662
if (!atomic)
16621663
cond_resched();
16631664
continue;
@@ -1719,6 +1720,7 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned int size)
17191720
clone->bi_private = io;
17201721
clone->bi_end_io = crypt_endio;
17211722
clone->bi_ioprio = io->base_bio->bi_ioprio;
1723+
clone->bi_iter.bi_sector = cc->start + io->sector;
17221724

17231725
remaining_size = size;
17241726

@@ -1909,7 +1911,6 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
19091911
crypt_dec_pending(io);
19101912
return 1;
19111913
}
1912-
clone->bi_iter.bi_sector = cc->start + io->sector;
19131914
crypt_convert_init(cc, &io->ctx, clone, clone, io->sector);
19141915
io->saved_bi_iter = clone->bi_iter;
19151916
dm_submit_bio_remap(io->base_bio, clone);
@@ -1925,13 +1926,13 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
19251926
clone = bio_alloc_clone(cc->dev->bdev, io->base_bio, gfp, &cc->bs);
19261927
if (!clone)
19271928
return 1;
1929+
1930+
clone->bi_iter.bi_sector = cc->start + io->sector;
19281931
clone->bi_private = io;
19291932
clone->bi_end_io = crypt_endio;
19301933

19311934
crypt_inc_pending(io);
19321935

1933-
clone->bi_iter.bi_sector = cc->start + io->sector;
1934-
19351936
if (dm_crypt_integrity_io_alloc(io, clone)) {
19361937
crypt_dec_pending(io);
19371938
bio_put(clone);
@@ -2039,8 +2040,6 @@ static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io, int async)
20392040
/* crypt_convert should have filled the clone bio */
20402041
BUG_ON(io->ctx.iter_out.bi_size);
20412042

2042-
clone->bi_iter.bi_sector = cc->start + io->sector;
2043-
20442043
if ((likely(!async) && test_bit(DM_CRYPT_NO_OFFLOAD, &cc->flags)) ||
20452044
test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags)) {
20462045
dm_submit_bio_remap(io->base_bio, clone);
@@ -2092,13 +2091,12 @@ static void kcryptd_crypt_write_continue(struct work_struct *work)
20922091
struct crypt_config *cc = io->cc;
20932092
struct convert_context *ctx = &io->ctx;
20942093
int crypt_finished;
2095-
sector_t sector = io->sector;
20962094
blk_status_t r;
20972095

20982096
wait_for_completion(&ctx->restart);
20992097
reinit_completion(&ctx->restart);
21002098

2101-
r = crypt_convert(cc, &io->ctx, true, false);
2099+
r = crypt_convert(cc, &io->ctx, false, false);
21022100
if (r)
21032101
io->error = r;
21042102
crypt_finished = atomic_dec_and_test(&ctx->cc_pending);
@@ -2109,10 +2107,8 @@ static void kcryptd_crypt_write_continue(struct work_struct *work)
21092107
}
21102108

21112109
/* Encryption was already finished, submit io now */
2112-
if (crypt_finished) {
2110+
if (crypt_finished)
21132111
kcryptd_crypt_write_io_submit(io, 0);
2114-
io->sector = sector;
2115-
}
21162112

21172113
crypt_dec_pending(io);
21182114
}
@@ -2123,14 +2119,13 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
21232119
struct convert_context *ctx = &io->ctx;
21242120
struct bio *clone;
21252121
int crypt_finished;
2126-
sector_t sector = io->sector;
21272122
blk_status_t r;
21282123

21292124
/*
21302125
* Prevent io from disappearing until this function completes.
21312126
*/
21322127
crypt_inc_pending(io);
2133-
crypt_convert_init(cc, ctx, NULL, io->base_bio, sector);
2128+
crypt_convert_init(cc, ctx, NULL, io->base_bio, io->sector);
21342129

21352130
clone = crypt_alloc_buffer(io, io->base_bio->bi_iter.bi_size);
21362131
if (unlikely(!clone)) {
@@ -2147,8 +2142,6 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
21472142
io->ctx.iter_in = clone->bi_iter;
21482143
}
21492144

2150-
sector += bio_sectors(clone);
2151-
21522145
crypt_inc_pending(io);
21532146
r = crypt_convert(cc, ctx,
21542147
test_bit(DM_CRYPT_NO_WRITE_WORKQUEUE, &cc->flags), true);
@@ -2172,10 +2165,8 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
21722165
}
21732166

21742167
/* Encryption was already finished, submit io now */
2175-
if (crypt_finished) {
2168+
if (crypt_finished)
21762169
kcryptd_crypt_write_io_submit(io, 0);
2177-
io->sector = sector;
2178-
}
21792170

21802171
dec:
21812172
crypt_dec_pending(io);
@@ -2203,7 +2194,7 @@ static void kcryptd_crypt_read_continue(struct work_struct *work)
22032194
wait_for_completion(&io->ctx.restart);
22042195
reinit_completion(&io->ctx.restart);
22052196

2206-
r = crypt_convert(cc, &io->ctx, true, false);
2197+
r = crypt_convert(cc, &io->ctx, false, false);
22072198
if (r)
22082199
io->error = r;
22092200

@@ -2221,7 +2212,6 @@ static void kcryptd_crypt_read_convert(struct dm_crypt_io *io)
22212212
crypt_inc_pending(io);
22222213

22232214
if (io->ctx.aead_recheck) {
2224-
io->ctx.cc_sector = io->sector + cc->iv_offset;
22252215
r = crypt_convert(cc, &io->ctx,
22262216
test_bit(DM_CRYPT_NO_READ_WORKQUEUE, &cc->flags), true);
22272217
} else {

drivers/md/dm-io.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ static void do_region(const blk_opf_t opf, unsigned int region,
379379

380380
atomic_inc(&io->count);
381381
submit_bio(bio);
382+
WARN_ON_ONCE(opf & REQ_ATOMIC && remaining);
382383
} while (remaining);
383384
}
384385

drivers/md/dm-linear.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ static size_t linear_dax_recovery_write(struct dm_target *ti, pgoff_t pgoff,
199199

200200
static struct target_type linear_target = {
201201
.name = "linear",
202-
.version = {1, 4, 0},
202+
.version = {1, 5, 0},
203203
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
204-
DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO,
204+
DM_TARGET_ZONED_HM | DM_TARGET_PASSES_CRYPTO |
205+
DM_TARGET_ATOMIC_WRITES,
205206
.report_zones = linear_report_zones,
206207
.module = THIS_MODULE,
207208
.ctr = linear_ctr,

drivers/md/dm-ps-io-affinity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int ioa_create(struct path_selector *ps, unsigned int argc, char **argv)
116116
if (!s)
117117
return -ENOMEM;
118118

119-
s->path_map = kzalloc(nr_cpu_ids * sizeof(struct path_info *),
119+
s->path_map = kcalloc(nr_cpu_ids, sizeof(struct path_info *),
120120
GFP_KERNEL);
121121
if (!s->path_map)
122122
goto free_selector;

drivers/md/dm-raid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3196,7 +3196,7 @@ static int raid_ctr(struct dm_target *ti, unsigned int argc, char **argv)
31963196
if (reshape_sectors || rs_is_raid1(rs)) {
31973197
/*
31983198
* We can only prepare for a reshape here, because the
3199-
* raid set needs to run to provide the repective reshape
3199+
* raid set needs to run to provide the respective reshape
32003200
* check functions via its MD personality instance.
32013201
*
32023202
* So do the reshape check after md_run() succeeded.

drivers/md/dm-raid1.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ static void do_write(struct mirror_set *ms, struct bio *bio)
656656
unsigned int i;
657657
struct dm_io_region io[MAX_NR_MIRRORS], *dest = io;
658658
struct mirror *m;
659-
blk_opf_t op_flags = bio->bi_opf & (REQ_FUA | REQ_PREFLUSH);
659+
blk_opf_t op_flags = bio->bi_opf & (REQ_FUA | REQ_PREFLUSH | REQ_ATOMIC);
660660
struct dm_io_request io_req = {
661661
.bi_opf = REQ_OP_WRITE | op_flags,
662662
.mem.type = DM_IO_BIO,
@@ -1483,8 +1483,9 @@ static int mirror_iterate_devices(struct dm_target *ti,
14831483

14841484
static struct target_type mirror_target = {
14851485
.name = "mirror",
1486-
.version = {1, 14, 0},
1486+
.version = {1, 15, 0},
14871487
.module = THIS_MODULE,
1488+
.features = DM_TARGET_ATOMIC_WRITES,
14881489
.ctr = mirror_ctr,
14891490
.dtr = mirror_dtr,
14901491
.map = mirror_map,

drivers/md/dm-stripe.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,9 @@ static void stripe_io_hints(struct dm_target *ti,
465465

466466
static struct target_type stripe_target = {
467467
.name = "striped",
468-
.version = {1, 6, 0},
469-
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT,
468+
.version = {1, 7, 0},
469+
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
470+
DM_TARGET_ATOMIC_WRITES,
470471
.module = THIS_MODULE,
471472
.ctr = stripe_ctr,
472473
.dtr = stripe_dtr,

drivers/md/dm-table.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,32 @@ static bool dm_table_supports_secure_erase(struct dm_table *t)
18061806
return true;
18071807
}
18081808

1809+
static int device_not_atomic_write_capable(struct dm_target *ti,
1810+
struct dm_dev *dev, sector_t start,
1811+
sector_t len, void *data)
1812+
{
1813+
return !bdev_can_atomic_write(dev->bdev);
1814+
}
1815+
1816+
static bool dm_table_supports_atomic_writes(struct dm_table *t)
1817+
{
1818+
for (unsigned int i = 0; i < t->num_targets; i++) {
1819+
struct dm_target *ti = dm_table_get_target(t, i);
1820+
1821+
if (!dm_target_supports_atomic_writes(ti->type))
1822+
return false;
1823+
1824+
if (!ti->type->iterate_devices)
1825+
return false;
1826+
1827+
if (ti->type->iterate_devices(ti,
1828+
device_not_atomic_write_capable, NULL)) {
1829+
return false;
1830+
}
1831+
}
1832+
return true;
1833+
}
1834+
18091835
int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18101836
struct queue_limits *limits)
18111837
{
@@ -1854,6 +1880,9 @@ int dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18541880
return r;
18551881
}
18561882

1883+
if (dm_table_supports_atomic_writes(t))
1884+
limits->features |= BLK_FEAT_ATOMIC_WRITES;
1885+
18571886
r = queue_limits_set(q, limits);
18581887
if (r)
18591888
return r;

0 commit comments

Comments
 (0)