Skip to contentSkip to conversation

f2fs: avoid the deadlock case when stopping discard thread

PATCH In review Jaegeuk Kim 4 participants 12 messages Mar 20, 2024 – Apr 16, 2024 2 messages not in the archive F2FS file system

lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/1 f2fs: avoid the deadlock case when stopping discard thread

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)
- sb_start_intwrite(SB_FREEZE_FS);
- f2fs_stop_checkpoint(sbi, false, : waiting

    STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

---
 fs/f2fs/segment.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +3 -1
index 4fd76e867e0a..088b8c48cffa 100644
@@ -1923,7 +1923,9 @@ static int issue_discard_thread(void *data)
 			continue;
 		}
 
-		sb_start_intwrite(sbi->sb);
+		/* Avoid the deadlock from F2FS_GOING_DOWN_NOSYNC. */
+		if (!sb_start_intwrite_trylock(sbi->sb))
+			continue;
 
 		issued = __issue_discard_cmd(sbi, &dpolicy);
 		if (issued > 0) {
Signature · 1 line
2.44.0.291.gc1ea87d7ee-goog
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jaegeuk Kim

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)
- sb_start_intwrite(SB_FREEZE_FS);
- f2fs_stop_checkpoint(sbi, false, : waiting

Quoted 8 lines
     STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

Thanks,

#2 lore raw
In reply to Jaegeuk Kim

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)

	 __sb_start_write()
	   percpu_down_read()
Quoted 1 line

- sb_start_intwrite(SB_FREEZE_FS);

						   __sb_start_write()
						     percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Quoted 7 lines

- f2fs_stop_checkpoint(sbi, false, : waiting

    STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

More important, feel free to add in spin.

author maintainer
#3 lore raw
Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)

	 __sb_start_write()
	   percpu_down_read()
Quoted 1 line

- sb_start_intwrite(SB_FREEZE_FS);

						   __sb_start_write()
						     percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

- f2fs_stop_checkpoint(sbi, false, : waiting

    STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

-> freeze_bdev()
-> thaw_bdev()
-> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines
#4 lore raw

On Thu, 21 Mar 2024 17:29:03 -0700 Jaegeuk Kim <[email protected]>

Quoted 2 lines

I posted this patch before Light reported.

Yeah, his report's timestamp is 2024-03-20 6:59, nearly 7 hours later, which shows that you constructed the deadlock with nothing to do with his report.

Quoted 5 lines

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

Quoted 8 lines

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

-> freeze_bdev()
-> thaw_bdev()
-> f2fs_stop_discard_thread()

Am I missing something?

Light, could you specify to help Jaegeuk understand the deadlock you reported?

A message that is not in the archive (sent off-list or not yet received): SI2PR03MB52607606AB0D29C8AB123C1484312@SI2PR03MB5260.apcprd03.prod.outlook.com

author maintainer
#6 lore raw
Quoted 1 line · Light Hsieh (謝明燈)

I don't see my added log in sb_free_unlock() which will invoke percpu_up_write to release the write semaphore.

May I ask more details whether thaw_super() was called or not?

Quoted 56 lines

________________________________
寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月22日 上午 08:29
收件者: Hillf Danton <[email protected]>
副本: [email protected] <[email protected]>; Light Hsieh (謝明燈) <[email protected]>; [email protected] <[email protected]> 主旨: Re: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)

__sb_start_write()
percpu_down_read()

Quoted 1 line

- sb_start_intwrite(SB_FREEZE_FS);

__sb_start_write()
percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

- f2fs_stop_checkpoint(sbi, false, : waiting

    STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

-> freeze_bdev()
-> thaw_bdev()
-> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines
author maintainer
#7 lore raw
Quoted 4 lines · Jaegeuk Kim
Quoted 1 line · Light Hsieh (謝明燈)

I don't see my added log in sb_free_unlock() which will invoke percpu_up_write to release the write semaphore.

May I ask more details whether thaw_super() was called or not?

Ping?

Quoted 57 lines
Quoted 57 lines

________________________________
寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月22日 上午 08:29
收件者: Hillf Danton <[email protected]>
副本: [email protected] <[email protected]>; Light Hsieh (謝明燈) <[email protected]>; [email protected] <[email protected]> 主旨: Re: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)

