Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4978913pxb; Mon, 15 Feb 2021 06:31:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcOlIMUmGPZGZhw2o5hvI+XkaMzDwJ7iePGnfcbKwkUlZdBOpvS9a/2DS3xlEG+g3ZETsA X-Received: by 2002:a05:6402:1383:: with SMTP id b3mr1609148edv.374.1613399488953; Mon, 15 Feb 2021 06:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613399488; cv=none; d=google.com; s=arc-20160816; b=nMX7+M3J0zMtOjmsQ3trs26eirICJ59pCxZ0kUMsgaNVSrI9ENlMVyp/B4WO+3YW+I 1V9sDuHvHgrxpP95BFQrxOThZQ2AUISKLVah9ksjwGhW2E6WeofJ2euhPMEM1JzgJQm4 GEYcK5hLz5rZ3auida7/IR7/YMqcLKNM5I1ILlvzQFVFW7X/l7Cjd18bD4PxWGybrDwb fJAbYFEHbq4E8H8nYZTHrveSwFL911wOOPjn3gk6VljnUnlZUEDmEL12OLxjXs0u8hJ2 Ur6Y/h2rF0BSg94ervn/ztmSyHIt/XEIKyhr+c+KLaHlMGhQ86EODI16UloD3L+qelah A52g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=qrCevLfFdOcAOvP2G6rLmgxAk6F03fnBmUqoITTwePM=; b=EzFgMjQh7qp9r22q0RxSVFJE5siusVZeg/WNSTFczKo5T4c3sefIoPwplzLju5WheZ jxa+fcv6d/nh90HSwTy0OPqHPl/7N0ttft1P1S6AeH3NvysDbpigq0GLmxtwYQHQlGAa 7e83u2pD0YLWRrEwxYEFlEa4vStOG2uMp7g4Z/GQTTyzMmRq3zEtcabCNelVEXMqzhal XCFxuOJavvSnwKQExCuNMhKu3pBnKOuqEV3NZxUhlxJb+pe+q/yzDCsQlzbmO1eKbQKW aRNRaDrQjSjmfPIIm65qYtV38f0qiMUZd2rCvj4bUpvLC+LluWXBAP09+iZDNSudnZIk Il8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si12649900edd.84.2021.02.15.06.31.04; Mon, 15 Feb 2021 06:31:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbhBOOaU (ORCPT + 99 others); Mon, 15 Feb 2021 09:30:20 -0500 Received: from mx2.suse.de ([195.135.220.15]:42140 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbhBOOaS (ORCPT ); Mon, 15 Feb 2021 09:30:18 -0500 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 C4E2BB1AC; Mon, 15 Feb 2021 14:29:35 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 8D22C1E6305; Mon, 15 Feb 2021 15:29:35 +0100 (CET) Date: Mon, 15 Feb 2021 15:29:35 +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: <20210215142935.GB22417@quack2.suse.cz> References: <000000000000563a0205bafb7970@google.com> <20210211104947.GL19070@quack2.suse.cz> <20210215124519.GA22417@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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 15-02-21 23:06:15, Tetsuo Handa wrote: > On 2021/02/15 21:45, Jan Kara wrote: > > On Sat 13-02-21 23:26:37, Tetsuo Handa wrote: > >> 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: > > Since syzbot can test filesystem images, syzbot might have tested a filesystem > image created both with and without journal within this boot. a) I think that syzbot reboots the VM between executing different tests to get reproducible conditions. But in theory I agree the test may have contained one image with and one image without a journal. *but* b) as I wrote in the email you are replying to, the jbd2_handle key is private per filesystem. Thus for lockdep to complain about jbd2_handle->fs_reclaim->jbd2_handle deadlock, those jbd2_handle lockdep maps must come from the same filesystem. *and* c) filesystem without journal doesn't use jbd2_handle lockdep map at all so for such filesystems lockdep creates no dependency for jbd2_handle map. Honza > > > > > 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: > > While locks held by kswapd0/2246 are fs_reclaim, shrinker_rwsem, &type->s_umount_key#38 > and jbd2_handle, isn't the dependency lockdep considers problematic is > > Chain exists of: > jbd2_handle --> &ei->xattr_sem --> fs_reclaim > > Possible unsafe locking scenario: > > CPU0 CPU1 > ---- ---- > lock(fs_reclaim); > lock(&ei->xattr_sem); > lock(fs_reclaim); > lock(jbd2_handle); > > where CPU0 is kswapd/2246 and CPU1 is the case of ext4_get_nojournal() path? > If someone has taken jbd2_handle and &ei->xattr_sem in this order, isn't this > dependency true? > > > > > 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. > > You can use CONFIG_DEBUG_AID_FOR_SYZBOT for adding such WARN_ONs on linux-next. > -- Jan Kara SUSE Labs, CR