From nobody Sun Nov 24 21:24:37 2024 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (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 0F0D8156678; Fri, 1 Nov 2024 08:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449590; cv=none; b=N4H2gu0QDN/UVIllT6zN7JD7tK0Ro5xuCmQMKwUavWZ2MTP/z1v2nIXuMDVHRDz4oA+5oLgMr+EMk1njQZ4Tb289l5UKjE/dF1IBxZiJacZ3VwPkaQCWq34sZaKEbEDuYrVb5PY0IEhrgIOReL8ewloZn2yz3hywsD/Bpza6M3U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449590; c=relaxed/simple; bh=+6/v9Azv9t0zjKhmI02pkI6wOoHelWUtYk6iSp1338A=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OpxuFBInX9a2V+l62k6kXnvJJIWr051Uqf/ejuaFV3iiXF3xFg9f1reaOg/xsUMh+pRVTnzaapH2uecwAzBPwd5qI+YfZThK7fAlpjXIptr8rqQesI3buUHBRZ8/gq9wJJIMJdt3IAW/ZX3AnSbrbfbtIcZvqlW6r1L5v+3mK/g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=aS5OYCVK; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="aS5OYCVK" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 8CEB1218D; Fri, 1 Nov 2024 08:10:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730448622; bh=EMJxi7gPPcRhavvgBEOenfkgLt+8pGTZpnPW3BV4h5M=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=aS5OYCVKxGlCERKclGyOdvhSNxtAa9uWVo+AZr/1ZiNOEbWHJS9OORcm4377uj4dx a0KDkO1TL3GrkoGMfANRAXkGn8KUC1YwW+2u9athn8I7qa22pwoxFfqFO2z0AffkTr vOBURBi4I29D5EN2VadRROticCDVFS/LjAMplBI0= Received: from ntfs3vm.paragon-software.com (192.168.211.142) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 1 Nov 2024 11:18:05 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , Subject: [PATCH 1/7] fs/ntfs3: Fix warning in ni_fiemap Date: Fri, 1 Nov 2024 11:17:47 +0300 Message-ID: <20241101081753.10585-2-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> References: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> 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-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Content-Type: text/plain; charset="utf-8" Use local runs_tree instead of cached. This way excludes rw_semaphore lock. Reported-by: syzbot+1c25748a40fe79b8a119@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- fs/ntfs3/attrib.c | 9 ++-- fs/ntfs3/frecord.c | 103 +++++++-------------------------------------- fs/ntfs3/ntfs_fs.h | 3 +- 3 files changed, 21 insertions(+), 94 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 0763202d00c9..8d789b017fa9 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -977,7 +977,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn= , CLST clen, CLST *lcn, =20 /* Check for compressed frame. */ err =3D attr_is_frame_compressed(ni, attr_b, vcn >> NTFS_LZNT_CUNIT, - &hint); + &hint, run); if (err) goto out; =20 @@ -1521,16 +1521,16 @@ int attr_wof_frame_info(struct ntfs_inode *ni, stru= ct ATTRIB *attr, * attr_is_frame_compressed - Used to detect compressed frame. * * attr - base (primary) attribute segment. + * run - run to use, usually =3D=3D &ni->file.run. * Only base segments contains valid 'attr->nres.c_unit' */ int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr, - CLST frame, CLST *clst_data) + CLST frame, CLST *clst_data, struct runs_tree *run) { int err; u32 clst_frame; CLST clen, lcn, vcn, alen, slen, vcn_next; size_t idx; - struct runs_tree *run; =20 *clst_data =3D 0; =20 @@ -1542,7 +1542,6 @@ int attr_is_frame_compressed(struct ntfs_inode *ni, s= truct ATTRIB *attr, =20 clst_frame =3D 1u << attr->nres.c_unit; vcn =3D frame * clst_frame; - run =3D &ni->file.run; =20 if (!run_lookup_entry(run, vcn, &lcn, &clen, &idx)) { err =3D attr_load_runs_vcn(ni, attr->type, attr_name(attr), @@ -1678,7 +1677,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST f= rame, size_t compr_size, if (err) goto out; =20 - err =3D attr_is_frame_compressed(ni, attr_b, frame, &clst_data); + err =3D attr_is_frame_compressed(ni, attr_b, frame, &clst_data, run); if (err) goto out; =20 diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 41c7ffad2790..c33e818b3164 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -1900,46 +1900,6 @@ enum REPARSE_SIGN ni_parse_reparse(struct ntfs_inode= *ni, struct ATTRIB *attr, return REPARSE_LINK; } =20 -/* - * fiemap_fill_next_extent_k - a copy of fiemap_fill_next_extent - * but it uses 'fe_k' instead of fieinfo->fi_extents_start - */ -static int fiemap_fill_next_extent_k(struct fiemap_extent_info *fieinfo, - struct fiemap_extent *fe_k, u64 logical, - u64 phys, u64 len, u32 flags) -{ - struct fiemap_extent extent; - - /* only count the extents */ - if (fieinfo->fi_extents_max =3D=3D 0) { - fieinfo->fi_extents_mapped++; - return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; - } - - if (fieinfo->fi_extents_mapped >=3D fieinfo->fi_extents_max) - return 1; - - if (flags & FIEMAP_EXTENT_DELALLOC) - flags |=3D FIEMAP_EXTENT_UNKNOWN; - if (flags & FIEMAP_EXTENT_DATA_ENCRYPTED) - flags |=3D FIEMAP_EXTENT_ENCODED; - if (flags & (FIEMAP_EXTENT_DATA_TAIL | FIEMAP_EXTENT_DATA_INLINE)) - flags |=3D FIEMAP_EXTENT_NOT_ALIGNED; - - memset(&extent, 0, sizeof(extent)); - extent.fe_logical =3D logical; - extent.fe_physical =3D phys; - extent.fe_length =3D len; - extent.fe_flags =3D flags; - - memcpy(fe_k + fieinfo->fi_extents_mapped, &extent, sizeof(extent)); - - fieinfo->fi_extents_mapped++; - if (fieinfo->fi_extents_mapped =3D=3D fieinfo->fi_extents_max) - return 1; - return (flags & FIEMAP_EXTENT_LAST) ? 1 : 0; -} - /* * ni_fiemap - Helper for file_fiemap(). * @@ -1950,11 +1910,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_e= xtent_info *fieinfo, __u64 vbo, __u64 len) { int err =3D 0; - struct fiemap_extent *fe_k =3D NULL; struct ntfs_sb_info *sbi =3D ni->mi.sbi; u8 cluster_bits =3D sbi->cluster_bits; - struct runs_tree *run; - struct rw_semaphore *run_lock; + struct runs_tree run; struct ATTRIB *attr; CLST vcn =3D vbo >> cluster_bits; CLST lcn, clen; @@ -1965,13 +1923,11 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_= extent_info *fieinfo, u32 flags; bool ok; =20 + run_init(&run); if (S_ISDIR(ni->vfs_inode.i_mode)) { - run =3D &ni->dir.alloc_run; attr =3D ni_find_attr(ni, NULL, NULL, ATTR_ALLOC, I30_NAME, ARRAY_SIZE(I30_NAME), NULL, NULL); - run_lock =3D &ni->dir.run_lock; } else { - run =3D &ni->file.run; attr =3D ni_find_attr(ni, NULL, NULL, ATTR_DATA, NULL, 0, NULL, NULL); if (!attr) { @@ -1986,7 +1942,6 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_ex= tent_info *fieinfo, "fiemap is not supported for compressed file (cp -r)"); goto out; } - run_lock =3D &ni->file.run_lock; } =20 if (!attr || !attr->non_res) { @@ -1998,51 +1953,33 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_= extent_info *fieinfo, goto out; } =20 - /* - * To avoid lock problems replace pointer to user memory by pointer to ke= rnel memory. - */ - fe_k =3D kmalloc_array(fieinfo->fi_extents_max, - sizeof(struct fiemap_extent), - GFP_NOFS | __GFP_ZERO); - if (!fe_k) { - err =3D -ENOMEM; - goto out; - } - end =3D vbo + len; alloc_size =3D le64_to_cpu(attr->nres.alloc_size); if (end > alloc_size) end =3D alloc_size; =20 - down_read(run_lock); =20 while (vbo < end) { if (idx =3D=3D -1) { - ok =3D run_lookup_entry(run, vcn, &lcn, &clen, &idx); + ok =3D run_lookup_entry(&run, vcn, &lcn, &clen, &idx); } else { CLST vcn_next =3D vcn; =20 - ok =3D run_get_entry(run, ++idx, &vcn, &lcn, &clen) && + ok =3D run_get_entry(&run, ++idx, &vcn, &lcn, &clen) && vcn =3D=3D vcn_next; if (!ok) vcn =3D vcn_next; } =20 if (!ok) { - up_read(run_lock); - down_write(run_lock); - err =3D attr_load_runs_vcn(ni, attr->type, attr_name(attr), - attr->name_len, run, vcn); - - up_write(run_lock); - down_read(run_lock); + attr->name_len, &run, vcn); =20 if (err) break; =20 - ok =3D run_lookup_entry(run, vcn, &lcn, &clen, &idx); + ok =3D run_lookup_entry(&run, vcn, &lcn, &clen, &idx); =20 if (!ok) { err =3D -EINVAL; @@ -2067,8 +2004,9 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_ex= tent_info *fieinfo, } else if (is_attr_compressed(attr)) { CLST clst_data; =20 - err =3D attr_is_frame_compressed( - ni, attr, vcn >> attr->nres.c_unit, &clst_data); + err =3D attr_is_frame_compressed(ni, attr, + vcn >> attr->nres.c_unit, + &clst_data, &run); if (err) break; if (clst_data < NTFS_LZNT_CLUSTERS) @@ -2097,8 +2035,8 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_ex= tent_info *fieinfo, if (vbo + dlen >=3D end) flags |=3D FIEMAP_EXTENT_LAST; =20 - err =3D fiemap_fill_next_extent_k(fieinfo, fe_k, vbo, lbo, - dlen, flags); + err =3D fiemap_fill_next_extent(fieinfo, vbo, lbo, dlen, + flags); =20 if (err < 0) break; @@ -2119,8 +2057,7 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_ex= tent_info *fieinfo, if (vbo + bytes >=3D end) flags |=3D FIEMAP_EXTENT_LAST; =20 - err =3D fiemap_fill_next_extent_k(fieinfo, fe_k, vbo, lbo, bytes, - flags); + err =3D fiemap_fill_next_extent(fieinfo, vbo, lbo, bytes, flags); if (err < 0) break; if (err =3D=3D 1) { @@ -2131,19 +2068,8 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_e= xtent_info *fieinfo, vbo +=3D bytes; } =20 - up_read(run_lock); - - /* - * Copy to user memory out of lock - */ - if (copy_to_user(fieinfo->fi_extents_start, fe_k, - fieinfo->fi_extents_max * - sizeof(struct fiemap_extent))) { - err =3D -EFAULT; - } - out: - kfree(fe_k); + run_close(&run); return err; } =20 @@ -2672,7 +2598,8 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vb= o, struct page **pages, down_write(&ni->file.run_lock); run_truncate_around(run, le64_to_cpu(attr->nres.svcn)); frame =3D frame_vbo >> (cluster_bits + NTFS_LZNT_CUNIT); - err =3D attr_is_frame_compressed(ni, attr, frame, &clst_data); + err =3D attr_is_frame_compressed(ni, attr, frame, &clst_data, + run); up_write(&ni->file.run_lock); if (err) goto out1; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 26e1e1379c04..cd8e8374bb5a 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -446,7 +446,8 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct A= TTRIB *attr, struct runs_tree *run, u64 frame, u64 frames, u8 frame_bits, u32 *ondisk_size, u64 *vbo_data); int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr, - CLST frame, CLST *clst_data); + CLST frame, CLST *clst_data, + struct runs_tree *run); int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_si= ze, u64 new_valid); int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes); --=20 2.34.1 From nobody Sun Nov 24 21:24:37 2024 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (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 02330154C15; Fri, 1 Nov 2024 08:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449590; cv=none; b=IkT9oIgxnGcJcpjUdKBMQjIhFiSdQu+p/ZXCROssXQ/bXDCq/GbnnYYhQkuq7+hXqzW9wUQP39oE9KO+j1BWJ/3FVYiOZpRJoqwyVhIbspgtit6D4TV2L49QjIwSGBozxOAL3BKJAoCcrV1mGArWWtC0o4u3ccc4pcl9ZZ4vBVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449590; c=relaxed/simple; bh=U0RXtdPp1WscZLdHFhcN92IhEj/x6c1cGQUaWXoIPc0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nj86cezYfzhdt1Rdxt0b0hB8a7Q3rbttUlgZXa8hjv/bxI5JgTqDM8pgZV6GiwZRbFt2ltIxlsFpxBC+iYJkddbVFQzHCSbMim/0jmRJMBqQsN49BB2K/bUqmjaKAgOkSJvJv+ssjIIWCo4xURLdFOGzaO+u7YQhoB5XzqFmXRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=ktN7mzhi; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=lH+Ja5dy; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="ktN7mzhi"; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="lH+Ja5dy" Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 457D5218E; Fri, 1 Nov 2024 08:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730448623; bh=9wn86gsG6BMDjW/ovhKBk4LvQkb8iLktrVduNY8huFI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ktN7mzhi1mF3s/X6chPXtlsyQdd05eZDfS0Oiy/acDXugjUoCFTXJQB8mB6VEHqg2 dZt4uMyWNA93bFRc0Kn9+mvdGuz1JXTm0ixTNJdJA00r0lYldTleerkpw3ktsLK8kR MQq38U//t8M4oQI1lTyia8+669Czila3iFStqM6M= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id CBCCD220E; Fri, 1 Nov 2024 08:18:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730449086; bh=9wn86gsG6BMDjW/ovhKBk4LvQkb8iLktrVduNY8huFI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=lH+Ja5dyM6wi5O0y9xkT6Wln32qiTAPZ36UlmLa/ier+eRPMftS6bq2VCA5J1mNmC meankEolfeRRymaf93W0faawPWhoaQ2MSjtDw+0xc987I8G1+Tdu3tOOUMU8yRfQ38 lN/vqPfjuEpsgQEmANlJHzQ3g1zmN8UdB5YN9Exo= Received: from ntfs3vm.paragon-software.com (192.168.211.142) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 1 Nov 2024 11:18:06 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , Subject: [PATCH 2/7] fs/ntfs3: Fix case when unmarked clusters intersect with zone Date: Fri, 1 Nov 2024 11:17:48 +0300 Message-ID: <20241101081753.10585-3-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> References: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> 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-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Content-Type: text/plain; charset="utf-8" Reported-by: syzbot+7f3761b790fa41d0f3d5@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- fs/ntfs3/run.c | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c index 58e988cd8049..48566dff0dc9 100644 --- a/fs/ntfs3/run.c +++ b/fs/ntfs3/run.c @@ -1055,8 +1055,8 @@ int run_unpack_ex(struct runs_tree *run, struct ntfs_= sb_info *sbi, CLST ino, { int ret, err; CLST next_vcn, lcn, len; - size_t index; - bool ok; + size_t index, done; + bool ok, zone; struct wnd_bitmap *wnd; =20 ret =3D run_unpack(run, sbi, ino, svcn, evcn, vcn, run_buf, run_buf_size); @@ -1087,8 +1087,9 @@ int run_unpack_ex(struct runs_tree *run, struct ntfs_= sb_info *sbi, CLST ino, continue; =20 down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS); + zone =3D max(wnd->zone_bit, lcn) < min(wnd->zone_end, lcn + len); /* Check for free blocks. */ - ok =3D wnd_is_used(wnd, lcn, len); + ok =3D !zone && wnd_is_used(wnd, lcn, len); up_read(&wnd->rw_lock); if (ok) continue; @@ -1096,14 +1097,33 @@ int run_unpack_ex(struct runs_tree *run, struct ntf= s_sb_info *sbi, CLST ino, /* Looks like volume is corrupted. */ ntfs_set_state(sbi, NTFS_DIRTY_ERROR); =20 - if (down_write_trylock(&wnd->rw_lock)) { - /* Mark all zero bits as used in range [lcn, lcn+len). */ - size_t done; - err =3D wnd_set_used_safe(wnd, lcn, len, &done); - up_write(&wnd->rw_lock); - if (err) - return err; + if (!down_write_trylock(&wnd->rw_lock)) + continue; + + if (zone) { + /* + * Range [lcn, lcn + len) intersects with zone. + * To avoid complex with zone just turn it off. + */ + wnd_zone_set(wnd, 0, 0); + } + + /* Mark all zero bits as used in range [lcn, lcn+len). */ + err =3D wnd_set_used_safe(wnd, lcn, len, &done); + if (zone) { + /* Restore zone. Lock mft run. */ + struct rw_semaphore *lock; + lock =3D is_mounted(sbi) ? &sbi->mft.ni->file.run_lock : + NULL; + if (lock) + down_read(lock); + ntfs_refresh_zone(sbi); + if (lock) + up_read(lock); } + up_write(&wnd->rw_lock); + if (err) + return err; } =20 return ret; --=20 2.34.1 From nobody Sun Nov 24 21:24:37 2024 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (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 024DD15665E; Fri, 1 Nov 2024 08:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449591; cv=none; b=nJF0m+QVaC3Mef0IaAD2MSLsU1gZCzpcDDPKnvALql5B0qM6AVzXpE4IwUFzB4LE2uEgMtDwJByCqKNJvyWvB3elnBLB60jIRNak3tIsha1nJ1CnY03CVtX3uk1yxf4LYp2gmisOai8cFq+ihZf1N+6nJ8YqRcV5RpSnPH97xQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449591; c=relaxed/simple; bh=g7eIdBsOsPzOm5qji0coNyVwB11i3SnzrvsU/3XmHLI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HfG2A5b3J6cmMLWwauYGNr519sY33lMN74JRgWT22Tm++5g/2mdfOUCq3MWHu45mywi2IYT6fawtR7XQEc0k/n5oMwYjxE3AgGmENZKf0Pms2UlqeK2y9/KmJX9SkKprcx/W5wAIn6PniRQ9VcWLlC2EDBK7VKzXgFgTdPsO3Wk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=SxO+gzkS; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="SxO+gzkS" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 8EECC2191; Fri, 1 Nov 2024 08:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730448623; bh=z4djlGColZmet8W39kJokRepLwxRG/E52YDLYRzCWC4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=SxO+gzkSCr3HTJR64qHLnkgMoNT9oCSpjUreOe6fu/TyoZ/5qgHpHAlCjqSXsAzoG eOABgVtQwztWh+smrgt5X9g5jJFNHtOfxLvtjT42GmTTSB8P+rVMEZEVAEGRq5rLpO MTjG4F0DSKyfRdypJdE4M65Vbm20p81URYtZRuy8= Received: from ntfs3vm.paragon-software.com (192.168.211.142) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 1 Nov 2024 11:18:06 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , Matthew Wilcox Subject: [PATCH 3/7] fs/ntfs3: Equivalent transition from page to folio Date: Fri, 1 Nov 2024 11:17:49 +0300 Message-ID: <20241101081753.10585-4-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> References: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> 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-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Content-Type: text/plain; charset="utf-8" If using the proposed function folio_zero_range(), should one switch from 'start + end' to 'start + length,' or use folio_zero_segment() Fixes: 1da86618bdce ("fs: Convert aops->write_begin to take a folio") Signed-off-by: Konstantin Komarov --- fs/ntfs3/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index e370eaf9bfe2..f704ceef9539 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -222,7 +222,7 @@ static int ntfs_extend_initialized_size(struct file *fi= le, if (err) goto out; =20 - folio_zero_range(folio, zerofrom, folio_size(folio)); + folio_zero_range(folio, zerofrom, folio_size(folio) - zerofrom); =20 err =3D ntfs_write_end(file, mapping, pos, len, len, folio, NULL); if (err < 0) --=20 2.34.1 From nobody Sun Nov 24 21:24:37 2024 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (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 023F0156222; Fri, 1 Nov 2024 08:26:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449590; cv=none; b=t8KqIjjLBB8WcuUJ+hDAoVHkGmrs5UUuUcNLLFA1BABxp6Zmg5CiS9HJo8KyCXst7yPr3uQ4capHFzb6aLNAe6xjKS325Venx1cTCSRDxG8FVVyj5fspUKhriUp1BjcejgskQeegQzZW2qVxlCWnP3wS/qZoT5NN8STmoTY1Y7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449590; c=relaxed/simple; bh=0oZBY97lul7yUbBl6y6b03JAdxgFn9GXH59r3A5xrqI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KZPIcmPRUhTPj2v0WtL+BanoofZarsB+PP7zS4v9W7GMs2Lt15A9L7Gnx0IWdDJsI14Lyo79NFk3NdaIlWX/Otf6cDfDFMW/IW7RLrYJ68D2vdlCa6ULBZR2EVc0TUlx7D1Fh5pdvy78gnNyOZ11NQHKDDiZWJONbgoOzSw0sxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=V1ZTFrkn; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="V1ZTFrkn" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id BB6912193; Fri, 1 Nov 2024 08:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730448623; bh=Zc8pWLu9PmdBKNyMNiH6MkfNdkErJ9Xuv7AE62v9sLE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=V1ZTFrknpeI4XZnwMs0ggOh2xVuTbomK9t0+TFDjON2Vt7pW4KOEc5P6v8L0KrxOg HxwR0S2peQUKBNDNyFIJl82V0yBtepcy0uDDA7SnRX2pvv2gy8udybnTCYbffYnUeD 9gGml0eIL2vVgdWhjqF3tjf0Qre5KtJkibwE6uxE= Received: from ntfs3vm.paragon-software.com (192.168.211.142) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 1 Nov 2024 11:18:07 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov , lei lu Subject: [PATCH 4/7] fs/ntfs3: Add more checks in mi_enum_attr (part 2) Date: Fri, 1 Nov 2024 11:17:50 +0300 Message-ID: <20241101081753.10585-5-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> References: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> 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-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Content-Type: text/plain; charset="utf-8" Add offset check before access to attr->non_res field as mentioned in [1]. [1] https://lore.kernel.org/ntfs3/20241010110005.42792-1-llfamsec@gmail.com/ Suggested-by: lei lu Signed-off-by: Konstantin Komarov --- fs/ntfs3/record.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index f810f0419d25..61d53d39f3b9 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -212,7 +212,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struc= t ATTRIB *attr) return NULL; =20 if (off >=3D used || off < MFTRECORD_FIXUP_OFFSET_1 || - !IS_ALIGNED(off, 4)) { + !IS_ALIGNED(off, 8)) { return NULL; } =20 @@ -236,8 +236,11 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, stru= ct ATTRIB *attr) off +=3D asize; } =20 - /* Can we use the first field (attr->type). */ - /* NOTE: this code also checks attr->size availability. */ + /* + * Can we use the first fields: + * attr->type, + * attr->size + */ if (off + 8 > used) { static_assert(ALIGN(sizeof(enum ATTR_TYPE), 8) =3D=3D 8); return NULL; @@ -259,10 +262,17 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi, str= uct ATTRIB *attr) =20 asize =3D le32_to_cpu(attr->size); =20 + if (!IS_ALIGNED(asize, 8)) + return NULL; + /* Check overflow and boundary. */ if (off + asize < off || off + asize > used) return NULL; =20 + /* Can we use the field attr->non_res. */ + if (off + 9 > used) + return NULL; + /* Check size of attribute. */ if (!attr->non_res) { /* Check resident fields. */ --=20 2.34.1 From nobody Sun Nov 24 21:24:37 2024 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (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 CD6F715665E; Fri, 1 Nov 2024 08:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449097; cv=none; b=q9A01B9lJs3xEw9iaHLtveUV8uZLTfZVBO1bQO811D63kgZYebyet7njMK99yov2lwLzpz8GRmol8TJxoFCA8H63KshbaUXGvJUAxK7QCXAbz2NWJNjjfO4mjt4xbdolrmib9j32x6IMYy6Wv3qk9YsXwx51Ketn5GifkRVUAz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449097; c=relaxed/simple; bh=tYU9NbbtAgq70BsaYYUR2bmcBrBdVA3gIQJ+XtgVBwU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=g/g8vyERDMoii6MAF085XlcHcSGITdDTnGD5IImUywkCspo/o6y+ihll9TxNHRN3ex5vqpT6PtC8gBNo+1uRsREEhSmRPMYTyifNdsTI3x4GutwjyTHDOgiE19SKBZxJnA7OUhvjbze1XN3GEKLR5iTsjB7OkK+ahF1fyn8vjUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=DgjM7FMR; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=XnwjQLen; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="DgjM7FMR"; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="XnwjQLen" Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 74FBA2194; Fri, 1 Nov 2024 08:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730448624; bh=lyTvVE83tJLRVQjKOlhu4Y9VF3FY60VMH0YBNXt7z3s=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=DgjM7FMRRxlEU+6pG+gCZ7j9kh7kY51AE3wrgz5sCR66RZIOpADWYgUaZ/l2qJ1QS dQAi78FtdVmI4tbrusGzbnDUXpYa0UOkgErDiIde1odIf7Mvmv69BBUPkNjaSZRL6y 1mcmnYvZMKenN+5xBGn6Mixce2yLwvfg/n2qEulA= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 0682F220E; Fri, 1 Nov 2024 08:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730449088; bh=lyTvVE83tJLRVQjKOlhu4Y9VF3FY60VMH0YBNXt7z3s=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XnwjQLenQNWnFVucW6OVxc4giGNvOrSZmBvx58Zvxq5d1xhyV/JCq2XURzypDj17g fflxKmpo5GeVMmJSdGKJv3Ot7KiXzuHh99U5w8RzSfY5QAZRf90QN0ot8QRrm6gLJS IxKx9Uf0jzCOsoCL0fZYRix6KSE9NuZkTmwQFBxE= Received: from ntfs3vm.paragon-software.com (192.168.211.142) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 1 Nov 2024 11:18:07 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov Subject: [PATCH 5/7] fs/ntfs3: Add check in ntfs_extend_initialized_size Date: Fri, 1 Nov 2024 11:17:51 +0300 Message-ID: <20241101081753.10585-6-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> References: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> 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-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Content-Type: text/plain; charset="utf-8" Check arguments again after lock. Signed-off-by: Konstantin Komarov --- fs/ntfs3/file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index f704ceef9539..0063e2351aa9 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -182,13 +182,15 @@ static int ntfs_extend_initialized_size(struct file *= file, loff_t pos =3D valid; int err; =20 + if (valid >=3D new_valid) + return 0; + if (is_resident(ni)) { ni->i_valid =3D new_valid; return 0; } =20 WARN_ON(is_compressed(ni)); - WARN_ON(valid >=3D new_valid); =20 for (;;) { u32 zerofrom, len; --=20 2.34.1 From nobody Sun Nov 24 21:24:37 2024 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (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 CAB06156644; Fri, 1 Nov 2024 08:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449097; cv=none; b=Sawx8G2O/g1PR+lbVurqTDAAzouj7RDJ8BIh9fGfM3Ey8Dkwt4KFmAgV/TO5NhOuX1KKgtyrlxc3o8fjaeq7O0KVslYs8xLFBX/MfflhTbFESfj0kUWwfAvaga1YFA5bAahgGZj72Buv9odQeqFZIXPACtGLaU8mCmfoo6n40GQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449097; c=relaxed/simple; bh=ip10q0afRCPufQl5vblhJgoIxGZLNRQ5cA/HQPEMSgs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P6PvQIWJyxpcSZXyzRN5t9jxMoK2L3jK3sahkec1Z5dYVjHp+HIyg5++8uFFvL2bSuKrNuc6IpDALv7+D8e5gNjcHXylnQwXJZBUojp9IqY1vCrl/96we32hPPPYi9X6Uxdv86MMVeJXMRFdLLcHtkuYV99gxnjA3QRDzjZuezc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=V0jT6IDN; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="V0jT6IDN" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id B926A2195; Fri, 1 Nov 2024 08:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730448624; bh=5KkQ+m9GyL5KPsZkuY61BI+zMKTicmhs5y2zpcYau+4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=V0jT6IDNJXH4dHMMTKvwLiYxBP+N/KDda0GjyCby6eP6hkEYal45lVUKtV/ul3h7X b3+XMHWSgcJgOXCmty79amTXktMUlFySx4tgGiPHd8fodSAvOaVfqchFiC1MEryhi4 3ufXL3H2ZnikOznaWk9Imc/VU1KO3Q6GPw6elv1w= Received: from ntfs3vm.paragon-software.com (192.168.211.142) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 1 Nov 2024 11:18:07 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov Subject: [PATCH 6/7] fs/ntfs3: Switch to folio to release resources Date: Fri, 1 Nov 2024 11:17:52 +0300 Message-ID: <20241101081753.10585-7-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> References: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> 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-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Content-Type: text/plain; charset="utf-8" As part of the process of switching from page to folio. Signed-off-by: Konstantin Komarov --- fs/ntfs3/file.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 0063e2351aa9..3f96a11804c9 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -989,6 +989,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, = struct iov_iter *from) u64 frame_vbo; pgoff_t index; bool frame_uptodate; + struct folio *folio; =20 if (frame_size < PAGE_SIZE) { /* @@ -1043,8 +1044,9 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb= , struct iov_iter *from) if (err) { for (ip =3D 0; ip < pages_per_frame; ip++) { page =3D pages[ip]; - unlock_page(page); - put_page(page); + folio =3D page_folio(page); + folio_unlock(folio); + folio_put(folio); } goto out; } @@ -1054,9 +1056,10 @@ static ssize_t ntfs_compress_write(struct kiocb *ioc= b, struct iov_iter *from) off =3D offset_in_page(valid); for (; ip < pages_per_frame; ip++, off =3D 0) { page =3D pages[ip]; + folio =3D page_folio(page); zero_user_segment(page, off, PAGE_SIZE); flush_dcache_page(page); - SetPageUptodate(page); + folio_mark_uptodate(folio); } =20 ni_lock(ni); @@ -1065,9 +1068,10 @@ static ssize_t ntfs_compress_write(struct kiocb *ioc= b, struct iov_iter *from) =20 for (ip =3D 0; ip < pages_per_frame; ip++) { page =3D pages[ip]; - SetPageUptodate(page); - unlock_page(page); - put_page(page); + folio =3D page_folio(page); + folio_mark_uptodate(folio); + folio_unlock(folio); + folio_put(folio); } =20 if (err) @@ -1109,8 +1113,9 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb= , struct iov_iter *from) for (ip =3D 0; ip < pages_per_frame; ip++) { page =3D pages[ip]; - unlock_page(page); - put_page(page); + folio =3D page_folio(page); + folio_unlock(folio); + folio_put(folio); } goto out; } @@ -1151,9 +1156,10 @@ static ssize_t ntfs_compress_write(struct kiocb *ioc= b, struct iov_iter *from) for (ip =3D 0; ip < pages_per_frame; ip++) { page =3D pages[ip]; ClearPageDirty(page); - SetPageUptodate(page); - unlock_page(page); - put_page(page); + folio =3D page_folio(page); + folio_mark_uptodate(folio); + folio_unlock(folio); + folio_put(folio); } =20 if (err) --=20 2.34.1 From nobody Sun Nov 24 21:24:37 2024 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (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 CC13D156649; Fri, 1 Nov 2024 08:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449098; cv=none; b=CCRa0CoLSXOGmNGjlRRNvR+XXTg/pkXgRoh6vbKmNNYfFYzFB1awC+J2yRgvLGkM95fdL/PjjNbbM4EnkxqgcG+71p6LpPzeHhpT5mEBGM3G9TjOD1rq1R5IokrVfGnCKtyWBDNIWheM3CfuenFOK8gJmevcMp79YwokCCwHldE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449098; c=relaxed/simple; bh=eEjdEWKEObATwCOy3KVNohZ3Bg9faDxQpQEjE01gX7E=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FBH0x9dCpKM4HA8Z69JR/gIHGaIDGx7q1BH+gLJIX8fKulkWP55K9CmaiRFS35NrVc8oQ7L3H276lv3VSvUGDDp/ZseFlAj7uXFTW++3N0zgrfVxFxY1gOaWOZ4ry1jxL+vvDzIgkc9ttyAoqclQvkh7SAeUPxNYKnuvoUSMEWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=XpCgs4qU; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="XpCgs4qU" Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id E50CB2198; Fri, 1 Nov 2024 08:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1730448625; bh=6wt1rNVXCzuM0Dm6pcjSNL7+UwMV97d4q0WaqD2PInU=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XpCgs4qUTjjovzfOdYUGp7KTmY6NdMlkqjpvVgEB1Q8oSsd52VOn5lgmVcajicX/m gdAwU7Rhj1U/p7Gf7jHwlDe5YD5kUPySdsffRtPx/uuJsQ57uc8aSlnSyUnC4Wiwiy wqhxQAAEnWbHqA0lz3M2EDy7dbHUGR3TkEpzKQAE= Received: from ntfs3vm.paragon-software.com (192.168.211.142) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 1 Nov 2024 11:18:08 +0300 From: Konstantin Komarov To: CC: , , Konstantin Komarov Subject: [PATCH 7/7] fs/ntfs3: Accumulated refactoring changes Date: Fri, 1 Nov 2024 11:17:53 +0300 Message-ID: <20241101081753.10585-8-almaz.alexandrovich@paragon-software.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> References: <20241101081753.10585-1-almaz.alexandrovich@paragon-software.com> 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-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Content-Type: text/plain; charset="utf-8" Changes made to improve readability and debuggability. Signed-off-by: Konstantin Komarov --- fs/ntfs3/bitmap.c | 62 +++++++++++++--------------------------------- fs/ntfs3/frecord.c | 1 - fs/ntfs3/fsntfs.c | 2 +- fs/ntfs3/run.c | 6 ++--- 4 files changed, 21 insertions(+), 50 deletions(-) diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index cf4fe21a5039..04107b950717 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -710,20 +710,17 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, = size_t bits) { int err =3D 0; struct super_block *sb =3D wnd->sb; - size_t bits0 =3D bits; u32 wbits =3D 8 * sb->s_blocksize; size_t iw =3D bit >> (sb->s_blocksize_bits + 3); u32 wbit =3D bit & (wbits - 1); struct buffer_head *bh; + u32 op; =20 - while (iw < wnd->nwnd && bits) { - u32 tail, op; - + for (; iw < wnd->nwnd && bits; iw++, bit +=3D op, bits -=3D op, wbit =3D = 0) { if (iw + 1 =3D=3D wnd->nwnd) wbits =3D wnd->bits_last; =20 - tail =3D wbits - wbit; - op =3D min_t(u32, tail, bits); + op =3D min_t(u32, wbits - wbit, bits); =20 bh =3D wnd_map(wnd, iw); if (IS_ERR(bh)) { @@ -736,20 +733,15 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, = size_t bits) ntfs_bitmap_clear_le(bh->b_data, wbit, op); =20 wnd->free_bits[iw] +=3D op; + wnd->total_zeroes +=3D op; =20 set_buffer_uptodate(bh); mark_buffer_dirty(bh); unlock_buffer(bh); put_bh(bh); =20 - wnd->total_zeroes +=3D op; - bits -=3D op; - wbit =3D 0; - iw +=3D 1; + wnd_add_free_ext(wnd, bit, op, false); } - - wnd_add_free_ext(wnd, bit, bits0, false); - return err; } =20 @@ -760,20 +752,17 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, = size_t bits) { int err =3D 0; struct super_block *sb =3D wnd->sb; - size_t bits0 =3D bits; size_t iw =3D bit >> (sb->s_blocksize_bits + 3); u32 wbits =3D 8 * sb->s_blocksize; u32 wbit =3D bit & (wbits - 1); struct buffer_head *bh; + u32 op; =20 - while (iw < wnd->nwnd && bits) { - u32 tail, op; - + for (; iw < wnd->nwnd && bits; iw++, bit +=3D op, bits -=3D op, wbit =3D = 0) { if (unlikely(iw + 1 =3D=3D wnd->nwnd)) wbits =3D wnd->bits_last; =20 - tail =3D wbits - wbit; - op =3D min_t(u32, tail, bits); + op =3D min_t(u32, wbits - wbit, bits); =20 bh =3D wnd_map(wnd, iw); if (IS_ERR(bh)) { @@ -785,21 +774,16 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, = size_t bits) =20 ntfs_bitmap_set_le(bh->b_data, wbit, op); wnd->free_bits[iw] -=3D op; + wnd->total_zeroes -=3D op; =20 set_buffer_uptodate(bh); mark_buffer_dirty(bh); unlock_buffer(bh); put_bh(bh); =20 - wnd->total_zeroes -=3D op; - bits -=3D op; - wbit =3D 0; - iw +=3D 1; + if (!RB_EMPTY_ROOT(&wnd->start_tree)) + wnd_remove_free_ext(wnd, bit, op); } - - if (!RB_EMPTY_ROOT(&wnd->start_tree)) - wnd_remove_free_ext(wnd, bit, bits0); - return err; } =20 @@ -852,15 +836,13 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, s= ize_t bit, size_t bits) size_t iw =3D bit >> (sb->s_blocksize_bits + 3); u32 wbits =3D 8 * sb->s_blocksize; u32 wbit =3D bit & (wbits - 1); + u32 op; =20 - while (iw < wnd->nwnd && bits) { - u32 tail, op; - + for (; iw < wnd->nwnd && bits; iw++, bits -=3D op, wbit =3D 0) { if (unlikely(iw + 1 =3D=3D wnd->nwnd)) wbits =3D wnd->bits_last; =20 - tail =3D wbits - wbit; - op =3D min_t(u32, tail, bits); + op =3D min_t(u32, wbits - wbit, bits); =20 if (wbits !=3D wnd->free_bits[iw]) { bool ret; @@ -875,10 +857,6 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, si= ze_t bit, size_t bits) if (!ret) return false; } - - bits -=3D op; - wbit =3D 0; - iw +=3D 1; } =20 return true; @@ -928,6 +906,7 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, si= ze_t bits) size_t iw =3D bit >> (sb->s_blocksize_bits + 3); u32 wbits =3D 8 * sb->s_blocksize; u32 wbit =3D bit & (wbits - 1); + u32 op; size_t end; struct rb_node *n; struct e_node *e; @@ -945,14 +924,11 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, = size_t bits) return false; =20 use_wnd: - while (iw < wnd->nwnd && bits) { - u32 tail, op; - + for (; iw < wnd->nwnd && bits; iw++, bits -=3D op, wbit =3D 0) { if (unlikely(iw + 1 =3D=3D wnd->nwnd)) wbits =3D wnd->bits_last; =20 - tail =3D wbits - wbit; - op =3D min_t(u32, tail, bits); + op =3D min_t(u32, wbits - wbit, bits); =20 if (wnd->free_bits[iw]) { bool ret; @@ -966,10 +942,6 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, s= ize_t bits) if (!ret) goto out; } - - bits -=3D op; - wbit =3D 0; - iw +=3D 1; } ret =3D true; =20 diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index c33e818b3164..8b39d0ce5f28 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -1958,7 +1958,6 @@ int ni_fiemap(struct ntfs_inode *ni, struct fiemap_ex= tent_info *fieinfo, if (end > alloc_size) end =3D alloc_size; =20 - while (vbo < end) { if (idx =3D=3D -1) { ok =3D run_lookup_entry(&run, vcn, &lcn, &clen, &idx); diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 0fa636038b4e..03471bc9371c 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -2699,4 +2699,4 @@ int ntfs_set_label(struct ntfs_sb_info *sbi, u8 *labe= l, int len) out: __putname(uni); return err; -} \ No newline at end of file +} diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c index 48566dff0dc9..6e86d66197ef 100644 --- a/fs/ntfs3/run.c +++ b/fs/ntfs3/run.c @@ -1112,9 +1112,9 @@ int run_unpack_ex(struct runs_tree *run, struct ntfs_= sb_info *sbi, CLST ino, err =3D wnd_set_used_safe(wnd, lcn, len, &done); if (zone) { /* Restore zone. Lock mft run. */ - struct rw_semaphore *lock; - lock =3D is_mounted(sbi) ? &sbi->mft.ni->file.run_lock : - NULL; + struct rw_semaphore *lock =3D + is_mounted(sbi) ? &sbi->mft.ni->file.run_lock : + NULL; if (lock) down_read(lock); ntfs_refresh_zone(sbi); --=20 2.34.1