On Mon, Sep 05, 2022 at 08:35:34PM -0400, Sweet Tea Dorminy wrote: > From: Omar Sandoval <osandov@xxxxxxxxxxx> > > Add in the necessary calls to encrypt and decrypt data to achieve > encryption of normal data. > A little more description of what these bounce pages are and what we're doing with them. > Signed-off-by: Omar Sandoval <osandov@xxxxxxxxxxx> > Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@xxxxxxxxxx> > --- > fs/btrfs/extent_io.c | 56 ++++++++++++++++++++++++++++++++++++----- > fs/btrfs/file-item.c | 9 +++++-- > fs/btrfs/fscrypt.c | 23 ++++++++++++++++- > fs/btrfs/tree-checker.c | 11 +++++--- > 4 files changed, 87 insertions(+), 12 deletions(-) > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > index a467a7553bd9..8adcee599844 100644 > --- a/fs/btrfs/extent_io.c > +++ b/fs/btrfs/extent_io.c > @@ -183,6 +183,7 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) > { > struct bio *bio; > struct bio_vec *bv; > + struct page *first_page; > struct inode *inode; > int mirror_num; > > @@ -191,13 +192,17 @@ static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl) > > bio = bio_ctrl->bio; > bv = bio_first_bvec_all(bio); > - inode = bv->bv_page->mapping->host; > + first_page = bio_first_page_all(bio); > + if (fscrypt_is_bounce_page(first_page)) > + inode = fscrypt_pagecache_page(first_page)->mapping->host; > + else > + inode = first_page->mapping->host; > mirror_num = bio_ctrl->mirror_num; > > /* Caller should ensure the bio has at least some range added */ > ASSERT(bio->bi_iter.bi_size); > > - btrfs_bio(bio)->file_offset = page_offset(bv->bv_page) + bv->bv_offset; > + btrfs_bio(bio)->file_offset = page_offset(first_page) + bv->bv_offset; > > if (!is_data_inode(inode)) > btrfs_submit_metadata_bio(inode, bio, mirror_num); > @@ -2810,9 +2815,19 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio) > ASSERT(!bio_flagged(bio, BIO_CLONED)); > bio_for_each_segment_all(bvec, bio, iter_all) { > struct page *page = bvec->bv_page; > - struct inode *inode = page->mapping->host; > - struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); > - const u32 sectorsize = fs_info->sectorsize; > + struct inode *inode; > + struct btrfs_fs_info *fs_info; > + u32 sectorsize; > + struct page *bounce_page = NULL; > + > + if (fscrypt_is_bounce_page(page)) { > + bounce_page = page; > + page = fscrypt_pagecache_page(bounce_page); > + } > + > + inode = page->mapping->host; > + fs_info = btrfs_sb(inode->i_sb); > + sectorsize = fs_info->sectorsize; > > /* Our read/write should always be sector aligned. */ > if (!IS_ALIGNED(bvec->bv_offset, sectorsize)) > @@ -2833,7 +2848,7 @@ static void end_bio_extent_writepage(struct btrfs_bio *bbio) > } > > end_extent_writepage(page, error, start, end); > - > + fscrypt_free_bounce_page(bounce_page); > btrfs_page_clear_writeback(fs_info, page, start, bvec->bv_len); > } > > @@ -3029,6 +3044,17 @@ static void end_bio_extent_readpage(struct btrfs_bio *bbio) > } > } > > + if (likely(uptodate)) { > + if (fscrypt_inode_uses_fs_layer_crypto(inode)) { > + int ret = fscrypt_decrypt_pagecache_blocks(page, > + bvec->bv_len, > + bvec->bv_offset); > + if (ret) { > + error_bitmap = (unsigned int) -1; > + uptodate = false; > + } This thing. Thanks, Josef