Skip to content

Commit 489734e

Browse files
committed
iomap: support direct I/O with fscrypt using blk-crypto
Encrypted files traditionally haven't supported DIO, due to the need to encrypt/decrypt the data. However, when the encryption is implemented using inline encryption (blk-crypto) instead of the traditional filesystem-layer encryption, it is straightforward to support DIO. Add support for this to the iomap DIO implementation by calling fscrypt_set_bio_crypt_ctx() to set encryption contexts on the bios. Don't check for the rare case where a DUN (crypto data unit number) discontiguity creates a boundary that bios must not cross. Instead, filesystems are expected to handle this in ->iomap_begin() by limiting the length of the mapping so that iomap doesn't have to worry about it. Co-developed-by: Satya Tangirala <[email protected]> Signed-off-by: Satya Tangirala <[email protected]> Acked-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent c6c8978 commit 489734e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/iomap/direct-io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/module.h>
77
#include <linux/compiler.h>
88
#include <linux/fs.h>
9+
#include <linux/fscrypt.h>
910
#include <linux/pagemap.h>
1011
#include <linux/iomap.h>
1112
#include <linux/backing-dev.h>
@@ -179,11 +180,14 @@ static void iomap_dio_bio_end_io(struct bio *bio)
179180
static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio,
180181
loff_t pos, unsigned len)
181182
{
183+
struct inode *inode = file_inode(dio->iocb->ki_filp);
182184
struct page *page = ZERO_PAGE(0);
183185
int flags = REQ_SYNC | REQ_IDLE;
184186
struct bio *bio;
185187

186188
bio = bio_alloc(GFP_KERNEL, 1);
189+
fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
190+
GFP_KERNEL);
187191
bio_set_dev(bio, iter->iomap.bdev);
188192
bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos);
189193
bio->bi_private = dio;
@@ -310,6 +314,8 @@ static loff_t iomap_dio_bio_iter(const struct iomap_iter *iter,
310314
}
311315

312316
bio = bio_alloc(GFP_KERNEL, nr_pages);
317+
fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
318+
GFP_KERNEL);
313319
bio_set_dev(bio, iomap->bdev);
314320
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
315321
bio->bi_write_hint = dio->iocb->ki_hint;

0 commit comments

Comments
 (0)