public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] fscrypt: remove d_lock on reading DCACHE_ENCRYPTED_WITH_KEY
@ 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
  0 siblings, 1 reply; 6+ messages in thread
From: Gao Xiang @ 2018-09-10 13:01 UTC (permalink / raw)
  To: Theodore Y. Ts'o, Jaegeuk Kim
  Cc: Eric Biggers, linux-fscrypt, linux-kernel, Chao Yu, Miao Xie,
	weidu.du, Gao Xiang

It seems there is no need to take d_lock when
accessing dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY
in fscrypt_d_revalidate. It only needs to be
serialized for updating.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
Hi,

At glance, I have no idea why fscrypt_d_revalidate disables
RCU-lookup. Therefore I made patches to raise a question and
do some basic test, and it seems to work.

Thanks,

 fs/crypto/crypto.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index 0f46cf5..b38c574 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -329,9 +329,8 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags)
 		return 0;
 	}
 
-	spin_lock(&dentry->d_lock);
-	cached_with_key = dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY;
-	spin_unlock(&dentry->d_lock);
+	cached_with_key = READ_ONCE(dentry->d_flags) &
+		DCACHE_ENCRYPTED_WITH_KEY;
 	dir_has_key = (d_inode(dir)->i_crypt_info != NULL);
 	dput(dir);
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [RFC PATCH v2 1/2] fscrypt: remove d_lock on reading DCACHE_ENCRYPTED_WITH_KEY
@ 2018-11-06 12:20 Gao Xiang
  2018-11-06 12:20 ` [RFC PATCH v2 2/2] fscrypt: enable RCU-walk path for .d_revalidate Gao Xiang
  0 siblings, 1 reply; 6+ messages in thread
From: Gao Xiang @ 2018-11-06 12:20 UTC (permalink / raw)
  To: Theodore Y . Ts'o, Jaegeuk Kim, Eric Biggers
  Cc: linux-fscrypt, linux-fsdevel, linux-kernel, Chao Yu, Miao Xie,
	weidu.du, Gao Xiang

It seems there is no need to take d_lock when accessing
dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY in
fscrypt_d_revalidate. It only needs to be serialized for updating.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---

Change log v2:
 - Fix negative dentry (NULL d_inode) issue as Eric pointed out;
 - Fix to use '__lockref_is_dead()' as Eric pointed out before;

[original message]
Hi,
 At glance, I have no idea why fscrypt_d_revalidate disables
RCU-lookup. Therefore I made patches to raise a question and
do some test (eg. fsstress w/ and w/o drop_caches) and it
seems to work.

Thanks,
Gao Xiang

 fs/crypto/crypto.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index 0f46cf550907..b38c574f70ac 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -329,9 +329,8 @@ static int fscrypt_d_revalidate(struct dentry *dentry, unsigned int flags)
 		return 0;
 	}
 
-	spin_lock(&dentry->d_lock);
-	cached_with_key = dentry->d_flags & DCACHE_ENCRYPTED_WITH_KEY;
-	spin_unlock(&dentry->d_lock);
+	cached_with_key = READ_ONCE(dentry->d_flags) &
+		DCACHE_ENCRYPTED_WITH_KEY;
 	dir_has_key = (d_inode(dir)->i_crypt_info != NULL);
 	dput(dir);
 
-- 
2.14.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-11-06 12:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [RFC PATCH 2/2] fscrypt: enable RCU-walk path for .d_revalidate Gao Xiang
2018-09-10 13:08   ` [RFC PATCH v2 " Gao Xiang
2018-09-10 23:20     ` Eric Biggers
2018-09-11  5:29       ` Gao Xiang
  -- strict thread matches above, loose matches on Subject: below --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox