add support for direct I/O with fscrypt using blk-crypto
Subsystems (6)
v3 cover add support for direct I/O with fscrypt using blk-crypto
This patch series adds support for direct I/O with fscrypt using blk-crypto. It has been rebased on fscrypt/master.
Patch 1 adds two functions to fscrypt that need to be called to determine if direct I/O is supported for a request.
Patches 2 and 3 wire up direct-io and iomap respectively with the functions introduced in Patch 1 and set bio crypt contexts on bios when appropriate by calling into fscrypt.
Patches 4 and 5 allow ext4 and f2fs direct I/O to support fscrypt without falling back to buffered I/O.
Patches 6 and 7 update the fscrypt documentation for inline encryption support and direct I/O. The documentation now notes the required conditions for inline encryption and direct I/O on encrypted files.
This patch series was tested by running xfstests with test_dummy_encryption with and without the 'inlinecrypt' mount option, and there were no meaningful regressions. One regression was for generic/587 on ext4, but that test isn't compatible with test_dummy_encryption in the first place, and the test "incorrectly" passes without the 'inlinecrypt' mount option - a patch will be sent out to exclude that test when test_dummy_encryption is turned on with ext4 (like the other quota related tests that use user visible quota files). The other regression was for generic/252 on ext4, which does direct I/O with a buffer aligned to the block device's blocksize, but not necessarily aligned to the filesystem's block size, which direct I/O with fscrypt requires.
Changes v2 => v3:
- add changelog to coverletter
Changes v1 => v2:
- Fix bug in f2fs caused by replacing f2fs_post_read_required() with !fscrypt_dio_supported() since the latter doesn't check for compressed inodes unlike the former.
- Add patches 6 and 7 for fscrypt documentation
- cleanups and comments
Eric Biggers (5):
fscrypt: Add functions for direct I/O support
direct-io: add support for fscrypt using blk-crypto
iomap: support direct I/O with fscrypt using blk-crypto
ext4: support direct I/O with fscrypt using blk-crypto
f2fs: support direct I/O with fscrypt using blk-crypto
Satya Tangirala (2):
fscrypt: document inline encryption support
fscrypt: update documentation for direct I/O support
Documentation/filesystems/fscrypt.rst | 36 +++++++++++- fs/crypto/crypto.c | 8 +++ fs/crypto/inline_crypt.c | 80 +++++++++++++++++++++++++++ fs/direct-io.c | 15 ++++- fs/ext4/file.c | 10 ++-- fs/f2fs/f2fs.h | 6 +- fs/iomap/direct-io.c | 8 +++ include/linux/fscrypt.h | 19 +++++++ 8 files changed, 173 insertions(+), 9 deletions(-)
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v3 1/7 fscrypt: Add functions for direct I/O support
From: Eric Biggers <[email protected]>
Introduce fscrypt_dio_supported() to check whether a direct I/O request is unsupported due to encryption constraints, and fscrypt_limit_io_pages() to check how many pages may be added to a bio being prepared for direct I/O.
The IV_INO_LBLK_32 fscrypt policy introduced the possibility that DUNs in logically continuous file blocks might wrap from 0xffffffff to 0. Since this was particularly difficult to handle when block_size != PAGE_SIZE, fscrypt only supports blk-crypto en/decryption with the IV_INO_LBLK_32 policy when block_size == PAGE_SIZE, and ensures that the DUN never wraps around within any submitted bio. fscrypt_limit_io_pages() can be used to determine the number of logically contiguous blocks/pages that may be added to the bio without causing the DUN to wrap around within the bio. This is an alternative to calling fscrypt_mergeable_bio() on each page in a range of logically contiguous pages.
--- fs/crypto/crypto.c | 8 ++++ fs/crypto/inline_crypt.c | 80 ++++++++++++++++++++++++++++++++++++++++ include/linux/fscrypt.h | 19 ++++++++++ 3 files changed, 107 insertions(+)
fs/crypto/crypto.c +8 -0
@@ -69,6 +69,14 @@ void fscrypt_free_bounce_page(struct page *bounce_page) }EXPORT_SYMBOL (fscrypt_free_bounce_page); +/* +* Generate the IV for the given logical block number within the given file. +* For filenames encryption, lblk_num == 0. +* +* Keep this in sync with fscrypt_limit_io_pages(). fscrypt_limit_io_pages() +* needs to know about any IV generation methods where the low bits of IV don't +* simply contain the lblk_num (e.g., IV_INO_LBLK_32). +*/ void fscrypt_generate_iv (union fscrypt_iv *iv,u64 lblk_num,const struct fscrypt_info *ci) {
fs/crypto/inline_crypt.c +80 -0
89 lines not on this page · raw message
include/linux/fscrypt.h +19 -0
@@ -559,6 +559,11 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,bool fscrypt_mergeable_bio_bh (struct bio *bio,const struct buffer_head *next_bh); +bool fscrypt_dio_supported (struct kiocb *iocb,struct iov_iter *iter); + +int fscrypt_limit_io_pages (const struct inode *inode,loff_t pos, +int nr_pages); +#else /* CONFIG_FS_ENCRYPTION_INLINE_CRYPT */ static inline bool __fscrypt_inode_uses_inline_crypto (const struct inode *inode)
@@ -587,6 +592,20 @@ static inline bool fscrypt_mergeable_bio_bh(struct bio *bio, {return true; } + +static inline bool fscrypt_dio_supported (struct kiocb *iocb, +struct iov_iter *iter) +{ +const struct inode *inode =file_inode (iocb->ki_filp); + +return !fscrypt_needs_contents_encryption (inode); +} + +static inline int fscrypt_limit_io_pages (const struct inode *inode,loff_t pos, +int nr_pages) +{ +return nr_pages; +}#endif /* !CONFIG_FS_ENCRYPTION_INLINE_CRYPT */ /**
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Eric Biggers
maintainerRe: [PATCH v3 1/7] fscrypt: Add functions for direct I/O support
Quoted 7 lines · Satya Tangirala
From: Eric Biggers <[email protected]>
Introduce
fscrypt_dio_supported()to check whether a direct I/O request is unsupported due to encryption constraints, andfscrypt_limit_io_pages()to check how many pages may be added to a bio being prepared for direct I/O.
Quoted 11 lines
The
IV_INO_LBLK_32fscrypt policy introduced the possibility that DUNs in logically continuous file blocks might wrap from0xffffffffto 0. Since this was particularly difficult to handle whenblock_size!=PAGE_SIZE, fscrypt only supports blk-crypto en/decryption with theIV_INO_LBLK_32policy whenblock_size==PAGE_SIZE, and ensures that the DUN never wraps around within any submitted bio.fscrypt_limit_io_pages()can be used to determine the number of logically contiguous blocks/pages that may be added to the bio without causing the DUN to wrap around within the bio. This is an alternative to callingfscrypt_mergeable_bio()on each page in a range of logically contiguous pages.
This is a bit hard to read, especially the second paragraph. How about:
"Introduce fscrypt_dio_supported() to check whether a direct I/O request is unsupported due to encryption constraints.
Also introduce fscrypt_limit_io_pages() to limit how many pages can be added to a bio being prepared for direct I/O. This is needed for the iomap direct I/O implementation to avoid DUN wraparound in the middle of a bio (which is possible with the IV_INO_LBLK_32 IV generation method). Elsewhere fscrypt_mergeable_bio() is used for this, but iomap operates on logical ranges directly and thus needs doesn't have a chance to call fscrypt_mergeable_bio() on every block or page. So we need a function which limits a logical range in one go."
In particular, the detail about PAGE_SIZE better belongs in the code, I think.
Quoted 7 lines
+/**
+ *fscrypt_limit_io_pages()- limit I/O pages to avoid discontiguous DUNs
+ * @inode: the file on which I/O is being done
+ * @pos: the file position (in bytes) at which the I/O is being done
+ * @nr_pages: the number of pages we want to submit starting at @pos
+ *
+ * Determine the limit to the number of pages that can be submitted in the bio
Quoted 8 lines
+ * targeting @pos without causing a data unit number (DUN) discontinuity.
+ *
+ * For IV generation methods that can't cause DUN wraparounds
+ * within logically continuous data blocks, the maximum number of pages is
+ * simply @nr_pages. For those IV generation methods that *might* cause DUN
+ * wraparounds, the returned number of pages is the largest possible number of
+ * pages (less than @nr_pages) that can be added to the bio without causing a
+ * DUN wraparound within the bio.
How about replacing the second paragraph here with:
* This is normally just @nr_pages, as normally the DUNs just increment along
* with the logical blocks. (Or the file is not encrypted.)
*
* In rare cases, fscrypt can be using an IV generation method that allows the
* DUN to wrap around within logically continuous blocks, and that wraparound
* will occur. If this happens, a value less than @nr_pages will be returned so
* that the wraparound doesn't occur in the middle of the bio. Note that we
* only support block_size == PAGE_SIZE (and page-aligned DIO) in such cases.
PATCH v3 2/7 direct-io: add support for fscrypt using blk-crypto
In reply to Satya TangiralaFrom: Eric Biggers <[email protected]>
Set bio crypt contexts on bios by calling into fscrypt when required, and explicitly check for DUN continuity when adding pages to the bio. (While DUN continuity is usually implied by logical block contiguity, this is not the case when using certain fscrypt IV generation methods like IV_INO_LBLK_32).
--- fs/direct-io.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
fs/direct-io.c +14 -1
@@ -24,6 +24,7 @@#include <linux/module.h> #include <linux/types.h> #include <linux/fs.h> +#include <linux/fscrypt.h> #include <linux/mm.h> #include <linux/slab.h> #include <linux/highmem.h>
@@ -411,6 +412,7 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio, sector_t first_sector, int nr_vecs) {struct bio *bio; +struct inode *inode = dio->inode;/* * bio_alloc() is guaranteed to return a bio when allowed to sleep and
@@ -418,6 +420,9 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,*/ bio =bio_alloc (GFP_KERNEL , nr_vecs); +fscrypt_set_bio_crypt_ctx (bio, inode, + sdio->cur_page_fs_offset >> inode->i_blkbits, +GFP_KERNEL );bio_set_dev (bio, bdev); bio->bi_iter.bi_sector = first_sector;bio_set_op_attrs (bio, dio->op, dio->op_flags);
@@ -782,9 +787,17 @@ static inline int dio_send_cur_page(struct dio *dio, struct dio_submit *sdio,* current logical offset in the file does not equal what would * be the next logical offset in the bio, submit the bio we * have. +* +* When fscrypt inline encryption is used, data unit number +* (DUN) contiguity is also required. Normally that's implied +* by logical contiguity. However, certain IV generation +* methods (e.g. IV_INO_LBLK_32) don't guarantee it. So, we +* must explicitly check fscrypt_mergeable_bio() too. */ if (sdio->final_block_in_bio != sdio->cur_page_block || - cur_offset != bio_next_offset) + cur_offset != bio_next_offset || + !fscrypt_mergeable_bio (sdio->bio, dio->inode, + cur_offset >> dio->inode->i_blkbits))dio_bio_submit (dio, sdio); }
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v3 3/7 iomap: support direct I/O with fscrypt using blk-crypto
In reply to Satya TangiralaFrom: Eric Biggers <[email protected]>
Wire up iomap direct I/O with the fscrypt additions for direct I/O, and set bio crypt contexts on bios when appropriate.
Make iomap_dio_bio_actor() call fscrypt_limit_io_pages() to ensure that DUNs remain contiguous within a bio, since it works directly with logical ranges and can't call fscrypt_mergeable_bio() on each page.
--- fs/iomap/direct-io.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/iomap/direct-io.c +8 -0
@@ -6,6 +6,7 @@#include <linux/module.h> #include <linux/compiler.h> #include <linux/fs.h> +#include <linux/fscrypt.h> #include <linux/iomap.h> #include <linux/backing-dev.h> #include <linux/uio.h>
@@ -183,11 +184,14 @@ static void iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos, unsigned len) { + struct inode *inode = file_inode(dio->iocb->ki_filp);struct page *page =ZERO_PAGE (0 );int flags =REQ_SYNC |REQ_IDLE ;struct bio *bio; 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->bi_iter.bi_sector =iomap_sector (iomap, pos); bio->bi_private = dio;
@@ -253,6 +257,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, ret = nr_pages; goto out; } + nr_pages =fscrypt_limit_io_pages (inode, pos, nr_pages);if (need_zeroout) {/* zero out from the start of the block to the write offset */
@@ -270,6 +275,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, } 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->bi_iter.bi_sector =iomap_sector (iomap, pos); bio->bi_write_hint = dio->iocb->ki_hint;
@@ -307,6 +314,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, copied += n; nr_pages =iov_iter_npages (dio->submit.iter,BIO_MAX_PAGES ); + nr_pages =fscrypt_limit_io_pages (inode, pos, nr_pages);iomap_dio_submit_bio (dio, iomap, bio, pos); pos += n; }while (nr_pages);
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Eric Biggers
maintainerRe: [PATCH v3 3/7] iomap: support direct I/O with fscrypt using blk-crypto
Quoted 8 lines · Satya Tangirala
From: Eric Biggers <[email protected]>
Wire up iomap direct I/O with the fscrypt additions for direct I/O, and set bio crypt contexts on bios when appropriate.
Make
iomap_dio_bio_actor()callfscrypt_limit_io_pages()to ensure that DUNs remain contiguous within a bio, since it works directly with logical ranges and can't callfscrypt_mergeable_bio()on each page.
This commit message is still confusing.
How about the following:
"Wire up iomap direct I/O with the fscrypt additions for direct I/O. This allows ext4 to support direct I/O on encrypted files when inline encryption is enabled.
This change consists of two parts:
- Set a bio_crypt_ctx on bios for encrypted files, so that the file contents get encrypted (or decrypted).
- Ensure that encryption data unit numbers (DUNs) are contiguous within each bio. Use the new function fscrypt_limit_io_pages() for this, since the iomap code works directly with logical ranges and thus doesn't have a chance to call fscrypt_mergeable_bio() on each page.
Note that fscrypt_limit_io_pages() is normally a no-op, as normally the DUNs simply increment along with the logical blocks. But it's needed to handle an edge case in one of the fscrypt IV generation methods."
Quoted 5 lines
fs/iomap/direct-io.c +1
-0@@ -183,11 +184,14 @@ static void iomap_dio_zero(struct iomap_dio *dio, struct iomap *iomap, loff_t pos, unsigned len) { + struct inode *inode = file_inode(dio->iocb->ki_filp);
fs/iomap/direct-io.c static void · line 197
Quoted 10 lines
fs/iomap/direct-io.c +2
-0struct page *page =ZERO_PAGE (0 );int flags =REQ_SYNC |REQ_IDLE ;struct bio *bio; 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->bi_iter.bi_sector =iomap_sector (iomap, pos); bio->bi_private = dio;
iomap_dio_zero() is only used on partial filesystem blocks. But, we only allow direct I/O on encrypted files when the I/O is filesystem-block-aligned.
So this part appears to be unnecessary.
How about replacing it with:
/* encrypted direct I/O is guaranteed to be fs-block aligned */ WARN_ON_ONCE(fscrypt_needs_contents_encryption(inode));
Quoted 18 lines
fs/iomap/direct-io.c +3
-0@@ -253,6 +257,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, ret = nr_pages; goto out; } + nr_pages =fscrypt_limit_io_pages (inode, pos, nr_pages);if (need_zeroout) {/* zero out from the start of the block to the write offset */ @@ -270,6 +275,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, } 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->bi_iter.bi_sector =iomap_sector (iomap, pos); bio->bi_write_hint = dio->iocb->ki_hint;
fs/iomap/direct-io.c iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, · line 320
Quoted 7 lines
fs/iomap/direct-io.c +1
-0@@ -307,6 +314,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, copied += n; nr_pages =iov_iter_npages (dio->submit.iter,BIO_MAX_PAGES ); + nr_pages =fscrypt_limit_io_pages (inode, pos, nr_pages);iomap_dio_submit_bio (dio, iomap, bio, pos); pos += n; }while (nr_pages);
I think the part at the end is wrong.
We want to limit the *next* bio, not the current one.
So 'pos' needs to be updated first.
I think it should be:
iomap_dio_submit_bio(dio, iomap, bio, pos);
pos += n;
nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES);
nr_pages = fscrypt_limit_io_pages(inode, pos, nr_pages);PATCH v3 4/7 ext4: support direct I/O with fscrypt using blk-crypto
In reply to Satya TangiralaFrom: Eric Biggers <[email protected]>
Wire up ext4 with fscrypt direct I/O support. direct I/O with fscrypt is only supported through blk-crypto (i.e. CONFIG_BLK_INLINE_ENCRYPTION must have been enabled, the 'inlinecrypt' mount option must have been specified, and either hardware inline encryption support must be present or CONFIG_BLK_INLINE_ENCYRPTION_FALLBACK must have been enabled). Further, direct I/O on encrypted files is only supported when I/O is aligned to the filesystem block size (which is *not* necessarily the same as the block device's block size).
--- fs/ext4/file.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/ext4/file.c +6 -4
@@ -36,9 +36,11 @@#include "acl.h" #include "truncate.h" -static bool ext4_dio_supported (struct inode *inode) +static bool ext4_dio_supported (struct kiocb *iocb,struct iov_iter *iter) { -if (IS_ENABLED (CONFIG_FS_ENCRYPTION ) &&IS_ENCRYPTED (inode)) +struct inode *inode =file_inode (iocb->ki_filp); + +if (!fscrypt_dio_supported (iocb, iter))return false;if (fsverity_active (inode))return false;
@@ -61,7 +63,7 @@ static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)inode_lock_shared (inode); } -if (!ext4_dio_supported (inode)) { +if (!ext4_dio_supported (iocb, to)) {inode_unlock_shared (inode);/* * Fallback to buffered I/O if the operation being performed on
@@ -490,7 +492,7 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from) }/* Fallback to buffered I/O if the inode does not support direct I/O. */ -if (!ext4_dio_supported (inode)) { +if (!ext4_dio_supported (iocb, from)) {if (ilock_shared)inode_unlock_shared (inode);else
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v3 5/7 f2fs: support direct I/O with fscrypt using blk-crypto
In reply to Satya TangiralaFrom: Eric Biggers <[email protected]>
Wire up f2fs with fscrypt direct I/O support. direct I/O with fscrypt is only supported through blk-crypto (i.e. CONFIG_BLK_INLINE_ENCRYPTION must have been enabled, the 'inlinecrypt' mount option must have been specified, and either hardware inline encryption support must be present or CONFIG_BLK_INLINE_ENCYRPTION_FALLBACK must have been enabled). Further, direct I/O on encrypted files is only supported when I/O is aligned to the filesystem block size (which is *not* necessarily the same as the block device's block size).
--- fs/f2fs/f2fs.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +5 -1
@@ -4082,7 +4082,11 @@ static inline bool f2fs_force_buffered_io(struct inode *inode,struct f2fs_sb_info *sbi =F2FS_I_SB (inode);int rw =iov_iter_rw (iter); -if (f2fs_post_read_required (inode)) +if (!fscrypt_dio_supported (iocb, iter)) +return true; +if (fsverity_active (inode)) +return true; +if (f2fs_compressed_file (inode))return true;if (f2fs_is_multi_device (sbi))return true;
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v3 6/7 fscrypt: document inline encryption support
In reply to Satya TangiralaUpdate the fscrypt documentation file for inline encryption support.
--- Documentation/filesystems/fscrypt.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
Documentation/filesystems/fscrypt.rst +15 -1
@@ -1204,6 +1204,18 @@ buffer. Some filesystems, such as UBIFS, already use temporary buffers regardless of encryption. Other filesystems, such as ext4 and F2FS, have to allocate bounce pages specially for encryption. +Fscrypt is also able to use inline encryption hardware instead of the +kernel crypto API for en/decryption of file contents. When possible, and +if directed to do so (by specifying the 'inlinecrypt' mount option for +an ext4/F2FS filesystem), it adds encryption contexts to bios and +uses blk-crypto to perform the en/decryption instead of making use +of the above read/write path changes. Of course, even if directed to make +use of inline encryption, fscrypt will only be able to do so if either +hardware inline encryption support is available for the selected encryption +algorithm or CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK is selected. If neither +is the case, fscrypt will fall back to using the above mentioned read/write +path changes for en/decryption. + Filename hashing and encoding -----------------------------
@@ -1250,7 +1262,9 @@ Tests To test fscrypt, use xfstests, which is Linux's de facto standard filesystem test suite. First, run all the tests in the "encrypt" -group on the relevant filesystem(s). For example, to test ext4 and +group on the relevant filesystem(s). One can also run the tests +with the 'inlinecrypt' mount option to test the implementation for +inline encryption support. For example, to test ext4 and f2fs encryption using `kvm-xfstests <https://github.com/tytso/xfstests-bld/blob/master/Documentation/kvm-quickstart.md>`_::
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Re: [PATCH v3 6/7] fscrypt: document inline encryption support
Quoted 3 lines · Satya Tangirala
Update the fscrypt documentation file for inline encryption support.
Signed-off-by Satya Tangirala <[email protected]>
Quoted 10 lines
Documentation/filesystems/fscrypt.rst +2
-0@@ -1204,6 +1204,18 @@ buffer. Some filesystems, such as UBIFS, already use temporary buffers regardless of encryption. Other filesystems, such as ext4 and F2FS, have to allocate bounce pages specially for encryption. +Fscrypt is also able to use inline encryption hardware instead of the +kernel crypto API for en/decryption of file contents. When possible, and
Documentation/filesystems/fscrypt.rst buffer. Some filesystems, such as UBIFS, already use temporary · line 1218
Quoted 10 lines
Documentation/filesystems/fscrypt.rst +10
-0+if directed to do so (by specifying the 'inlinecrypt' mount option for +an ext4/F2FS filesystem), it adds encryption contexts to bios and +uses blk-crypto to perform the en/decryption instead of making use +of the above read/write path changes. Of course, even if directed to make +use of inline encryption, fscrypt will only be able to do so if either +hardware inline encryption support is available for the selected encryption +algorithm or CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK is selected. If neither +is the case, fscrypt will fall back to using the above mentioned read/write +path changes for en/decryption. +
Nit: most of the text in this file is formatted with textwidth=70.
Quoted 17 lines
Documentation/filesystems/fscrypt.rst +3
-1Filename hashing and encoding -----------------------------@@ -1250,7 +1262,9 @@ Tests To test fscrypt, use xfstests, which is Linux's de facto standard filesystem test suite. First, run all the tests in the "encrypt" -group on the relevant filesystem(s). For example, to test ext4 and +group on the relevant filesystem(s). One can also run the tests +with the 'inlinecrypt' mount option to test the implementation for +inline encryption support. For example, to test ext4 and f2fs encryption using `kvm-xfstests <https://github.com/tytso/xfstests-bld/blob/master/Documentation/kvm-quickstart.md>`_::Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
PATCH v3 7/7 fscrypt: update documentation for direct I/O support
In reply to Satya TangiralaUpdate fscrypt documentation to reflect the addition of direct I/O support and document the necessary conditions for direct I/O on encrypted files.
--- Documentation/filesystems/fscrypt.rst | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
Documentation/filesystems/fscrypt.rst +18 -2
@@ -1049,8 +1049,10 @@ astute users may notice some differences in behavior: may be used to overwrite the source files but isn't guaranteed to be effective on all filesystems and storage devices. -- Direct I/O is not supported on encrypted files. Attempts to use - direct I/O on such files will fall back to buffered I/O. +- Direct I/O is supported on encrypted files only under some circumstances + (see `Direct I/O support`_ for details). When these circumstances are not + met, attempts to use direct I/O on such files will fall back to buffered + I/O. - The fallocate operations FALLOC_FL_COLLAPSE_RANGE and FALLOC_FL_INSERT_RANGE are not supported on encrypted files and will
@@ -1257,6 +1259,20 @@ without the key is subject to change in the future. It is only meant as a way to temporarily present valid filenames so that commands like ``rm -r`` work as expected on encrypted directories. +Direct I/O support +------------------ + +Direct I/O on encrypted files is supported through blk-crypto. In +particular, this means the kernel must have CONFIG_BLK_INLINE_ENCRYPTION +enabled, the filesystem must have had the 'inlinecrypt' mount option +specified, and either hardware inline encryption must be present, or +CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK must have been enabled. Further, +any I/O must be aligned to the filesystem block size (*not* necessarily +the same as the block device's block size) - in particular, any userspace +buffer into which data is read/written from must also be aligned to the +filesystem block size. If any of these conditions isn't met, attempts to do +direct I/O on an encrypted file will fall back to buffered I/O. + Tests =====
Signature · 1 line
2.28.0.rc0.105.gf9edc3c819-goog
Eric Biggers
maintainerRe: [PATCH v3 7/7] fscrypt: update documentation for direct I/O support
Quoted 13 lines · Satya Tangirala
Update fscrypt documentation to reflect the addition of direct I/O support and document the necessary conditions for direct I/O on encrypted files.
Signed-off-by Satya Tangirala <[email protected]>--- Documentation/filesystems/fscrypt.rst | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)Documentation/filesystems/fscrypt.rst +0
-0
Documentation/filesystems/fscrypt.rst astute users may notice some differences in behavior: · line 1055
Quoted 9 lines
Documentation/filesystems/fscrypt.rst +4
-2@@ -1049,8 +1049,10 @@ astute users may notice some differences in behavior: may be used to overwrite the source files but isn't guaranteed to be effective on all filesystems and storage devices. -- Direct I/O is not supported on encrypted files. Attempts to use - direct I/O on such files will fall back to buffered I/O. +- Direct I/O is supported on encrypted files only under some circumstances + (see `Direct I/O support`_ for details). When these circumstances are not + met, attempts to use direct I/O on such files will fall back to buffered + I/O.
Nit: "such files" => "encrypted files".
Nit: most of the text in this file is formatted with textwidth=70.
Quoted 10 lines
Documentation/filesystems/fscrypt.rst +3
-0- The fallocate operations FALLOC_FL_COLLAPSE_RANGE and FALLOC_FL_INSERT_RANGE are not supported on encrypted files and will@@ -1257,6 +1259,20 @@ without the key is subject to change in the future. It is only meant as a way to temporarily present valid filenames so that commands like ``rm -r`` work as expected on encrypted directories. +Direct I/O support +------------------ +
Documentation/filesystems/fscrypt.rst without the key is subject to change in the future. It is only meant · line 1274
Quoted 10 lines
Documentation/filesystems/fscrypt.rst +10
-0+Direct I/O on encrypted files is supported through blk-crypto. In +particular, this means the kernel must have CONFIG_BLK_INLINE_ENCRYPTION +enabled, the filesystem must have had the 'inlinecrypt' mount option +specified, and either hardware inline encryption must be present, or +CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK must have been enabled. Further, +any I/O must be aligned to the filesystem block size (*not* necessarily +the same as the block device's block size) - in particular, any userspace +buffer into which data is read/written from must also be aligned to the +filesystem block size. If any of these conditions isn't met, attempts to do +direct I/O on an encrypted file will fall back to buffered I/O.
This is placing "Direct I/O support" as a subsection of the "Implementation details" section.
But the direct I/O support is more than just an implementation detail.
How about moving it to a top-level section?
I'd probably put it between "Access semantics" and "Encryption policy enforcement".
- Eric