From mboxrd@z Thu Jan 1 00:00:00 1970 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 690962989BB; Mon, 5 May 2025 22:41:58 +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=1746484919; cv=none; b=jUHlaJlhwCXKOTKA8MezN12pRXRifdwkZeD2zzFLQb9XO9kIO2Zoiuh5Pp+6szHkjaDgc2VAh1rRd4UvFPPMmlxUy7ygzK/QiAnRqGXisWu3pLDV6xn96pMWnxoTjGFh4DrZUDnR13qr5NAALHG7kt4eYm/s6JXoDG5+ZQxtXSE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746484919; c=relaxed/simple; bh=VNOKF8xI7e59n51/M8qZEz+BtT33P9azI3xUaNaek7I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HK8LklfcTAWGlOsmqj91BRI3D20YWuogPcY+TBrRMMjQqwFotPapZLattcuhGkFC6kMABDiR1ut1WXkcG/pTbUAhMD2NIWt7wnOvp0/eGwox+1+y2JGDw0nIHj6eemive2zve+W5JidQbYUHbHSeFrkXrw2pkBStRPkeFfS5rIY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GMqtrAWi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GMqtrAWi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4395C4CEEF; Mon, 5 May 2025 22:41:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746484918; bh=VNOKF8xI7e59n51/M8qZEz+BtT33P9azI3xUaNaek7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GMqtrAWiWmVtO+qEVj9UBeHTOnSRlvTX9Zq28RR2blH7tS6G0/MkKLcMhT3SxO0bM 9Ox6FrlZdQTOyz0DLdbx3lJlvj+eQKYm8zcAn+C3wRnl6Ka+IC0akUnc5j+3L5J6Qy IdM+9O94GMO78jX4rYzincEzFMYvZbF8NJaOy0BEoWoQiK7Gd2zyO19ARSiDFZ7bHI lZRX7diEYxZOCAFX1fWmhVh0BTGbY/4nzEpZbXXNDM0EGginovV5n6W6SlF/IIc/Ls 84KqAJOUUEpyhie3Amd5H5FiH7BL+xMNlPY5h8iFnxq7Pz9SgTnlxsDMyYKn5MSM4Y cBClaxOHGG1QQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Filipe Manana , David Sterba , Qu Wenruo , Sasha Levin , clm@fb.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 6.12 075/486] btrfs: fix non-empty delayed iputs list on unmount due to async workers Date: Mon, 5 May 2025 18:32:31 -0400 Message-Id: <20250505223922.2682012-75-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250505223922.2682012-1-sashal@kernel.org> References: <20250505223922.2682012-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.12.26 Content-Transfer-Encoding: 8bit From: Filipe Manana [ Upstream commit cda76788f8b0f7de3171100e3164ec1ce702292e ] At close_ctree() after we have ran delayed iputs either explicitly through calling btrfs_run_delayed_iputs() or later during the call to btrfs_commit_super() or btrfs_error_commit_super(), we assert that the delayed iputs list is empty. We have (another) race where this assertion might fail because we have queued an async write into the fs_info->workers workqueue. Here's how it happens: 1) We are submitting a data bio for an inode that is not the data relocation inode, so we call btrfs_wq_submit_bio(); 2) btrfs_wq_submit_bio() submits a work for the fs_info->workers queue that will run run_one_async_done(); 3) We enter close_ctree(), flush several work queues except fs_info->workers, explicitly run delayed iputs with a call to btrfs_run_delayed_iputs() and then again shortly after by calling btrfs_commit_super() or btrfs_error_commit_super(), which also run delayed iputs; 4) run_one_async_done() is executed in the work queue, and because there was an IO error (bio->bi_status is not 0) it calls btrfs_bio_end_io(), which drops the final reference on the associated ordered extent by calling btrfs_put_ordered_extent() - and that adds a delayed iput for the inode; 5) At close_ctree() we find that after stopping the cleaner and transaction kthreads the delayed iputs list is not empty, failing the following assertion: ASSERT(list_empty(&fs_info->delayed_iputs)); Fix this by flushing the fs_info->workers workqueue before running delayed iputs at close_ctree(). David reported this when running generic/648, which exercises IO error paths by using the DM error table. Reported-by: David Sterba Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/disk-io.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index e0e740e4d7c75..147c50ef912ac 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -4282,6 +4282,19 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) */ btrfs_flush_workqueue(fs_info->delalloc_workers); + /* + * We can have ordered extents getting their last reference dropped from + * the fs_info->workers queue because for async writes for data bios we + * queue a work for that queue, at btrfs_wq_submit_bio(), that runs + * run_one_async_done() which calls btrfs_bio_end_io() in case the bio + * has an error, and that later function can do the final + * btrfs_put_ordered_extent() on the ordered extent attached to the bio, + * which adds a delayed iput for the inode. So we must flush the queue + * so that we don't have delayed iputs after committing the current + * transaction below and stopping the cleaner and transaction kthreads. + */ + btrfs_flush_workqueue(fs_info->workers); + /* * When finishing a compressed write bio we schedule a work queue item * to finish an ordered extent - btrfs_finish_compressed_write_work() -- 2.39.5