Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2566710lqp; Mon, 25 Mar 2024 02:52:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWj8vCs5gFhhYEfMhKhoVyNEDG/Drd94QsfTsG6FzcqK8GD4TWgk/aP3EubmBCmj+v0Dh46dPdiWPDlG0kHYXsov35qcIKteWuFj0GKYw== X-Google-Smtp-Source: AGHT+IFztZuss1EWAD3WYniT5WpW69xCiV5V2K9yAcAZwkwD5Rv2i0wm0TXJd2cf9cJHC6Z/oWv3 X-Received: by 2002:a17:907:7d8d:b0:a47:53b2:2041 with SMTP id oz13-20020a1709077d8d00b00a4753b22041mr2325127ejc.11.1711360337094; Mon, 25 Mar 2024 02:52:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711360337; cv=pass; d=google.com; s=arc-20160816; b=gBi765gVTvXPsA9dvsqa7ayMmKt46Gv0JAn8fQelzErhW/ak4pyb62Z/YWE3ahcCNI ng9spsCoBHZ18iVJbZxKk8kfHyHsvCLbR+AC6SE9wmYizlJLJtcSkcXpDFD7Z1kJvEej EcYegWYzm4fI3MNL1eORu08y1xi4wkmmfxCHr5CDBZfikBHvc7VsjHinnSHoc1+G2VA6 GfD/GVmY4ReWkxTJdAS6vWq1G4evBVAujXy6HKW3tMG4yd1MjXSPy8ABgCy1eaoMifLD 5gkKPix/Rp3Zzm6Db2YTsOijfHRqYhyltiVbUPqEiAP+Vgg7N2hFjflu3JjpYjpyOA51 MhEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KLlzJTzEUWMc/9/sjxRRbdQcQJYgcM+uUyKh0D4wqVQ=; fh=YRwqlI8URNx2lieogdhP5AhVB9o9RuaaNickGjPmmCs=; b=M3yMGaA0P9DEWwj+i/U4lRYnKHz9v7SiWv49iHUK9IlVgRPksLmhdN3wGyIkfDbFoP FSRQHiqRr5xVItIGcE3qvYvNicKigU5MUEkL1A/R4Z5651tIs7Pw2RFPGEtepHtLN4RV qxMZLDwtWj/DTl1CwqoMIuIblBVcEOXlew8nlGVRj2gXZwpDJ8Qkzy0lXeVDPjsTwZ6O HILd86yx9Pr+z6gyfagNyX0qcFLsJXlekz8SqevALL1nG/yjCCzcJVd5jKjmsFluBmZr kZOCF3pcDMJwSOY81Sq62ms/GqUzgkGV0Mkgnh9pN88tyraiVEGlnH0x/IMc7yPZtx5K eTeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s+1zoBQg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r20-20020a17090638d400b00a46b291e5d7si2289674ejd.904.2024.03.25.02.52.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 02:52:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-115951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s+1zoBQg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-115951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-115951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C46D01F2CEBB for ; Mon, 25 Mar 2024 09:52:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AF6C391408; Mon, 25 Mar 2024 03:04:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s+1zoBQg" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 913CB22E141; Sun, 24 Mar 2024 23:16:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322195; cv=none; b=QPETgAH64KI0f7V0PtYvL2SpNLFMBVfj3YFyJ/sOaKNlAuteFBxWNKffRgodKlJkHijbJF7zdJEqHRKxLeLMbsgabS6u2NeaepIV8pLrK0TxURnXj1p/FYThatCT+7CZ+92/cFEbXh1vzfZSZjAXEnBKey/8ZJemcSh6tQ2XUfA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711322195; c=relaxed/simple; bh=KER8bZzciCHbeBCuGOVRIdNqfbhATTMUIsmkFhl/6ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bl3zlYrj6otP1TF3MlJUjuLcrzndULnBsAqVcX89qIqeTkHvhXvnguEzNYjiwgnUT1fXdNFUv4+Mi45UTfqFKMqa+cmKDftcKEz9fRqIxFos1IxK4Eq45+3HcHmAPRpRhCGAP9bg7jOoxy+GnF5R1Ni8cR/NXGz45BH2zNOLUpU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s+1zoBQg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2BECC43390; Sun, 24 Mar 2024 23:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711322194; bh=KER8bZzciCHbeBCuGOVRIdNqfbhATTMUIsmkFhl/6ec=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+1zoBQgWUo28BJCVw3xwVU/g6NjN1J3+sLiE4EgElMYsTMnzgyOksvLI/5tj1h7h 2XYOdt3obJXszCsWdobjHR3ct3JsjLCxJnotf6yj0Wn61q8gwUlCp8a8kbwEChgIit oNc7uDgIS3DUIA6nDSQdf64gpWpsbffNJsNxWIzQdua1L83E/pb7R06i98gsl9FxII k7wPK3WCWV1V8TF4M78imnBZLHEa47Oi9TuT74Z6BD92xE6WSPTloXfsMpizfbKUSY xMoGBLzeCM9dY6v49H1PCNYSrBV19lt6uSEWmC3LY3k2dkpJF8wqLF5+eWd+nERyEm rtpMBXVDFtcBA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Baokun Li , Jan Kara , Sasha Levin Subject: [PATCH 6.1 273/451] quota: simplify drop_dquot_ref() Date: Sun, 24 Mar 2024 19:09:09 -0400 Message-ID: <20240324231207.1351418-274-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324231207.1351418-1-sashal@kernel.org> References: <20240324231207.1351418-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Baokun Li [ Upstream commit 7bce48f0fec602b3b6c335963b26d9eefa417788 ] As Honza said, remove_inode_dquot_ref() currently does not release the last dquot reference but instead adds the dquot to tofree_head list. This is because dqput() can sleep while dropping of the last dquot reference (writing back the dquot and calling ->release_dquot()) and that must not happen under dq_list_lock. Now that dqput() queues the final dquot cleanup into a workqueue, remove_inode_dquot_ref() can call dqput() unconditionally and we can significantly simplify it. Here we open code the simplified code of remove_inode_dquot_ref() into remove_dquot_ref() and remove the function put_dquot_list() which is no longer used. Signed-off-by: Baokun Li Signed-off-by: Jan Kara Message-Id: <20230630110822.3881712-6-libaokun1@huawei.com> Stable-dep-of: 179b8c97ebf6 ("quota: Fix rcu annotations of inode dquot pointers") Signed-off-by: Sasha Levin --- fs/quota/dquot.c | 70 +++++++----------------------------------------- 1 file changed, 9 insertions(+), 61 deletions(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index b0cf3869d3bf5..730d8ffc4928a 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -1084,59 +1084,7 @@ static int add_dquot_ref(struct super_block *sb, int type) return err; } -/* - * Remove references to dquots from inode and add dquot to list for freeing - * if we have the last reference to dquot - */ -static void remove_inode_dquot_ref(struct inode *inode, int type, - struct list_head *tofree_head) -{ - struct dquot **dquots = i_dquot(inode); - struct dquot *dquot = dquots[type]; - - if (!dquot) - return; - - dquots[type] = NULL; - if (list_empty(&dquot->dq_free)) { - /* - * The inode still has reference to dquot so it can't be in the - * free list - */ - spin_lock(&dq_list_lock); - list_add(&dquot->dq_free, tofree_head); - spin_unlock(&dq_list_lock); - } else { - /* - * Dquot is already in a list to put so we won't drop the last - * reference here. - */ - dqput(dquot); - } -} - -/* - * Free list of dquots - * Dquots are removed from inodes and no new references can be got so we are - * the only ones holding reference - */ -static void put_dquot_list(struct list_head *tofree_head) -{ - struct list_head *act_head; - struct dquot *dquot; - - act_head = tofree_head->next; - while (act_head != tofree_head) { - dquot = list_entry(act_head, struct dquot, dq_free); - act_head = act_head->next; - /* Remove dquot from the list so we won't have problems... */ - list_del_init(&dquot->dq_free); - dqput(dquot); - } -} - -static void remove_dquot_ref(struct super_block *sb, int type, - struct list_head *tofree_head) +static void remove_dquot_ref(struct super_block *sb, int type) { struct inode *inode; #ifdef CONFIG_QUOTA_DEBUG @@ -1153,11 +1101,16 @@ static void remove_dquot_ref(struct super_block *sb, int type, */ spin_lock(&dq_data_lock); if (!IS_NOQUOTA(inode)) { + struct dquot **dquots = i_dquot(inode); + struct dquot *dquot = dquots[type]; + #ifdef CONFIG_QUOTA_DEBUG if (unlikely(inode_get_rsv_space(inode) > 0)) reserved = 1; #endif - remove_inode_dquot_ref(inode, type, tofree_head); + dquots[type] = NULL; + if (dquot) + dqput(dquot); } spin_unlock(&dq_data_lock); } @@ -1174,13 +1127,8 @@ static void remove_dquot_ref(struct super_block *sb, int type, /* Gather all references from inodes and drop them */ static void drop_dquot_ref(struct super_block *sb, int type) { - LIST_HEAD(tofree_head); - - if (sb->dq_op) { - remove_dquot_ref(sb, type, &tofree_head); - synchronize_srcu(&dquot_srcu); - put_dquot_list(&tofree_head); - } + if (sb->dq_op) + remove_dquot_ref(sb, type); } static inline -- 2.43.0