__sb_start_write()
percpu_down_read()

Quoted 1 line

- sb_start_intwrite(SB_FREEZE_FS);

__sb_start_write()
percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

- f2fs_stop_checkpoint(sbi, false, : waiting

    STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

-> freeze_bdev()
-> thaw_bdev()
-> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines

A message that is not in the archive (sent off-list or not yet received): SI2PR03MB526041E42B6BD9C9DA9FBAC184352@SI2PR03MB5260.apcprd03.prod.outlook.com

#9 lore raw

Our log shows that thaw_super_locked() find that sb is readonly, so sb_freeze_unlock() is not invoked.

static int thaw_super_locked(struct super_block *sb, enum freeze_holder who) {
      ...
      if (sb_rdonly(sb)) {
            sb->s_writers.freeze_holders &= ~who; sb->s_writers.frozen = SB_UNFROZEN; wake_up_var(&sb->s_writers.frozen);
            goto out;
      }
               ...
      sb_freeze_unlock(sb, SB_FREEZE_FS);
out:
      deactivate_locked_super(sb);
      return 0;
}

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月27日 上午 12:52
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 4 lines · Jaegeuk Kim
Quoted 1 line · Light Hsieh (謝明燈)

I don't see my added log in sb_free_unlock() which will invoke percpu_up_write to release the write semaphore.

May I ask more details whether thaw_super() was called or not?

Ping?

Quoted 57 lines
Quoted 57 lines

________________________________
寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月22日 上午 08:29
收件者: Hillf Danton <[email protected]>
副本: [email protected] <[email protected]>; Light Hsieh (謝明燈) <[email protected]>; [email protected] <[email protected]> 主旨: Re: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)

__sb_start_write()
percpu_down_read()

Quoted 1 line

- sb_start_intwrite(SB_FREEZE_FS);

__sb_start_write()
percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

- f2fs_stop_checkpoint(sbi, false, : waiting

    STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

-> freeze_bdev()
-> thaw_bdev()
-> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines
author maintainer
#10 lore raw
Quoted 17 lines · Light Hsieh (謝明燈)

Our log shows that thaw_super_locked() find that sb is readonly, so sb_freeze_unlock() is not invoked.

static int thaw_super_locked(struct super_block *sb, enum freeze_holder who) {
      ...
      if (sb_rdonly(sb)) {
            sb->s_writers.freeze_holders &= ~who; sb->s_writers.frozen = SB_UNFROZEN; wake_up_var(&sb->s_writers.frozen);
            goto out;
      }
               ...
      sb_freeze_unlock(sb, SB_FREEZE_FS);
out:
      deactivate_locked_super(sb);
      return 0;
}

Thank you. Could you please take a look at this patch?

https://lore.kernel.org/linux-f2fs-devel/[email protected]/T/#u

Quoted 74 lines

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月27日 上午 12:52
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 4 lines · Jaegeuk Kim
Quoted 1 line · Light Hsieh (謝明燈)

I don't see my added log in sb_free_unlock() which will invoke percpu_up_write to release the write semaphore.

May I ask more details whether thaw_super() was called or not?

Ping?

Quoted 57 lines
Quoted 57 lines

________________________________
寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月22日 上午 08:29
收件者: Hillf Danton <[email protected]>
副本: [email protected] <[email protected]>; Light Hsieh (謝明燈) <[email protected]>; [email protected] <[email protected]> 主旨: Re: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC) issue_discard_thread
- mnt_want_write_file()
- sb_start_write(SB_FREEZE_WRITE)

__sb_start_write()
percpu_down_read()

Quoted 1 line

- sb_start_intwrite(SB_FREEZE_FS);

__sb_start_write()
percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

- f2fs_stop_checkpoint(sbi, false, : waiting

    STOP_CP_REASON_SHUTDOWN);

- f2fs_stop_discard_thread(sbi);
- kthread_stop()
: waiting

- mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

-> freeze_bdev()
-> thaw_bdev()
-> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines
#11 lore raw

