Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1837418pxb; Fri, 22 Oct 2021 08:35:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyg38sn0DH04vSUuhk5Mf8SOuURpeR4CsQLcgfxnbT+Xii/zD7Uu+soFu2eTlcI6pYEAilH X-Received: by 2002:a17:906:c205:: with SMTP id d5mr330776ejz.528.1634916909179; Fri, 22 Oct 2021 08:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634916909; cv=none; d=google.com; s=arc-20160816; b=gzb2H/G7Mjul/RT00s2pYoqsPI0db2AioKDhgVFFucjephFbngMBQDd0IqEOKrTgg+ jGT6bwRhhD7EU1Za4kQ+VviPCe3x7nb+6ssSnUdvKat3liaACbx8kLQ6isyaOXDIf6ZH NwQzBlVoL0wJgGxvB3PJFyLDdm4FgtHyfOE/N/d0YkykTS0S70+trgwqT9LcJQgFu0Eg t7ZPzoqATm4+79623NQbJkbq5harZqPQM+VR7uQrZKTGJaQoeM+ea2tdZgP6/03hSzXt 6EGGe7+zr/R8xkAwQOBcwvdRs2fbUGtjjdcEKznEPTxWGa7auXKBVvS+tOeU0wIwmjYK beuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=vzmn7a/XdwXzsj0OI+skwq6aSHdLz8K8GMedL6eNm0Y=; b=bYFoRzj421RMO4e8gwi8aU/R/y3CD9jVR4MfE9OxFl4Z8pd4gL8Mj0y4LVPYFO6SXZ Bb7If4jf0eWxXUF00MnsqXi7bQ7YuuXFvOsPSVVQFVQUgS/zwShT3DNOS6MhTqAhcUJg MfUsQdjbFPK6pM8z+Y5nzjdorGeLRBCV7gV7sXMVUN4NReihDLEOT0wrKJPwfKtkQ5L6 ywRf4g8+Vdihi3Q3TSfmI7TeFsoddaMjXc1GCJ0qCFl53bQJrsvTnJUvLvWWnTRXNAQF ImoW8J9ijx4aIT9LukZPWJHsis5umxNyvm+tq97n/oSpQgiutzwkQQYIN5BUF2XYnG/H q4IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="lQWW/kv4"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd10si13772671ejc.222.2021.10.22.08.34.43; Fri, 22 Oct 2021 08:35:09 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="lQWW/kv4"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233122AbhJVPej (ORCPT + 99 others); Fri, 22 Oct 2021 11:34:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:38220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbhJVPeh (ORCPT ); Fri, 22 Oct 2021 11:34:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0DCEC6054E; Fri, 22 Oct 2021 15:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634916740; bh=dsX++Uq9HxwTDlQDY7ato4NKF0kNAEUBDapYaqRA0mI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lQWW/kv4bYwG2eiGsk3PVYg9jXIMXMKfD1qt40pxIisJzhuO9iPyELNTcPrDIMU// ECQ8d9i3TlKupqDUH+GCtLlcdYYrJcWNhBfitlIYYJBJ0roxybxflXr43fn+G2i7pf jfqsWwqGSzJTco7W/4iE4hQ+VOp97sdF9Ww+kWi91vm3wjzGQxZxZ2KHmfujNLKQvy 1Ns3wrxF5xFusbkj8TBUOzXWxc+Gaeq5Gy10uLTThbfYTY100ke9UKU1GnUj4Yv3Z5 1jXHMi96uF3jATU7SHVhhs3zNKBkHktLInR0tgccjaxATjTSJAE2+KQ35nBtAM4MKk gBaue/wr7AXcw== Message-ID: <3ddb4013-8d63-7c00-6fdd-1f21752bd60c@kernel.org> Date: Fri, 22 Oct 2021 23:32:16 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [f2fs-dev] [PATCH] f2fs: remove circular locking between sb_internal and fs_reclaim Content-Language: en-US To: Daeho Jeong Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Daeho Jeong References: <20211014190503.717830-1-daeho43@gmail.com> From: Chao Yu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/10/22 0:44, Daeho Jeong wrote: > There is a deadlock between sb_internal lock (sb_start_intwrite()) and > dquot related lock. > It's because we call f2fs_truncate(), which eventually calls > dquot_initialize(), while holding sb_internal lock. > So, I called dquot_initialize() in advance to make the 2nd calling of > it in f2fs_truncate() ineffective. > This is similar with the thing in f2fs_evict_inode() in inode.c Well, if dquot_initialize() fails in f2fs_drop_inode(), will we still run into deadlock? Thanks, > > Thanks, > > On Thu, Oct 21, 2021 at 5:11 AM Chao Yu wrote: >> >> On 2021/10/15 3:05, Daeho Jeong wrote: >>> From: Daeho Jeong >>> >>> We detected the below circular locking dependency between sb_internal >>> and fs_reclaim. So, removed it by calling dquot_initialize() before >>> sb_start_intwrite(). >>> >>> ====================================================== >>> WARNING: possible circular locking dependency detected >>> ------------------------------------------------------ >>> kswapd0/133 is trying to acquire lock: >>> ffffff80d5fb9680 (sb_internal#2){.+.+}-{0:0}, at: evict+0xd4/0x2f8 >>> >>> but task is already holding lock: >>> ffffffda597c93a8 (fs_reclaim){+.+.}-{0:0}, at: >>> __fs_reclaim_acquire+0x4/0x50 >>> >>> which lock already depends on the new lock. >>> ... >>> other info that might help us debug this: >>> >>> Chain exists of: >>> >>> sb_internal#2 --> &s->s_dquot.dqio_sem --> fs_reclaim >>> >>> Possible unsafe locking scenario: >>> >>> CPU0 CPU1 >>> ---- ---- >>> lock(fs_reclaim); >>> lock(&s->s_dquot.dqio_sem); >>> lock(fs_reclaim); >>> lock(sb_internal#2); >> >> Sorry, I still didn't get the root cause of this deadlock issue, could >> you please explain more about this? >> >> And why calling dquot_initialize() in drop_inode() could break the >> circular locking dependency? >> >> Thanks, >> >>> >>> Signed-off-by: Daeho Jeong >>> --- >>> fs/f2fs/super.c | 2 ++ >>> 1 file changed, 2 insertions(+) >>> >>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c >>> index 86eeb019cc52..a133932333c5 100644 >>> --- a/fs/f2fs/super.c >>> +++ b/fs/f2fs/super.c >>> @@ -1370,6 +1370,8 @@ static int f2fs_drop_inode(struct inode *inode) >>> /* should remain fi->extent_tree for writepage */ >>> f2fs_destroy_extent_node(inode); >>> >>> + dquot_initialize(inode); >>> + >>> sb_start_intwrite(inode->i_sb); >>> f2fs_i_size_write(inode, 0); >>> >>>