From 05e1912555d471e1c2fae2a42b3caf5ed74821ab Mon Sep 17 00:00:00 2001 From: LongPing Wei Date: Thu, 17 Oct 2024 10:03:25 +0800 Subject: [PATCH] ANDROID: set emulate_zone_append=true in dm-default-key All zone append writes to a zone of a zoned block device will have the same BIO sector, the start of the zone. When the cypher IV mode uses sector values, all data targeting a zone will be encrypted using the first sector numbers of the zone. This will not result in write errors but will cause most reads to fail as reads will use the sector values for the actual data locations, resulting in IV mismatch. To avoid this problem, ask DM core to emulate zone append operations with regular writes. Bug: 374251833 Change-Id: I620687c41d04e9ea1f54c5037dae97ddd5bb67eb Signed-off-by: LongPing Wei --- drivers/md/dm-default-key.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/md/dm-default-key.c b/drivers/md/dm-default-key.c index 15c963ab907e..40aa171e6e46 100644 --- a/drivers/md/dm-default-key.c +++ b/drivers/md/dm-default-key.c @@ -217,6 +217,22 @@ static int default_key_ctr(struct dm_target *ti, unsigned int argc, char **argv) } dkc->start = tmpll; + if (bdev_is_zoned(dkc->dev->bdev)) { + /* + * All zone append writes to a zone of a zoned block device will + * have the same BIO sector, the start of the zone. When the + * cypher IV mode uses sector values, all data targeting a + * zone will be encrypted using the first sector numbers of the + * zone. This will not result in write errors but will + * cause most reads to fail as reads will use the sector values + * for the actual data locations, resulting in IV mismatch. + * To avoid this problem, ask DM core to emulate zone append + * operations with regular writes. + */ + DMDEBUG("Zone append operations will be emulated"); + ti->emulate_zone_append = true; + } + /* optional arguments */ dkc->sector_size = SECTOR_SIZE; if (argc > 5) {