Skip to contentSkip to conversation

add support for direct I/O with fscrypt using blk-crypto

PATCH Superseded Satya Tangirala 4 participants 15 messages Jul 9, 2020 – Jul 17, 2020

Subsystems (5)

v1 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/5 fscrypt: Add functions for direct I/O support

In reply to 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, and fscrypt_limit_dio_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 introduces the possibility that DUNs in logically continuous file blocks might wrap from 0xffffffff to 0. Bios in which the DUN wraps around like this cannot be submitted. This is especially difficult to handle when block_size != PAGE_SIZE, since in that case the DUN can wrap in the middle of a page.

For now, we add direct I/O support while using IV_INO_LBLK_32 policies only for the case when block_size == PAGE_SIZE. When IV_INO_LBLK_32 policy is used, fscrypt_dio_supported() rejects the bio when block_size != PAGE_SIZE. fscrypt_limit_dio_pages() returns the number of pages that may be added to the bio without causing the DUN to wrap around within the bio.

---
 fs/crypto/crypto.c       |  8 +++++
 fs/crypto/inline_crypt.c | 72 ++++++++++++++++++++++++++++++++++++++++
 include/linux/fscrypt.h  | 19 +++++++++++
 3 files changed, 99 insertions(+)
fs/crypto/crypto.c +8 -0
index a52cf32733ab..b88d97618efb 100644
@@ -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_dio_pages().  fscrypt_limit_dio_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 +72 -0

81 lines not on this page · raw message

