linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: viro@zeniv.linux.org.uk, ebiggers@kernel.org, jaegeuk@kernel.org,
	tytso@mit.edu
Cc: linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-fsdevel@vger.kernel.org, amir73il@gmail.com,
	Gabriel Krisman Bertazi <krisman@suse.de>
Subject: [PATCH v3 04/10] fscrypt: Drop d_revalidate once the key is added
Date: Fri, 19 Jan 2024 15:47:36 -0300	[thread overview]
Message-ID: <20240119184742.31088-5-krisman@suse.de> (raw)
In-Reply-To: <20240119184742.31088-1-krisman@suse.de>

From fscrypt perspective, once the key is available, the dentry will
remain valid until evicted for other reasons, since keyed dentries don't
require revalidation and, if the key is removed, the dentry is
forcefully evicted.  Therefore, we don't need to keep revalidating them
repeatedly.

Obviously, we can only do this if fscrypt is the only thing requiring
revalidation for a dentry.  For this reason, we only disable
d_revalidate if the .d_revalidate hook is fscrypt_d_revalidate itself.

It is safe to do it here because when moving the dentry to the
plain-text version, we are holding the d_lock.  We might race with a
concurrent RCU lookup but this is harmless because, at worst, we will
get an extra d_revalidate on the keyed dentry, which is will find the
dentry is valid.

Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>

---
Changes since v3:
  - Fix null-ptr-deref for filesystems that don't support fscrypt (ktr)
Changes since v2:
  - Do it when moving instead of when revalidating the dentry. (me)

Changes since v1:
  - Improve commit message (Eric)
  - Drop & in function comparison (Eric)
---
 include/linux/fscrypt.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index 3801c5c94fb6..0ba3928f3020 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -192,6 +192,8 @@ struct fscrypt_operations {
 					     unsigned int *num_devs);
 };
 
+int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
+
 static inline struct fscrypt_inode_info *
 fscrypt_get_inode_info(const struct inode *inode)
 {
@@ -230,6 +232,14 @@ static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
 static inline void fscrypt_handle_d_move(struct dentry *dentry)
 {
 	dentry->d_flags &= ~DCACHE_NOKEY_NAME;
+
+	/*
+	 * Save the d_revalidate call cost during VFS operations.  We
+	 * can do it because, when the key is available, the dentry
+	 * can't go stale and the key won't go away without eviction.
+	 */
+	if (dentry->d_op && dentry->d_op->d_revalidate == fscrypt_d_revalidate)
+		dentry->d_flags &= ~DCACHE_OP_REVALIDATE;
 }
 
 /**
@@ -368,7 +378,6 @@ int fscrypt_fname_disk_to_usr(const struct inode *inode,
 bool fscrypt_match_name(const struct fscrypt_name *fname,
 			const u8 *de_name, u32 de_name_len);
 u64 fscrypt_fname_siphash(const struct inode *dir, const struct qstr *name);
-int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags);
 
 /* bio.c */
 bool fscrypt_decrypt_bio(struct bio *bio);
-- 
2.43.0


  parent reply	other threads:[~2024-01-19 18:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 18:47 [PATCH v3 00/10] Set casefold/fscrypt dentry operations through sb->s_d_op Gabriel Krisman Bertazi
2024-01-19 18:47 ` [PATCH v3 01/10] ovl: Reject mounting case-insensitive filesystems Gabriel Krisman Bertazi
2024-01-25  2:51   ` Eric Biggers
2024-01-25 16:55     ` Gabriel Krisman Bertazi
2024-01-27  7:08       ` Eric Biggers
2024-01-19 18:47 ` [PATCH v3 02/10] fscrypt: Share code between functions that prepare lookup Gabriel Krisman Bertazi
2024-01-25  3:05   ` Eric Biggers
2024-01-25 20:18     ` Gabriel Krisman Bertazi
2024-01-19 18:47 ` [PATCH v3 03/10] fscrypt: Drop d_revalidate for valid dentries during lookup Gabriel Krisman Bertazi
2024-01-19 18:47 ` Gabriel Krisman Bertazi [this message]
2024-01-25  3:12   ` [PATCH v3 04/10] fscrypt: Drop d_revalidate once the key is added Eric Biggers
2024-01-25 20:20     ` Gabriel Krisman Bertazi
2024-01-27  7:17       ` Eric Biggers
2024-01-29 19:34         ` Gabriel Krisman Bertazi
2024-01-19 18:47 ` [PATCH v3 05/10] libfs: Merge encrypted_ci_dentry_ops and ci_dentry_ops Gabriel Krisman Bertazi
2024-01-19 18:47 ` [PATCH v3 06/10] libfs: Add helper to choose dentry operations at mount Gabriel Krisman Bertazi
2024-01-25  3:13   ` Eric Biggers
2024-01-19 18:47 ` [PATCH v3 07/10] ext4: Configure dentry operations at dentry-creation time Gabriel Krisman Bertazi
2024-01-19 18:47 ` [PATCH v3 08/10] f2fs: " Gabriel Krisman Bertazi
2024-01-19 18:47 ` [PATCH v3 09/10] ubifs: " Gabriel Krisman Bertazi
2024-01-19 18:47 ` [PATCH v3 10/10] libfs: Drop generic_set_encrypted_ci_d_ops Gabriel Krisman Bertazi
  -- strict thread matches above, loose matches on Subject: below --
2024-01-11 22:58 [PATCH v3 00/10] Set casefold/fscrypt dentry operations through sb->s_d_op Gabriel Krisman Bertazi
2024-01-11 22:58 ` [PATCH v3 04/10] fscrypt: Drop d_revalidate once the key is added Gabriel Krisman Bertazi
2024-01-18  8:23   ` kernel test robot
2024-01-18 18:58     ` 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=20240119184742.31088-5-krisman@suse.de \
    --to=krisman@suse.de \
    --cc=amir73il@gmail.com \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --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 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).