From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7640CC433E0 for ; Mon, 15 Feb 2021 12:45:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2361564DEC for ; Mon, 15 Feb 2021 12:45:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2361564DEC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A26B78D0101; Mon, 15 Feb 2021 07:45:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9ADE78D00FD; Mon, 15 Feb 2021 07:45:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 876768D0101; Mon, 15 Feb 2021 07:45:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0240.hostedemail.com [216.40.44.240]) by kanga.kvack.org (Postfix) with ESMTP id 6AB2F8D00FD for ; Mon, 15 Feb 2021 07:45:22 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2D2584DD8 for ; Mon, 15 Feb 2021 12:45:22 +0000 (UTC) X-FDA: 77820472884.21.5A5F013 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf18.hostedemail.com (Postfix) with ESMTP id 8978E2000D9B for ; Mon, 15 Feb 2021 12:45:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7449CAC32; Mon, 15 Feb 2021 12:45:20 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id ECF951E6305; Mon, 15 Feb 2021 13:45:19 +0100 (CET) Date: Mon, 15 Feb 2021 13:45:19 +0100 From: Jan Kara To: Tetsuo Handa Cc: Jan Kara , jack@suse.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, tytso@mit.edu, mhocko@suse.cz, linux-mm@kvack.org, syzbot Subject: Re: possible deadlock in start_this_handle (2) Message-ID: <20210215124519.GA22417@quack2.suse.cz> References: <000000000000563a0205bafb7970@google.com> <20210211104947.GL19070@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8978E2000D9B X-Stat-Signature: 8snanr4tofmwhtaup7q16wc3mspii5ro Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf18; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1613393121-596487 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat 13-02-21 23:26:37, Tetsuo Handa wrote: > On 2021/02/11 19:49, Jan Kara wrote: > > This stacktrace should never happen. ext4_xattr_set() starts a transaction. > > That internally goes through start_this_handle() which calls: > > > > handle->saved_alloc_context = memalloc_nofs_save(); > > > > and we restore the allocation context only in stop_this_handle() when > > stopping the handle. And with this fs_reclaim_acquire() should remove > > __GFP_FS from the mask and not call __fs_reclaim_acquire(). > > Excuse me, but it seems to me that nothing prevents > ext4_xattr_set_handle() from reaching ext4_xattr_inode_lookup_create() > without memalloc_nofs_save() when hitting ext4_get_nojournal() path. > Will you explain when ext4_get_nojournal() path is executed? That's a good question but sadly I don't think that's it. ext4_get_nojournal() is called when the filesystem is created without a journal. In that case we also don't acquire jbd2_handle lockdep map. In the syzbot report we can see: kswapd0/2246 is trying to acquire lock: ffff888041a988e0 (jbd2_handle){++++}-{0:0}, at: start_this_handle+0xf81/0x1380 fs/jbd2/transaction.c:444 but task is already holding lock: ffffffff8be892c0 (fs_reclaim){+.+.}-{0:0}, at: __fs_reclaim_acquire+0x0/0x30 mm/page_alloc.c:5195 So this filesystem has very clearly been created with a journal. Also the journal lockdep tracking machinery uses: rwsem_acquire_read(&journal->j_trans_commit_map, 0, 0, _THIS_IP_); so a lockdep key is per-filesystem. Thus it is not possible that lockdep would combine lock dependencies from two different filesystems. But I guess we could narrow the search for this problem by adding WARN_ONs to ext4_xattr_set_handle() and ext4_xattr_inode_lookup_create() like: WARN_ON(ext4_handle_valid(handle) && !(current->flags & PF_MEMALLOC_NOFS)); It would narrow down a place in which PF_MEMALLOC_NOFS flag isn't set properly... At least that seems like the most plausible way forward to me. Honza > > ext4_xattr_set() { > handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits) == __ext4_journal_start() { > return __ext4_journal_start_sb() { > journal = EXT4_SB(sb)->s_journal; > if (!journal || (EXT4_SB(sb)->s_mount_state & EXT4_FC_REPLAY)) > return ext4_get_nojournal(); // Never calls memalloc_nofs_save() despite returning !IS_ERR() value. > return jbd2__journal_start(journal, blocks, rsv_blocks, revoke_creds, GFP_NOFS, type, line); // Calls memalloc_nofs_save() when start_this_handle() returns 0. > } > } > } > error = ext4_xattr_set_handle(handle, inode, name_index, name, value, value_len, flags); { > ext4_write_lock_xattr(inode, &no_expand); // Grabs &ei->xattr_sem > error = ext4_xattr_ibody_set(handle, inode, &i, &is) { > error = ext4_xattr_set_entry(i, s, handle, inode, false /* is_block */) { > ret = ext4_xattr_inode_lookup_create(handle, inode, i->value, i->value_len, &new_ea_inode); // Using GFP_KERNEL based on assumption that ext4_journal_start() called memalloc_nofs_save(). > } > } > } > } > -- Jan Kara SUSE Labs, CR