Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9094018pxu; Mon, 28 Dec 2020 06:30:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJyrKnBSAZvOCzOwihWjSLoMD0AVrSFCMujzA7HXqvtWqtxZkbf67O2BCKmI3Q/6xFf4omD4 X-Received: by 2002:a17:907:2061:: with SMTP id qp1mr40575241ejb.222.1609165802373; Mon, 28 Dec 2020 06:30:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609165802; cv=none; d=google.com; s=arc-20160816; b=NZeCGTvhFrJLFs0XQT/VFw5T+gPnlKwnOWfIOcPk0RVeIjHcrxuSj95RGAY//bUinP QQoS0xJsglUnMHEPaoBvrFqI85PdxIHVdnU22fY1SFUdSKP43yO/mDCS6iXecHx6AgV0 TigMahLSeIMcFCMJcIWfnweB9Nv4rehs0+6nKzKaYEeDU0ZKF/wWOSi+9pjxjgmM9Jpq D60u2H+8ewitXr6w4t6aqWKNaq6WKIYhqT4j/KFKvHDWoITa0BdIJYOphKgSJzkzQHdL wg2/S4Hi3PXHP8wfzErQQIM0t7smZHyYxX1pLFQ0JuifmEqCYSd4Ctxsb4ac2K0FhOkv 4bCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dK+6ZWvaRTJAkeiwg5QpC1HN9rJWVtwmVn+9IFzpfiU=; b=geL3OlaZYXHWmDF6DAV6xHkf+h3sEqsXbJrrHU/XFirl70X6guQ9QLQK+ZOPyCLJJ+ cJSA8KgytuQlAOiQgiFF7R9thzdLm1kU96lTBEruUKx+zpGl9GlYtfN0sEajFFCTKMkl iXFSEkXi2hRP3g9snDLBrX+qPwQur7gIOXRZ+7Kbq/zmrVUrpRG/mKp9Q54JVT7dK6zU Bh5Q58NK2HBOwckpin8LPwGj+NQI0NA6VpSTn+0LI/pCujHtFBDdMeWshJW7qEEF8//x W6M8ACO5QwFqw8MQ1o02PzarxIJOBaDgRuEhsFYdz/h8T4ABfvGEu2kPuJovREf+kD+d 3T/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sB+WvhSm; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ck16si20349372edb.36.2020.12.28.06.29.40; Mon, 28 Dec 2020 06:30:02 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sB+WvhSm; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503978AbgL1O1z (ORCPT + 99 others); Mon, 28 Dec 2020 09:27:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:35216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502299AbgL1O12 (ORCPT ); Mon, 28 Dec 2020 09:27:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C99AC229C5; Mon, 28 Dec 2020 14:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165608; bh=ouWmlPyMFKcL4kW80E8RxcRo03ImrAsfCNh707PK3Tg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sB+WvhSmIuHP/tDUEe5V/dZnZ+yhu5wIENqpPAQ09SR3SlLn0X1VuQIyZ4oYuPFkK 2yDn4HuljLWAFbfoqzc+t72lRZzxKLl5vcTaDqNmmz0M3GHcET6dWueFW3mYJK9+Vi 0iBx0tvEOjHI/SaQz1BsqNuy6Koz0JtXF5BD7OZs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Andreas Dilger , Theodore Tso Subject: [PATCH 5.10 592/717] ext4: fix deadlock with fs freezing and EA inodes Date: Mon, 28 Dec 2020 13:49:50 +0100 Message-Id: <20201228125049.274273481@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kara commit 46e294efc355c48d1dd4d58501aa56dac461792a upstream. Xattr code using inodes with large xattr data can end up dropping last inode reference (and thus deleting the inode) from places like ext4_xattr_set_entry(). That function is called with transaction started and so ext4_evict_inode() can deadlock against fs freezing like: CPU1 CPU2 removexattr() freeze_super() vfs_removexattr() ext4_xattr_set() handle = ext4_journal_start() ... ext4_xattr_set_entry() iput(old_ea_inode) ext4_evict_inode(old_ea_inode) sb->s_writers.frozen = SB_FREEZE_FS; sb_wait_write(sb, SB_FREEZE_FS); ext4_freeze() jbd2_journal_lock_updates() -> blocks waiting for all handles to stop sb_start_intwrite() -> blocks as sb is already in SB_FREEZE_FS state Generally it is advisable to delete inodes from a separate transaction as it can consume quite some credits however in this case it would be quite clumsy and furthermore the credits for inode deletion are quite limited and already accounted for. So just tweak ext4_evict_inode() to avoid freeze protection if we have transaction already started and thus it is not really needed anyway. Cc: stable@vger.kernel.org Fixes: dec214d00e0d ("ext4: xattr inode deduplication") Signed-off-by: Jan Kara Reviewed-by: Andreas Dilger Link: https://lore.kernel.org/r/20201127110649.24730-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -175,6 +175,7 @@ void ext4_evict_inode(struct inode *inod */ int extra_credits = 6; struct ext4_xattr_inode_array *ea_inode_array = NULL; + bool freeze_protected = false; trace_ext4_evict_inode(inode); @@ -232,9 +233,14 @@ void ext4_evict_inode(struct inode *inod /* * Protect us against freezing - iput() caller didn't have to have any - * protection against it - */ - sb_start_intwrite(inode->i_sb); + * protection against it. When we are in a running transaction though, + * we are already protected against freezing and we cannot grab further + * protection due to lock ordering constraints. + */ + if (!ext4_journal_current_handle()) { + sb_start_intwrite(inode->i_sb); + freeze_protected = true; + } if (!IS_NOQUOTA(inode)) extra_credits += EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb); @@ -253,7 +259,8 @@ void ext4_evict_inode(struct inode *inod * cleaned up. */ ext4_orphan_del(NULL, inode); - sb_end_intwrite(inode->i_sb); + if (freeze_protected) + sb_end_intwrite(inode->i_sb); goto no_delete; } @@ -294,7 +301,8 @@ void ext4_evict_inode(struct inode *inod stop_handle: ext4_journal_stop(handle); ext4_orphan_del(NULL, inode); - sb_end_intwrite(inode->i_sb); + if (freeze_protected) + sb_end_intwrite(inode->i_sb); ext4_xattr_inode_array_free(ea_inode_array); goto no_delete; } @@ -323,7 +331,8 @@ stop_handle: else ext4_free_inode(handle, inode); ext4_journal_stop(handle); - sb_end_intwrite(inode->i_sb); + if (freeze_protected) + sb_end_intwrite(inode->i_sb); ext4_xattr_inode_array_free(ea_inode_array); return; no_delete: