public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Josef Bacik <josef@toxicpanda.com>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v4 02/46] fscrypt: add per-extent encryption support
Date: Tue, 5 Dec 2023 15:57:49 -0800	[thread overview]
Message-ID: <20231205235749.GA1118@sol.localdomain> (raw)
In-Reply-To: <20231205224809.GA15355@localhost.localdomain>

On Tue, Dec 05, 2023 at 05:48:09PM -0500, Josef Bacik wrote:
> > Also, I think that for now we should keep things simple by doing the following
> > instead of fscrypt_generate_dun():
> > 
> > 	u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE] = { first_lblk };
> > 
> > Note that these two changes would eliminate the need for the inode parameter to
> > the function.
> > 
> > Please also make sure to update the function comment.  Note that the first line
> > gives the function name incorrectly.
> > 
> 
> First off thanks for the review, I'm currently going through it one by one, so
> I've come to this bit and I've got a question.
> 
> The DUN has to be le64, so this strictly isn't ok.  So would you be ok with
> 
> __le64 first_lblk_le = le64_to_cpu(first_lblk;
> u64 dun [BLK_CRYPTO_DUN_ARRAY_SIZE] = { first_lblk_le };
> 
> or do you want something different?  Additionally fscrypt_generate_dun() also
> takes into account the data units per block bits, which as I'm typing this out
> I'm realizing doesn't really matter for us even if we have different sectorsize
> per pagesize.  I guess I'll put a big comment about why we're not using that in
> there to make sure future Josef isn't confused.

The blk-crypto DUN is CPU endian, as indicated by the type (array of u64).  Note
that fscrypt_generate_dun() converts u64 => __le64 => u64.  (And then
blk-crypto-fallback converts u64 => __le64.)  Getting rid of that round trip is
nice, which is why I'm recommending it.  The only reason that
fscrypt_generate_dun() does the round trip is because it allows it to reuse
fscrypt_generate_iv(), and I wanted to be 100% sure that all of the IV methods
were implemented the same as in FS layer encryption.  With the extent-based
encryption we're just supporting one method, so things are simpler.

Yeah, it should be 'first_lblk << ci_data_units_per_block_bits'.
That would just be for future-proofing, since btrfs isn't setting
supports_subblock_data_units anyway.

> > > +/**
> > > + * fscrypt_extent_context_size() - Return the size of the on-disk extent context
> > > + * @inode: the inode this extent belongs to.
> > > + *
> > > + * Return the size of the extent context for this inode.  Since there is only
> > > + * one extent context version currently this is just the size of the extent
> > > + * context if the inode is encrypted.
> > > + */
> > > +size_t fscrypt_extent_context_size(struct inode *inode)
> > > +{
> > > +	if (!IS_ENCRYPTED(inode))
> > > +		return 0;
> > > +
> > > +	return sizeof(struct fscrypt_extent_context);
> > > +}
> > > +EXPORT_SYMBOL_GPL(fscrypt_extent_context_size);
> > 
> > Huh, shouldn't the filesystem use the size from fscrypt_set_extent_context() (or
> > fscrypt_context_for_new_extent() as I recommend calling it)?  Why is the above
> > function necessary?
> 
> This is because we need to know how big the context is ahead of time before
> searching down the b-tree to insert the file extent item, and we have to add
> this size to the file extent item ahead of time.  The disconnect between when we
> need to know how big it'll be and when we actually generate the context to save
> on disk is the reason for there being two helpers.
> 
> The main reason for this is code separation.  I would have to have the context
> on stack for the !fscrypt case if I were to only have one helper, because I
> would need it there to generate the extent context to save on disk to pass it
> around to all the things that add file extents, and I could use the length from
> that.  Not a huge deal, but this way is a little cleaner.  You can see how I've
> used the two helpers in later patches, but the general flow is
> 
> total_size = sizeof(our file extent);
> total_size += fscrypt_extent_context_size(inode);
> 
> btrfs_insert_empty_item(path, total_size);
> 
> btrfs_fscrypt_save_extent_info(path, inode);
> 
> and then in btrfs_fscrypt_save_extent_info() we do
> 
> u8 ctx[BTRFS_MAX_EXTENT_CTX_SIZE];
> 
> size = fscrypt_set_extent_context(inode, ctx);
> 
> Now the above case does seem like we could just uconditionally do something like
> 
> u8 ctx[BTRFS_MAX_EXTENT_CTX_SIZE];
> 
> total_size = sizeof(our file extent);
> ctx_size = fscrypt_set_extent_context(inode, ctx);
> if (ctx_size < 0)
> 	goto error;
> total_size += ctx_size;
> btrfs_insert_empty_item(path, total_size);
> copy_ctx_into_file_extent(path, ctx);
> 
> But there's some other file extent manipulation cases that aren't this clear
> cut, so I'd have to pass this ctx around to be copied in.  And in the !encrypted
> part we're paying a higher stack memory cost.
> 
> If you still don't like this I can rework it, but I wanted to explain my
> reasoning before I went changing a bunch of stuff to make the new paradigm fit.
> 
> The rest of the comments make sense, I'll fix everything up.  Thanks,

