All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: Gabriel Krisman Bertazi <krisman@suse.de>
Cc: viro@zeniv.linux.org.uk, jaegeuk@kernel.org, tytso@mit.edu,
	amir73il@gmail.com, linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v5 06/12] fscrypt: Ignore plaintext dentries during d_move
Date: Tue, 30 Jan 2024 16:55:10 -0800	[thread overview]
Message-ID: <20240131005510.GD2020@sol.localdomain> (raw)
In-Reply-To: <20240129204330.32346-7-krisman@suse.de>

On Mon, Jan 29, 2024 at 05:43:24PM -0300, Gabriel Krisman Bertazi wrote:
> Now that we do more than just clear the DCACHE_NOKEY_NAME in
> fscrypt_handle_d_move, skip it entirely for plaintext dentries, to avoid
> extra costs.
> 
> Note that VFS will call this function for any dentry, whether the volume
> has fscrypt on not.  But, since we only care about DCACHE_NOKEY_NAME, we
> can check for that, to avoid touching the superblock for other fields
> that identify a fscrypt volume.
> 
> Note also that fscrypt_handle_d_move is hopefully inlined back into
> __d_move, so the call cost is not significant.  Considering that
> DCACHE_NOKEY_NAME is a fscrypt-specific flag, we do the check in fscrypt
> code instead of the caller.
> 
> Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
> 
> ---
> Changes since v4:
>   - Check based on the dentry itself (eric)
> ---
>  include/linux/fscrypt.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
> index c1e285053b3e..ab668760d63e 100644
> --- a/include/linux/fscrypt.h
> +++ b/include/linux/fscrypt.h
> @@ -232,6 +232,15 @@ static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
>   */
>  static inline void fscrypt_handle_d_move(struct dentry *dentry)
>  {
> +	/*
> +	 * VFS calls fscrypt_handle_d_move even for non-fscrypt
> +	 * filesystems.  Since we only care about DCACHE_NOKEY_NAME
> +	 * dentries here, check that to bail out quickly, if possible.
> +	 */
> +	if (!(dentry->d_flags & DCACHE_NOKEY_NAME))
> +		return;

I think you're over-complicating this a bit.  This should be merged with patch
5, since this is basically fixing patch 5, and the end result should look like:

/*
 * When d_splice_alias() moves a directory's no-key alias to its plaintext alias
 * as a result of the encryption key being added, DCACHE_NOKEY_NAME must be
 * cleared and there might be an opportunity to disable d_revalidate.  Note that
 * we don't have to support the inverse operation because fscrypt doesn't allow
 * no-key names to be the source or target of a rename().
 */
static inline void fscrypt_handle_d_move(struct dentry *dentry)
{
	if (dentry->d_flags & DCACHE_NOKEY_NAME) {
		dentry->d_flags &= ~DCACHE_NOKEY_NAME;
		if (dentry->d_op->d_revalidate == fscrypt_d_revalidate)
			dentry->d_flags &= ~DCACHE_OP_REVALIDATE;
	}
}

Note that checking for NULL dentry->d_op is not necessary, since it's already
been verified that DCACHE_NOKEY_NAME is set, which means fscrypt is in use,
which means that there are dentry_operations.

- Eric

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: Gabriel Krisman Bertazi <krisman@suse.de>
Cc: tytso@mit.edu, amir73il@gmail.com,
	linux-f2fs-devel@lists.sourceforge.net, viro@zeniv.linux.org.uk,
	linux-fsdevel@vger.kernel.org, jaegeuk@kernel.org,
	linux-ext4@vger.kernel.org
Subject: Re: [f2fs-dev] [PATCH v5 06/12] fscrypt: Ignore plaintext dentries during d_move
Date: Tue, 30 Jan 2024 16:55:10 -0800	[thread overview]
Message-ID: <20240131005510.GD2020@sol.localdomain> (raw)
In-Reply-To: <20240129204330.32346-7-krisman@suse.de>

On Mon, Jan 29, 2024 at 05:43:24PM -0300, Gabriel Krisman Bertazi wrote:
> Now that we do more than just clear the DCACHE_NOKEY_NAME in
> fscrypt_handle_d_move, skip it entirely for plaintext dentries, to avoid
> extra costs.
> 
> Note that VFS will call this function for any dentry, whether the volume
> has fscrypt on not.  But, since we only care about DCACHE_NOKEY_NAME, we
> can check for that, to avoid touching the superblock for other fields
> that identify a fscrypt volume.
> 
> Note also that fscrypt_handle_d_move is hopefully inlined back into
> __d_move, so the call cost is not significant.  Considering that
> DCACHE_NOKEY_NAME is a fscrypt-specific flag, we do the check in fscrypt
> code instead of the caller.
> 
> Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
> 
> ---
> Changes since v4:
>   - Check based on the dentry itself (eric)
> ---
>  include/linux/fscrypt.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
> index c1e285053b3e..ab668760d63e 100644
> --- a/include/linux/fscrypt.h
> +++ b/include/linux/fscrypt.h
> @@ -232,6 +232,15 @@ static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
>   */
>  static inline void fscrypt_handle_d_move(struct dentry *dentry)
>  {
> +	/*
> +	 * VFS calls fscrypt_handle_d_move even for non-fscrypt
> +	 * filesystems.  Since we only care about DCACHE_NOKEY_NAME
> +	 * dentries here, check that to bail out quickly, if possible.
> +	 */
> +	if (!(dentry->d_flags & DCACHE_NOKEY_NAME))
> +		return;

I think you're over-complicating this a bit.  This should be merged with patch
5, since this is basically fixing patch 5, and the end result should look like:

/*
 * When d_splice_alias() moves a directory's no-key alias to its plaintext alias
 * as a result of the encryption key being added, DCACHE_NOKEY_NAME must be
 * cleared and there might be an opportunity to disable d_revalidate.  Note that
 * we don't have to support the inverse operation because fscrypt doesn't allow
 * no-key names to be the source or target of a rename().
 */
static inline void fscrypt_handle_d_move(struct dentry *dentry)
{
	if (dentry->d_flags & DCACHE_NOKEY_NAME) {
		dentry->d_flags &= ~DCACHE_NOKEY_NAME;
		if (dentry->d_op->d_revalidate == fscrypt_d_revalidate)
			dentry->d_flags &= ~DCACHE_OP_REVALIDATE;
	}
}

Note that checking for NULL dentry->d_op is not necessary, since it's already
been verified that DCACHE_NOKEY_NAME is set, which means fscrypt is in use,
which means that there are dentry_operations.

- Eric


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2024-01-31  0:55 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-29 20:43 [PATCH v5 00/12] Set casefold/fscrypt dentry operations through sb->s_d_op Gabriel Krisman Bertazi
2024-01-29 20:43 ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 01/12] ovl: Reject mounting over case-insensitive directories Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-31  0:22   ` Eric Biggers
2024-01-31  0:22     ` [f2fs-dev] " Eric Biggers
2024-01-31  0:31     ` Gabriel Krisman Bertazi
2024-01-31  0:31       ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 02/12] fscrypt: Factor out a helper to configure the lookup dentry Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-31  0:29   ` Eric Biggers
2024-01-31  0:29     ` [f2fs-dev] " Eric Biggers
2024-01-29 20:43 ` [PATCH v5 03/12] fscrypt: Call fscrypt_prepare_lookup_dentry on unencrypted dentries Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 04/12] fscrypt: Drop d_revalidate for valid dentries during lookup Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-31  0:47   ` Eric Biggers
2024-01-31  0:47     ` [f2fs-dev] " Eric Biggers
2024-01-31 18:35     ` Gabriel Krisman Bertazi
2024-01-31 18:35       ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-02-01  3:24       ` Eric Biggers
2024-02-01  3:24         ` [f2fs-dev] " Eric Biggers
2024-02-02 14:50         ` Gabriel Krisman Bertazi
2024-02-02 14:50           ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-02-09 14:03           ` Christian Brauner
2024-02-09 14:03             ` [f2fs-dev] " Christian Brauner
2024-02-09 14:46             ` Gabriel Krisman Bertazi
2024-02-09 14:46               ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 05/12] fscrypt: Drop d_revalidate once the key is added Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 06/12] fscrypt: Ignore plaintext dentries during d_move Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-31  0:55   ` Eric Biggers [this message]
2024-01-31  0:55     ` Eric Biggers
2024-01-29 20:43 ` [PATCH v5 07/12] libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-31  1:00   ` Eric Biggers
2024-01-31  1:00     ` [f2fs-dev] " Eric Biggers
2024-01-29 20:43 ` [PATCH v5 08/12] libfs: Add helper to choose dentry operations at mount-time Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 09/12] ext4: Configure dentry operations at dentry-creation time Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-02-02 15:56   ` Theodore Ts'o
2024-02-02 15:56     ` [f2fs-dev] " Theodore Ts'o
2024-01-29 20:43 ` [PATCH v5 10/12] f2fs: " Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 11/12] ubifs: " Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi
2024-01-29 20:43 ` [PATCH v5 12/12] libfs: Drop generic_set_encrypted_ci_d_ops Gabriel Krisman Bertazi
2024-01-29 20:43   ` [f2fs-dev] " Gabriel Krisman Bertazi

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=20240131005510.GD2020@sol.localdomain \
    --to=ebiggers@kernel.org \
    --cc=amir73il@gmail.com \
    --cc=jaegeuk@kernel.org \
    --cc=krisman@suse.de \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.