Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2334669ybh; Mon, 9 Mar 2020 03:57:59 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsJktzQ4QBoSuY/blhMWeME4TRPXUB25NgM7BPI0Llvqb389FWxcYScZZJbSIMnYMmx1TDc X-Received: by 2002:a9d:4b15:: with SMTP id q21mr3872293otf.84.1583751479355; Mon, 09 Mar 2020 03:57:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583751479; cv=none; d=google.com; s=arc-20160816; b=zhY+yv8RuNKVIKFSp7wfnNhWriiMN+jMR7vpva/bw25WEnQtg89PLIixZFwSq5vcc1 rVXnsO65ibEV+CdLrGBhpxRoVmxM+DHM+/l4cbLoY1KyV2JA3T33HSmmXjD3DQr43F6x 6jMlWRAAvgyMnkldxgd0HKPnlA8QGxWdwiZfk6g4FlhfJsPz9tawvNP1inEyCRk3x0tW pt4VrgaBXvqXy17dUAn66owF4fiQ0qFvumTC+YA/1ncLl5ePNsZlwHgjdpVhAP8/0FSY 4wBbZDVa8joU4uA12htbYbhtp7vz1kA7g/vaTPh1Z03y4auv/UIrDUQ5j79JJQE0lpPd +/5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=xOLtbpkEtoBfkKGGOTIvWhE3qqxQoqcopRPrLUYG0b8=; b=XRvUlF9XM0n5EiY8ugBhKLXFc99itmakRm2VwRFIRoQJ66YZmzFaxbOn5lBwuaeNAA Q7AVY8gXwqyZadpf1E8dCkm2kKfd/Sf2eU4Iy2esPrPhap9FsVCej4AczP4SHqswoAgh MaGCJH7aiMBGp4rXUogOM85dWo5LLv6L+P424WYNEuNR6DUKgug4s06FA032rdA5qgAJ b+lDooFlCiQm84XqkWaTyLI3k1RbxB0oC9HnF4pk1jweKDmRJSk2Oi9vitrwZP39AybE wJUA8RFGuKROCezC4c49dsr5UHat9eGfYS/v8V5Cu+ILld4vHMyGslo3ZBaDngo1tcyS eMnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d+FhlV7u; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m7si4038585oie.138.2020.03.09.03.57.35; Mon, 09 Mar 2020 03:57:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d+FhlV7u; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725956AbgCIK5N (ORCPT + 99 others); Mon, 9 Mar 2020 06:57:13 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:44294 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726389AbgCIK5M (ORCPT ); Mon, 9 Mar 2020 06:57:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583751431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xOLtbpkEtoBfkKGGOTIvWhE3qqxQoqcopRPrLUYG0b8=; b=d+FhlV7udMPWc7aTqojeTfqSinpZssRZuQ4VVMVd+7q1MRAUGlsA7ONNLEzEPVhsQRxuaI uqyibPotdF1yNRexFlj43Ft/8vNV0E3JWNXJsZUSWVuX5JltJm+LarE6jGOjQcPbrxy9VT 8KyoozLRlLZjLVvG9S/5xvjhaOyYsyk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-327-kesc2179MmiUsjkFlfkzcQ-1; Mon, 09 Mar 2020 06:57:07 -0400 X-MC-Unique: kesc2179MmiUsjkFlfkzcQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F64D1007268; Mon, 9 Mar 2020 10:57:06 +0000 (UTC) Received: from bfoster (dhcp-41-2.bos.redhat.com [10.18.41.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74CEB91D95; Mon, 9 Mar 2020 10:57:05 +0000 (UTC) Date: Mon, 9 Mar 2020 06:57:03 -0400 From: Brian Foster To: Eric Biggers Cc: linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] xfs: clear PF_MEMALLOC before exiting xfsaild thread Message-ID: <20200309105703.GA36070@bfoster> References: <20200309010410.GA371527@sol.localdomain> <20200309043430.143206-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200309043430.143206-1-ebiggers@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Sun, Mar 08, 2020 at 09:34:30PM -0700, Eric Biggers wrote: > From: Eric Biggers > > 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 > --- Reviewed-by: Brian Foster > > 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 >