On 2023/01/02 10:40, Linus Torvalds wrote: > So I think that we have: > > - ntfs_truncate() gets the ni_lock (fs/ntfs3/file.c:393) > > - it then - while holding that lock - calls (on line 395): > > truncate_setsize -> > truncate_pagecache -> > truncate_inode_pages -> > truncate_inode_pages_range -> > folio_lock > > but that deadlocks on another process that wants to read that page, > and that needs ni_lock to do so. > > So yes, it does look like a ntfs3 deadlock involving ni_lock. Yes, I think you are right. My patch confirmed that other threads are not holding ni_lock lock, which means that this is a deadlock between PG_locked bit and ni_lock lock. filemap_update_page() calls filemap_read_folio() after calling folio_trylock(). Since folio_trylock() sets PG_locked bit, mutex_lock_nested+0x17/0x20 kernel/locking/mutex.c:799 ni_lock fs/ntfs3/ntfs_fs.h:1122 [inline] attr_data_get_block+0x4a6/0x2e40 fs/ntfs3/attrib.c:919 ntfs_get_block_vbo+0x374/0xd20 fs/ntfs3/inode.c:573 do_mpage_readpage+0x98b/0x1bb0 fs/mpage.c:208 mpage_read_folio+0x103/0x1d0 fs/mpage.c:379 filemap_read_folio+0x1ba/0x7f0 mm/filemap.c:2426 filemap_update_page+0x3ca/0x550 mm/filemap.c:2511 filemap_get_pages+0x8d8/0x1110 mm/filemap.c:2624 filemap_read+0x3e7/0xee0 mm/filemap.c:2694 is trying to take ni_lock after setting PG_locked bit. On the other hand, folio_lock() waits until PG_locked bit is cleared, but unfortunately ntfs3_setattr() already took ni_lock before calling folio_lock(). io_schedule+0x83/0x100 kernel/sched/core.c:8811 folio_wait_bit_common+0x8ca/0x1390 mm/filemap.c:1297 folio_lock include/linux/pagemap.h:938 [inline] truncate_inode_pages_range+0xc8d/0x1650 mm/truncate.c:421 truncate_inode_pages mm/truncate.c:448 [inline] truncate_pagecache mm/truncate.c:743 [inline] truncate_setsize+0xcb/0xf0 mm/truncate.c:768 ntfs_truncate fs/ntfs3/file.c:395 [inline] ntfs3_setattr+0x5a5/0xca0 fs/ntfs3/file.c:696 Since no lockdep annotation is used for e.g. PG_locked bit, this deadlock cannot be detected by lockdep...