Skip to contentSkip to conversation

block: avoild hang when bio_list is non-NULL in submit_bio_wait()

PATCH In review Jiucheng Xu 3 participants 8 messages Mar 2 – Mar 3 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: avoild hang when bio_list is non-NULL in submit_bio_wait()

When current->bio_list is non-NULL in submit_bio_wait(), submit_bio_noacct_nocheck appends bio to bio_list but skips IO submission, causing submit_bio_wait() to hang indefinitely.

Fix this by temporarily backup bio_list, setting bio_list to NULL before calling submit_bio(), then restoring bio_list after submit_bio() returns.

I've trimmed down the call stack, as follows:

f2fs_submit_read_io
submit_bio
mmc_blk_mq_recovery
z_erofs_endio
vm_map_ram
__pte_alloc_kernel
__alloc_pages_direct_reclaim
shrink_folio_list
__swap_writepage
submit_bio_wait hang!!!

---
 block/bio.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
block/bio.c +11 -2
index d80d5d26804e32944bcfe4506ca190033308844f..22c8769722cc89620c239310a0f3d4924de68cf9 100644
@@ -1505,8 +1505,17 @@ int submit_bio_wait(struct bio *bio)
 	bio->bi_private = &done;
 	bio->bi_end_io = submit_bio_wait_endio;
 	bio->bi_opf |= REQ_SYNC;
-	submit_bio(bio);
-	blk_wait_io(&done);
+	if (!current->bio_list) {
+		submit_bio(bio);
+		blk_wait_io(&done);
+	} else {
+		struct bio_list *tmp = current->bio_list;
+
+		current->bio_list = NULL;
+		submit_bio(bio);
+		blk_wait_io(&done);
+		current->bio_list = tmp;
+	}
 
 	return blk_status_to_errno(bio->bi_status);
 }

---
base-commit: 8c5f40a3ba43ae9a26991f0e4a01a3a06e8958fc
change-id: 20260224-for-next-df6f02c3694d

Best regards,

Signature · 1 line
Jiucheng Xu <[email protected]>
#1 lore raw
Quoted 9 lines · On Mon, Mar 02, 2026 at 10:51:03AM +0800, Jiucheng Xu via B4 Relay wrote:

From: Jiucheng Xu <[email protected]>

When current->bio_list is non-NULL in submit_bio_wait(), submit_bio_noacct_nocheck appends bio to bio_list but skips IO submission, causing submit_bio_wait() to hang indefinitely.

Fix this by temporarily backup bio_list, setting bio_list to NULL before calling submit_bio(), then restoring bio_list after submit_bio() returns.

No. Fix this by not doing something that is a bad idea.

Quoted 7 lines

I've trimmed down the call stack, as follows:

f2fs_submit_read_io
submit_bio
mmc_blk_mq_recovery
z_erofs_endio
vm_map_ram

->bi_end_io code really should not be having random in_atomic() checks that make it completely different, but even if they have that need to use GFP_NOIO.

#2 lore raw

Hi Christoph,

Quoted 15 lines · Christoph Hellwig
Quoted 9 lines · On Mon, Mar 02, 2026 at 10:51:03AM +0800, Jiucheng Xu via B4 Relay wrote:

From: Jiucheng Xu <[email protected]>

When current->bio_list is non-NULL in submit_bio_wait(), submit_bio_noacct_nocheck appends bio to bio_list but skips IO submission, causing submit_bio_wait() to hang indefinitely.

Fix this by temporarily backup bio_list, setting bio_list to NULL before calling submit_bio(), then restoring bio_list after submit_bio() returns.

No. Fix this by not doing something that is a bad idea.

Quoted 2 lines

I've trimmed down the call stack, as follows:

Quoted 8 lines
Quoted 5 lines

f2fs_submit_read_io
submit_bio
mmc_blk_mq_recovery
z_erofs_endio
vm_map_ram

->bi_end_io code really should not be having random in_atomic() checks that make it completely different, but even if they have

Thanks for the head-up.

For this part, I'm pretty sure we need this particular one otherwise the scheduling performance (latency sensitive) is unacceptable for all Android phone users.

Quoted 1 line

that need to use GFP_NOIO.

Yes, it should make vm_map_ram() in the end_io path use GFP_NOIO instead.

Jiucheng, could you add memalloc_noio_{save,restore}() to wrap up this path?

Thanks,
Gao Xiang

#3 lore raw
Quoted 8 lines · Gao Xiang
Quoted 8 lines
Quoted 7 lines

I've trimmed down the call stack, as follows:

