Re: [PATCH 08/32] mm/khugepaged: flush file after unlocking folios in collapse_file()
From: Baolin Wang
Date: Wed Dec 02 2026 - 04:13:44 EST
On 11/29/26 6:06 PM, David Hildenbrand (Arm) wrote:
From: Chris Mason <mason@xxxxxxxxxx>
collapse_file() calls filemap_flush() when it encounters a dirty folio in
a file that is not open for writing. At that point, source folios earlier
in the range are still locked. The writable-open check is racy: a writer
can open the file after the check.
On ext4, the flush may need a journal handle, while EXT4_IOC_MOVE_EXT
takes a journal handle before locking folios, and a journal commit blocks
new handles while waiting for existing handles to be released.
Consequently, we can deadlock: collapse_file() waits for a handle, the
commit waits for extent movement to finish, and extent movement waits for
a source folio lock.
Let's fix it by deferring filemap_flush() until rollback has unlocked all
source folios.
This has medium urgency, as it can deadlock ext4 in some scenarios.
Fixes: 75f360696ce9 ("mm/thp: flush file for !is_shmem PageDirty() case in collapse_file()")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
[ david: rework code; simplify comments and description ]
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
LGTM.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>