Skip to content

Commit 983c7db

Browse files
Milan Brozkergon
authored andcommitted
dm crypt: always disable discard_zeroes_data
If optional discard support in dm-crypt is enabled, discards requests bypass the crypt queue and blocks of the underlying device are discarded. For the read path, discarded blocks are handled the same as normal ciphertext blocks, thus decrypted. So if the underlying device announces discarded regions return zeroes, dm-crypt must disable this flag because after decryption there is just random noise instead of zeroes. Signed-off-by: Milan Broz <mbroz@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent 8232480 commit 983c7db

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

drivers/md/dm-crypt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
16981698
}
16991699

17001700
ti->num_flush_requests = 1;
1701+
ti->discard_zeroes_data_unsupported = 1;
1702+
17011703
return 0;
17021704

17031705
bad:

drivers/md/dm-table.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,22 @@ static bool dm_table_supports_flush(struct dm_table *t, unsigned flush)
12831283
return 0;
12841284
}
12851285

1286+
static bool dm_table_discard_zeroes_data(struct dm_table *t)
1287+
{
1288+
struct dm_target *ti;
1289+
unsigned i = 0;
1290+
1291+
/* Ensure that all targets supports discard_zeroes_data. */
1292+
while (i < dm_table_get_num_targets(t)) {
1293+
ti = dm_table_get_target(t, i++);
1294+
1295+
if (ti->discard_zeroes_data_unsupported)
1296+
return 0;
1297+
}
1298+
1299+
return 1;
1300+
}
1301+
12861302
void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
12871303
struct queue_limits *limits)
12881304
{
@@ -1305,6 +1321,9 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
13051321
}
13061322
blk_queue_flush(q, flush);
13071323

1324+
if (!dm_table_discard_zeroes_data(t))
1325+
q->limits.discard_zeroes_data = 0;
1326+
13081327
dm_table_set_integrity(t);
13091328

13101329
/*

include/linux/device-mapper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ struct dm_target {
197197
* whether or not its underlying devices have support.
198198
*/
199199
unsigned discards_supported:1;
200+
201+
/*
202+
* Set if this target does not return zeroes on discarded blocks.
203+
*/
204+
unsigned discard_zeroes_data_unsupported:1;
200205
};
201206

202207
/* Each target can link one of these into the table */

0 commit comments

Comments
 (0)