include/linux/fscrypt.h +19 -0
index bb257411365f..9c65d949c611 100644
@@ -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_dio_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_dio_pages(const struct inode *inode, loff_t pos,
+					  int nr_pages)
+{
+	return nr_pages;
+}
 #endif /* !CONFIG_FS_ENCRYPTION_INLINE_CRYPT */
 
 /**
Signature · 8 lines
2.27.0.383.g050319c2ae-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#3 lore raw

PATCH 2/5 direct-io: add support for fscrypt using blk-crypto

In reply to Satya Tangirala

From: 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
index 6d5370eac2a8..f27f7e3780ee 100644
@@ -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 · 8 lines
2.27.0.383.g050319c2ae-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#9 lore raw

PATCH 4/5 ext4: support direct I/O with fscrypt using blk-crypto

In reply to Satya Tangirala

From: Eric Biggers <[email protected]>

Wire up ext4 with fscrypt direct I/O support.

---
 fs/ext4/file.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/ext4/file.c +6 -4
index 2a01e31a032c..d534f72675d9 100644
@@ -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 · 8 lines
2.27.0.383.g050319c2ae-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#11 lore raw

PATCH 5/5 f2fs: support direct I/O with fscrypt using blk-crypto

In reply to Satya Tangirala

From: Eric Biggers <[email protected]>

Wire up f2fs with fscrypt direct I/O support.

---
 fs/f2fs/f2fs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +3 -1
index b35a50f4953c..6d662a37b445 100644
@@ -4082,7 +4082,9 @@ 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_is_multi_device(sbi))
 		return true;
Signature · 8 lines
2.27.0.383.g050319c2ae-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#0 lore raw

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/inline-encryption.

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.

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. The only 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).

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

 fs/crypto/crypto.c       |  8 +++++
 fs/crypto/inline_crypt.c | 72 ++++++++++++++++++++++++++++++++++++++++
 fs/direct-io.c           | 15 ++++++++-
 fs/ext4/file.c           | 10 +++---
 fs/f2fs/f2fs.h           |  4 ++-
 fs/iomap/direct-io.c     |  8 +++++
 include/linux/fscrypt.h  | 19 +++++++++++
 7 files changed, 130 insertions(+), 6 deletions(-)
Signature · 1 line
2.27.0.383.g050319c2ae-goog
#7 lore raw

PATCH 3/5 iomap: support direct I/O with fscrypt using blk-crypto

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.

---
 fs/iomap/direct-io.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/iomap/direct-io.c +8 -0
index ec7b78e6feca..1e123d785199 100644
@@ -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_dio_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_dio_pages(inode, pos, nr_pages);
 		iomap_dio_submit_bio(dio, iomap, bio, pos);
 		pos += n;
 	} while (nr_pages);
Signature · 1 line
2.27.0.383.g050319c2ae-goog
maintainer
#2 lore raw

Re: [PATCH 1/5] fscrypt: Add functions for direct I/O support

In reply to Satya Tangirala
Quoted 13 lines · On Thu, Jul 09, 2020 at 07:47:47PM +0000, Satya Tangirala via Linux-f2fs-devel…

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_dio_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 introduces the possibility that DUNs in logically continuous file blocks might wrap from 0xffffffff to 0. Bios in which the DUN wraps around like this cannot be submitted. This is especially difficult to handle when block_size != PAGE_SIZE, since in that case the DUN can wrap in the middle of a page.

Quoted 6 lines

For now, we add direct I/O support while using IV_INO_LBLK_32 policies only for the case when block_size == PAGE_SIZE. When IV_INO_LBLK_32 policy is used, fscrypt_dio_supported() rejects the bio when block_size != PAGE_SIZE. fscrypt_limit_dio_pages() returns the number of pages that may be added to the bio without causing the DUN to wrap around within the bio.

This commit message is a bit outdated, since the latest version of "fscrypt: add inline encryption support" already makes IV_INO_LBLK_32 with block_size != PAGE_SIZE fall back to filesystem-layer encryption, and hence it won't allow direct I/O.

Quoted 3 lines

Can you mention any changes you made, e.g.:

[ST: split original change into separate patches, and updated to account
for inline encryption no longer being allowed with IV_INO_LBLK_32 and blocksize != PAGE_SIZE]

Quoted 11 lines

+/**
+ * fscrypt_limit_dio_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
+ *
+ * For direct I/O: limit the number of pages that will be submitted in the bio
+ * targeting @pos, in order to avoid crossing a data unit number (DUN)
+ * discontinuity. This is only needed for certain IV generation methods.
+ *
+ * This assumes block_size == PAGE_SIZE; see fscrypt_dio_supported().

The note about block_size == PAGE_SIZE here is outdated.

I was also struggling a bit to decide what to name this function. Note that it's not really direct I/O specific. Also, fs/iomap/direct-io.c needs it but fs/direct-io.c does not.

What this function really does is batch together the mergeability checks for a logical range.

Maybe the comment could explain this better, and maybe the function should be called "fscrypt_limit_io_pages()" instead.

Quoted 16 lines

+ * Return: the actual number of pages that can be submitted
+ */

