mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
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 <satyat@google.com> Signed-off-by: Satya Tangirala <satyat@google.com> Acked-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20220128233940.79464-3-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@google.com>
This commit is contained in:
committed by
Jaegeuk Kim
parent
b6da748bab
commit
4b613cb0c4
@@ -6,6 +6,7 @@
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/compiler.h>
|
#include <linux/compiler.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
#include <linux/fscrypt.h>
|
||||||
#include <linux/iomap.h>
|
#include <linux/iomap.h>
|
||||||
#include <linux/backing-dev.h>
|
#include <linux/backing-dev.h>
|
||||||
#include <linux/uio.h>
|
#include <linux/uio.h>
|
||||||
@@ -185,11 +186,14 @@ static void
|
|||||||
iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,
|
iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos,
|
||||||
unsigned len)
|
unsigned len)
|
||||||
{
|
{
|
||||||
|
struct inode *inode = file_inode(dio->iocb->ki_filp);
|
||||||
struct page *page = ZERO_PAGE(0);
|
struct page *page = ZERO_PAGE(0);
|
||||||
int flags = REQ_SYNC | REQ_IDLE;
|
int flags = REQ_SYNC | REQ_IDLE;
|
||||||
struct bio *bio;
|
struct bio *bio;
|
||||||
|
|
||||||
bio = bio_alloc(GFP_KERNEL, 1);
|
bio = bio_alloc(GFP_KERNEL, 1);
|
||||||
|
fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
|
||||||
|
GFP_KERNEL);
|
||||||
bio_set_dev(bio, iomap->bdev);
|
bio_set_dev(bio, iomap->bdev);
|
||||||
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
|
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
|
||||||
bio->bi_private = dio;
|
bio->bi_private = dio;
|
||||||
@@ -272,6 +276,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bio = bio_alloc(GFP_KERNEL, nr_pages);
|
bio = bio_alloc(GFP_KERNEL, nr_pages);
|
||||||
|
fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits,
|
||||||
|
GFP_KERNEL);
|
||||||
bio_set_dev(bio, iomap->bdev);
|
bio_set_dev(bio, iomap->bdev);
|
||||||
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
|
bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
|
||||||
bio->bi_write_hint = dio->iocb->ki_hint;
|
bio->bi_write_hint = dio->iocb->ki_hint;
|
||||||
|
|||||||
Reference in New Issue
Block a user