From: Gao Xiang <gaoxiang25@huawei.com> To: "Theodore Y. Ts'o" <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org> Cc: Eric Biggers <ebiggers@google.com>, linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Yu <yuchao0@huawei.com>, Miao Xie <miaoxie@huawei.com>, weidu.du@huawei.com, Gao Xiang <gaoxiang25@huawei.com> Subject: [RFC PATCH v2 2/2] fscrypt: enable RCU-walk path for .d_revalidate Date: Mon, 10 Sep 2018 21:08:57 +0800 [thread overview] Message-ID: <1536584937-16960-1-git-send-email-gaoxiang25@huawei.com> (raw) In-Reply-To: <1536584468-15695-2-git-send-email-gaoxiang25@huawei.com> This patch attempts to enable RCU-walk for fscrypt. It looks harmless at glance and could have better performance than do ref-walk only. Signed-off-by: Gao Xiang <gaoxiang25@huawei.com> --- change log v2: - READ_ONCE(dir->d_parent) -> READ_ONCE(dentry->d_parent) fs/crypto/crypto.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index b38c574..9bd21c0 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -319,20 +319,24 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) { struct dentry *dir; int dir_has_key, cached_with_key; - - if (flags & LOOKUP_RCU) - return -ECHILD; - - dir = dget_parent(dentry); - if (!IS_ENCRYPTED(d_inode(dir))) { - dput(dir); + struct inode *dir_inode; + + rcu_read_lock(); +repeat: + dir = READ_ONCE(dentry->d_parent); + dir_inode = d_inode_rcu(dir); + if (!IS_ENCRYPTED(dir_inode)) { + rcu_read_unlock(); return 0; } + dir_has_key = (dir_inode->i_crypt_info != NULL); + if (unlikely(READ_ONCE(dir->d_lockref.count) < 0 || + READ_ONCE(dentry->d_parent) != dir)) + goto repeat; + rcu_read_unlock(); cached_with_key = READ_ONCE(dentry->d_flags) & DCACHE_ENCRYPTED_WITH_KEY; - dir_has_key = (d_inode(dir)->i_crypt_info != NULL); - dput(dir); /* * If the dentry was cached without the key, and it is a -- 1.9.1
WARNING: multiple messages have this Message-ID (diff)
From: Gao Xiang <gaoxiang25@huawei.com> To: "Theodore Y. Ts'o" <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org> Cc: Eric Biggers <ebiggers@google.com>, <linux-fscrypt@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Chao Yu <yuchao0@huawei.com>, Miao Xie <miaoxie@huawei.com>, <weidu.du@huawei.com>, Gao Xiang <gaoxiang25@huawei.com> Subject: [RFC PATCH v2 2/2] fscrypt: enable RCU-walk path for .d_revalidate Date: Mon, 10 Sep 2018 21:08:57 +0800 [thread overview] Message-ID: <1536584937-16960-1-git-send-email-gaoxiang25@huawei.com> (raw) In-Reply-To: <1536584468-15695-2-git-send-email-gaoxiang25@huawei.com> This patch attempts to enable RCU-walk for fscrypt. It looks harmless at glance and could have better performance than do ref-walk only. Signed-off-by: Gao Xiang <gaoxiang25@huawei.com> --- change log v2: - READ_ONCE(dir->d_parent) -> READ_ONCE(dentry->d_parent) fs/crypto/crypto.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index b38c574..9bd21c0 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -319,20 +319,24 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags) { struct dentry *dir; int dir_has_key, cached_with_key; - - if (flags & LOOKUP_RCU) - return -ECHILD; - - dir = dget_parent(dentry); - if (!IS_ENCRYPTED(d_inode(dir))) { - dput(dir); + struct inode *dir_inode; + + rcu_read_lock(); +repeat: + dir = READ_ONCE(dentry->d_parent); + dir_inode = d_inode_rcu(dir); + if (!IS_ENCRYPTED(dir_inode)) { + rcu_read_unlock(); return 0; } + dir_has_key = (dir_inode->i_crypt_info != NULL); + if (unlikely(READ_ONCE(dir->d_lockref.count) < 0 || + READ_ONCE(dentry->d_parent) != dir)) + goto repeat; + rcu_read_unlock(); cached_with_key = READ_ONCE(dentry->d_flags) & DCACHE_ENCRYPTED_WITH_KEY; - dir_has_key = (d_inode(dir)->i_crypt_info != NULL); - dput(dir); /* * If the dentry was cached without the key, and it is a -- 1.9.1
next prev parent reply other threads:[~2018-09-10 18:03 UTC|newest] Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-09-10 13:01 [RFC PATCH 1/2] fscrypt: remove d_lock on reading DCACHE_ENCRYPTED_WITH_KEY Gao Xiang 2018-09-10 13:01 ` Gao Xiang 2018-09-10 13:01 ` [RFC PATCH 2/2] fscrypt: enable RCU-walk path for .d_revalidate Gao Xiang 2018-09-10 13:01 ` Gao Xiang 2018-09-10 13:08 ` Gao Xiang [this message] 2018-09-10 13:08 ` [RFC PATCH v2 " Gao Xiang 2018-09-10 23:20 ` Eric Biggers 2018-09-11 5:29 ` Gao Xiang 2018-09-11 5:29 ` Gao Xiang 2018-11-06 12:20 [RFC PATCH v2 1/2] fscrypt: remove d_lock on reading DCACHE_ENCRYPTED_WITH_KEY Gao Xiang 2018-11-06 12:20 ` [RFC PATCH v2 2/2] fscrypt: enable RCU-walk path for .d_revalidate Gao Xiang 2018-11-06 12:20 ` Gao Xiang
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=1536584937-16960-1-git-send-email-gaoxiang25@huawei.com \ --to=gaoxiang25@huawei.com \ --cc=ebiggers@google.com \ --cc=jaegeuk@kernel.org \ --cc=linux-fscrypt@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=miaoxie@huawei.com \ --cc=tytso@mit.edu \ --cc=weidu.du@huawei.com \ --cc=yuchao0@huawei.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: linkBe 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.