fs/crypto/inline_crypt.c +14 -0
+int fscrypt_limit_dio_pages(const struct inode *inode, loff_t pos, int nr_pages)
+{
+	const struct fscrypt_info *ci = inode->i_crypt_info;
+	u32 dun;
+
+	if (!fscrypt_inode_uses_inline_crypto(inode))
+		return nr_pages;
+
+	if (nr_pages <= 1)
+		return nr_pages;
+
+	if (!(fscrypt_policy_flags(&ci->ci_policy) &
+	      FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32))
+		return nr_pages;

fs/crypto/inline_crypt.c bool fscrypt_mergeable_bio_bh(struct bio *bio, · line 436

Quoted 10 lines
fs/crypto/inline_crypt.c +10 -0
+
+	if (WARN_ON_ONCE(i_blocksize(inode) != PAGE_SIZE))
+		return 1;
+
+	/* With IV_INO_LBLK_32, the DUN can wrap around from U32_MAX to 0. */
+
+	dun = ci->ci_hashed_ino + (pos >> inode->i_blkbits);
+
+	return min_t(u64, nr_pages, (u64)U32_MAX + 1 - dun);
+}

- Eric

maintainer
#8 lore raw

Re: [PATCH 3/5] iomap: support direct I/O with fscrypt using blk-crypto

In reply to Satya Tangirala
Quoted 4 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.

It might be useful to mention why the calls to fscrypt_limit_dio_pages() are needed. (It's because the iomap code works directly with logical ranges, so it doesn't have a chance to do fscrypt_mergeable_bio() on every page.)

Quoted 6 lines
---
 fs/iomap/direct-io.c | 8 ++++++++
 1 file changed, 8 insertions(+)

You probably should add [email protected] to Cc, as per './scripts/get_maintainer.pl fs/iomap/'.

- Eric

maintainer
#10 lore raw

Re: [PATCH 4/5] ext4: support direct I/O with fscrypt using blk-crypto

In reply to Satya Tangirala
Quoted 6 lines · Satya Tangirala

From: Eric Biggers <[email protected]>

Wire up ext4 with fscrypt direct I/O support.

This commit message could use some more details. I think it should clarify that the direct I/O support is limited to cases where the filesystem has been mounted with '-o inlinecrypt' and CONFIG_BLK_INLINE_ENCRYPTION has been enabled, along with CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK if hardware support isn't present.

As-is, it sounds a bit over-promising.

Likewise for f2fs.

We need to properly document this too. At the very least, in the fscrypt patch, Documentation/filesystems/fscrypt.rst needs to be updated because it currently says "Direct I/O is not supported on encrypted files."

fscrypt.rst could also use some information about inline encryption. Currently inline encryption for fscrypt is only documented in the ext4 and f2fs documentation in the context of the inlinecrypt mount option. (Though, this suggestion applies even without direct I/O support.)

- Eric

maintainer
#14 lore raw
In reply to Satya Tangirala
Quoted 2 lines · Satya Tangirala

This patch series adds support for direct I/O with fscrypt using blk-crypto. It has been rebased on fscrypt/inline-encryption.

Nit: use fscrypt/master instead. (Eventually I'll delete the "inline-encryption" branch.)

Quoted 10 lines

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.

Quoted 8 lines

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. The only 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).

Note that xfstests has a check that prevents most of the direct I/O tests from running when the 'test_dummy_encryption' mount option was specified:

_require_odirect()
{
if [ $FSTYP = "ext4" ] || [ $FSTYP = "f2fs" ] ; then
if echo "$MOUNT_OPTIONS" | grep -q "test_dummy_encryption"; then
_notrun "$FSTYP encryption doesn't support O_DIRECT"
fi
fi

We should try changing that check to not skip the test if the 'inlinecrypt' mount option was also specified.

- Eric

#12 lore raw

Re: [PATCH 5/5] f2fs: support direct I/O with fscrypt using blk-crypto

In reply to Satya Tangirala
Quoted 15 lines · Satya Tangirala

From: Eric Biggers <[email protected]>

Wire up f2fs with fscrypt direct I/O support.

---
 fs/f2fs/f2fs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +0 -0
index b35a50f4953c..6d662a37b445 100644

fs/f2fs/f2fs.h static inline bool f2fs_force_buffered_io(struct inode *inode, · line 4087

Quoted 7 lines
fs/f2fs/f2fs.h +3 -1
@@ -4082,7 +4082,9 @@ 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))

static inline bool f2fs_post_read_required(struct inode *inode)

{
	return f2fs_encrypted_file(inode) || fsverity_active(inode) ||
		f2fs_compressed_file(inode);
}

That's not correct, missed to check compression condition.

Quoted 4 lines
fs/f2fs/f2fs.h +0 -0
 		return true;
 	if (f2fs_is_multi_device(sbi))
 		return true;
maintainer
#13 lore raw

Re: [PATCH 5/5] f2fs: support direct I/O with fscrypt using blk-crypto

Quoted 25 lines · Chao Yu
Quoted 15 lines · Satya Tangirala

From: Eric Biggers <[email protected]>

Wire up f2fs with fscrypt direct I/O support.

---
 fs/f2fs/f2fs.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +0 -0
index b35a50f4953c..6d662a37b445 100644

fs/f2fs/f2fs.h static inline bool f2fs_force_buffered_io(struct inode *inode, · line 4087

Quoted 7 lines
fs/f2fs/f2fs.h +3 -1
@@ -4082,7 +4082,9 @@ 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))

