Re: [syzbot] [nilfs?] possible deadlock in nilfs_dirty_inode (4)

From: Edward Adam Davis
Date: Sat Oct 19 2024 - 23:42:26 EST


make sure all allocations with GFP_NOFS

#syz test

diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
index be6acf6e2bfc..183c16ad8776 100644
--- a/fs/nilfs2/inode.c
+++ b/fs/nilfs2/inode.c
@@ -252,11 +252,14 @@ static int nilfs_write_begin(struct file *file, struct address_space *mapping,
{
struct inode *inode = mapping->host;
int err = nilfs_transaction_begin(inode->i_sb, NULL, 1);
+ unsigned flags;

if (unlikely(err))
return err;

+ flags = memalloc_nofs_save();
err = block_write_begin(mapping, pos, len, foliop, nilfs_get_block);
+ memalloc_nofs_restore(flags);
if (unlikely(err)) {
nilfs_write_failed(mapping, pos + len);
nilfs_transaction_abort(inode->i_sb);