Ryusuke Konishi a4ca369ca2 nilfs2: fix potential kernel bug due to lack of writeback flag waiting
Destructive writes to a block device on which nilfs2 is mounted can cause
a kernel bug in the folio/page writeback start routine or writeback end
routine (__folio_start_writeback in the log below):

 kernel BUG at mm/page-writeback.c:3070!
 Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI
 ...
 RIP: 0010:__folio_start_writeback+0xbaa/0x10e0
 Code: 25 ff 0f 00 00 0f 84 18 01 00 00 e8 40 ca c6 ff e9 17 f6 ff ff
  e8 36 ca c6 ff 4c 89 f7 48 c7 c6 80 c0 12 84 e8 e7 b3 0f 00 90 <0f>
  0b e8 1f ca c6 ff 4c 89 f7 48 c7 c6 a0 c6 12 84 e8 d0 b3 0f 00
 ...
 Call Trace:
  <TASK>
  nilfs_segctor_do_construct+0x4654/0x69d0 [nilfs2]
  nilfs_segctor_construct+0x181/0x6b0 [nilfs2]
  nilfs_segctor_thread+0x548/0x11c0 [nilfs2]
  kthread+0x2f0/0x390
  ret_from_fork+0x4b/0x80
  ret_from_fork_asm+0x1a/0x30
  </TASK>

This is because when the log writer starts a writeback for segment summary
blocks or a super root block that use the backing device's page cache, it
does not wait for the ongoing folio/page writeback, resulting in an
inconsistent writeback state.

Fix this issue by waiting for ongoing writebacks when putting
folios/pages on the backing device into writeback state.

Link: https://lkml.kernel.org/r/20240530141556.4411-1-konishi.ryusuke@gmail.com
Fixes: 9ff05123e3bf ("nilfs2: segment constructor")
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Tested-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-06-05 19:19:24 -07:00
..
2024-05-01 18:07:38 +01:00
2024-05-13 12:14:03 -07:00
2024-01-11 20:11:35 -08:00
2024-05-24 09:07:22 -07:00
2024-05-24 09:40:31 -07:00
2024-05-13 14:14:05 -07:00
2024-05-24 09:31:50 -07:00
2024-05-21 09:51:42 -07:00
2024-05-20 13:23:43 -07:00
2024-05-23 12:04:36 -07:00
2024-05-21 09:51:42 -07:00
2023-12-29 11:58:34 -08:00
2024-05-18 12:39:20 -07:00
2024-05-21 09:51:42 -07:00
2024-03-27 13:17:15 +01:00
2024-05-23 13:51:09 -07:00
2024-05-25 14:19:01 -07:00
2024-05-22 09:23:18 -07:00
2024-03-27 13:17:15 +01:00
2024-04-23 13:27:43 +02:00
2024-04-23 15:37:02 +02:00
2024-03-12 20:03:34 -07:00
2024-05-02 20:35:57 +02:00
2023-10-30 19:28:19 -10:00
2024-05-21 09:51:42 -07:00
2024-05-23 12:04:36 -07:00
2024-04-25 20:56:20 -07:00
2024-05-10 08:26:31 +02:00
2024-03-12 20:03:34 -07:00
2024-03-15 09:00:09 -07:00
2024-05-02 20:35:57 +02:00
2024-04-17 13:49:44 +02:00
2024-03-11 10:21:06 -07:00
2024-05-22 09:23:18 -07:00
2024-03-13 12:53:53 -07:00
2024-04-15 16:03:25 -04:00
2024-02-02 13:11:49 +01:00
2024-03-12 20:03:34 -07:00
2024-05-02 16:28:20 +02:00
2024-04-10 16:23:04 -06:00
2024-03-26 09:01:18 +01:00
\n
2024-05-20 12:31:43 -07:00
2024-04-10 16:23:02 -06:00
2024-02-15 23:43:47 -05:00