Consolidate FS read I/O callbacks code
Subsystems (5)
PATCH v4 1/8 buffer_head: Introduce BH_Read_Cb flag
In reply to Chandan RajendraDecryption of file content encrypted using fscrypt relies on bio->bi_private holding a pointer to an encryption context i.e. Decryption operation is not performed for bios having a NULL value at bio->bi_private.
The same logic cannot be used on buffer heads because,
1. In Btrfs, write_dev_supers() sets bh->b_private to 'struct btrfs_device' pointer and submits the buffer head for a write operation.
1. In btrfs/146 test, the write operation fails and hence the endio function clears the BH_Uptodate flag.
2. A read operation initiated later will submit the buffer head to the block layer. During endio processing, bh_>b_private would have a non-NULL value.
2. Another instance is when an Ext4 metadata block with BH_Uptodate set and also part of the in-memory JBD list undergoes the following,
1. A sync() syscall is invoked by the userspace and the write operation on the metadata block is initiated.
2. Due to an I/O failure, the BH_Uptodate flag is cleared by end_buffer_async_write(). The bh->b_private member would be pointing to a journal head structure.
3. In such a case, a read operation invoked on the block mapped by the buffer head will initiate a read from the disk since the buffer head is missing the BH_Uptodate flag.
4. After the read I/O request is submitted, end_buffer_async_read()
will find a non-NULL value at bh->b_private.
This scenario was observed when executing generic/475 test case.
Hence this commit introduces a new buffer head flag to reliably check for decryption of a buffer head's contents after the block has been read from the disk.
--- include/linux/buffer_head.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/buffer_head.h +2 -0
@@ -38,6 +38,7 @@ enum bh_state_bits { BH_Meta,/* Buffer contains metadata */ BH_Prio,/* Buffer should be submitted with REQ_PRIO */ BH_Defer_Completion,/* Defer AIO completion to workqueue */ + BH_Read_Cb,/* Block's contents needs to be decrypted */ BH_PrivateStart,/* not a state bit, but the first bit available* for private allocation by other entities
@@ -134,6 +135,7 @@ BUFFER_FNS(Unwritten, unwritten) BUFFER_FNS(Meta, meta) BUFFER_FNS(Prio, prio) BUFFER_FNS(Defer_Completion, defer_completion) +BUFFER_FNS(Read_Cb, read_cb)#define bh_offset (bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
Signature · 1 line
2.19.1
PATCH v4 2/8 FS: Introduce read callbacks
In reply to Chandan RajendraRead callbacks implements a state machine to be executed after a buffered read I/O is completed. They help in further processing the file data read from the backing store. Currently, decryption is the only post processing step to be supported.
The execution of the state machine is to be initiated by the endio function associated with the read operation.
--- fs/Kconfig | 3 + fs/Makefile | 1 + fs/ext4/Kconfig | 1 + fs/f2fs/Kconfig | 1 + fs/read_callbacks.c | 285 +++++++++++++++++++++++++++++++++ include/linux/read_callbacks.h | 48 ++++++ 6 files changed, 339 insertions(+) create mode 100644 fs/read_callbacks.c create mode 100644 include/linux/read_callbacks.h
fs/Kconfig +3 -0
@@ -20,6 +20,9 @@ if BLOCK config FS_IOMAP bool +config FS_READ_CALLBACKS + bool + source "fs/ext2/Kconfig" source "fs/ext4/Kconfig" source "fs/jbd2/Kconfig"
fs/Makefile +1 -0
@@ -53,6 +53,7 @@ obj-$(CONFIG_SYSCTL) += drop_caches.o obj-$(CONFIG_FHANDLE) += fhandle.o obj-$(CONFIG_FS_IOMAP) += iomap.o +obj-$(CONFIG_FS_READ_CALLBACKS) += read_callbacks.o obj-y += quota/
fs/ext4/Kconfig +1 -0
@@ -38,6 +38,7 @@ config EXT4_FS select CRYPTO select CRYPTO_CRC32C select FS_IOMAP + select FS_READ_CALLBACKS if FS_ENCRYPTION help This is the next generation of the ext3 filesystem.
fs/f2fs/Kconfig +1 -0
@@ -4,6 +4,7 @@ config F2FS_FS select CRYPTO select CRYPTO_CRC32 select F2FS_FS_XATTR if FS_ENCRYPTION + select FS_READ_CALLBACKS if FS_ENCRYPTION help F2FS is based on Log-structured File System (LFS), which supports versatile "flash-friendly" features. The design has been focused on
fs/read_callbacks.c new file +285 -0
285 lines not on this page · raw message
include/linux/read_callbacks.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v4 3/8 fs/mpage.c: Integrate read callbacks
In reply to Chandan RajendraThis commit adds code to make do_mpage_readpage() to be "read callbacks" aware i.e. for files requiring decryption, do_mpage_readpage() now sets up the read callbacks state machine when allocating a bio and later starts execution of the state machine after file data is read from the underlying disk.
--- fs/mpage.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
fs/mpage.c +21 -3
@@ -30,6 +30,7 @@#include <linux/backing-dev.h> #include <linux/pagevec.h> #include <linux/cleancache.h> +#include <linux/read_callbacks.h> #include "internal.h" /*
@@ -44,7 +45,7 @@* status of that page is hard. See end_buffer_async_read() for the details. * There is no point in duplicating all that complexity. */ -static void mpage_end_io (struct bio *bio) +static void end_bio (struct bio *bio) {struct bio_vec *bv;int i;
@@ -52,13 +53,24 @@ static void mpage_end_io(struct bio *bio)bio_for_each_segment_all (bv, bio, i, iter_all) {struct page *page = bv->bv_page; -page_endio (page,bio_op (bio), -blk_status_to_errno (bio->bi_status)); +int err; + + err =blk_status_to_errno (bio->bi_status); + +if (!err &&read_callbacks_failed (page)) + err = -EIO ; + +page_endio (page,bio_op (bio), err); }bio_put (bio); } +static void mpage_end_io (struct bio *bio) +{ +read_callbacks_endio_bio (bio, end_bio); +} +static struct bio *mpage_bio_submit (int op,int op_flags,struct bio *bio) { bio->bi_end_io = mpage_end_io;
@@ -310,6 +322,12 @@ static struct bio *do_mpage_readpage(struct mpage_readpage_args *args) gfp);if (args->bio ==NULL ) goto confused; + +if (read_callbacks_setup_bio (inode, args->bio)) { +bio_put (args->bio); + args->bio =NULL ; + goto confused; + } } length = first_hole << blkbits;
Signature · 1 line
2.19.1
PATCH v4 5/8 f2fs: Use read_callbacks for decrypting file data
In reply to Chandan RajendraF2FS has a copy of "post read processing" code using which encrypted file data is decrypted. This commit replaces it to make use of the generic read_callbacks facility.
--- fs/f2fs/data.c | 109 ++++-------------------------------------------- fs/f2fs/f2fs.h | 2 - fs/f2fs/super.c | 9 +--- 3 files changed, 11 insertions(+), 109 deletions(-)
fs/f2fs/data.c +9 -100
@@ -18,6 +18,7 @@#include <linux/uio.h> #include <linux/cleancache.h> #include <linux/sched/signal.h> +#include <linux/read_callbacks.h> #include "f2fs.h" #include "node.h"
@@ -25,11 +26,6 @@#include "trace.h" #include <trace/events/f2fs.h> -#define NUM_PREALLOC_POST_READ_CTXS 128 - -static struct kmem_cache *bio_post_read_ctx_cache; -static mempool_t *bio_post_read_ctx_pool; -static bool __is_cp_guaranteed (struct page *page) {struct address_space *mapping = page->mapping;
@@ -69,19 +65,6 @@ static enum count_type __read_io_type(struct page *page)return F2FS_RD_DATA ; } -/* postprocessing steps for read bios */ -enum bio_post_read_step { -STEP_INITIAL =0 , -STEP_DECRYPT , -}; - -struct bio_post_read_ctx { -struct bio *bio; -struct work_struct work; -unsigned int cur_step; -unsigned int enabled_steps; -}; -static void __read_end_io (struct bio *bio) {struct page *page;
@@ -93,7 +76,7 @@ static void __read_end_io(struct bio *bio) page = bv->bv_page;/* PG_error was set if any post_read step failed */ -if (bio->bi_status ||PageError (page)) { +if (bio->bi_status ||read_callbacks_failed (page)) {ClearPageUptodate (page);/* will re-read again later */ ClearPageError (page);
@@ -103,42 +86,8 @@ static void __read_end_io(struct bio *bio)dec_page_count (F2FS_P_SB (page),__read_io_type (page));unlock_page (page); } -if (bio->bi_private) -mempool_free (bio->bi_private, bio_post_read_ctx_pool); -bio_put (bio); -} -static void bio_post_read_processing (struct bio_post_read_ctx *ctx); - -static void decrypt_work (struct work_struct *work) -{ -struct bio_post_read_ctx *ctx = - container_of(work, struct bio_post_read_ctx, work); - -fscrypt_decrypt_bio (ctx->bio); - -bio_post_read_processing (ctx); -} - -static void bio_post_read_processing (struct bio_post_read_ctx *ctx) -{ -switch (++ctx->cur_step) { -case STEP_DECRYPT : -if (ctx->enabled_steps & (1 <<STEP_DECRYPT )) { -INIT_WORK (&ctx->work, decrypt_work); -fscrypt_enqueue_decrypt_work (&ctx->work); -return ; - } - ctx->cur_step++; -/* fall-through */ -default : -__read_end_io (ctx->bio); - } -} - -static bool f2fs_bio_post_read_required (struct bio *bio) -{ -return bio->bi_private && !bio->bi_status; +bio_put (bio); }static void f2fs_read_end_io (struct bio *bio)
@@ -149,15 +98,7 @@ static void f2fs_read_end_io(struct bio *bio) bio->bi_status =BLK_STS_IOERR ; } -if (f2fs_bio_post_read_required (bio)) { -struct bio_post_read_ctx *ctx = bio->bi_private; - - ctx->cur_step =STEP_INITIAL ; -bio_post_read_processing (ctx); -return ; - } - -__read_end_io (bio); +read_callbacks_endio_bio (bio, __read_end_io); }static void f2fs_write_end_io (struct bio *bio)
@@ -556,8 +497,7 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, {struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct bio *bio; -struct bio_post_read_ctx *ctx; -unsigned int post_read_steps =0 ; +int err;if (!f2fs_is_valid_blkaddr (sbi, blkaddr,DATA_GENERIC ))return ERR_PTR (-EFAULT );
@@ -569,17 +509,10 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, bio->bi_end_io = f2fs_read_end_io;bio_set_op_attrs (bio,REQ_OP_READ , op_flag); -if (f2fs_encrypted_file (inode)) - post_read_steps |=1 <<STEP_DECRYPT ; -if (post_read_steps) { - ctx =mempool_alloc (bio_post_read_ctx_pool,GFP_NOFS ); -if (!ctx) { -bio_put (bio); -return ERR_PTR (-ENOMEM ); - } - ctx->bio = bio; - ctx->enabled_steps = post_read_steps; - bio->bi_private = ctx; + err =read_callbacks_setup_bio (inode, bio); +if (err) { +bio_put (bio); +return ERR_PTR (err); }return bio;
@@ -2860,27 +2793,3 @@ void f2fs_clear_page_cache_dirty_tag(struct page *page) PAGECACHE_TAG_DIRTY);xa_unlock_irqrestore (&mapping->i_pages, flags); } - -int __init f2fs_init_post_read_processing (void ) -{ - bio_post_read_ctx_cache =KMEM_CACHE (bio_post_read_ctx,0 ); -if (!bio_post_read_ctx_cache) - goto fail; - bio_post_read_ctx_pool = -mempool_create_slab_pool (NUM_PREALLOC_POST_READ_CTXS , - bio_post_read_ctx_cache); -if (!bio_post_read_ctx_pool) - goto fail_free_cache; -return 0 ; - -fail_free_cache: -kmem_cache_destroy (bio_post_read_ctx_cache); -fail: -return -ENOMEM ; -} - -void __exit f2fs_destroy_post_read_processing(void) -{ -mempool_destroy (bio_post_read_ctx_pool); -kmem_cache_destroy (bio_post_read_ctx_cache); -}
fs/f2fs/f2fs.h +0 -2
@@ -3125,8 +3125,6 @@ void f2fs_destroy_checkpoint_caches(void);/* * data.c */ -int f2fs_init_post_read_processing (void ); -void f2fs_destroy_post_read_processing (void );void f2fs_submit_merged_write (struct f2fs_sb_info *sbi,enum page_type type); void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, struct inode *inode, struct page *page,
fs/f2fs/super.c +2 -7
@@ -3597,15 +3597,11 @@ static int __init init_f2fs_fs(void) err =register_filesystem (&f2fs_fs_type);if (err) goto free_shrinker; +f2fs_create_root_stats (); - err =f2fs_init_post_read_processing (); -if (err) - goto free_root_stats; +return 0 ; -free_root_stats: -f2fs_destroy_root_stats (); -unregister_filesystem (&f2fs_fs_type); free_shrinker:unregister_shrinker (&f2fs_shrinker_info); free_sysfs:
@@ -3626,7 +3622,6 @@ static int __init init_f2fs_fs(void) static void __exit exit_f2fs_fs(void) { -f2fs_destroy_post_read_processing ();f2fs_destroy_root_stats ();unregister_filesystem (&f2fs_fs_type);unregister_shrinker (&f2fs_shrinker_info);
Signature · 1 line
2.19.1
PATCH v4 7/8 ext4: Enable encryption for subpage-sized blocks
In reply to Chandan RajendraNow that we have the code to support encryption for subpage-sized blocks, this commit removes the conditional check in filesystem mount code.
The commit also changes the support statement in Documentation/filesystems/fscrypt.rst to reflect the fact that encryption of filesystems with blocksize less than page size now works.
--- Documentation/filesystems/fscrypt.rst | 4 ++-- fs/ext4/super.c | 7 ------- 2 files changed, 2 insertions(+), 9 deletions(-)
Documentation/filesystems/fscrypt.rst +2 -2
@@ -213,8 +213,8 @@ Contents encryption ------------------- For file contents, each filesystem block is encrypted independently. -Currently, only the case where the filesystem block size is equal to -the system's page size (usually 4096 bytes) is supported. +Starting from Linux kernel 5.4, encryption of filesystems with block +size less than system's page size is supported. Each block's IV is set to the logical block number within the file as a little endian number, except that:
fs/ext4/super.c +0 -7
@@ -4322,13 +4322,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) } } -if ((DUMMY_ENCRYPTION_ENABLED (sbi) ||ext4_has_feature_encrypt (sb)) && - (blocksize !=PAGE_SIZE )) { -ext4_msg (sb,KERN_ERR , -"Unsupported blocksize for fs encryption" ); - goto failed_mount_wq; - } -if (DUMMY_ENCRYPTION_ENABLED (sbi) && !sb_rdonly (sb) && !ext4_has_feature_encrypt (sb)) {ext4_set_feature_encrypt (sb);
Signature · 1 line
2.19.1
PATCH v4 4/8 fs/buffer.c: add decryption support via read_callbacks
In reply to Chandan RajendraThis commit sets up read_callbacks context for buffer heads whose contents need to be decrypted on endio.
--- fs/buffer.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
fs/buffer.c +22 -11
@@ -45,6 +45,7 @@#include <linux/bit_spinlock.h> #include <linux/pagevec.h> #include <linux/sched/mm.h> +#include <linux/read_callbacks.h> #include <trace/events/block.h> static int fsync_buffers_list (spinlock_t *lock,struct list_head *list);
@@ -245,11 +246,7 @@ __find_get_block_slow(struct block_device *bdev, sector_t block)return ret; } -/* -* I/O completion handler for block_read_full_page() - pages -* which come unlocked at the end of I/O. -*/ -static void end_buffer_async_read (struct buffer_head *bh,int uptodate) +void end_buffer_async_read (struct buffer_head *bh,int uptodate) {unsigned long flags;struct buffer_head *first;
@@ -257,8 +254,6 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)struct page *page;int page_uptodate =1 ; -BUG_ON (!buffer_async_read (bh)); - page = bh->b_page;if (uptodate) {set_buffer_uptodate (bh);
@@ -306,6 +301,17 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)return ; } +/* +* I/O completion handler for block_read_full_page(). Pages are unlocked +* after the I/O completes and the read callbacks (if any) have executed. +*/ +static void __end_buffer_async_read (struct buffer_head *bh,int uptodate) +{ +BUG_ON (!buffer_async_read (bh)); + +read_callbacks_endio_bh (bh, uptodate, end_buffer_async_read); +} +/* * Completion handler for block_write_full_page() - pages which are unlocked * during I/O, and which have PageWriteback cleared upon I/O completion.
@@ -378,7 +384,7 @@ EXPORT_SYMBOL(end_buffer_async_write);*/ static void mark_buffer_async_read (struct buffer_head *bh) { - bh->b_end_io = end_buffer_async_read; + bh->b_end_io = __end_buffer_async_read;set_buffer_async_read (bh); }
@@ -2293,10 +2299,15 @@ int block_read_full_page(struct page *page, get_block_t *get_block)*/ for (i =0 ; i < nr; i++) { bh = arr[i]; -if (buffer_uptodate (bh)) -end_buffer_async_read (bh,1 ); -else +if (buffer_uptodate (bh)) { +__end_buffer_async_read (bh,1 ); + }else { +if (WARN_ON (read_callbacks_setup_bh (inode, bh))) { +__end_buffer_async_read (bh,0 ); +continue ; + }submit_bh (REQ_OP_READ ,0 , bh); + } }return 0 ; }
Signature · 8 lines
2.19.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v4 6/8 ext4: Wire up ext4_readpage[s] to use mpage_readpage[s]
In reply to Chandan RajendraNow that do_mpage_readpage() is "post read process" aware, this commit gets ext4_readpage[s] to use mpage_readpage[s] and deletes ext4's readpage.c since the associated functionality is not required anymore.
--- fs/ext4/Makefile | 2 +- fs/ext4/inode.c | 5 +- fs/ext4/readpage.c | 295 --------------------------------------------- 3 files changed, 3 insertions(+), 299 deletions(-) delete mode 100644 fs/ext4/readpage.c
fs/ext4/Makefile +1 -1
@@ -8,7 +8,7 @@ obj-$(CONFIG_EXT4_FS) += ext4.o ext4-y := balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \ extents_status.o file.o fsmap.o fsync.o hash.o ialloc.o \ indirect.o inline.o inode.o ioctl.o mballoc.o migrate.o \ - mmp.o move_extent.o namei.o page-io.o readpage.o resize.o \ + mmp.o move_extent.o namei.o page-io.o resize.o \ super.o symlink.o sysfs.o xattr.o xattr_trusted.o xattr_user.o ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
fs/ext4/inode.c +2 -3
@@ -3361,8 +3361,7 @@ static int ext4_readpage(struct file *file, struct page *page) ret =ext4_readpage_inline (inode, page);if (ret == -EAGAIN ) -return ext4_mpage_readpages (page->mapping,NULL , page,1 , - false); +return mpage_readpage (page, ext4_get_block);return ret; }
@@ -3377,7 +3376,7 @@ ext4_readpages(struct file *file, struct address_space *mapping,if (ext4_has_inline_data (inode))return 0 ; -return ext4_mpage_readpages (mapping, pages,NULL , nr_pages, true); +return mpage_readpages (mapping, pages, nr_pages, ext4_get_block); } static void ext4_invalidatepage(struct page *page, unsigned int offset,
fs/ext4/readpage.c deleted +0 -295
295 lines not on this page · raw message
Signature · 8 lines
2.19.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
PATCH v4 8/8 fscrypt: remove struct fscrypt_ctx
In reply to Chandan RajendraCommit "fscrypt: remove the 'write' part of struct fscrypt_ctx" reduced "struct fscrypt_ctx" to be used only for decryption. With "read callbacks" being integrated into Ext4 and F2FS, we don't use "struct fscrypt_ctx" anymore. Hence this commit removes the structure and the associated code.
While at it, this commit also removes definitions of __fscrypt_decrypt_bio() and fscrypt_decrypt_bio() since we have to now use the APIs provided by read_callbacks facility.
--- fs/crypto/bio.c | 43 ------------------ fs/crypto/crypto.c | 89 +------------------------------------ fs/crypto/fscrypt_private.h | 3 -- include/linux/fscrypt.h | 38 ---------------- 4 files changed, 2 insertions(+), 171 deletions(-)
fs/crypto/bio.c +0 -43
@@ -26,49 +26,6 @@#include <linux/namei.h> #include "fscrypt_private.h" -static void __fscrypt_decrypt_bio (struct bio *bio,bool done) -{ -struct bio_vec *bv; -int i; -struct bvec_iter_all iter_all; - -bio_for_each_segment_all (bv, bio, i, iter_all) { -struct page *page = bv->bv_page; -int ret =fscrypt_decrypt_pagecache_blocks (page, bv->bv_len, - bv->bv_offset); -if (ret) -SetPageError (page); -else if (done) -SetPageUptodate (page); -if (done) -unlock_page (page); - } -} - -void fscrypt_decrypt_bio (struct bio *bio) -{ -__fscrypt_decrypt_bio (bio, false); -} -EXPORT_SYMBOL (fscrypt_decrypt_bio); - -static void completion_pages (struct work_struct *work) -{ - struct fscrypt_ctx *ctx = container_of(work, struct fscrypt_ctx, work); -struct bio *bio = ctx->bio; - -__fscrypt_decrypt_bio (bio, true); -fscrypt_release_ctx (ctx); -bio_put (bio); -} - -void fscrypt_enqueue_decrypt_bio (struct fscrypt_ctx *ctx,struct bio *bio) -{ -INIT_WORK (&ctx->work, completion_pages); - ctx->bio = bio; -fscrypt_enqueue_decrypt_work (&ctx->work); -} -EXPORT_SYMBOL (fscrypt_enqueue_decrypt_bio); -int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) {
fs/crypto/crypto.c +2 -87
146 lines not on this page · raw message
fs/crypto/fscrypt_private.h +0 -3
@@ -93,9 +93,6 @@ typedef enum {FS_ENCRYPT , } fscrypt_direction_t; -#define FS_CTX_REQUIRES_FREE_ENCRYPT_FL 0x00000001 -#define FS_CTX_HAS_BOUNCE_BUFFER_FL 0x00000002 -static inline bool fscrypt_valid_enc_modes (u32 contents_mode,u32 filenames_mode) {
include/linux/fscrypt.h +0 -38
@@ -19,7 +19,6 @@#define FS_CRYPTO_BLOCK_SIZE 16 -struct fscrypt_ctx ;struct fscrypt_info ;struct fscrypt_str {
@@ -63,18 +62,6 @@ struct fscrypt_operations {unsigned int max_namelen; }; -/* Decryption work */ -struct fscrypt_ctx { -union { -struct { -struct bio *bio; -struct work_struct work; - }; -struct list_head free_list;/* Free list */ - }; -u8 flags;/* Flags */ -}; -static inline bool fscrypt_has_encryption_key (const struct inode *inode) {/* pairs with cmpxchg_release() in fscrypt_get_encryption_info() */
@@ -101,8 +88,6 @@ static inline void fscrypt_handle_d_move(struct dentry *dentry)/* crypto.c */ extern void fscrypt_enqueue_decrypt_work (struct work_struct *); -extern struct fscrypt_ctx *fscrypt_get_ctx (gfp_t ); -extern void fscrypt_release_ctx (struct fscrypt_ctx *); extern struct page *fscrypt_encrypt_pagecache_blocks(struct page *page, unsigned int len,
@@ -232,9 +217,6 @@ static inline bool fscrypt_match_name(const struct fscrypt_name *fname, }/* bio.c */ -extern void fscrypt_decrypt_bio (struct bio *); -extern void fscrypt_enqueue_decrypt_bio (struct fscrypt_ctx *ctx, -struct bio *bio);extern int fscrypt_zeroout_range (const struct inode *,pgoff_t ,sector_t ,unsigned int );
@@ -279,16 +261,6 @@ static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work) { } -static inline struct fscrypt_ctx *fscrypt_get_ctx (gfp_t gfp_flags) -{ -return ERR_PTR (-EOPNOTSUPP ); -} - -static inline void fscrypt_release_ctx (struct fscrypt_ctx *ctx) -{ -return ; -} - static inline struct page *fscrypt_encrypt_pagecache_blocks(struct page *page, unsigned int len, unsigned int offs,
@@ -425,16 +397,6 @@ static inline bool fscrypt_match_name(const struct fscrypt_name *fname,return !memcmp (de_name, fname->disk_name.name, fname->disk_name.len); } -/* bio.c */ -static inline void fscrypt_decrypt_bio (struct bio *bio) -{ -} - -static inline void fscrypt_enqueue_decrypt_bio (struct fscrypt_ctx *ctx, -struct bio *bio) -{ -} -static inline int fscrypt_zeroout_range (const struct inode *inode,pgoff_t lblk,sector_t pblk,unsigned int len) {
Signature · 1 line
2.19.1
v4 cover Consolidate FS read I/O callbacks code
This patchset moves the "FS read I/O callbacks" code into a file of its own (i.e. fs/read_callbacks.c) and modifies the generic do_mpage_readpge() to make use of the functionality provided.
"FS read I/O callbacks" code implements the state machine that needs to be executed after reading data from files that are encrypted and/or have verity metadata associated with them.
With these changes in place, the patchset changes Ext4 to use mpage_readpage[s] instead of its own custom ext4_readpage[s]() functions. This is done to reduce duplication of code across filesystems. Also, "FS read I/O callbacks" source files will be built only if CONFIG_FS_ENCRYPTION is enabled.
The patchset also modifies fs/buffer.c to get file encryption/decryption to work with subpage-sized blocks.
The patches can also be obtained from
https://github.com/chandanr/linux.git at branch subpage-encryption-v4.
Changelog:
V3 -> V4:
1. A new buffer_head flag (i.e. BH_Read_Cb) is introduced to reliably check if a buffer head's content has to be decrypted.
2. Fix layering violation. Now the code flow for decryption happens as shown below, FS => read callbacks => fscrypt
3. Select FS_READ_CALLBACKS from FS specific kconfig file if FS_ENCRYPTION is enabled.
4. Make 'struct read_callbacks_ctx' an opaque structure.
5. Make use of FS' endio function rather than implementing one in read callbacks.
6. Make read_callbacks.h self-contained.
7. Split patchset to separate out ext4 and f2fs changes.
V2 -> V3:
1. Split the V2 patch "Consolidate 'read callbacks' into a new file" into three patches,
- Introduce the read_callbacks functionality.
- Convert encryption to use read_callbacks.
- Remove union from struct fscrypt_context.
2. fs/Kconfig
Do not explicitly set the default value of 'n' for FS_READ_CALLBACKS.
3. fs/crypto/Kconfig
Select CONFIG_FS_READ_CALLBACKS only if CONFIG_BLOCK is selected.
4. Remove verity associated code in read_callbacks code.
5. Introduce a callback argument to read_callbacks_setup() function which gets invoked for each page for bio. F2FS uses this to perform custom operations like decrementing the value of f2fs_sb_info->nr_pages[].
6. Encapsulate the details of "read callbacks" (e.g. Usage of "struct read_callbacks *ctx") within its own functions. When CONFIG_FS_READ_CALLBACKS is set to 'n', the corresponding stub functions return approriate error values.
7. Split fscrypt_decrypt() function into fscrypt_decrypt_bio() and fscrypt_decrypt_bh().
8. Split end_read_callbacks() function into end_read_callbacks_bio() and end_read_callbacks_bh().
V1 -> V2:
1. Removed the phrase "post_read_process" from file names and functions. Instead we now use the phrase "read_callbacks" in its place.
2. When performing changes associated with (1), the changes made by the patch "Remove the term 'bio' from post read processing" are made in the earlier patch "Consolidate 'read callbacks' into a new file". Hence the patch "Remove the term 'bio' from post read processing" is removed from the patchset.
RFC V2 -> V1:
1. Test and verify FS_CFLG_OWN_PAGES subset of fscrypt_encrypt_page() code by executing fstests on UBIFS.
2. Implement F2fs function call back to check if the contents of a page holding a verity file's data needs to be verified.
RFC V1 -> RFC V2:
1. Describe the purpose of "Post processing code" in the cover letter.
2. Fix build errors when CONFIG_FS_VERITY is enabled.
Chandan Rajendra (8):
buffer_head: Introduce BH_Read_Cb flag
FS: Introduce read callbacks
fs/mpage.c: Integrate read callbacks fs/buffer.c: add decryption support via read_callbacks
f2fs: Use read_callbacks for decrypting file data
ext4: Wire up ext4_readpage[s] to use mpage_readpage[s]
ext4: Enable encryption for subpage-sized blocks
fscrypt: remove struct fscrypt_ctx
Documentation/filesystems/fscrypt.rst | 4 +- fs/Kconfig | 3 + fs/Makefile | 1 + fs/buffer.c | 33 ++- fs/crypto/bio.c | 43 ---- fs/crypto/crypto.c | 89 +------- fs/crypto/fscrypt_private.h | 3 - fs/ext4/Kconfig | 1 + fs/ext4/Makefile | 2 +- fs/ext4/inode.c | 5 +- fs/ext4/readpage.c | 295 -------------------------- fs/ext4/super.c | 7 - fs/f2fs/Kconfig | 1 + fs/f2fs/data.c | 109 +--------- fs/f2fs/f2fs.h | 2 - fs/f2fs/super.c | 9 +- fs/mpage.c | 24 ++- fs/read_callbacks.c | 285 +++++++++++++++++++++++++ include/linux/buffer_head.h | 2 + include/linux/fscrypt.h | 38 ---- include/linux/read_callbacks.h | 48 +++++ 21 files changed, 402 insertions(+), 602 deletions(-) delete mode 100644 fs/ext4/readpage.c create mode 100644 fs/read_callbacks.c create mode 100644 include/linux/read_callbacks.h
Signature · 1 line
2.19.1
Chao Yu
maintainerRe: [f2fs-dev] [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
In reply to Chandan RajendraHi Chandan,
Quoted 3 lines · Chandan Rajendra
F2FS has a copy of "post read processing" code using which encrypted file data is decrypted. This commit replaces it to make use of the generic
read_callbacksfacility.
I remember that previously Jaegeuk had mentioned f2fs will support compression later, and it needs to reuse 'post read processing' fwk.
There is very initial version of compression feature in below link:
https://git.kernel.org/pub/scm/linux/kernel/git/chao/linux.git/log/?h=compression
So my concern is how can we uplift the most common parts of this fwk into vfs, and meanwhile keeping the ability and flexibility when introducing private feature/step in specified filesytem(now f2fs)?
According to current f2fs compression's requirement, maybe we can expand to
- support callback to let filesystem set the function for the flow in decompression/verity/decryption step.
- support to use individual/common workqueue according the parameter.
Any thoughts?
Thanks,
Quoted 226 lines
Signed-off-by Chandan Rajendra <[email protected]>--- fs/f2fs/data.c | 109 ++++-------------------------------------------- fs/f2fs/f2fs.h | 2 - fs/f2fs/super.c | 9 +--- 3 files changed, 11 insertions(+), 109 deletions(-)fs/f2fs/data.c +9
-100@@ -18,6 +18,7 @@#include <linux/uio.h> #include <linux/cleancache.h> #include <linux/sched/signal.h> +#include <linux/read_callbacks.h> #include "f2fs.h" #include "node.h" @@ -25,11 +26,6 @@#include "trace.h" #include <trace/events/f2fs.h> -#define NUM_PREALLOC_POST_READ_CTXS 128 - -static struct kmem_cache *bio_post_read_ctx_cache; -static mempool_t *bio_post_read_ctx_pool; -static bool __is_cp_guaranteed (struct page *page) {struct address_space *mapping = page->mapping;@@ -69,19 +65,6 @@ static enum count_type __read_io_type(struct page *page)return F2FS_RD_DATA ; } -/* postprocessing steps for read bios */ -enum bio_post_read_step { -STEP_INITIAL =0 , -STEP_DECRYPT , -}; - -struct bio_post_read_ctx { -struct bio *bio; -struct work_struct work; -unsigned int cur_step; -unsigned int enabled_steps; -}; -static void __read_end_io (struct bio *bio) {struct page *page;@@ -93,7 +76,7 @@ static void __read_end_io(struct bio *bio) page = bv->bv_page;/* PG_error was set if any post_read step failed */ -if (bio->bi_status ||PageError (page)) { +if (bio->bi_status ||read_callbacks_failed (page)) {ClearPageUptodate (page);/* will re-read again later */ ClearPageError (page);@@ -103,42 +86,8 @@ static void __read_end_io(struct bio *bio)dec_page_count (F2FS_P_SB (page),__read_io_type (page));unlock_page (page); } -if (bio->bi_private) -mempool_free (bio->bi_private, bio_post_read_ctx_pool); -bio_put (bio); -} -static void bio_post_read_processing (struct bio_post_read_ctx *ctx); - -static void decrypt_work (struct work_struct *work) -{ -struct bio_post_read_ctx *ctx = - container_of(work, struct bio_post_read_ctx, work); - -fscrypt_decrypt_bio (ctx->bio); - -bio_post_read_processing (ctx); -} - -static void bio_post_read_processing (struct bio_post_read_ctx *ctx) -{ -switch (++ctx->cur_step) { -case STEP_DECRYPT : -if (ctx->enabled_steps & (1 <<STEP_DECRYPT )) { -INIT_WORK (&ctx->work, decrypt_work); -fscrypt_enqueue_decrypt_work (&ctx->work); -return ; - } - ctx->cur_step++; -/* fall-through */ -default : -__read_end_io (ctx->bio); - } -} - -static bool f2fs_bio_post_read_required (struct bio *bio) -{ -return bio->bi_private && !bio->bi_status; +bio_put (bio); }static void f2fs_read_end_io (struct bio *bio)@@ -149,15 +98,7 @@ static void f2fs_read_end_io(struct bio *bio) bio->bi_status =BLK_STS_IOERR ; } -if (f2fs_bio_post_read_required (bio)) { -struct bio_post_read_ctx *ctx = bio->bi_private; - - ctx->cur_step =STEP_INITIAL ; -bio_post_read_processing (ctx); -return ; - } - -__read_end_io (bio); +read_callbacks_endio_bio (bio, __read_end_io); }static void f2fs_write_end_io (struct bio *bio)@@ -556,8 +497,7 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, {struct f2fs_sb_info *sbi =F2FS_I_SB (inode);struct bio *bio; -struct bio_post_read_ctx *ctx; -unsigned int post_read_steps =0 ; +int err;if (!f2fs_is_valid_blkaddr (sbi, blkaddr,DATA_GENERIC ))return ERR_PTR (-EFAULT );@@ -569,17 +509,10 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr, bio->bi_end_io = f2fs_read_end_io;bio_set_op_attrs (bio,REQ_OP_READ , op_flag); -if (f2fs_encrypted_file (inode)) - post_read_steps |=1 <<STEP_DECRYPT ; -if (post_read_steps) { - ctx =mempool_alloc (bio_post_read_ctx_pool,GFP_NOFS ); -if (!ctx) { -bio_put (bio); -return ERR_PTR (-ENOMEM ); - } - ctx->bio = bio; - ctx->enabled_steps = post_read_steps; - bio->bi_private = ctx; + err =read_callbacks_setup_bio (inode, bio); +if (err) { +bio_put (bio); +return ERR_PTR (err); }return bio;@@ -2860,27 +2793,3 @@ void f2fs_clear_page_cache_dirty_tag(struct page *page) PAGECACHE_TAG_DIRTY);xa_unlock_irqrestore (&mapping->i_pages, flags); } - -int __init f2fs_init_post_read_processing (void ) -{ - bio_post_read_ctx_cache =KMEM_CACHE (bio_post_read_ctx,0 ); -if (!bio_post_read_ctx_cache) - goto fail; - bio_post_read_ctx_pool = -mempool_create_slab_pool (NUM_PREALLOC_POST_READ_CTXS , - bio_post_read_ctx_cache); -if (!bio_post_read_ctx_pool) - goto fail_free_cache; -return 0 ; - -fail_free_cache: -kmem_cache_destroy (bio_post_read_ctx_cache); -fail: -return -ENOMEM ; -} - -void __exit f2fs_destroy_post_read_processing(void) -{ -mempool_destroy (bio_post_read_ctx_pool); -kmem_cache_destroy (bio_post_read_ctx_cache); -}fs/f2fs/f2fs.h +0
-2@@ -3125,8 +3125,6 @@ void f2fs_destroy_checkpoint_caches(void);/* * data.c */ -int f2fs_init_post_read_processing (void ); -void f2fs_destroy_post_read_processing (void );void f2fs_submit_merged_write (struct f2fs_sb_info *sbi,enum page_type type); void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, struct inode *inode, struct page *page,fs/f2fs/super.c +2
-7@@ -3597,15 +3597,11 @@ static int __init init_f2fs_fs(void) err =register_filesystem (&f2fs_fs_type);if (err) goto free_shrinker; +f2fs_create_root_stats (); - err =f2fs_init_post_read_processing (); -if (err) - goto free_root_stats; +return 0 ; -free_root_stats: -f2fs_destroy_root_stats (); -unregister_filesystem (&f2fs_fs_type); free_shrinker:unregister_shrinker (&f2fs_shrinker_info); free_sysfs:@@ -3626,7 +3622,6 @@ static int __init init_f2fs_fs(void) static void __exit exit_f2fs_fs(void) { -f2fs_destroy_post_read_processing ();f2fs_destroy_root_stats ();unregister_filesystem (&f2fs_fs_type);unregister_shrinker (&f2fs_shrinker_info);
Re: [f2fs-dev] [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
Quoted 18 lines · IST Chao Yu
Hi Chandan,
Quoted 3 lines · Chandan Rajendra
F2FS has a copy of "post read processing" code using which encrypted file data is decrypted. This commit replaces it to make use of the generic
read_callbacksfacility.I remember that previously Jaegeuk had mentioned f2fs will support compression later, and it needs to reuse 'post read processing' fwk.
There is very initial version of compression feature in below link:
https://git.kernel.org/pub/scm/linux/kernel/git/chao/linux.git/log/?h=compression
So my concern is how can we uplift the most common parts of this fwk into vfs, and meanwhile keeping the ability and flexibility when introducing private feature/step in specified filesytem(now f2fs)?
Quoted 8 lines
According to current f2fs compression's requirement, maybe we can expand to
- support callback to let filesystem set the function for the flow in decompression/verity/decryption step.
- support to use individual/common workqueue according the parameter.Any thoughts?
Hi,
F2FS can be made to use fscrypt's queue for decryption and hence can reuse "read callbacks" code for decrypting data.
For decompression, we could have a STEP_MISC where we invoke a FS provided callback function for FS specific post read processing?
Something like the following can be implemented in read_callbacks(),
case STEP_MISC:
if (ctx->enabled_steps & (1 << STEP_MISC)) {
/*
ctx->fs_misc() must process bio in a workqueue
and later invoke read_callbacks() with
bio->bi_private's value as an argument.
*/
ctx->fs_misc(ctx->bio);
return;
}
ctx->cur_step++;The fs_misc() callback can be passed in by the filesystem when invoking read_callbacks_setup_bio().
Signature · 1 line
chandan
Re: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
In reply to Chandan RajendraQuoted 5 lines · Chandan Rajendra
F2FS has a copy of "post read processing" code using which encrypted file data is decrypted. This commit replaces it to make use of the generic
read_callbacksfacility.Signed-off-by Chandan Rajendra <[email protected]>
Hi Eric and Ted,
Looks like F2FS requires a lot more flexiblity than what can be offered by read callbacks i.e.
1. F2FS wants to make use of its own workqueue for decryption, verity and decompression.
2. F2FS' decompression code is not an FS independent entity like fscrypt and fsverity. Hence they would need Filesystem specific callback functions to be invoked from "read callbacks".
Hence I would suggest that we should drop F2FS changes made in this patchset. Please let me know your thoughts on this.
Signature · 1 line
chandan
Re: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
Hi Chandan,
Quoted 12 lines · Chandan Rajendra
Quoted 5 lines · Chandan Rajendra
F2FS has a copy of "post read processing" code using which encrypted file data is decrypted. This commit replaces it to make use of the generic
read_callbacksfacility.Signed-off-by Chandan Rajendra <[email protected]>Hi Eric and Ted,
Looks like F2FS requires a lot more flexiblity than what can be offered by read callbacks i.e.
Quoted 8 lines
1. F2FS wants to make use of its own workqueue for decryption, verity and decompression.
2. F2FS' decompression code is not an FS independent entity like fscrypt and fsverity. Hence they would need Filesystem specific callback functions to be invoked from "read callbacks".Hence I would suggest that we should drop F2FS changes made in this patchset. Please let me know your thoughts on this.
Add a word, I have some little concern about post read procession order a bit as I mentioned before, because I'd like to move common EROFS decompression code out in the future as well for other fses to use after we think it's mature enough.
It seems the current code mainly addresses eliminating duplicated code, therefore I have no idea about that...
Thanks,
Gao Xiang
Quoted 6 lines
Signature · 2 lines
-- chandan
Re: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
Quoted 21 lines · Gao Xiang
Hi Chandan,
Quoted 18 lines · Chandan Rajendra
Quoted 5 lines · Chandan Rajendra
F2FS has a copy of "post read processing" code using which encrypted file data is decrypted. This commit replaces it to make use of the generic
read_callbacksfacility.Signed-off-by Chandan Rajendra <[email protected]>Hi Eric and Ted,
Looks like F2FS requires a lot more flexiblity than what can be offered by read callbacks i.e.
1. F2FS wants to make use of its own workqueue for decryption, verity and decompression.
2. F2FS' decompression code is not an FS independent entity like fscrypt and fsverity. Hence they would need Filesystem specific callback functions to be invoked from "read callbacks".
Quoted 4 lines
Quoted 2 lines
Hence I would suggest that we should drop F2FS changes made in this patchset. Please let me know your thoughts on this.
Add a word, I have some little concern about post read procession order
FYI. Just a minor concern about its flexibility, not big though.
https://lore.kernel.org/r/20190808042640.GA28630@138/
Thanks,
Gao Xiang
Quoted 16 lines
a bit as I mentioned before, because I'd like to move common EROFS decompression code out in the future as well for other fses to use after we think it's mature enough.
It seems the current code mainly addresses eliminating duplicated code, therefore I have no idea about that...
Thanks,
Gao XiangQuoted 6 lines
Signature · 2 lines
-- chandan
Re: [f2fs-dev] [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
In reply to Chandan RajendraQuoted 49 lines · Chandan Rajendra
Quoted 18 lines · IST Chao Yu
Hi Chandan,
Quoted 3 lines · Chandan Rajendra
F2FS has a copy of "post read processing" code using which encrypted file data is decrypted. This commit replaces it to make use of the generic
read_callbacksfacility.I remember that previously Jaegeuk had mentioned f2fs will support compression later, and it needs to reuse 'post read processing' fwk.
There is very initial version of compression feature in below link:
https://git.kernel.org/pub/scm/linux/kernel/git/chao/linux.git/log/?h=compression
So my concern is how can we uplift the most common parts of this fwk into vfs, and meanwhile keeping the ability and flexibility when introducing private feature/step in specified filesytem(now f2fs)?
Quoted 8 lines
According to current f2fs compression's requirement, maybe we can expand to
- support callback to let filesystem set the function for the flow in decompression/verity/decryption step.
- support to use individual/common workqueue according the parameter.Any thoughts?
Hi,
F2FS can be made to use fscrypt's queue for decryption and hence can reuse "read callbacks" code for decrypting data.
For decompression, we could have a
STEP_MISCwhere we invoke a FS provided callback function for FS specific post read processing?Something like the following can be implemented in
read_callbacks(),case STEP_MISC: if (ctx->enabled_steps & (1 << STEP_MISC)) { /* ctx->fs_misc() must process bio in a workqueue and later invoke read_callbacks() with bio->bi_private's value as an argument. */ ctx->fs_misc(ctx->bio); return; } ctx->cur_step++;
Quoted 2 lines
The
fs_misc()callback can be passed in by the filesystem when invokingread_callbacks_setup_bio().
Hi,
Yes, something like this, can we just use STEP_DECOMPRESS and fs_decompress(), not sure, I doubt this interface may has potential user which has compression feature.
One more concern is that to avoid more context switch, maybe we can merge all background works into one workqueue if there is no conflict when call wants to.
static void bio_post_read_processing(struct bio_post_read_ctx *ctx)
{
switch (++ctx->cur_step) {
case STEP_DECRYPT:
if (ctx->enabled_steps & (1 << STEP_DECRYPT)) {
...
if (ctx->separated_wq)
return;
}
ctx->cur_step++;
/* fall-through */
case STEP_DECOMPRESS:
...
default:
__read_end_io(ctx->bio);Quoted 1 line
Theodore Y. Ts'o
maintainerRe: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
In reply to Gao XiangQuoted 7 lines · Gao Xiang
Add a word, I have some little concern about post read procession order a bit as I mentioned before, because I'd like to move common EROFS decompression code out in the future as well for other fses to use after we think it's mature enough.
It seems the current code mainly addresses eliminating duplicated code, therefore I have no idea about that...
Actually, we should chat. I was actually thinking about "borrowing" code from erofs to provide ext4-specific compression. I was really impressed with the efficiency goals in the erofs design[1] when I reviewed the Usenix ATC paper, and as the saying goes, the best artists know how to steal from the best. :-)
[1] https://www.usenix.org/conference/atc19/presentation/gao
My original specific thinking was to do code reuse by copy and paste, simply because it was simpler, and I have limited time to work on it. But if you are interested in making the erofs pipeline reusable by other file systems, and have the time to do the necessary code refactoring, I'd love to work with you on that.
It should be noted that the f2fs developers have been working on their own compression scheme that was going to be f2fs-specific, unlike the file system generic approach used with fsverity and fscrypt.
My expectation is that we will need to modify the read pipeling code to support compression. That's true whether we are looking at the existing file system-specific code used by ext4 and f2fs or in some combined work such as what Chandan has proposed.
Cheers,
- Ted
Theodore Y. Ts'o
maintainerRe: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
In reply to Chandan RajendraQuoted 11 lines · Chandan Rajendra
Looks like F2FS requires a lot more flexiblity than what can be offered by read callbacks i.e.
1. F2FS wants to make use of its own workqueue for decryption, verity and decompression.
2. F2FS' decompression code is not an FS independent entity like fscrypt and fsverity. Hence they would need Filesystem specific callback functions to be invoked from "read callbacks".Hence I would suggest that we should drop F2FS changes made in this patchset. Please let me know your thoughts on this.
That's probably the best way to go for now. My one concern is that it means that only ext4 will be using your framework. I could imagine that some people might argue that should just move the callback scheme into ext4 code as opposed to leaving it in fscrypt --- at least until we can find other file systems where we can show that it will be useful for those other file systems.
(Perhaps a useful experiment would be to have someone implement patches to support fscrypt and fsverity in ext2 --- the patch might or might not be accepted for upstream inclusion, but it would be useful to demonstrate how easy it is to add fscrypt and fsverity.)
The other thing to consider is that there has been some discussion about adding generalized support for I/O submission to the iomap library. It might be that if that work is accepted, support for fscrypt and fsverity would be a requirement for ext4 to use that portion of iomap's functionality. So in that eventuality, it might be that we'll want to move your read callbacks code into iomap, or we'll need to rework the read callbacks code so it can work with iomap.
But this is all work for the future. I'm a firm believe that the perfect should not be the enemy of the good, and that none of this should be a fundamental obstacle in having your code upstream.
Cheers,
- Ted
Re: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
In reply to Theodore Y. Ts'oHi Ted,
Quoted 9 lines · Theodore Y. Ts'o
Quoted 7 lines · Gao Xiang
Add a word, I have some little concern about post read procession order a bit as I mentioned before, because I'd like to move common EROFS decompression code out in the future as well for other fses to use after we think it's mature enough.
It seems the current code mainly addresses eliminating duplicated code, therefore I have no idea about that...
Quoted 7 lines
Actually, we should chat. I was actually thinking about "borrowing" code from erofs to provide ext4-specific compression. I was really impressed with the efficiency goals in the erofs design[1] when I reviewed the Usenix ATC paper, and as the saying goes, the best artists know how to steal from the best. :-)
[1] https://www.usenix.org/conference/atc19/presentation/gao
I also guessed it's you reviewed our work as well from some written words :) (even though it's analymous...) and I personally think there are some useful stuffs in our EROFS effort.
Quoted 6 lines
My original specific thinking was to do code reuse by copy and paste, simply because it was simpler, and I have limited time to work on it. But if you are interested in making the erofs pipeline reusable by other file systems, and have the time to do the necessary code refactoring, I'd love to work with you on that.
Yes, I have interest in making the erofs pipeline for generic fses. Now I'm still investigating sequential read on very high speed NVME (like SAMSUNG 970pro, one thread seq read >3GB/s), it seems it still has some optimization space.
And then I will do that work for generic fses as well... (but the first thing I want to do is getting erofs out of staging, as Greg said [1])
Metadata should be designed for each fs like ext4, but maybe not flexible and compacted as EROFS, therefore it could be some extra metadata overhead than EROFS.
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 9 lines
It should be noted that the f2fs developers have been working on their own compression scheme that was going to be f2fs-specific, unlike the file system generic approach used with fsverity and fscrypt.
My expectation is that we will need to modify the read pipeling code to support compression. That's true whether we are looking at the existing file system-specific code used by ext4 and f2fs or in some combined work such as what Chandan has proposed.
I think either form is fine with me. :) But it seems that is some minor which tree we will work on (Maybe Chandan's work will be merged then).
The first thing I need to do is to tidy up the code, and making it more general, and then it will be very easy for fses to integrate :)
Thanks,
Gao Xiang
Quoted 4 lines
Cheers,
- Ted
Jaegeuk Kim
maintainerRe: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
In reply to Theodore Y. Ts'oHi Chandan,
Quoted 13 lines · Theodore Y. Ts'o
Quoted 11 lines · Chandan Rajendra
Looks like F2FS requires a lot more flexiblity than what can be offered by read callbacks i.e.
1. F2FS wants to make use of its own workqueue for decryption, verity and decompression.
2. F2FS' decompression code is not an FS independent entity like fscrypt and fsverity. Hence they would need Filesystem specific callback functions to be invoked from "read callbacks".Hence I would suggest that we should drop F2FS changes made in this patchset. Please let me know your thoughts on this.
Quoted 6 lines
That's probably the best way to go for now. My one concern is that it means that only ext4 will be using your framework. I could imagine that some people might argue that should just move the callback scheme into ext4 code as opposed to leaving it in fscrypt --- at least until we can find other file systems where we can show that it will be useful for those other file systems.
I also have to raise a flag on this. Doesn't this patch series try to get rid of redundant work? What'd be the rationale, if it only supports ext4?
How about generalizing the framework to support generic_post_read and per-fs post_read for fscrypt/fsverity/... selectively?
Thanks,
Quoted 22 lines
(Perhaps a useful experiment would be to have someone implement patches to support fscrypt and fsverity in ext2 --- the patch might or might not be accepted for upstream inclusion, but it would be useful to demonstrate how easy it is to add fscrypt and fsverity.)
The other thing to consider is that there has been some discussion about adding generalized support for I/O submission to the iomap library. It might be that if that work is accepted, support for fscrypt and fsverity would be a requirement for ext4 to use that portion of iomap's functionality. So in that eventuality, it might be that we'll want to move your read callbacks code into iomap, or we'll need to rework the read callbacks code so it can work with iomap.
But this is all work for the future. I'm a firm believe that the perfect should not be the enemy of the good, and that none of this should be a fundamental obstacle in having your code upstream.
Cheers,
- Ted
Re: [PATCH V4 5/8] f2fs: Use read_callbacks for decrypting file data
Quoted 23 lines · Jaegeuk Kim
Hi Chandan,
Quoted 13 lines · Theodore Y. Ts'o
Quoted 11 lines · Chandan Rajendra
Looks like F2FS requires a lot more flexiblity than what can be offered by read callbacks i.e.
1. F2FS wants to make use of its own workqueue for decryption, verity and decompression.
2. F2FS' decompression code is not an FS independent entity like fscrypt and fsverity. Hence they would need Filesystem specific callback functions to be invoked from "read callbacks".Hence I would suggest that we should drop F2FS changes made in this patchset. Please let me know your thoughts on this.
Quoted 6 lines
That's probably the best way to go for now. My one concern is that it means that only ext4 will be using your framework. I could imagine that some people might argue that should just move the callback scheme into ext4 code as opposed to leaving it in fscrypt --- at least until we can find other file systems where we can show that it will be useful for those other file systems.
Quoted 2 lines
I also have to raise a flag on this. Doesn't this patch series try to get rid of redundant work? What'd be the rationale, if it only supports ext4?
This patchset gets encryption working with subpage blocksize by making relevant changes in the generic code (i.e. do_mpage_readpage() and block_read_full_page()) and removing duplicate code from ext4 (i.e. ext4_readpage() and friends). Without these changes the only way to get subpage blocksize support was to add more duplicate code into Ext4 i.e. import a copy of block_read_full_page() into Ext4 and make necessary edits to support encryption.
So this patchset actually does help in removing exiting duplicate code in Ext4 and also prevents addition of more such code.
Quoted 3 lines
How about generalizing the framework to support
generic_post_readand per-fspost_readfor fscrypt/fsverity/... selectively?
Quoting what I had said earlier,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
1. F2FS wants to make use of its own workqueue for decryption, verity and decompression.
2. F2FS' decompression code is not an FS independent entity like fscrypt and fsverity. Hence they would need Filesystem specific callback functions to be invoked from "read callbacks".
I am not sure if read callbacks can be made flexible enough to support the above use cases. fscrypt and fsverity already provide workqueues and any new post processing code added should follow the same convention. I see that F2FS use case is special since,
1. It uses its own workqueues.
2. Decompression code inside F2FS isn't written as an FS independent subsystem like how fscrypt and fsverity are implemented.
To summarize, I believe the users of read callbacks should follow the conventions set by fscrypt/fsverity and new post processing code that needs to be plugged into read callbacks should provide APIs similar to fscrypt/fsverity. Otherwise the state machine logic implemented by read callbacks will get complex/convoluted.
Quoted 26 lines
Thanks,
Quoted 22 lines
(Perhaps a useful experiment would be to have someone implement patches to support fscrypt and fsverity in ext2 --- the patch might or might not be accepted for upstream inclusion, but it would be useful to demonstrate how easy it is to add fscrypt and fsverity.)
The other thing to consider is that there has been some discussion about adding generalized support for I/O submission to the iomap library. It might be that if that work is accepted, support for fscrypt and fsverity would be a requirement for ext4 to use that portion of iomap's functionality. So in that eventuality, it might be that we'll want to move your read callbacks code into iomap, or we'll need to rework the read callbacks code so it can work with iomap.
But this is all work for the future. I'm a firm believe that the perfect should not be the enemy of the good, and that none of this should be a fundamental obstacle in having your code upstream.
Cheers,
- Ted
Signature · 1 line
chandan