Maybe fscrypt_set_extent_context() (or fscrypt_context_for_new_extent()?) should
return the size if it's passed a NULL pointer?  It just seems error-prone have
the size of the thing being generated be returned by a different function.

- Eric

  reply	other threads:[~2023-12-05 23:57 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01 22:10 [PATCH v4 00/46] btrfs: add fscrypt support Josef Bacik
2023-12-01 22:10 ` [PATCH v4 01/46] fs: move fscrypt keyring destruction to after ->put_super Josef Bacik
2023-12-05  1:58   ` Eric Biggers
2023-12-05 22:48     ` Josef Bacik
2023-12-06  0:01       ` Eric Biggers
2023-12-01 22:10 ` [PATCH v4 02/46] fscrypt: add per-extent encryption support Josef Bacik
2023-12-05  3:58   ` Eric Biggers
2023-12-05 22:48     ` Josef Bacik
2023-12-05 23:57       ` Eric Biggers [this message]
2023-12-13  4:16     ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 03/46] fscrypt: add a fscrypt_inode_open helper Josef Bacik
2023-12-05  4:14   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 04/46] fscrypt: conditionally don't wipe mk secret until the last active user is done Josef Bacik
2023-12-01 22:11 ` [PATCH v4 05/46] blk-crypto: add a process bio callback Josef Bacik
2023-12-05  4:54   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 06/46] fscrypt: expose fscrypt_nokey_name Josef Bacik
2023-12-05  5:03   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 07/46] fscrypt: add documentation about extent encryption Josef Bacik
2023-12-01 22:11 ` [PATCH v4 08/46] btrfs: add infrastructure for safe em freeing Josef Bacik
2023-12-01 22:11 ` [PATCH v4 09/46] btrfs: disable various operations on encrypted inodes Josef Bacik
2023-12-01 22:11 ` [PATCH v4 10/46] btrfs: disable verity " Josef Bacik
2023-12-05  5:07   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 11/46] btrfs: start using fscrypt hooks Josef Bacik
2023-12-01 22:11 ` [PATCH v4 12/46] btrfs: add inode encryption contexts Josef Bacik
2023-12-05  5:22   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 13/46] btrfs: add new FEATURE_INCOMPAT_ENCRYPT flag Josef Bacik
2023-12-01 22:11 ` [PATCH v4 14/46] btrfs: adapt readdir for encrypted and nokey names Josef Bacik
2023-12-01 22:11 ` [PATCH v4 15/46] btrfs: handle " Josef Bacik
2023-12-05  5:29   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 16/46] btrfs: implement fscrypt ioctls Josef Bacik
2023-12-01 22:11 ` [PATCH v4 17/46] btrfs: add encryption to CONFIG_BTRFS_DEBUG Josef Bacik
2023-12-05  5:11   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 18/46] btrfs: add get_devices hook for fscrypt Josef Bacik
2023-12-01 22:11 ` [PATCH v4 19/46] btrfs: turn on inlinecrypt mount option for encrypt Josef Bacik
2023-12-05  5:41   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 20/46] btrfs: set file extent encryption excplicitly Josef Bacik
2023-12-01 22:11 ` [PATCH v4 21/46] btrfs: add fscrypt_info and encryption_type to extent_map Josef Bacik
2023-12-01 22:11 ` [PATCH v4 22/46] btrfs: add fscrypt_info and encryption_type to ordered_extent Josef Bacik
2023-12-01 22:11 ` [PATCH v4 23/46] btrfs: plumb through setting the fscrypt_info for ordered extents Josef Bacik
2023-12-01 22:11 ` [PATCH v4 24/46] btrfs: plumb the fscrypt extent context through create_io_em Josef Bacik
2023-12-01 22:11 ` [PATCH v4 25/46] btrfs: populate the ordered_extent with the fscrypt context Josef Bacik
2023-12-01 22:11 ` [PATCH v4 26/46] btrfs: keep track of fscrypt info and orig_start for dio reads Josef Bacik
2023-12-05  5:44   ` Eric Biggers
2023-12-01 22:11 ` [PATCH v4 27/46] btrfs: add an optional encryption context to the end of file extents Josef Bacik
2023-12-01 22:11 ` [PATCH v4 28/46] btrfs: explicitly track file extent length for replace and drop Josef Bacik
2023-12-01 22:11 ` [PATCH v4 29/46] btrfs: pass through fscrypt_extent_info to the file extent helpers Josef Bacik
2023-12-01 22:11 ` [PATCH v4 30/46] btrfs: pass the fscrypt_info through the replace extent infrastructure Josef Bacik
2023-12-01 22:11 ` [PATCH v4 31/46] btrfs: implement the fscrypt extent encryption hooks Josef Bacik
2023-12-01 22:11 ` [PATCH v4 32/46] btrfs: setup fscrypt_extent_info for new extents Josef Bacik
2023-12-01 22:11 ` [PATCH v4 33/46] btrfs: populate ordered_extent with the orig offset Josef Bacik
2023-12-01 22:11 ` [PATCH v4 34/46] btrfs: set the bio fscrypt context when applicable Josef Bacik
2023-12-01 22:11 ` [PATCH v4 35/46] btrfs: add a bio argument to btrfs_csum_one_bio Josef Bacik
2023-12-01 22:11 ` [PATCH v4 36/46] btrfs: add orig_logical to btrfs_bio Josef Bacik
2023-12-01 22:11 ` [PATCH v4 37/46] btrfs: limit encrypted writes to 256 segments Josef Bacik
2023-12-01 22:11 ` [PATCH v4 38/46] btrfs: implement process_bio cb for fscrypt Josef Bacik
2023-12-01 22:11 ` [PATCH v4 39/46] btrfs: add test_dummy_encryption support Josef Bacik
2023-12-01 22:11 ` [PATCH v4 40/46] btrfs: don't rewrite ret from inode_permission Josef Bacik
2023-12-01 22:11 ` [PATCH v4 41/46] btrfs: move inode_to_path higher in backref.c Josef Bacik
2023-12-01 22:11 ` [PATCH v4 42/46] btrfs: make btrfs_ref_to_path handle encrypted filenames Josef Bacik
2023-12-01 22:11 ` [PATCH v4 43/46] btrfs: don't search back for dir inode item in INO_LOOKUP_USER Josef Bacik
2023-12-01 22:11 ` [PATCH v4 44/46] btrfs: deal with encrypted symlinks in send Josef Bacik
2023-12-01 22:11 ` [PATCH v4 45/46] btrfs: decrypt file names for send Josef Bacik
2023-12-01 22:11 ` [PATCH v4 46/46] btrfs: load the inode context before sending writes Josef Bacik
2023-12-05  5:54   ` Eric Biggers
2023-12-01 22:15 ` [PATCH v4 00/46] btrfs: add fscrypt support Josef Bacik
2023-12-05  1:49 ` Eric Biggers
2023-12-05 14:16   ` David Sterba
2023-12-05 20:02     ` Eric Biggers
2024-04-09 23:42 ` Eric Biggers
2024-04-11 18:45   ` Josef Bacik

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=20231205235749.GA1118@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    /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