From: Eric Biggers <ebiggers@kernel.org>
To: Satya Tangirala <satyat@google.com>
Cc: linux-scsi@vger.kernel.org, Kim Boojin <boojin.kim@samsung.com>,
Kuohong Wang <kuohong.wang@mediatek.com>,
Barani Muthukumaran <bmuthuku@qti.qualcomm.com>,
linux-f2fs-devel@lists.sourceforge.net,
linux-block@vger.kernel.org, linux-fscrypt@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [f2fs-dev] [PATCH v6 7/9] fscrypt: add inline encryption support
Date: Tue, 14 Jan 2020 13:12:43 -0800 [thread overview]
Message-ID: <20200114211243.GC41220@gmail.com> (raw)
In-Reply-To: <20191218145136.172774-8-satyat@google.com>
On Wed, Dec 18, 2019 at 06:51:34AM -0800, Satya Tangirala wrote:
> diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
> index 1f4b8a277060..d28d8e803554 100644
> --- a/fs/crypto/bio.c
> +++ b/fs/crypto/bio.c
> @@ -46,26 +46,35 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
> {
> const unsigned int blockbits = inode->i_blkbits;
> const unsigned int blocksize = 1 << blockbits;
> + const bool inlinecrypt = fscrypt_inode_uses_inline_crypto(inode);
> struct page *ciphertext_page;
> struct bio *bio;
> int ret, err = 0;
>
> - ciphertext_page = fscrypt_alloc_bounce_page(GFP_NOWAIT);
> - if (!ciphertext_page)
> - return -ENOMEM;
> + if (inlinecrypt) {
> + ciphertext_page = ZERO_PAGE(0);
> + } else {
> + ciphertext_page = fscrypt_alloc_bounce_page(GFP_NOWAIT);
> + if (!ciphertext_page)
> + return -ENOMEM;
> + }
>
> while (len--) {
> - err = fscrypt_crypt_block(inode, FS_ENCRYPT, lblk,
> - ZERO_PAGE(0), ciphertext_page,
> - blocksize, 0, GFP_NOFS);
> - if (err)
> - goto errout;
> + if (!inlinecrypt) {
> + err = fscrypt_crypt_block(inode, FS_ENCRYPT, lblk,
> + ZERO_PAGE(0), ciphertext_page,
> + blocksize, 0, GFP_NOFS);
> + if (err)
> + goto errout;
> + }
>
> bio = bio_alloc(GFP_NOWAIT, 1);
> if (!bio) {
> err = -ENOMEM;
> goto errout;
> }
> + fscrypt_set_bio_crypt_ctx(bio, inode, lblk, GFP_NOIO);
> +
> bio_set_dev(bio, inode->i_sb->s_bdev);
> bio->bi_iter.bi_sector = pblk << (blockbits - 9);
> bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
> @@ -87,7 +96,8 @@ int fscrypt_zeroout_range(const struct inode *inode, pgoff_t lblk,
> }
> err = 0;
> errout:
> - fscrypt_free_bounce_page(ciphertext_page);
> + if (!inlinecrypt)
> + fscrypt_free_bounce_page(ciphertext_page);
> return err;
> }
> EXPORT_SYMBOL(fscrypt_zeroout_range);
FYI, I've just applied a patch
(https://lore.kernel.org/r/20191226160813.53182-1-ebiggers@kernel.org/)
to fscrypt.git#master that optimizes this function to write multiple pages at a
time. So this part of this patch will need to be reworked. I suggest just
handling the inline and fs-layer encryption cases separately.
I maintain a testing branch that has all the pending patches I'm interested in
applied, so I actually already hacked together the following to resolve the
conflict. Please double check it carefully before using it in v7 though:
static int fscrypt_zeroout_range_inlinecrypt(const struct inode *inode,
pgoff_t lblk,
sector_t pblk, unsigned int len)
{
const unsigned int blockbits = inode->i_blkbits;
const unsigned int blocks_per_page_bits = PAGE_SHIFT - blockbits;
const unsigned int blocks_per_page = 1 << blocks_per_page_bits;
unsigned int i;
struct bio *bio;
int ret, err;
/* This always succeeds since __GFP_DIRECT_RECLAIM is set. */
bio = bio_alloc(GFP_NOFS, BIO_MAX_PAGES);
do {
bio_set_dev(bio, inode->i_sb->s_bdev);
bio->bi_iter.bi_sector = pblk << (blockbits - 9);
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
fscrypt_set_bio_crypt_ctx(bio, inode, lblk, GFP_NOFS);
i = 0;
do {
unsigned int blocks_this_page =
min(len, blocks_per_page);
unsigned int bytes_this_page =
blocks_this_page << blockbits;
ret = bio_add_page(bio, ZERO_PAGE(0),
bytes_this_page, 0);
if (WARN_ON(ret != bytes_this_page)) {
err = -EIO;
goto out;
}
lblk += blocks_this_page;
pblk += blocks_this_page;
len -= blocks_this_page;
} while (++i != BIO_MAX_PAGES && len != 0);
err = submit_bio_wait(bio);
if (err)
goto out;
bio_reset(bio);
} while (len != 0);
err = 0;
out:
bio_put(bio);
return err;
}
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2020-01-14 21:12 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-18 14:51 [f2fs-dev] [PATCH v6 0/9] Inline Encryption Support Satya Tangirala via Linux-f2fs-devel
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 1/9] block: Keyslot Manager for Inline Encryption Satya Tangirala via Linux-f2fs-devel
2019-12-18 20:13 ` Eric Biggers
2020-01-17 9:10 ` Christoph Hellwig
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 2/9] block: Add encryption context to struct bio Satya Tangirala via Linux-f2fs-devel
2019-12-18 21:10 ` Eric Biggers
2019-12-18 21:21 ` Darrick J. Wong
2019-12-18 21:25 ` Martin K. Petersen
2019-12-18 22:27 ` Eric Biggers
2019-12-19 0:47 ` Martin K. Petersen
2019-12-20 3:52 ` Eric Biggers
2020-01-07 4:35 ` Martin K. Petersen
2020-01-08 14:07 ` Christoph Hellwig
2020-01-08 17:26 ` Eric Biggers
2020-01-17 8:32 ` Christoph Hellwig
2020-01-18 5:11 ` Eric Biggers
2020-01-21 22:05 ` Satya Tangirala via Linux-f2fs-devel
2020-01-09 3:40 ` Martin K. Petersen
2020-01-14 21:24 ` Eric Biggers
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 3/9] block: blk-crypto for Inline Encryption Satya Tangirala via Linux-f2fs-devel
2019-12-20 3:14 ` Eric Biggers
2019-12-20 5:10 ` Eric Biggers
2020-01-14 21:22 ` Eric Biggers
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 4/9] scsi: ufs: UFS driver v2.1 spec crypto additions Satya Tangirala via Linux-f2fs-devel
2020-01-17 12:31 ` Christoph Hellwig
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 5/9] scsi: ufs: UFS crypto API Satya Tangirala via Linux-f2fs-devel
2019-12-20 4:48 ` Eric Biggers
2020-01-14 21:16 ` Eric Biggers
2020-01-17 13:51 ` Christoph Hellwig
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 6/9] scsi: ufs: Add inline encryption support to UFS Satya Tangirala via Linux-f2fs-devel
2019-12-20 5:44 ` Eric Biggers
2020-01-17 13:58 ` Christoph Hellwig
2020-01-18 5:27 ` Eric Biggers
2020-02-05 18:07 ` Christoph Hellwig
2020-01-18 3:58 ` Eric Biggers
2020-02-05 20:47 ` Eric Biggers
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 7/9] fscrypt: add inline encryption support Satya Tangirala via Linux-f2fs-devel
2020-01-14 21:12 ` Eric Biggers [this message]
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 8/9] f2fs: " Satya Tangirala via Linux-f2fs-devel
2019-12-20 4:23 ` Eric Biggers
2019-12-18 14:51 ` [f2fs-dev] [PATCH v6 9/9] ext4: " Satya Tangirala via Linux-f2fs-devel
2019-12-19 0:12 ` Eric Biggers
2019-12-19 0:31 ` Satya Tangirala via Linux-f2fs-devel
2019-12-22 0:16 ` Eric Biggers
2020-01-08 14:05 ` [f2fs-dev] [PATCH v6 0/9] Inline Encryption Support Christoph Hellwig
2020-01-08 18:43 ` Satya Tangirala via Linux-f2fs-devel
2020-01-17 8:52 ` Christoph Hellwig
2020-02-01 0:53 ` Satya Tangirala via Linux-f2fs-devel
2020-02-03 9:15 ` Christoph Hellwig
2020-02-04 3:39 ` Satya Tangirala via Linux-f2fs-devel
2020-02-04 14:58 ` Christoph Hellwig
2020-02-04 21:21 ` Eric Biggers
2020-02-05 7:36 ` Eric Biggers
2020-02-05 18:05 ` Christoph Hellwig
2020-02-21 12:30 ` Satya Tangirala via Linux-f2fs-devel
2020-02-21 14:20 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200114211243.GC41220@gmail.com \
--to=ebiggers@kernel.org \
--cc=bmuthuku@qti.qualcomm.com \
--cc=boojin.kim@samsung.com \
--cc=kuohong.wang@mediatek.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=satyat@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).