I think 'readon' in this line may be typo of 'reason'

+ f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年4月5日 上午 03:55
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

Quoted 17 lines · Light Hsieh (謝明燈)

Our log shows that thaw_super_locked() find that sb is readonly, so sb_freeze_unlock() is not invoked.

static int thaw_super_locked(struct super_block *sb, enum freeze_holder who) {
      ...
      if (sb_rdonly(sb)) {
            sb->s_writers.freeze_holders &= ~who; sb->s_writers.frozen = SB_UNFROZEN; wake_up_var(&sb->s_writers.frozen);
            goto out;
      }
               ...
      sb_freeze_unlock(sb, SB_FREEZE_FS);
out:
      deactivate_locked_super(sb);
      return 0;
}

Thank you. Could you please take a look at this patch?

https://lore.kernel.org/linux-f2fs-devel/[email protected]/T/#u

Quoted 74 lines

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月27日 上午 12:52
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 4 lines · Jaegeuk Kim
Quoted 1 line · Light Hsieh (謝明燈)

I don't see my added log in sb_free_unlock() which will invoke percpu_up_write to release the write semaphore.

May I ask more details whether thaw_super() was called or not?

Ping?

Quoted 57 lines
Quoted 57 lines

________________________________
寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月22日 上午 08:29
收件者: Hillf Danton <[email protected]>
副本: [email protected] <[email protected]>; Light Hsieh (謝明燈) <[email protected]>; [email protected] <[email protected]> 主旨: Re: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC)  issue_discard_thread
 - mnt_want_write_file()
   - sb_start_write(SB_FREEZE_WRITE)

 __sb_start_write()
   percpu_down_read()

Quoted 1 line

                                             - sb_start_intwrite(SB_FREEZE_FS);

   __sb_start_write()
     percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

 - f2fs_stop_checkpoint(sbi, false,            : waiting STOP_CP_REASON_SHUTDOWN);
 - f2fs_stop_discard_thread(sbi);
   - kthread_stop()
     : waiting

 - mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

 -> freeze_bdev()
 -> thaw_bdev()
 -> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines
author maintainer
#12 lore raw
Quoted 1 line · Light Hsieh (謝明燈)

I think 'readon' in this line may be typo of 'reason'

Was fixed as well. Thanks.

Quoted 109 lines
(quoted diff) +1 -0
+		f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年4月5日 上午 03:55
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

Quoted 17 lines · Light Hsieh (謝明燈)

Our log shows that thaw_super_locked() find that sb is readonly, so sb_freeze_unlock() is not invoked.

static int thaw_super_locked(struct super_block *sb, enum freeze_holder who) {
      ...
      if (sb_rdonly(sb)) {
            sb->s_writers.freeze_holders &= ~who; sb->s_writers.frozen = SB_UNFROZEN; wake_up_var(&sb->s_writers.frozen);
            goto out;
      }
               ...
      sb_freeze_unlock(sb, SB_FREEZE_FS);
out:
      deactivate_locked_super(sb);
      return 0;
}

Thank you. Could you please take a look at this patch?

https://lore.kernel.org/linux-f2fs-devel/[email protected]/T/#u

Quoted 74 lines

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月27日 上午 12:52
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 4 lines · Jaegeuk Kim
Quoted 1 line · Light Hsieh (謝明燈)

I don't see my added log in sb_free_unlock() which will invoke percpu_up_write to release the write semaphore.

May I ask more details whether thaw_super() was called or not?

Ping?

Quoted 57 lines
Quoted 57 lines

________________________________
寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月22日 上午 08:29
收件者: Hillf Danton <[email protected]>
副本: [email protected] <[email protected]>; Light Hsieh (謝明燈) <[email protected]>; [email protected] <[email protected]> 主旨: Re: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC)  issue_discard_thread
 - mnt_want_write_file()
   - sb_start_write(SB_FREEZE_WRITE)

 __sb_start_write()
   percpu_down_read()

