From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8A78D263F44; Sat, 30 May 2026 17:24:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780161861; cv=none; b=c6kLiBftovgMX26FVE8yKOlnIpn12xOgHNb/Ja78nRWhkYf5TWAzaUiLNy05kcCV6vs7Hqx26KP4vGYoBOKFzbJUT581U5ErGMNZ2RtQwtO2Rk+wl7VbDirb+Zbdag2WD8Ot4Wj0THKxEGsXmzS6ZY17g+A759j+UkEGBzeiH2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780161861; c=relaxed/simple; bh=n/EBHAeJjMJRMjfEKCTSmijm2/5kylPwkW8Mt9RLUQo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LHii2GnKY9PYFkIA5Xwrdo47SK263G39+99sScc7bTe7C9F3/x/ZdEH6kAH3vfznF+U0w7DxGVohPXLx/+QmLf3XD8qkEirga4q6GHHuoW1PT4hCgLUb1i+vE279niIy4l0VcrN6oh3lAaTA1nClyuI2k1m7qaafCUaUDzs6SXY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=squ3Tqmy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="squ3Tqmy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FA851F00893; Sat, 30 May 2026 17:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780161859; bh=rezWjxoYb6p6wg5GmqDfcg/6ve1SZid+7gJ4Bm6XrGE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=squ3TqmyxuKvX7Rmtv4pa8OZRqq4oBBEpSHFOAezV0n1ZKuR0CyRIszizhV/axnbC 8G5S2d1pc3WQKQkv0myzWAOTunJVDCX3q99ZfHi7L8DI8owPYcEMjNa55m+jUWt+Z0 tkAadioXN2B659ZhmexcmXlYsEi9ys20xXlnXRRk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qu Wenruo , Mark Harmstone , David Sterba , Sasha Levin Subject: [PATCH 6.1 731/969] btrfs: fix double-decrement of bytes_may_use in submit_one_async_extent() Date: Sat, 30 May 2026 18:04:15 +0200 Message-ID: <20260530160320.730703450@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160300.485627683@linuxfoundation.org> References: <20260530160300.485627683@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mark Harmstone [ Upstream commit 82323b1a7088b7a5c3e528a5d634bff447fa286f ] submit_one_async_extent() calls btrfs_reserve_extent(), which decrements bytes_may_use. If the call btrfs_create_io_em() fails, we jump to out_free_reserve, which calls extent_clear_unlock_delalloc(). Because we're specifying EXTENT_DO_ACCOUNTING, i.e. EXTENT_CLEAR_META_RESV | EXTENT_CLEAR_DATA_RESV, this decreases bytes_may_use again. This can lead to problems later on, as an initial write can fail only for the writeback to silently ENOSPC. Fix this by replacing EXTENT_DO_ACCOUNTING with EXTENT_CLEAR_META_RESV. This parallels a4fe134fc1d8eb ("btrfs: fix a double release on reserved extents in cow_one_range()"), which is the same fix in cow_one_range(). Fixes: 151a41bc46df ("Btrfs: fix what bits we clear when erroring out from delalloc") Reviewed-by: Qu Wenruo Signed-off-by: Mark Harmstone Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6a5364b466be1..3cdda1e4ad79e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1069,7 +1069,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, extent_clear_unlock_delalloc(inode, start, end, NULL, EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING, + EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV, PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_END_WRITEBACK | PAGE_SET_ERROR); free_async_extent_pages(async_extent); -- 2.53.0