static inline bool f2fs_post_read_required(struct inode *inode)

Quoted 7 lines
{
	return f2fs_encrypted_file(inode) || fsverity_active(inode) ||
		f2fs_compressed_file(inode);
}

That's not correct, missed to check compression condition.

Thanks Chao, great catch. This used to be correct, but we missed that the second f2fs_compressed_file() check got removed by commit b5f4684b5f5f ("f2fs: remove redundant compress inode check").

- Eric

#4 lore raw

Re: [PATCH 2/5] direct-io: add support for fscrypt using blk-crypto

In reply to Satya Tangirala
Quoted 7 lines · Satya Tangirala

From: 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).

I know it is asking you for more work, but instead of adding more features to the legacy direct I/O code, could you just switch the user of it (I guess this is for f2f2?) to the iomap one?

maintainer
#5 lore raw

Re: [PATCH 2/5] direct-io: add support for fscrypt using blk-crypto

Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Satya Tangirala

From: 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).

Quoted 3 lines

I know it is asking you for more work, but instead of adding more features to the legacy direct I/O code, could you just switch the user of it (I guess this is for f2f2?) to the iomap one?

Eventually we should do that, as well as convert f2fs's fiemap, bmap, and llseek to use iomap. However there's a nontrivial barrier to entry, at least for someone who isn't an expert in iomap, especially since f2fs currently doesn't use iomap at all and thus doesn't have an iomap_ops implementation. And using ext4 as an example, there will be some subtle cases that need to be handled.

Satya says he's looking into it; we'll see what he can come up with and what the f2fs developers say.

If it turns out to be difficult and people think this patchset is otherwise ready, we probably shouldn't hold it up on that. This is a very small patch, and Satya and I have to maintain it for years in downstream kernels anyway, so it will be used and tested regardless. It would also be nice to allow userspace (e.g. xfstests) to assume that if the inlinecrypt mount option is supported, then direct I/O is supported too, without having to handle intermediate kernel releases where inlinecrypt was supported but not direct I/O.

- Eric

#6 lore raw

Re: [PATCH 2/5] direct-io: add support for fscrypt using blk-crypto

Quoted 23 lines · Eric Biggers
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Satya Tangirala

From: 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).

Quoted 3 lines

I know it is asking you for more work, but instead of adding more features to the legacy direct I/O code, could you just switch the user of it (I guess this is for f2f2?) to the iomap one?

Eventually we should do that, as well as convert f2fs's fiemap, bmap, and llseek to use iomap. However there's a nontrivial barrier to entry, at least for someone who isn't an expert in iomap, especially since f2fs currently doesn't use iomap at all and thus doesn't have an iomap_ops implementation. And using ext4 as an example, there will be some subtle cases that need to be handled.

Satya says he's looking into it; we'll see what he can come up with and what the f2fs developers say.

Quoted 8 lines

If it turns out to be difficult and people think this patchset is otherwise ready, we probably shouldn't hold it up on that. This is a very small patch, and Satya and I have to maintain it for years in downstream kernels anyway, so it will be used and tested regardless. It would also be nice to allow userspace (e.g. xfstests) to assume that if the inlinecrypt mount option is supported, then direct I/O is supported too, without having to handle intermediate kernel releases where inlinecrypt was supported but not direct I/O.

As Eric pointed out, it doesn't seem to be completely straightforward to move f2fs to using iomap - I'm still looking into it, but for now I've sent out v2 (and v3 just because I forgot to add a changelog to v2) with the changes to fs/direct-io.c as is from v1, but (again, for the reasons Eric points out) I think it'd be better not to hold this patch up for that.

Quoted 1 line

- Eric