linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs/dcache: prevent repeated locking
@ 2021-12-07 10:16 cgel.zte
  2021-12-07 13:17 ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: cgel.zte @ 2021-12-07 10:16 UTC (permalink / raw)
  To: viro; +Cc: linux-fsdevel, linux-kernel, Lv Ruyi, Zeal Robot

From: Lv Ruyi <lv.ruyi@zte.com.cn>

Move the spin_lock above the restart to prevent to lock twice 
when the code goto restart.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Lv Ruyi <lv.ruyi@zte.com.cn>
---
 fs/dcache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index c84269c6e8bf..8580d51b397a 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1102,8 +1102,8 @@ struct dentry *d_find_alias_rcu(struct inode *inode)
 void d_prune_aliases(struct inode *inode)
 {
 	struct dentry *dentry;
-restart:
 	spin_lock(&inode->i_lock);
+restart:
 	hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
 		spin_lock(&dentry->d_lock);
 		if (!dentry->d_lockref.count) {
-- 
2.25.1


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

* Re: [PATCH] fs/dcache: prevent repeated locking
  2021-12-07 10:16 [PATCH] fs/dcache: prevent repeated locking cgel.zte
@ 2021-12-07 13:17 ` Matthew Wilcox
  2021-12-07 21:25   ` Eric Biggers
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2021-12-07 13:17 UTC (permalink / raw)
  To: cgel.zte; +Cc: viro, linux-fsdevel, linux-kernel, Lv Ruyi, Zeal Robot

On Tue, Dec 07, 2021 at 10:16:46AM +0000, cgel.zte@gmail.com wrote:
> From: Lv Ruyi <lv.ruyi@zte.com.cn>
> 
> Move the spin_lock above the restart to prevent to lock twice 
> when the code goto restart.

This is madness.

void d_prune_aliases(struct inode *inode)
        spin_lock(&inode->i_lock);
                        if (likely(!dentry->d_lockref.count)) {
                                __dentry_kill(dentry);
                                goto restart;
...
static void __dentry_kill(struct dentry *dentry)
        if (dentry->d_inode)
                dentry_unlink_inode(dentry);
...
static void dentry_unlink_inode(struct dentry * dentry)
        spin_unlock(&inode->i_lock);

Did you even test this patch?

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

* Re: [PATCH] fs/dcache: prevent repeated locking
  2021-12-07 13:17 ` Matthew Wilcox
@ 2021-12-07 21:25   ` Eric Biggers
  2021-12-07 22:11     ` Matthew Wilcox
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2021-12-07 21:25 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: cgel.zte, viro, linux-fsdevel, linux-kernel, Lv Ruyi, Zeal Robot

On Tue, Dec 07, 2021 at 01:17:41PM +0000, Matthew Wilcox wrote:
> On Tue, Dec 07, 2021 at 10:16:46AM +0000, cgel.zte@gmail.com wrote:
> > From: Lv Ruyi <lv.ruyi@zte.com.cn>
> > 
> > Move the spin_lock above the restart to prevent to lock twice 
> > when the code goto restart.
> 
> This is madness.
> 
> void d_prune_aliases(struct inode *inode)
>         spin_lock(&inode->i_lock);
>                         if (likely(!dentry->d_lockref.count)) {
>                                 __dentry_kill(dentry);
>                                 goto restart;
> ...
> static void __dentry_kill(struct dentry *dentry)
>         if (dentry->d_inode)
>                 dentry_unlink_inode(dentry);
> ...
> static void dentry_unlink_inode(struct dentry * dentry)
>         spin_unlock(&inode->i_lock);
> 
> Did you even test this patch?

This same wrong patch has been sent several times before.  I think it's fair to
say that this code could use a comment, e.g.:

	/* i_lock was dropped */
	goto restart;

- Eric

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

* Re: [PATCH] fs/dcache: prevent repeated locking
  2021-12-07 21:25   ` Eric Biggers
@ 2021-12-07 22:11     ` Matthew Wilcox
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2021-12-07 22:11 UTC (permalink / raw)
  To: Eric Biggers
  Cc: cgel.zte, viro, linux-fsdevel, linux-kernel, Lv Ruyi, Zeal Robot

On Tue, Dec 07, 2021 at 01:25:18PM -0800, Eric Biggers wrote:
> On Tue, Dec 07, 2021 at 01:17:41PM +0000, Matthew Wilcox wrote:
> > On Tue, Dec 07, 2021 at 10:16:46AM +0000, cgel.zte@gmail.com wrote:
> > > From: Lv Ruyi <lv.ruyi@zte.com.cn>
> > > 
> > > Move the spin_lock above the restart to prevent to lock twice 
> > > when the code goto restart.
> > 
> > This is madness.
> > 
> > void d_prune_aliases(struct inode *inode)
> >         spin_lock(&inode->i_lock);
> >                         if (likely(!dentry->d_lockref.count)) {
> >                                 __dentry_kill(dentry);
> >                                 goto restart;
> > ...
> > static void __dentry_kill(struct dentry *dentry)
> >         if (dentry->d_inode)
> >                 dentry_unlink_inode(dentry);
> > ...
> > static void dentry_unlink_inode(struct dentry * dentry)
> >         spin_unlock(&inode->i_lock);
> > 
> > Did you even test this patch?
> 
> This same wrong patch has been sent several times before.  I think it's fair to
> say that this code could use a comment, e.g.:
> 
> 	/* i_lock was dropped */
> 	goto restart;

Not sure that'll do much good.  It seems to be fools running some script
that they haven't the wit to understand.

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07 10:16 [PATCH] fs/dcache: prevent repeated locking cgel.zte
2021-12-07 13:17 ` Matthew Wilcox
2021-12-07 21:25   ` Eric Biggers
2021-12-07 22:11     ` Matthew Wilcox

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).