From nobody Wed Dec 17 08:57:46 2025 Received: from mx0a-0064b401.pphosted.com (mx0a-0064b401.pphosted.com [205.220.166.238]) (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 33B6122B8C6; Fri, 9 May 2025 10:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.166.238 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746785018; cv=none; b=CSklN/rm/CYtToYmUURqchuswQOX6cKTkj17CLw4+B3wj6mUu3q77WSobKPxcKCxtq+EQ2o3KmNG0qzwhCtjaPXJT5D0y5tO0zZiK6HcNjh/7RcWAwhLbQjDAu+0vIlxThvnok33u3lEfWSW8ndgH/WW6qnjPXOB9B5pA8S7KQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746785018; c=relaxed/simple; bh=cJeBvAWk5V7QMXha8hOE8yPmQyzAgTiQwMe3aVFYiEo=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=U5/wTTufaT7i65bsQSpnznCuVbMtl9ssBCgdSLMy0FHAaiwhqjEahVQWJ4GqMY1zKOG36y82nrL5B0/mSpZo8iLrplQ9X4JKd2b4J0hqEF/bLWmgab0Q6jSmX4HtdbalXn4wG1rEqLeDq4zO93xWTGII9ITBDJdYp56yKupuqao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com; spf=pass smtp.mailfrom=windriver.com; arc=none smtp.client-ip=205.220.166.238 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=windriver.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=windriver.com Received: from pps.filterd (m0250810.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5498UaTs012563; Fri, 9 May 2025 03:03:29 -0700 Received: from ala-exchng02.corp.ad.wrs.com (ala-exchng02.wrs.com [147.11.82.254]) by mx0a-0064b401.pphosted.com (PPS) with ESMTPS id 46dee3f12s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 09 May 2025 03:03:29 -0700 (PDT) Received: from ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) by ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.43; Fri, 9 May 2025 03:03:28 -0700 Received: from pek-lpg-core1.wrs.com (147.11.136.210) by ALA-EXCHNG02.corp.ad.wrs.com (147.11.82.254) with Microsoft SMTP Server id 15.1.2507.43 via Frontend Transport; Fri, 9 May 2025 03:03:26 -0700 From: To: , CC: , , , , , , , , Subject: [PATCH 5.10.y] btrfs: don't BUG_ON() when 0 reference count at btrfs_lookup_extent_info() Date: Fri, 9 May 2025 18:03:25 +0800 Message-ID: <20250509100325.3246741-1-jianqi.ren.cn@windriver.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: lNkUu6k4qk0RmGKDbb333UEK1G6mz8lB X-Authority-Analysis: v=2.4 cv=Pd3/hjhd c=1 sm=1 tr=0 ts=681dd2f1 cx=c_pps a=K4BcnWQioVPsTJd46EJO2w==:117 a=K4BcnWQioVPsTJd46EJO2w==:17 a=dt9VzEwgFbYA:10 a=iox4zFpeAAAA:8 a=t7CeM3EgAAAA:8 a=cm_jlSa5FMeQIn3fhkUA:9 a=WzC6qhA0u3u7Ye7llzcV:22 a=FdTzh2GWekK77mhwV6Dw:22 X-Proofpoint-GUID: lNkUu6k4qk0RmGKDbb333UEK1G6mz8lB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNTA5MDA5NiBTYWx0ZWRfXy8SZi3Equ5Qe SvVqfI/Ec8V/EsXcJZcssPT6zSbzxqaQhGf4uB6b6/MbyC3r220FWglSnGJgsilA49eEXl5toV+ 4YSD6KHa8RZlzh8G030O+deYhdS8RyY68tmaqE90uGmMfuz3J60HZloePiyU3MvqWdJKt0asKZA VwZ1SxQFVNWZX/TnoEhB9mioo/U3ch4E9Go8AL8Hskk65G1UEefsl8SKlXGzNw+jqTvzpXrpmks MPbogws+RwTQm1KGelq/0hBReA49g16m007VAdgSREChqjsFK/d4MNGKI4ozXOxG/zvNB0ZKf4L OMDh87sFXizNuI6X8Iv7LTVBibBh2gLq2jizl1LnAZ2n4pAw1ApeGdwWch3ZNowgulizmYbkNsU 8QKGSL1kxuInkgHM/77ig4JAHcbaWv/DjBDclvR4mhrEk+qUj4hZk3O6rxWFx9gsw5fEychu X-Sensitive_Customer_Information: Yes X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-05-09_04,2025-05-08_04,2025-02-21_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 priorityscore=1501 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 impostorscore=0 clxscore=1015 mlxlogscore=873 phishscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.21.0-2504070000 definitions=main-2505090096 Content-Type: text/plain; charset="utf-8" From: Filipe Manana [ Upstream commit 28cb13f29faf6290597b24b728dc3100c019356f ] Instead of doing a BUG_ON() handle the error by returning -EUCLEAN, aborting the transaction and logging an error message. Reviewed-by: Qu Wenruo Signed-off-by: Filipe Manana Signed-off-by: David Sterba [Minor conflict resolved due to code context change.] Signed-off-by: Jianqi Ren Signed-off-by: He Zhe --- Verified the build test --- fs/btrfs/extent-tree.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index cf2b65be04b5..d652d4091b2b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -174,6 +174,14 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle= *trans, ei =3D btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item); num_refs =3D btrfs_extent_refs(leaf, ei); + if (unlikely(num_refs =3D=3D 0)) { + ret =3D -EUCLEAN; + btrfs_err(fs_info, + "unexpected zero reference count for extent item (%llu %u %llu)", + key.objectid, key.type, key.offset); + btrfs_abort_transaction(trans, ret); + goto out_free; + } extent_flags =3D btrfs_extent_flags(leaf, ei); } else { ret =3D -EINVAL; @@ -185,8 +193,6 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handle = *trans, =20 goto out_free; } - - BUG_ON(num_refs =3D=3D 0); } else { num_refs =3D 0; extent_flags =3D 0; @@ -216,10 +222,19 @@ int btrfs_lookup_extent_info(struct btrfs_trans_handl= e *trans, goto search_again; } spin_lock(&head->lock); - if (head->extent_op && head->extent_op->update_flags) + if (head->extent_op && head->extent_op->update_flags) { extent_flags |=3D head->extent_op->flags_to_set; - else - BUG_ON(num_refs =3D=3D 0); + } else if (unlikely(num_refs =3D=3D 0)) { + spin_unlock(&head->lock); + mutex_unlock(&head->mutex); + spin_unlock(&delayed_refs->lock); + ret =3D -EUCLEAN; + btrfs_err(fs_info, + "unexpected zero reference count for extent %llu (%s)", + bytenr, metadata ? "metadata" : "data"); + btrfs_abort_transaction(trans, ret); + goto out_free; + } =20 num_refs +=3D head->ref_mod; spin_unlock(&head->lock); --=20 2.34.1