f2fs_submit_read_io
submit_bio
mmc_blk_mq_recovery
z_erofs_endio
vm_map_ram

Quoted 8 lines
Quoted 2 lines

->bi_end_io code really should not be having random in_atomic() checks that make it completely different, but even if they have

Thanks for the head-up.

For this part, I'm pretty sure we need this particular one otherwise the scheduling performance (latency sensitive) is unacceptable for all Android phone users.

Where do you regularly get user context calls to ->bi_end_io?

#4 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Gao Xiang
Quoted 10 lines
Quoted 7 lines

I've trimmed down the call stack, as follows:

f2fs_submit_read_io
submit_bio
mmc_blk_mq_recovery
z_erofs_endio
vm_map_ram

->bi_end_io code really should not be having random in_atomic() checks that make it completely different, but even if they have

Quoted 7 lines
Quoted 5 lines

Thanks for the head-up.

For this part, I'm pretty sure we need this particular one otherwise the scheduling performance (latency sensitive) is unacceptable for all Android phone users.

Where do you regularly get user context calls to ->bi_end_io?

The obvious one is that dm-verity, it's actually in the workqueue context.

Thanks,
Gao Xiang

#5 lore raw
In reply to Gao Xiang
Quoted 37 lines · Gao Xiang

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https:// aka.ms/LearnAboutSenderIdentification ]

[ EXTERNAL EMAIL ]

Hi Christoph,

Quoted 15 lines · Christoph Hellwig
Quoted 9 lines · On Mon, Mar 02, 2026 at 10:51:03AM +0800, Jiucheng Xu via B4 Relay wrote:

From: Jiucheng Xu <[email protected]>

When current->bio_list is non-NULL in submit_bio_wait(), submit_bio_noacct_nocheck appends bio to bio_list but skips IO submission, causing submit_bio_wait() to hang indefinitely.

Fix this by temporarily backup bio_list, setting bio_list to NULL before calling submit_bio(), then restoring bio_list after submit_bio() returns.

No.  Fix this by not doing something that is a bad idea.

Quoted 2 lines

I've trimmed down the call stack, as follows:

Quoted 8 lines
Quoted 5 lines

f2fs_submit_read_io
   submit_bio
     mmc_blk_mq_recovery
       z_erofs_endio
         vm_map_ram

->bi_end_io code really should not be having random in_atomic() checks that make it completely different, but even if they have

Thanks for the head-up.

For this part, I'm pretty sure we need this particular one otherwise the scheduling performance (latency sensitive) is unacceptable for all Android phone users.

Quoted 7 lines
Quoted 1 line

that need to use GFP_NOIO.

Yes, it should make vm_map_ram() in the end_io path use GFP_NOIO instead.

Jiucheng, could you add memalloc_noio_{save,restore}() to wrap up this path?

Thanks for Christoph's and Xiang's comments, I will try it. Thanks!

Best Regards,
Jiucheng

#6 lore raw
Quoted 2 lines · Jiucheng Xu

...

Quoted 10 lines
Quoted 8 lines
Quoted 2 lines

that need to use GFP_NOIO.

Yes, it should make vm_map_ram() in the end_io path use GFP_NOIO instead.

Jiucheng, could you add memalloc_noio_{save,restore}() to wrap up this path?

Thanks for Christoph's and Xiang's comments, I will try it. Thanks!

Just one more note: just wrap up z_erofs_decompressqueue_work() in z_erofs_decompress_kickoff() with memalloc_noio_{save,restore}() is enough.

...
memalloc_noio_save()
z_erofs_decompressqueue_work()
memalloc_noio_restore()

Quoted 3 lines

Best Regards,
Jiucheng

#7 lore raw
Quoted 21 lines · Gao Xiang

[Some people who received this message don't often get email from [email protected]. Learn why this is important at https:// aka.ms/LearnAboutSenderIdentification ]

[ EXTERNAL EMAIL ]

Quoted 2 lines · Jiucheng Xu

...

Quoted 10 lines
Quoted 8 lines
Quoted 2 lines

that need to use GFP_NOIO.

Yes, it should make vm_map_ram() in the end_io path use GFP_NOIO instead.

Jiucheng, could you add memalloc_noio_{save,restore}() to wrap up this path?

Thanks for Christoph's and Xiang's comments, I will try it. Thanks!

Quoted 8 lines

Just one more note: just wrap up z_erofs_decompressqueue_work() in z_erofs_decompress_kickoff() with memalloc_noio_{save,restore}() is enough.

 ...
 memalloc_noio_save()
 z_erofs_decompressqueue_work()
 memalloc_noio_restore()

Got it, thanks for the details!