Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp898555rwb; Mon, 26 Sep 2022 07:14:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Z2xnMYZWIxpK9AJu/foJ2AcAagtdcsoUOfNBFbczH0bgUofGsyyjQ7GuSqbmcxJH5DlFf X-Received: by 2002:a17:907:25c1:b0:77b:9966:ccf1 with SMTP id ae1-20020a17090725c100b0077b9966ccf1mr18649140ejc.763.1664201695930; Mon, 26 Sep 2022 07:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664201695; cv=none; d=google.com; s=arc-20160816; b=dqWFOuR6csb7OtSTU4dlZYIXNuDPYtg0lPZrWdtKSYS/r1syqzRgjYxX1uWP70gPBy ZLrWSPVYlGeC1qPOGZLdyVHN7XC6fa8e9Y5HW9W+Hp9Ui4NxPhcbiI9tOwzq2R9RqKok DmUD8e5bMXu31kNU2TA6qQai1szI9HOgI/E1cAgYFOIGgg5P91ysEumwZxYlc6o9eJAT aNl/SUWIXZJKN/goC88Vmhx0O/pxoWKt0Iv45T2ING50CVArhH3y6VztslWP/Vn+5wMS N5Mx7aEPrxzChmpHccTQPW48sD6YOdWI1aheF6/jd93EpDuz6R9hU+auHF2vYEpXN6Qu posQ== 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=jyw6STIt9/Vbg/Lqv1slC/LnHk2+1YgAwcOQelM+Z9A=; b=nDTTVwb/NQB7rcI+lU6dG7agOYOJzCMLm+Cb4vuIowSOfHQBMqSXtTNwsZWNUnbYUa Ub0+GNR6hKiNMJjrpaCpWzN5/ihrT8xMlzJBmXzn4xCBkWZ9Z1zVhuS51ZZrA0d27fIK cPudZKffktEnyJVjA+Sb6Vb6FwcjNgYf3bfBRrGZDKVZyZbyvoevMjsFQoR3MfZ8Macw gzTgypn/MK3Tmeu7Gvc9aIJa9m1sNAcZ6VrwO5cdI4Q1Q8NOkMPY307t33LlyEg402zS kaVREwqdwHaGTF4u4G+IH1R05uCFdz5236y4kG369u6PkCXUIMezpDM0jiVzvzek5Fpp zBhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eYRQruPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go18-20020a1709070d9200b0073d6481dedesi12266ejc.224.2022.09.26.07.14.22; Mon, 26 Sep 2022 07:14:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eYRQruPC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235108AbiIZLWO (ORCPT + 99 others); Mon, 26 Sep 2022 07:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234148AbiIZLUU (ORCPT ); Mon, 26 Sep 2022 07:20:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD8AD67152; Mon, 26 Sep 2022 03:39:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E97ABB80972; Mon, 26 Sep 2022 10:38:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55C74C433D6; Mon, 26 Sep 2022 10:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188682; bh=RqrU5MsNEEi2OoDcJbOsUurapZKJ0LPU68LapHF6ga4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eYRQruPCP+oQOKMX3q/5vxdGXvMXhCgZZm/2YLsm7GlG9aPLmfSbM4ObiRg4CFPC3 YCqlggqOhCMtlLK+noGgEv9HQ0LsvZ+oMSpVOJXmkGQJR9fstE48OeDkeYIkTlq+to vmpY4mRlX5k6hBlAev6awzM4JnF73o6oXlzhdqq8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Frank Hofmann , Dave Chinner , "Darrick J. Wong" , Dave Chinner , Leah Rumancik , "Darrick J. Wong" Subject: [PATCH 5.15 055/148] xfs: reorder iunlink remove operation in xfs_ifree Date: Mon, 26 Sep 2022 12:11:29 +0200 Message-Id: <20220926100758.096465787@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Chinner [ Upstream commit 9a5280b312e2e7898b6397b2ca3cfd03f67d7be1 ] The O_TMPFILE creation implementation creates a specific order of operations for inode allocation/freeing and unlinked list modification. Currently both are serialised by the AGI, so the order doesn't strictly matter as long as the are both in the same transaction. However, if we want to move the unlinked list insertions largely out from under the AGI lock, then we have to be concerned about the order in which we do unlinked list modification operations. O_TMPFILE creation tells us this order is inode allocation/free, then unlinked list modification. Change xfs_ifree() to use this same ordering on unlinked list removal. This way we always guarantee that when we enter the iunlinked list removal code from this path, we already have the AGI locked and we don't have to worry about lock nesting AGI reads inside unlink list locks because it's already locked and attached to the transaction. We can do this safely as the inode freeing and unlinked list removal are done in the same transaction and hence are atomic operations with respect to log recovery. Reported-by: Frank Hofmann Fixes: 298f7bec503f ("xfs: pin inode backing buffer to the inode log item") Signed-off-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_inode.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2599,14 +2599,13 @@ xfs_ifree_cluster( } /* - * This is called to return an inode to the inode free list. - * The inode should already be truncated to 0 length and have - * no pages associated with it. This routine also assumes that - * the inode is already a part of the transaction. + * This is called to return an inode to the inode free list. The inode should + * already be truncated to 0 length and have no pages associated with it. This + * routine also assumes that the inode is already a part of the transaction. * - * The on-disk copy of the inode will have been added to the list - * of unlinked inodes in the AGI. We need to remove the inode from - * that list atomically with respect to freeing it here. + * The on-disk copy of the inode will have been added to the list of unlinked + * inodes in the AGI. We need to remove the inode from that list atomically with + * respect to freeing it here. */ int xfs_ifree( @@ -2628,13 +2627,16 @@ xfs_ifree( pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino)); /* - * Pull the on-disk inode from the AGI unlinked list. + * Free the inode first so that we guarantee that the AGI lock is going + * to be taken before we remove the inode from the unlinked list. This + * makes the AGI lock -> unlinked list modification order the same as + * used in O_TMPFILE creation. */ - error = xfs_iunlink_remove(tp, pag, ip); + error = xfs_difree(tp, pag, ip->i_ino, &xic); if (error) - goto out; + return error; - error = xfs_difree(tp, pag, ip->i_ino, &xic); + error = xfs_iunlink_remove(tp, pag, ip); if (error) goto out;