linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext2: do not sleep in ext2_error()
@ 2021-09-03  9:05 Dan Carpenter
  2021-09-03 12:48 ` Theodore Ts'o
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-09-03  9:05 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, linux-kernel, kernel-janitors

No one expects error logging functions to sleep so sometimes they are
called with spinlocks held.  In this case the problematic call tree is:

ext2_statfs() <- disables preempt
-> ext2_count_free_inodes()
   -> ext2_get_group_desc()
      -> ext2_error()

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This is just from static analysis.  NOT TESTED!

Probably a safer fix would be to just call pr_err() instead of
ext2_error() in ext2_get_group_desc().  I can send that fix instead if
people want.

 fs/ext2/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index d8d580b609ba..ba345ab860f0 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -59,7 +59,7 @@ void ext2_error(struct super_block *sb, const char *function,
 		sbi->s_mount_state |= EXT2_ERROR_FS;
 		es->s_state |= cpu_to_le16(EXT2_ERROR_FS);
 		spin_unlock(&sbi->s_lock);
-		ext2_sync_super(sb, es, 1);
+		ext2_sync_super(sb, es, 0);
 	}
 
 	va_start(args, fmt);
-- 
2.20.1


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

* Re: [PATCH] ext2: do not sleep in ext2_error()
  2021-09-03  9:05 [PATCH] ext2: do not sleep in ext2_error() Dan Carpenter
@ 2021-09-03 12:48 ` Theodore Ts'o
  2021-09-03 13:09   ` Dan Carpenter
  2021-09-16  9:48   ` Jan Kara
  0 siblings, 2 replies; 4+ messages in thread
From: Theodore Ts'o @ 2021-09-03 12:48 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Jan Kara, linux-ext4, linux-kernel, kernel-janitors

On Fri, Sep 03, 2021 at 12:05:38PM +0300, Dan Carpenter wrote:
> No one expects error logging functions to sleep so sometimes they are
> called with spinlocks held.  In this case the problematic call tree is:
> 
> ext2_statfs() <- disables preempt
> -> ext2_count_free_inodes()
>    -> ext2_get_group_desc()
>       -> ext2_error()
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> This is just from static analysis.  NOT TESTED!
> 
> Probably a safer fix would be to just call pr_err() instead of
> ext2_error() in ext2_get_group_desc().  I can send that fix instead if
> people want.

Looking at both of the ext2_error() calls in ext2_get_group_desc(),
those are really more in the way of assertions rather than warning of
an on-disk corruption issue.  The second "group descriptor not loaded"
should never happen, and the "block_group >= groups_count" should have
been caught via an invalid block number or check by the caller (or an
outright code bug in say ext2_statfs().

So I suspect both of those would be more usefule as a WARN() rather
than a call to ext2_error(), since stack trace would actually provide
more useful data to root causing the issue.  Jan, what do you think?

     	    	    	 	 - Ted

P.S.  The same analysis applies for ext4_get_group_desc(), BTW.  We
don't take a lock in ext4_statfs() so trying to take a lock while
sleeping is not an issue.

For both ext2 and ext4, the caller is not supposed to holding spin
locks when it calls ext[24]_error().  In cases where it is absolutely
not avoidable, special measures are required --- see for example
__ext4_grp_locked_error().

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

* Re: [PATCH] ext2: do not sleep in ext2_error()
  2021-09-03 12:48 ` Theodore Ts'o
@ 2021-09-03 13:09   ` Dan Carpenter
  2021-09-16  9:48   ` Jan Kara
  1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-09-03 13:09 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: Jan Kara, linux-ext4, linux-kernel, kernel-janitors

On Fri, Sep 03, 2021 at 08:48:38AM -0400, Theodore Ts'o wrote:
> On Fri, Sep 03, 2021 at 12:05:38PM +0300, Dan Carpenter wrote:
> > No one expects error logging functions to sleep so sometimes they are
> > called with spinlocks held.  In this case the problematic call tree is:
> > 
> > ext2_statfs() <- disables preempt
> > -> ext2_count_free_inodes()
> >    -> ext2_get_group_desc()
> >       -> ext2_error()
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > This is just from static analysis.  NOT TESTED!
> > 
> > Probably a safer fix would be to just call pr_err() instead of
> > ext2_error() in ext2_get_group_desc().  I can send that fix instead if
> > people want.
> 
> Looking at both of the ext2_error() calls in ext2_get_group_desc(),
> those are really more in the way of assertions rather than warning of
> an on-disk corruption issue.  The second "group descriptor not loaded"
> should never happen, and the "block_group >= groups_count" should have
> been caught via an invalid block number or check by the caller (or an
> outright code bug in say ext2_statfs().
> 
> So I suspect both of those would be more usefule as a WARN() rather
> than a call to ext2_error(), since stack trace would actually provide
> more useful data to root causing the issue.  Jan, what do you think?
> 
>      	    	    	 	 - Ted

Thanks Ted,

I'll resend with the WARN() change.

regards,
dan carpenter


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

* Re: [PATCH] ext2: do not sleep in ext2_error()
  2021-09-03 12:48 ` Theodore Ts'o
  2021-09-03 13:09   ` Dan Carpenter
@ 2021-09-16  9:48   ` Jan Kara
  1 sibling, 0 replies; 4+ messages in thread
From: Jan Kara @ 2021-09-16  9:48 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: Dan Carpenter, Jan Kara, linux-ext4, linux-kernel, kernel-janitors

On Fri 03-09-21 08:48:38, Theodore Ts'o wrote:
> On Fri, Sep 03, 2021 at 12:05:38PM +0300, Dan Carpenter wrote:
> > No one expects error logging functions to sleep so sometimes they are
> > called with spinlocks held.  In this case the problematic call tree is:
> > 
> > ext2_statfs() <- disables preempt
> > -> ext2_count_free_inodes()
> >    -> ext2_get_group_desc()
> >       -> ext2_error()
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > This is just from static analysis.  NOT TESTED!
> > 
> > Probably a safer fix would be to just call pr_err() instead of
> > ext2_error() in ext2_get_group_desc().  I can send that fix instead if
> > people want.
> 
> Looking at both of the ext2_error() calls in ext2_get_group_desc(),
> those are really more in the way of assertions rather than warning of
> an on-disk corruption issue.  The second "group descriptor not loaded"
> should never happen, and the "block_group >= groups_count" should have
> been caught via an invalid block number or check by the caller (or an
> outright code bug in say ext2_statfs().
> 
> So I suspect both of those would be more usefule as a WARN() rather
> than a call to ext2_error(), since stack trace would actually provide
> more useful data to root causing the issue.  Jan, what do you think?

Yes, I agree. Definitely better than not flushing error on other
ext2_error() calls. BTW, Dan, I don't see a patch with WARN() in my inbox.
Did it get lost somewhere?

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2021-09-16  9:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03  9:05 [PATCH] ext2: do not sleep in ext2_error() Dan Carpenter
2021-09-03 12:48 ` Theodore Ts'o
2021-09-03 13:09   ` Dan Carpenter
2021-09-16  9:48   ` Jan Kara

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