Skip to content

Commit 1fdae00

Browse files
committed
Pull ntfs3 updates from Konstantin Komarov: - additional checks to address issues identified by syzbot - continuation of the transition from 'page' to 'folio' * tag 'ntfs3_for_6.13' of https://github.com/Paragon-Software-Group/linux-ntfs3: fs/ntfs3: Accumulated refactoring changes fs/ntfs3: Switch to folio to release resources fs/ntfs3: Add check in ntfs_extend_initialized_size fs/ntfs3: Add more checks in mi_enum_attr (part 2) fs/ntfs3: Equivalent transition from page to folio fs/ntfs3: Fix case when unmarked clusters intersect with zone fs/ntfs3: Fix warning in ni_fiemap
2 parents 8170a99 + bac89bb commit 1fdae00

File tree

8 files changed

+103
-167
lines changed

8 files changed

+103
-167
lines changed

fs/ntfs3/attrib.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST vcn, CLST clen, CLST *lcn,
977977

978978
/* Check for compressed frame. */
979979
err = attr_is_frame_compressed(ni, attr_b, vcn >> NTFS_LZNT_CUNIT,
980-
&hint);
980+
&hint, run);
981981
if (err)
982982
goto out;
983983

@@ -1521,16 +1521,16 @@ int attr_wof_frame_info(struct ntfs_inode *ni, struct ATTRIB *attr,
15211521
* attr_is_frame_compressed - Used to detect compressed frame.
15221522
*
15231523
* attr - base (primary) attribute segment.
1524+
* run - run to use, usually == &ni->file.run.
15241525
* Only base segments contains valid 'attr->nres.c_unit'
15251526
*/
15261527
int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
1527-
CLST frame, CLST *clst_data)
1528+
CLST frame, CLST *clst_data, struct runs_tree *run)
15281529
{
15291530
int err;
15301531
u32 clst_frame;
15311532
CLST clen, lcn, vcn, alen, slen, vcn_next;
15321533
size_t idx;
1533-
struct runs_tree *run;
15341534

15351535
*clst_data = 0;
15361536

@@ -1542,7 +1542,6 @@ int attr_is_frame_compressed(struct ntfs_inode *ni, struct ATTRIB *attr,
15421542

15431543
clst_frame = 1u << attr->nres.c_unit;
15441544
vcn = frame * clst_frame;
1545-
run = &ni->file.run;
15461545

15471546
if (!run_lookup_entry(run, vcn, &lcn, &clen, &idx)) {
15481547
err = attr_load_runs_vcn(ni, attr->type, attr_name(attr),
@@ -1678,7 +1677,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,
16781677
if (err)
16791678
goto out;
16801679

1681-
err = attr_is_frame_compressed(ni, attr_b, frame, &clst_data);
1680+
err = attr_is_frame_compressed(ni, attr_b, frame, &clst_data, run);
16821681
if (err)
16831682
goto out;
16841683

fs/ntfs3/bitmap.c

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -710,20 +710,17 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
710710
{
711711
int err = 0;
712712
struct super_block *sb = wnd->sb;
713-
size_t bits0 = bits;
714713
u32 wbits = 8 * sb->s_blocksize;
715714
size_t iw = bit >> (sb->s_blocksize_bits + 3);
716715
u32 wbit = bit & (wbits - 1);
717716
struct buffer_head *bh;
717+
u32 op;
718718

719-
while (iw < wnd->nwnd && bits) {
720-
u32 tail, op;
721-
719+
for (; iw < wnd->nwnd && bits; iw++, bit += op, bits -= op, wbit = 0) {
722720
if (iw + 1 == wnd->nwnd)
723721
wbits = wnd->bits_last;
724722

725-
tail = wbits - wbit;
726-
op = min_t(u32, tail, bits);
723+
op = min_t(u32, wbits - wbit, bits);
727724

728725
bh = wnd_map(wnd, iw);
729726
if (IS_ERR(bh)) {
@@ -736,20 +733,15 @@ int wnd_set_free(struct wnd_bitmap *wnd, size_t bit, size_t bits)
736733
ntfs_bitmap_clear_le(bh->b_data, wbit, op);
737734

738735
wnd->free_bits[iw] += op;
736+
wnd->total_zeroes += op;
739737

740738
set_buffer_uptodate(bh);
741739
mark_buffer_dirty(bh);
742740
unlock_buffer(bh);
743741
put_bh(bh);
744742

745-
wnd->total_zeroes += op;
746-
bits -= op;
747-
wbit = 0;
748-
iw += 1;
743+
wnd_add_free_ext(wnd, bit, op, false);
749744
}
750-
751-
wnd_add_free_ext(wnd, bit, bits0, false);
752-
753745
return err;
754746
}
755747

@@ -760,20 +752,17 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
760752
{
761753
int err = 0;
762754
struct super_block *sb = wnd->sb;
763-
size_t bits0 = bits;
764755
size_t iw = bit >> (sb->s_blocksize_bits + 3);
765756
u32 wbits = 8 * sb->s_blocksize;
766757
u32 wbit = bit & (wbits - 1);
767758
struct buffer_head *bh;
759+
u32 op;
768760

769-
while (iw < wnd->nwnd && bits) {
770-
u32 tail, op;
771-
761+
for (; iw < wnd->nwnd && bits; iw++, bit += op, bits -= op, wbit = 0) {
772762
if (unlikely(iw + 1 == wnd->nwnd))
773763
wbits = wnd->bits_last;
774764

775-
tail = wbits - wbit;
776-
op = min_t(u32, tail, bits);
765+
op = min_t(u32, wbits - wbit, bits);
777766

778767
bh = wnd_map(wnd, iw);
779768
if (IS_ERR(bh)) {
@@ -785,21 +774,16 @@ int wnd_set_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
785774

786775
ntfs_bitmap_set_le(bh->b_data, wbit, op);
787776
wnd->free_bits[iw] -= op;
777+
wnd->total_zeroes -= op;
788778

789779
set_buffer_uptodate(bh);
790780
mark_buffer_dirty(bh);
791781
unlock_buffer(bh);
792782
put_bh(bh);
793783

794-
wnd->total_zeroes -= op;
795-
bits -= op;
796-
wbit = 0;
797-
iw += 1;
784+
if (!RB_EMPTY_ROOT(&wnd->start_tree))
785+
wnd_remove_free_ext(wnd, bit, op);
798786
}
799-
800-
if (!RB_EMPTY_ROOT(&wnd->start_tree))
801-
wnd_remove_free_ext(wnd, bit, bits0);
802-
803787
return err;
804788
}
805789

@@ -852,15 +836,13 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
852836
size_t iw = bit >> (sb->s_blocksize_bits + 3);
853837
u32 wbits = 8 * sb->s_blocksize;
854838
u32 wbit = bit & (wbits - 1);
839+
u32 op;
855840

856-
while (iw < wnd->nwnd && bits) {
857-
u32 tail, op;
858-
841+
for (; iw < wnd->nwnd && bits; iw++, bits -= op, wbit = 0) {
859842
if (unlikely(iw + 1 == wnd->nwnd))
860843
wbits = wnd->bits_last;
861844

862-
tail = wbits - wbit;
863-
op = min_t(u32, tail, bits);
845+
op = min_t(u32, wbits - wbit, bits);
864846

865847
if (wbits != wnd->free_bits[iw]) {
866848
bool ret;
@@ -875,10 +857,6 @@ static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits)
875857
if (!ret)
876858
return false;
877859
}
878-
879-
bits -= op;
880-
wbit = 0;
881-
iw += 1;
882860
}
883861

884862
return true;
@@ -928,6 +906,7 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
928906
size_t iw = bit >> (sb->s_blocksize_bits + 3);
929907
u32 wbits = 8 * sb->s_blocksize;
930908
u32 wbit = bit & (wbits - 1);
909+
u32 op;
931910
size_t end;
932911
struct rb_node *n;
933912
struct e_node *e;
@@ -945,14 +924,11 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
945924
return false;
946925

947926
use_wnd:
948-
while (iw < wnd->nwnd && bits) {
949-
u32 tail, op;
950-
927+
for (; iw < wnd->nwnd && bits; iw++, bits -= op, wbit = 0) {
951928
if (unlikely(iw + 1 == wnd->nwnd))
952929
wbits = wnd->bits_last;
953930

954-
tail = wbits - wbit;
955-
op = min_t(u32, tail, bits);
931+
op = min_t(u32, wbits - wbit, bits);
956932

957933
if (wnd->free_bits[iw]) {
958934
bool ret;
@@ -966,10 +942,6 @@ bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
966942
if (!ret)
967943
goto out;
968944
}
969-
970-
bits -= op;
971-
wbit = 0;
972-
iw += 1;
973945
}
974946
ret = true;
975947

fs/ntfs3/file.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,15 @@ static int ntfs_extend_initialized_size(struct file *file,
182182
loff_t pos = valid;
183183
int err;
184184

185+
if (valid >= new_valid)
186+
return 0;
187+
185188
if (is_resident(ni)) {
186189
ni->i_valid = new_valid;
187190
return 0;
188191
}
189192

190193
WARN_ON(is_compressed(ni));
191-
WARN_ON(valid >= new_valid);
192194

193195
for (;;) {
194196
u32 zerofrom, len;
@@ -222,7 +224,7 @@ static int ntfs_extend_initialized_size(struct file *file,
222224
if (err)
223225
goto out;
224226

225-
folio_zero_range(folio, zerofrom, folio_size(folio));
227+
folio_zero_range(folio, zerofrom, folio_size(folio) - zerofrom);
226228

227229
err = ntfs_write_end(file, mapping, pos, len, len, folio, NULL);
228230
if (err < 0)
@@ -987,6 +989,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
987989
u64 frame_vbo;
988990
pgoff_t index;
989991
bool frame_uptodate;
992+
struct folio *folio;
990993

991994
if (frame_size < PAGE_SIZE) {
992995
/*
@@ -1041,8 +1044,9 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
10411044
if (err) {
10421045
for (ip = 0; ip < pages_per_frame; ip++) {
10431046
page = pages[ip];
1044-
unlock_page(page);
1045-
put_page(page);
1047+
folio = page_folio(page);
1048+
folio_unlock(folio);
1049+
folio_put(folio);
10461050
}
10471051
goto out;
10481052
}
@@ -1052,9 +1056,10 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
10521056
off = offset_in_page(valid);
10531057
for (; ip < pages_per_frame; ip++, off = 0) {
10541058
page = pages[ip];
1059+
folio = page_folio(page);
10551060
zero_user_segment(page, off, PAGE_SIZE);
10561061
flush_dcache_page(page);
1057-
SetPageUptodate(page);
1062+
folio_mark_uptodate(folio);
10581063
}
10591064

10601065
ni_lock(ni);
@@ -1063,9 +1068,10 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
10631068

10641069
for (ip = 0; ip < pages_per_frame; ip++) {
10651070
page = pages[ip];
1066-
SetPageUptodate(page);
1067-
unlock_page(page);
1068-
put_page(page);
1071+
folio = page_folio(page);
1072+
folio_mark_uptodate(folio);
1073+
folio_unlock(folio);
1074+
folio_put(folio);
10691075
}
10701076

10711077
if (err)
@@ -1107,8 +1113,9 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
11071113
for (ip = 0; ip < pages_per_frame;
11081114
ip++) {
11091115
page = pages[ip];
1110-
unlock_page(page);
1111-
put_page(page);
1116+
folio = page_folio(page);
1117+
folio_unlock(folio);
1118+
folio_put(folio);
11121119
}
11131120
goto out;
11141121
}
@@ -1149,9 +1156,10 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from)
11491156
for (ip = 0; ip < pages_per_frame; ip++) {
11501157
page = pages[ip];
11511158
ClearPageDirty(page);
1152-
SetPageUptodate(page);
1153-
unlock_page(page);
1154-
put_page(page);
1159+
folio = page_folio(page);
1160+
folio_mark_uptodate(folio);
1161+
folio_unlock(folio);
1162+
folio_put(folio);
11551163
}
11561164

11571165
if (err)

0 commit comments

Comments
 (0)