From: Eric Biggers <ebiggers@kernel.org>
To: linux-xfs@vger.kernel.org
Cc: linux-ext4@vger.kernel.org, syzkaller-bugs@googlegroups.com,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] xfs: clear PF_MEMALLOC before exiting xfsaild thread
Date: Sun, 8 Mar 2020 21:34:30 -0700 [thread overview]
Message-ID: <20200309043430.143206-1-ebiggers@kernel.org> (raw)
In-Reply-To: <20200309010410.GA371527@sol.localdomain>
From: Eric Biggers <ebiggers@google.com>
Leaving PF_MEMALLOC set when exiting a kthread causes it to remain set
during do_exit(). That can confuse things. For example, if BSD process
accounting is enabled and the accounting file has FS_SYNC_FL set and is
located on an ext4 filesystem without a journal, then do_exit() ends up
calling ext4_write_inode(). That triggers the
WARN_ON_ONCE(current->flags & PF_MEMALLOC) there, as it assumes
(appropriately) that inodes aren't written when allocating memory.
Fix this in xfsaild() by using the helper functions to save and restore
PF_MEMALLOC.
This can be reproduced as follows in the kvm-xfstests test appliance
modified to add the 'acct' Debian package, and with kvm-xfstests's
recommended kconfig modified to add CONFIG_BSD_PROCESS_ACCT=y:
mkfs.ext2 -F /dev/vdb
mount /vdb -t ext4
touch /vdb/file
chattr +S /vdb/file
accton /vdb/file
mkfs.xfs -f /dev/vdc
mount /vdc
umount /vdc
It causes:
WARNING: CPU: 0 PID: 332 at fs/ext4/inode.c:5097 ext4_write_inode+0x140/0x1a0
CPU: 0 PID: 332 Comm: xfsaild/vdc Not tainted 5.6.0-rc5 #5
[...]
RIP: 0010:ext4_write_inode+0x140/0x1a0 fs/ext4/inode.c:5097
[...]
Call Trace:
write_inode fs/fs-writeback.c:1312 [inline]
__writeback_single_inode+0x465/0x5f0 fs/fs-writeback.c:1511
writeback_single_inode+0xad/0x120 fs/fs-writeback.c:1565
sync_inode fs/fs-writeback.c:2602 [inline]
sync_inode_metadata+0x3d/0x57 fs/fs-writeback.c:2622
ext4_fsync_nojournal fs/ext4/fsync.c:94 [inline]
ext4_sync_file+0x243/0x4b0 fs/ext4/fsync.c:172
generic_write_sync include/linux/fs.h:2867 [inline]
ext4_buffered_write_iter+0xe1/0x130 fs/ext4/file.c:277
call_write_iter include/linux/fs.h:1901 [inline]
new_sync_write+0x130/0x1d0 fs/read_write.c:483
__kernel_write+0x54/0xe0 fs/read_write.c:515
do_acct_process+0x122/0x170 kernel/acct.c:522
slow_acct_process kernel/acct.c:581 [inline]
acct_process+0x1d4/0x27c kernel/acct.c:607
do_exit+0x83d/0xbc0 kernel/exit.c:791
kthread+0xf1/0x140 kernel/kthread.c:257
ret_from_fork+0x27/0x50 arch/x86/entry/entry_64.S:352
This case was originally reported by syzbot at
https://lore.kernel.org/r/0000000000000e7156059f751d7b@google.com.
Reported-by: syzbot+1f9dc49e8de2582d90c2@syzkaller.appspotmail.com
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
v2: include more details in the commit message.
fs/xfs/xfs_trans_ail.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/xfs/xfs_trans_ail.c b/fs/xfs/xfs_trans_ail.c
index 00cc5b8734be8..3bc570c90ad97 100644
--- a/fs/xfs/xfs_trans_ail.c
+++ b/fs/xfs/xfs_trans_ail.c
@@ -529,8 +529,9 @@ xfsaild(
{
struct xfs_ail *ailp = data;
long tout = 0; /* milliseconds */
+ unsigned int noreclaim_flag;
- current->flags |= PF_MEMALLOC;
+ noreclaim_flag = memalloc_noreclaim_save();
set_freezable();
while (1) {
@@ -601,6 +602,7 @@ xfsaild(
tout = xfsaild_push(ailp);
}
+ memalloc_noreclaim_restore(noreclaim_flag);
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2020-03-09 4:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-26 6:57 WARNING in ext4_write_inode syzbot
2020-03-08 4:35 ` [PATCH] xfs: clear PF_MEMALLOC before exiting xfsaild thread Eric Biggers
2020-03-08 23:03 ` Dave Chinner
2020-03-09 1:04 ` Eric Biggers
2020-03-09 4:34 ` Eric Biggers [this message]
2020-03-09 10:57 ` [PATCH v2] " Brian Foster
2020-03-09 16:24 ` Darrick J. Wong
2020-03-09 18:04 ` Eric Biggers
2020-03-09 18:13 ` Darrick J. Wong
2020-03-09 18:57 ` [PATCH v3] " Eric Biggers
2020-03-10 15:47 ` Darrick J. Wong
2020-03-11 6:34 ` Christoph Hellwig
2020-03-12 22:20 ` [PATCH v2] " Eric Biggers
2020-03-08 4:36 ` [PATCH] cifs: clear PF_MEMALLOC before exiting demultiplex thread Eric Biggers
2020-03-08 6:16 ` [PATCH v2] " Eric Biggers
2020-03-08 18:43 ` Steve French
2020-03-09 5:56 ` Eric Biggers
2020-03-09 5:58 ` [PATCH v3] " Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200309043430.143206-1-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).