From nobody Thu Sep 24 14:27:14 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 C908E3A1CEA for ; Thu, 24 Sep 2026 01:46:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214362; cv=none; b=KTX0EEW3/5ckMUGoZUG9ITkEov93xA89z3cKtqiJGqy80XR6kWtqySfCqHy4GhLcWhb4EBMTXYubzoJI4K0h8V/uY6w8IFPTY15mSfJuRGWE3hsGd1Q4Yl9zoxuU7fVUP70DxkDZDsL810tIcORFmm+qAlnKLEDdS/XAvTf8D9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214362; c=relaxed/simple; bh=dxy399WUjBoRMIH8cJhYZYgATLxdcgUdisCMgfangPI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ecsyHqK9HkPEtryMugR/eQEwFFvA/SjgFOD3uQqXyBs07ePqFIlGcqyBikTWy0VFwsQEb8+DzUpDGL8qDqXLkTS/QvNVG99JgNHEMxWdk6ao065fZROVswfQiiKmBelyn3dUjyd0UfznR30U+VihhYTyMRU7ixwhUpu2UsnSp4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: ab34e3b4b7b911f19a56ed5b684f684d-20260924 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, SA_TRUSTED, SA_EXISTED SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:11d9a4eb-7260-4c2a-9369-c0a7919a8468,IP:20, URL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:45 X-CID-INFO: VERSION:1.3.19,REQID:11d9a4eb-7260-4c2a-9369-c0a7919a8468,IP:20,UR L:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:45 X-CID-META: VersionHash:7db8b62,CLOUDID:e9f6c5b322c338abeb9d4d80d0611d3f,BulkI D:260924094224I221WTT7,BulkQuantity:1,SF:17|19|38|66|78|81|82|102|127|850| 865|898,TC:nil,Content:0|15|50|99,EDM:5,IP:-2,URL:0,File:nil,RT:nil,Bulk:4 0,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE :0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: ab34e3b4b7b911f19a56ed5b684f684d-20260924 X-User: wangxuewen@kylinos.cn Received: from localhost.localdomain [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 520938948; Thu, 24 Sep 2026 09:45:49 +0800 From: Xuewen Wang To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v1 1/4] ntfs: bound the adjacent cluster in MFT bitmap extension Date: Thu, 24 Sep 2026 09:45:11 +0800 Message-Id: <20260924014514.1678828-2-wangxuewen@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260924014514.1678828-1-wangxuewen@kylinos.cn> References: <20260924014514.1678828-1-wangxuewen@kylinos.cn> 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 Content-Type: text/plain; charset="utf-8" When the last MFT bitmap run reaches the volume boundary, the direct allocation path tests the bit for nr_clusters, an invalid LCN. A clear bit allows an out-of-volume allocation; a bitmap read failure aborts extension even if valid clusters remain available. Check the candidate LCN before accessing $Bitmap and fall back to ntfs_cluster_alloc() with no locality hint when it is outside the volume. Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- fs/ntfs/mft.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index 8bb8b4085c8b..88bac85d22bc 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c @@ -1377,6 +1377,11 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(= struct ntfs_volume *vol) lcn =3D rl->lcn + rl->length; ntfs_debug("Last lcn of mft bitmap attribute is 0x%llx.", (long long)lcn); + /* There is no adjacent cluster if the last run ends at the volume end. */ + if (lcn >=3D vol->nr_clusters) { + lcn =3D -1; + goto alloc_cluster; + } /* * Attempt to get the cluster following the last allocated cluster by * hand as it may be in the MFT zone so the allocator would not give it @@ -1413,6 +1418,7 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(s= truct ntfs_volume *vol) kunmap_local(b); folio_put(folio); up_write(&vol->lcnbmp_lock); +alloc_cluster: /* Allocate a cluster from the DATA_ZONE. */ rl2 =3D ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, DATA_ZONE, true, false, false); --=20 2.25.1 From nobody Thu Sep 24 14:27:14 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 CFF8C39B49A for ; Thu, 24 Sep 2026 01:45:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214361; cv=none; b=REKlhB2Qrck2GNny+sS8va9PlS6dhC63knaJgAGKo2du7VeW/QRd+1GRz1PyDNG9BNOoLQ0pjqea/7TXBxOYxlgtu/w7iZ4MsTabvQtgtUQbj6Zmrfr4SeqKfvdd90V1gcy+cMVG6Dh4qMhpWXCEeorCUySe7X8SJGwmGr6K2CE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214361; c=relaxed/simple; bh=qAZ4/9+Tox0YpY0TsXe4o3Fh2mO+2N43EJOmI3rPFmI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cxGIw1fi40L0V7+TkYWb9obytrBlGjdE1n1H7IeB5Mu7X/B72vahWqCrWBDPJtyPhYFlKwu/jW8ofA/KYJ3Fb3kwTDlmPudxxfuSHqF+w/wX8XAas8E8ktXkej+umEAg79EjsptoY65fuLID0q7kLKXRpgss3qq99kRZDj4E744= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: ad5b29b4b7b911f19a56ed5b684f684d-20260924 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, SA_TRUSTED, SA_EXISTED SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:9cdb7bbf-42a3-4331-8af3-0d5407e45726,IP:20, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:20 X-CID-INFO: VERSION:1.3.19,REQID:9cdb7bbf-42a3-4331-8af3-0d5407e45726,IP:20,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:20 X-CID-META: VersionHash:7db8b62,CLOUDID:a08f7343481c5f8f54eb5fae658f5ca5,BulkI D:260924094557KZ3KSU5J,BulkQuantity:0,SF:17|19|38|66|78|81|82|102|127|850| 865|898,TC:nil,Content:0|15|50|99,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk: nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,B RE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: ad5b29b4b7b911f19a56ed5b684f684d-20260924 X-User: wangxuewen@kylinos.cn Received: from localhost.localdomain [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 927248115; Thu, 24 Sep 2026 09:45:53 +0800 From: Xuewen Wang To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v1 2/4] ntfs: fix rollback after MFT bitmap run coalescing Date: Thu, 24 Sep 2026 09:45:12 +0800 Message-Id: <20260924014514.1678828-3-wangxuewen@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260924014514.1678828-1-wangxuewen@kylinos.cn> References: <20260924014514.1678828-1-wangxuewen@kylinos.cn> 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 Content-Type: text/plain; charset="utf-8" After the direct allocation attempt drops lcnbmp_lock, a concurrent free can let ntfs_cluster_alloc() return the adjacent cluster. The merged runlist then extends the existing last run, but rollback assumes a new run was added. A later metadata failure removes the old mapping and frees its first cluster. Record whether the allocated cluster is adjacent before merging the runlists. On rollback, shorten a coalesced run by one cluster and free only that cluster; remove the new run for a non-adjacent allocation. Suggested-by: Baolin Liu Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- fs/ntfs/mft.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index 88bac85d22bc..12666668a80e 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c @@ -1428,6 +1428,8 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(s= truct ntfs_volume *vol) "Failed to allocate a cluster for the mft bitmap."); return PTR_ERR(rl2); } + /* The adjacent cluster may have become available while unlocked. */ + status.added_cluster =3D rl2->lcn =3D=3D lcn; rl =3D ntfs_runlists_merge(&mftbmp_ni->runlist, rl2, 0, &new_rl_count); if (IS_ERR(rl)) { up_write(&mftbmp_ni->runlist.lock); @@ -1442,8 +1444,8 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(s= truct ntfs_volume *vol) } mftbmp_ni->runlist.rl =3D rl; mftbmp_ni->runlist.count =3D new_rl_count; - status.added_run =3D 1; - ntfs_debug("Adding one run to mft bitmap."); + status.added_run =3D !status.added_cluster; + ntfs_debug("Allocated one cluster for mft bitmap."); /* Find the last run in the new runlist. */ for (; rl[1].length; rl++) ; --=20 2.25.1 From nobody Thu Sep 24 14:27:14 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 C83733A6F09 for ; Thu, 24 Sep 2026 01:46:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214365; cv=none; b=N1qedkqPPhDP/VF3DsSr54elF40gpuXh1Q8JIDnwCySnpvpF7Eg714HKp7lSzgcuHyUEjW9qAg2I16wSl4UTkI7cuB4UODjXdBJr53CupyHAZx5RcArtLbScunNc4Qm4piztW69jYKrv6q2sVZeo8QWHRa9QSf08sqoKnvB1XQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214365; c=relaxed/simple; bh=NlzbwuWqoBofbCF25WPMDEBWH+DmLB9TroDEhB95QU4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hbuqhN0keFnXW68K4Tq41s1feE4TTdvM0N12Gseu5sUEpE2OEzLlJqEEVJMQ/03Q6qxdwBP5jw6POumEzDdK+bNx47w7VuBd6tH9sv1BEqMLvb5Fx68b1nyuzFT8OeofrHDRLtdnX4FcAzxmFSsk2q5eE+YHN3eZRPawWFxYE0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: aec3a056b7b911f19a56ed5b684f684d-20260924 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, SA_TRUSTED, SA_EXISTED SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:2d3a67bd-64ee-4467-8d8f-cc6ca95007c5,IP:20, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:20 X-CID-INFO: VERSION:1.3.19,REQID:2d3a67bd-64ee-4467-8d8f-cc6ca95007c5,IP:20,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:20 X-CID-META: VersionHash:7db8b62,CLOUDID:2e19eaed52b24fbbd406f6a668586cba,BulkI D:2609240946005FWDQJVK,BulkQuantity:0,SF:17|19|38|66|78|81|82|102|127|850| 865|898,TC:nil,Content:0|15|50|99,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk: nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,B RE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: aec3a056b7b911f19a56ed5b684f684d-20260924 X-User: wangxuewen@kylinos.cn Received: from localhost.localdomain [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1269013409; Thu, 24 Sep 2026 09:45:55 +0800 From: Xuewen Wang To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v1 3/4] ntfs: wait for the bitmap scan before MFT bitmap extension Date: Thu, 24 Sep 2026 09:45:13 +0800 Message-Id: <20260924014514.1678828-4-wangxuewen@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260924014514.1678828-1-wangxuewen@kylinos.cn> References: <20260924014514.1678828-1-wangxuewen@kylinos.cn> 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 Content-Type: text/plain; charset="utf-8" If MFT bitmap extension fails before the initial $Bitmap scan completes, rollback calls ntfs_bitmap_clear_bit(), which holds a folio lock while ntfs_set_lcn_empty_bits() waits for the scan. The scanner deadlocks if it still needs that folio. Wait for the initial scan before taking the runlist or bitmap folio locks and attempting allocation. Fixes: 11ccc9107dc4 ("ntfs: update runlist handling and cluster allocator") Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- fs/ntfs/mft.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index 12666668a80e..489a5935202c 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c @@ -1352,6 +1352,10 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(= struct ntfs_volume *vol) size_t new_rl_count; =20 ntfs_debug("Extending mft bitmap allocation."); + /* The initial bitmap scan must finish before we lock or change a folio. = */ + if (!NVolFreeClusterKnown(vol)) + wait_event(vol->free_waitq, NVolFreeClusterKnown(vol)); + mft_ni =3D NTFS_I(vol->mft_ino); mftbmp_ni =3D NTFS_I(vol->mftbmp_ino); /* --=20 2.25.1 From nobody Thu Sep 24 14:27:14 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 9DA9C3A9DBA for ; Thu, 24 Sep 2026 01:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214367; cv=none; b=HmVpT7LlRjZUhrrNk9mz9pSRw+2OYDj6fUr+cQvtWmt8NCfes5nIaeV5FntdKGDyd99vpwTlio1NTMV3IEWp/uozXlb1z2ZfmOd8UEERJs3p2Jek9cycSl34bDyofO13JGAB6eWbcUHXnO5OBfoePd4bhEJcVOCEPyHZFrb8+Dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790214367; c=relaxed/simple; bh=o6Xsq5PXmfsVjo59cvMQE85Pyf3MO+LSaNm6LSwjOaY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VKptN7ljRB6Dpjq+w51oH5therjMCpl6XHLydxG9xhDASvVxploBDsoY47UCfvUn8odKWr5ZUKJrGzz+DXuE3AVznSbjj4PHuIQ4JkRLTht40w9peZKoSj3ugD/AuOwJAlR8xXPKIrQc9TbhGS5wg6n4/Z6s0ygGy+60EgYu3D4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: b0ff8d44b7b911f19a56ed5b684f684d-20260924 X-CTIC-Tags: HR_CC_COUNT, HR_CC_DOMAIN_COUNT, HR_CC_NAME, HR_CC_NO_NAME, HR_CTE_8B HR_CTT_MISS, HR_DATE_H, HR_DATE_WKD, HR_DATE_ZONE, HR_FROM_NAME HR_SJ_DIGIT_LEN, HR_SJ_LANG, HR_SJ_LEN, HR_SJ_LETTER, HR_SJ_NOR_SYM HR_SJ_PHRASE, HR_SJ_PHRASE_LEN, HR_SJ_WS, HR_TO_COUNT, HR_TO_DOMAIN_COUNT HR_TO_NO_NAME, IP_TRUSTED, SRC_TRUSTED, SA_TRUSTED, SA_EXISTED SN_EXISTED, SPF_NOPASS, DKIM_NOPASS, DMARC_NOPASS, CIE_BAD CIE_GOOD, CIE_GOOD_SPF, GTI_FG_BS, GTI_RG_INFO, GTI_C_BU AMN_GOOD, ABX_MISS_RDNS X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:8a75d225-a362-4866-9324-879bb8d8882a,IP:20, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:20 X-CID-INFO: VERSION:1.3.19,REQID:8a75d225-a362-4866-9324-879bb8d8882a,IP:20,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:20 X-CID-META: VersionHash:7db8b62,CLOUDID:52f49434290bd4dd8d18e6b1f36f1e36,BulkI D:2609240946036NTKH88E,BulkQuantity:0,SF:17|19|38|66|78|81|82|102|127|136| 850|865|898,TC:nil,Content:0|15|50|99,EDM:-3|-100,IP:-2,URL:0,File:nil,RT: nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP: 0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: b0ff8d44b7b911f19a56ed5b684f684d-20260924 X-User: wangxuewen@kylinos.cn Received: from localhost.localdomain [(223.70.159.239)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 487114032; Thu, 24 Sep 2026 09:45:59 +0800 From: Xuewen Wang To: linkinjeon@kernel.org, hyc.lee@gmail.com Cc: ntfs@lists.linux.dev, linux-kernel@vger.kernel.org, Xuewen Wang , Baolin Liu Subject: [PATCH v1 4/4] ntfs: account for direct MFT bitmap cluster allocation Date: Thu, 24 Sep 2026 09:45:14 +0800 Message-Id: <20260924014514.1678828-5-wangxuewen@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260924014514.1678828-1-wangxuewen@kylinos.cn> References: <20260924014514.1678828-1-wangxuewen@kylinos.cn> 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 Content-Type: text/plain; charset="utf-8" The MFT bitmap extension fast path sets $Bitmap directly, bypassing ntfs_cluster_alloc() and its free_clusters and lcn_empty_bits_per_page updates. Successful extensions overreport free space, and rollback adds back counts that were never deducted. Update both counts under lcnbmp_lock and the bitmap folio lock. Require a nonzero page count and space remaining after delayed-allocation reservations; otherwise use the regular allocator. The page check also prevents underflow when the initial scan recorded zero after a read error. Fixes: 6251f0b0de7d ("ntfs: update super block operations") Suggested-by: Baolin Liu Reviewed-by: Baolin Liu Signed-off-by: Xuewen Wang --- fs/ntfs/mft.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index 489a5935202c..e01e367a588d 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c @@ -1404,10 +1404,18 @@ static int ntfs_mft_bitmap_extend_allocation_nolock= (struct ntfs_volume *vol) folio_lock(folio); b =3D (u8 *)kmap_local_folio(folio, 0) + (ll & ~PAGE_MASK); tb =3D 1 << (lcn & 7ull); - if (*b !=3D 0xff && !(*b & tb)) { + /* + * A page skipped by the initial scan has no free bits recorded. + * Honor that and the space reserved for delayed allocation. + */ + if (*b !=3D 0xff && !(*b & tb) && + vol->lcn_empty_bits_per_page[ll >> PAGE_SHIFT] && + ntfs_available_clusters_count(vol, 1) > 0) { /* Next cluster is free, allocate it. */ *b |=3D tb; folio_mark_dirty(folio); + ntfs_dec_free_clusters(vol, 1); + ntfs_set_lcn_empty_bits(vol, ll >> PAGE_SHIFT, 1, 1); folio_unlock(folio); kunmap_local(b); folio_put(folio); --=20 2.25.1