Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2535746lqp; Mon, 25 Mar 2024 01:33:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUxsnJcEBPOqXCCTZJs2glyNWtyfFiIurGHu2PzgVt7wH7hbHEXEwzJ7RfedeckUJoDxSSyKjWwBALbO+sjQeY7RMT6IkGr81irLPqVWw== X-Google-Smtp-Source: AGHT+IHhSKSJOVqKPohX9X7TLgHlP4MYccpSvFOnDyIq1nLuMrpWlsihEu0BDR56JfmzG7DLdH2G X-Received: by 2002:a17:906:483:b0:a46:6f8f:d7f0 with SMTP id f3-20020a170906048300b00a466f8fd7f0mr3542316eja.3.1711355609163; Mon, 25 Mar 2024 01:33:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711355609; cv=pass; d=google.com; s=arc-20160816; b=o3sEKgUgGyFag+yi8ROTMyxELTXgh7ZHmSF10UWE0opogMfIiKxYFB6+fokvmHjA7J 9kTeAKLUx2yIFBSgK9a3DiF3PNE9Ooup988LuAfnP/SelyJPCtOT/GtgDvvYWHZhb4si PQjY/MpZik5vWv64Z35Jr8nIV0Rpu3xLVhcJy8JqcIzaxPPOIQll8X8HDsdfaYxLGcqR BwQjy/9WLtOFUbdTuE+eJnZX/UaLvMOdiP/b4Z+3457x4eV+CMjOrp65thqjiA8LiIzP aJ7c9iOnglY8up3dtQTarmZ+FvnqNVi5RQ9rfy1gF+Dqr1BVSTkq7FnR9iAMGefd87o/ GT9g== 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=mUiSPHXV9MaFvjhTOKKvvGdt+X4JjFhVGH8kAtLxAyw=; fh=YRwqlI8URNx2lieogdhP5AhVB9o9RuaaNickGjPmmCs=; b=rvHPnYPQWjRa+17Z5kdZDF03smuWSpki61LroFhaKvtYh/9m57IJ99z6nuqmkEJQNU FcvKZhus5y59l/0hPFL6H6311BkXlibX9WQXu7Vc7gE5n5GvcsGogyqvc1P8gpcNwrHz AntsTLZWT+3pKhCSJkQAxRX6//4hde62V45fx5/bgwnwe+zAQN+Od3ltWl/rKE7f6N83 +6Quoe9e/tw7a9sJ13Meu2IDfWK+dWbngjM84l0W66cZZVUVuc8eKdeuJ18bVdwSGIDt p5+knoQhvH4qrgFt+iWSvnmoE9g2IH1TmxOkbZilgYVy7daS7bQJglbRdInHPRqDsf75 RPSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ERfjF/ia"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116066-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116066-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 z6-20020a50cd06000000b0056c07c82e5fsi1340594edi.34.2024.03.25.01.33.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 01:33:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-116066-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="ERfjF/ia"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-116066-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-116066-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 6C5A31F3341A for ; Mon, 25 Mar 2024 08:24:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C86BB282A9E; Mon, 25 Mar 2024 03:29:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ERfjF/ia" 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 79CCF1774ED; Sun, 24 Mar 2024 23:38:05 +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=1711323486; cv=none; b=o8xu01W7Ex0xyV51W/iput1lLd6bgNCEAWIyxTyjQ8ePRJ/pIq/Hhd1FCF3NUd3d+NV4QTadZbYOei9uvC1z4CfpN+peq0FNMCdoqWN+OZQ0oaDm7xI/s5x6GPDpayKOeDF4DBMv3WhoQioY0Kj2l11jJIWpKKM9DPV7bPB3ALs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711323486; c=relaxed/simple; bh=BH/Oe6Za7hwJSjCNdDO1HHW6sU+06qst04XA7RxXClw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DBE3OWUoaD9GUc5PbmgAk3D3Gt2X84SZmAgCVOdy8R2/LSBkxrhUapeo5WD+3Px0vLthV5fOzplY7+PyOlAXLmrBKPt7fEa3cpUjEsfc5SgGdsFQAcJmWe0gZRpMnSCsEcQ9tJaRKCIRWN1eldqmR53K6lUpweRHB7uhovsdM2w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ERfjF/ia; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B79FEC43390; Sun, 24 Mar 2024 23:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711323485; bh=BH/Oe6Za7hwJSjCNdDO1HHW6sU+06qst04XA7RxXClw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ERfjF/ia6pPCjyscUNTzBzYaUCJqTE3v+nvKlXAumwYy3lzJaqW+9P5tMytQmUEz1 grblSTqeDXZrTSLkbP8i+TrVSdcL41jVPBoxCYn0m3b6H+fgZ7gQBNXVip5N6fPyZW 7M7SPOd7P7Qmq/pns1K4eYtmSMlNLKi3ssGEr9e7gjaguxqwoAIg4gxY8zURLBV/Rn rGEATx+ejrg5+r+3+doHWS5yBr7x0LbHyTEf9AiDAeE4OSnIEjloP62XnlpH5bzhiz 7tegW+2O8slpgICb8DQDin2+Jc90rK9DJizBzRPRD04lVdeL7iRl0q+y5RuIZ0jIjR XcndrAu62WAcA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Baokun Li , Jan Kara , Sasha Levin Subject: [PATCH 5.15 190/317] quota: simplify drop_dquot_ref() Date: Sun, 24 Mar 2024 19:32:50 -0400 Message-ID: <20240324233458.1352854-191-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324233458.1352854-1-sashal@kernel.org> References: <20240324233458.1352854-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 75e593b1c03e8..b7d8cd84df576 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