Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1826405imm; Mon, 3 Sep 2018 10:26:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZpTTtGYV0zO1pw+REpeYn6uAsi86P0tXDA17zxkJcnTi7sLfybRhN1iONVlh0d0j1PPMH2 X-Received: by 2002:a63:8c0b:: with SMTP id m11-v6mr27029104pgd.372.1535995572004; Mon, 03 Sep 2018 10:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995571; cv=none; d=google.com; s=arc-20160816; b=Y6U0VqK1Uz2Ms2TnztIIzFUotjaag/56MfsmUNFgyVYeGsHidK1XfX+5Mn84hDjcFk Lcu0ZvjF9zScJnpXes4FijRCR3nc3tbAzANiRu7fHDXuoNaTh2cbLBvBk4NITMxRBWiV 7iticfOssJQ21+JsJkHchv59s8w6brSvpewpjNPVweDk62yTh/MXKPEZWRO4kQo/xWog WvltTz5o9riZldxgmfhV5QoYHn3JsWm0LjDcONSUctdGgQjE+ZrgNW+qc9b3QA5SbcTU CC6F+B2e37+4RA+Xqcprx0rJs2xj6eG+akNvdPzsGzldc/uC8PDul/n1b7bhpo6cirho d7RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=k8+7czK+w9qaw6Ro5XDcoaYUIwTfIJOoSERCgWepEqA=; b=XQAA9ZSV7z3v/ZERJA1m0t0HLUEHMmbatLggFkMet8bwYKssu9HcnMPQALfSFmsRuQ ZwiEfgXs4d1Qfm1X9PauNYl4cmU+ipLaynfj3iMiiGIqjwehaaq+tGt0cFHntxNkIbBR LpFoijFtBjgSU7qQ5Xsg52x2U+SvYuNzb+9Hu5D30cgOfkPLkOWCfNZHiCT+cHH2umK5 WFMtJLVr+EuWPxDHKJ8VAuB1osDL8+xmFBbZcp9WsXJHqsOaCFxwQf/CzGNfrcB6egOo slEhjv9aGL2tPg5AL1dxyhkgVKZlVLeYiE2cKGU0qbVt5zdrUdQMTJE1w+zq+3WaiK74 mAjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si19636505pfb.280.2018.09.03.10.25.57; Mon, 03 Sep 2018 10:26:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730484AbeICVoM (ORCPT + 99 others); Mon, 3 Sep 2018 17:44:12 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45392 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729864AbeICVoM (ORCPT ); Mon, 3 Sep 2018 17:44:12 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 750ABD2F; Mon, 3 Sep 2018 17:23:05 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Omar Sandoval , David Sterba Subject: [PATCH 4.14 092/165] Btrfs: fix btrfs_write_inode vs delayed iput deadlock Date: Mon, 3 Sep 2018 18:56:18 +0200 Message-Id: <20180903165700.129590327@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit 3c4276936f6fbe52884b4ea4e6cc120b890a0f9f upstream. We recently ran into the following deadlock involving btrfs_write_inode(): [ +0.005066] __schedule+0x38e/0x8c0 [ +0.007144] schedule+0x36/0x80 [ +0.006447] bit_wait+0x11/0x60 [ +0.006446] __wait_on_bit+0xbe/0x110 [ +0.007487] ? bit_wait_io+0x60/0x60 [ +0.007319] __inode_wait_for_writeback+0x96/0xc0 [ +0.009568] ? autoremove_wake_function+0x40/0x40 [ +0.009565] inode_wait_for_writeback+0x21/0x30 [ +0.009224] evict+0xb0/0x190 [ +0.006099] iput+0x1a8/0x210 [ +0.006103] btrfs_run_delayed_iputs+0x73/0xc0 [ +0.009047] btrfs_commit_transaction+0x799/0x8c0 [ +0.009567] btrfs_write_inode+0x81/0xb0 [ +0.008008] __writeback_single_inode+0x267/0x320 [ +0.009569] writeback_sb_inodes+0x25b/0x4e0 [ +0.008702] wb_writeback+0x102/0x2d0 [ +0.007487] wb_workfn+0xa4/0x310 [ +0.006794] ? wb_workfn+0xa4/0x310 [ +0.007143] process_one_work+0x150/0x410 [ +0.008179] worker_thread+0x6d/0x520 [ +0.007490] kthread+0x12c/0x160 [ +0.006620] ? put_pwq_unlocked+0x80/0x80 [ +0.008185] ? kthread_park+0xa0/0xa0 [ +0.007484] ? do_syscall_64+0x53/0x150 [ +0.007837] ret_from_fork+0x29/0x40 Writeback calls: btrfs_write_inode btrfs_commit_transaction btrfs_run_delayed_iputs If iput() is called on that same inode, evict() will wait for writeback forever. btrfs_write_inode() was originally added way back in 4730a4bc5bf3 ("btrfs_dirty_inode") to support O_SYNC writes. However, ->write_inode() hasn't been used for O_SYNC since 148f948ba877 ("vfs: Introduce new helpers for syncing after writing to O_SYNC file or IS_SYNC inode"), so btrfs_write_inode() is actually unnecessary (and leads to a bunch of unnecessary commits). Get rid of it, which also gets rid of the deadlock. CC: stable@vger.kernel.org # 3.2+ Signed-off-by: Josef Bacik [Omar: new commit message] Signed-off-by: Omar Sandoval Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/inode.c | 26 -------------------------- fs/btrfs/super.c | 1 - 2 files changed, 27 deletions(-) --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -6152,32 +6152,6 @@ err: return ret; } -int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc) -{ - struct btrfs_root *root = BTRFS_I(inode)->root; - struct btrfs_trans_handle *trans; - int ret = 0; - bool nolock = false; - - if (test_bit(BTRFS_INODE_DUMMY, &BTRFS_I(inode)->runtime_flags)) - return 0; - - if (btrfs_fs_closing(root->fs_info) && - btrfs_is_free_space_inode(BTRFS_I(inode))) - nolock = true; - - if (wbc->sync_mode == WB_SYNC_ALL) { - if (nolock) - trans = btrfs_join_transaction_nolock(root); - else - trans = btrfs_join_transaction(root); - if (IS_ERR(trans)) - return PTR_ERR(trans); - ret = btrfs_commit_transaction(trans); - } - return ret; -} - /* * This is somewhat expensive, updating the tree every time the * inode changes. But, it is most likely to find the inode in cache. --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2271,7 +2271,6 @@ static const struct super_operations btr .sync_fs = btrfs_sync_fs, .show_options = btrfs_show_options, .show_devname = btrfs_show_devname, - .write_inode = btrfs_write_inode, .alloc_inode = btrfs_alloc_inode, .destroy_inode = btrfs_destroy_inode, .statfs = btrfs_statfs,