Linux-ext4 Archive on lore.kernel.org
 help / color / Atom feed
* [RFC PATCH] ext4: use the normal helper to get the actual inode
@ 2020-10-10  8:10 xiakaixu1987
  2020-10-12  9:33 ` Lukas Czerner
  0 siblings, 1 reply; 3+ messages in thread
From: xiakaixu1987 @ 2020-10-10  8:10 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, adilger.kernel, Kaixu Xia

From: Kaixu Xia <kaixuxia@tencent.com>

Here we use the READ_ONCE to fix race conditions in ->d_compare() and
->d_hash() when they are called in RCU-walk mode, seems we can use
the normal helper d_inode_rcu() to get the actual inode.

Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
 fs/ext4/dir.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 1d82336b1cd4..3bf6cb8e55f6 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -674,7 +674,7 @@ static int ext4_d_compare(const struct dentry *dentry, unsigned int len,
 {
 	struct qstr qstr = {.name = str, .len = len };
 	const struct dentry *parent = READ_ONCE(dentry->d_parent);
-	const struct inode *inode = READ_ONCE(parent->d_inode);
+	const struct inode *inode = d_inode_rcu(parent);
 	char strbuf[DNAME_INLINE_LEN];
 
 	if (!inode || !IS_CASEFOLDED(inode) ||
@@ -706,7 +706,7 @@ static int ext4_d_hash(const struct dentry *dentry, struct qstr *str)
 {
 	const struct ext4_sb_info *sbi = EXT4_SB(dentry->d_sb);
 	const struct unicode_map *um = sbi->s_encoding;
-	const struct inode *inode = READ_ONCE(dentry->d_inode);
+	const struct inode *inode = d_inode_rcu(dentry);
 	unsigned char *norm;
 	int len, ret = 0;
 
-- 
2.20.0


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

* Re: [RFC PATCH] ext4: use the normal helper to get the actual inode
  2020-10-10  8:10 [RFC PATCH] ext4: use the normal helper to get the actual inode xiakaixu1987
@ 2020-10-12  9:33 ` Lukas Czerner
  2020-10-14 15:48   ` Theodore Y. Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Lukas Czerner @ 2020-10-12  9:33 UTC (permalink / raw)
  To: xiakaixu1987; +Cc: linux-ext4, tytso, adilger.kernel, Kaixu Xia

On Sat, Oct 10, 2020 at 04:10:16PM +0800, xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
> 
> Here we use the READ_ONCE to fix race conditions in ->d_compare() and
> ->d_hash() when they are called in RCU-walk mode, seems we can use
> the normal helper d_inode_rcu() to get the actual inode.

Looks good to me.
Thanks!

Reviewed-by: Lukas Czerner <lczerner@redhat.com>

> 
> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> ---
>  fs/ext4/dir.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> index 1d82336b1cd4..3bf6cb8e55f6 100644
> --- a/fs/ext4/dir.c
> +++ b/fs/ext4/dir.c
> @@ -674,7 +674,7 @@ static int ext4_d_compare(const struct dentry *dentry, unsigned int len,
>  {
>  	struct qstr qstr = {.name = str, .len = len };
>  	const struct dentry *parent = READ_ONCE(dentry->d_parent);
> -	const struct inode *inode = READ_ONCE(parent->d_inode);
> +	const struct inode *inode = d_inode_rcu(parent);
>  	char strbuf[DNAME_INLINE_LEN];
>  
>  	if (!inode || !IS_CASEFOLDED(inode) ||
> @@ -706,7 +706,7 @@ static int ext4_d_hash(const struct dentry *dentry, struct qstr *str)
>  {
>  	const struct ext4_sb_info *sbi = EXT4_SB(dentry->d_sb);
>  	const struct unicode_map *um = sbi->s_encoding;
> -	const struct inode *inode = READ_ONCE(dentry->d_inode);
> +	const struct inode *inode = d_inode_rcu(dentry);
>  	unsigned char *norm;
>  	int len, ret = 0;
>  
> -- 
> 2.20.0
> 


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

* Re: [RFC PATCH] ext4: use the normal helper to get the actual inode
  2020-10-12  9:33 ` Lukas Czerner
@ 2020-10-14 15:48   ` Theodore Y. Ts'o
  0 siblings, 0 replies; 3+ messages in thread
From: Theodore Y. Ts'o @ 2020-10-14 15:48 UTC (permalink / raw)
  To: Lukas Czerner; +Cc: xiakaixu1987, linux-ext4, adilger.kernel, Kaixu Xia

On Mon, Oct 12, 2020 at 11:33:04AM +0200, Lukas Czerner wrote:
> On Sat, Oct 10, 2020 at 04:10:16PM +0800, xiakaixu1987@gmail.com wrote:
> > From: Kaixu Xia <kaixuxia@tencent.com>
> > 
> > Here we use the READ_ONCE to fix race conditions in ->d_compare() and
> > ->d_hash() when they are called in RCU-walk mode, seems we can use
> > the normal helper d_inode_rcu() to get the actual inode.
> 
> Looks good to me.
> Thanks!
> 
> Reviewed-by: Lukas Czerner <lczerner@redhat.com>

Thanks, applied.

				- Ted

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-10  8:10 [RFC PATCH] ext4: use the normal helper to get the actual inode xiakaixu1987
2020-10-12  9:33 ` Lukas Czerner
2020-10-14 15:48   ` Theodore Y. Ts'o

Linux-ext4 Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-ext4/0 linux-ext4/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-ext4 linux-ext4/ https://lore.kernel.org/linux-ext4 \
		linux-ext4@vger.kernel.org
	public-inbox-index linux-ext4

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-ext4


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git