Quoted 1 line

                                             - sb_start_intwrite(SB_FREEZE_FS);

   __sb_start_write()
     percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

 - f2fs_stop_checkpoint(sbi, false,            : waiting STOP_CP_REASON_SHUTDOWN);
 - f2fs_stop_discard_thread(sbi);
   - kthread_stop()
     : waiting

 - mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

 -> freeze_bdev()
 -> thaw_bdev()
 -> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines
#13 lore raw
Quoted 1 line
Quoted 1 line

https://lore.kernel.org/linux-f2fs-devel/[email protected]/T/#u

With provided patch, issue does not occur during 60hours test.

Please help merge this patch into ACK also.

Light

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年4月13日 上午 04:50
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: 回覆: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

Quoted 1 line · Light Hsieh (謝明燈)

I think 'readon' in this line may be typo of  'reason'

Was fixed as well. Thanks.

Quoted 109 lines

+f2fs_warn(sbi, "Stopped filesystem due to readon: %d", reason);

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年4月5日 上午 03:55
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

Quoted 17 lines · Light Hsieh (謝明燈)

Our log shows that thaw_super_locked() find that sb is readonly, so sb_freeze_unlock() is not invoked.

static int thaw_super_locked(struct super_block *sb, enum freeze_holder who) {
      ...
      if (sb_rdonly(sb)) {
            sb->s_writers.freeze_holders &= ~who; sb->s_writers.frozen = SB_UNFROZEN; wake_up_var(&sb->s_writers.frozen);
            goto out;
      }
               ...
      sb_freeze_unlock(sb, SB_FREEZE_FS);
out:
      deactivate_locked_super(sb);
      return 0;
}

Thank you. Could you please take a look at this patch?

https://lore.kernel.org/linux-f2fs-devel/[email protected]/T/#u

Quoted 74 lines

寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月27日 上午 12:52
收件者: Light Hsieh (謝明燈) <[email protected]>
副本: Hillf Danton <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]> 主旨: Re: 回覆: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 4 lines · Jaegeuk Kim
Quoted 1 line · Light Hsieh (謝明燈)

I don't see my added log in sb_free_unlock() which will invoke percpu_up_write to release the write semaphore.

May I ask more details whether thaw_super() was called or not?

Ping?

Quoted 57 lines
Quoted 57 lines

________________________________
寄件者: Jaegeuk Kim <[email protected]>
寄件日期: 2024年3月22日 上午 08:29
收件者: Hillf Danton <[email protected]>
副本: [email protected] <[email protected]>; Light Hsieh (謝明燈) <[email protected]>; [email protected] <[email protected]> 主旨: Re: [PATCH] f2fs: avoid the deadlock case when stopping discard thread

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 11 lines · Hillf Danton

On Tue, 19 Mar 2024 17:14:42 -0700 Jaegeuk Kim <[email protected]>

Quoted 3 lines

f2fs_ioc_shutdown(F2FS_GOING_DOWN_NOSYNC)  issue_discard_thread
 - mnt_want_write_file()
   - sb_start_write(SB_FREEZE_WRITE)

 __sb_start_write()
   percpu_down_read()

Quoted 1 line

                                             - sb_start_intwrite(SB_FREEZE_FS);

   __sb_start_write()
     percpu_down_read()

Given lock acquirers for read on both sides, wtf deadlock are you fixing?

Damn. I couldn't think _write uses _read sem.

Quoted 10 lines
Quoted 8 lines

 - f2fs_stop_checkpoint(sbi, false,            : waiting STOP_CP_REASON_SHUTDOWN);
 - f2fs_stop_discard_thread(sbi);
   - kthread_stop()
     : waiting

 - mnt_drop_write_file(filp);

More important, feel free to add in spin.

I posted this patch before Light reported.

And, in the report, I didn't get this:

f2fs_ioc_shutdown() --> freeze_bdev() --> freeze_super() --> sb_wait_write(sb, SB_FREEZE_FS) --> ... ->percpu_down_write().

because f2fs_ioc_shutdown() calls f2fs_stop_discard_thread() after thaw_bdev() like this order.

 -> freeze_bdev()
 -> thaw_bdev()
 -> f2fs_stop_discard_thread()

Am I missing something?

Quoted 2 lines