History

Merge tag 'ext4_for_linus-6.6-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 fixes from Ted Ts'o: "Regression and bug fixes for ext4" * tag 'ext4_for_linus-6.6-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: fix rec_len verify error ext4: do not let fstrim block system suspend ext4: move setting of trimmed bit into ext4_try_to_trim_range() jbd2: Fix memory leak in journal_init_common() jbd2: Remove page size assumptions buffer: Make bh_offset() work for compound pages

Linus Torvalds committed 3 years ago

Commit 3fde3002 parents f0b0d40 7fda67e6 files · +64 −51Browse files

Unified · Split

6 files
  1. fs/ext4/mballoc.c +33 −21
  2. fs/ext4/namei.c +15 −11
  3. fs/jbd2/commit.c +6 −10
  4. fs/jbd2/journal.c +2 −0
  5. fs/jbd2/transaction.c +4 −8
  6. include/linux/buffer_head.h +4 −1
fs/ext4/mballoc.c+33−21
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 #include <linux/slab.h>
1717 #include <linux/nospec.h>
1818 #include <linux/backing-dev.h>
19+#include <linux/freezer.h>
1920 #include <trace/events/ext4.h>
2021
2122 /*
@@ -6906,6 +6907,21 @@ __acquires(bitlock) · 6884 unmodified lines
69066907 return ret;
69076908 }
69086909
6910+static ext4_grpblk_t ext4_last_grp_cluster(struct super_block *sb,
6911+ ext4_group_t grp)
6912+{
6913+ if (grp < ext4_get_groups_count(sb))
6914+ return EXT4_CLUSTERS_PER_GROUP(sb) - 1;
6915+ return (ext4_blocks_count(EXT4_SB(sb)->s_es) -
6916+ ext4_group_first_block_no(sb, grp) - 1) >>
6917+ EXT4_CLUSTER_BITS(sb);
6918+}
6919+
6920+static bool ext4_trim_interrupted(void)
6921+{
6922+ return fatal_signal_pending(current) || freezing(current);
6923+}
6924+
69096925 static int ext4_try_to_trim_range(struct super_block *sb,
69106926 struct ext4_buddy *e4b, ext4_grpblk_t start,
69116927 ext4_grpblk_t max, ext4_grpblk_t minblocks)
@@ -6913,9 +6929,12 @@ __acquires(ext4_group_lock_ptr(sb, e4b->bd_group)) · 1 unmodified line
69136929 __releases(ext4_group_lock_ptr(sb, e4b->bd_group))
69146930 {
69156931 ext4_grpblk_t next, count, free_count;
6932+ bool set_trimmed = false;
69166933 void *bitmap;
69176934
69186935 bitmap = e4b->bd_bitmap;
6936+ if (start == 0 && max >= ext4_last_grp_cluster(sb, e4b->bd_group))
6937+ set_trimmed = true;
69196938 start = max(e4b->bd_info->bb_first_free, start);
69206939 count = 0;
69216940 free_count = 0;
@@ -6930,16 +6949,14 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group)) · 8 unmodified lines
69306949 int ret = ext4_trim_extent(sb, start, next - start, e4b);
69316950
69326951 if (ret && ret != -EOPNOTSUPP)
6933− break;
6952+ return count;
69346953 count += next - start;
69356954 }
69366955 free_count += next - start;
69376956 start = next + 1;
69386957
6939− if (fatal_signal_pending(current)) {
6940− count = -ERESTARTSYS;
6941− break;
6942− }
6958+ if (ext4_trim_interrupted())
6959+ return count;
69436960
69446961 if (need_resched()) {
69456962 ext4_unlock_group(sb, e4b->bd_group);
@@ -6951,6 +6968,9 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group)) · 5 unmodified lines
69516968 break;
69526969 }
69536970
6971+ if (set_trimmed)
6972+ EXT4_MB_GRP_SET_TRIMMED(e4b->bd_info);
6973+
69546974 return count;
69556975 }
69566976
@@ -6961,7 +6981,6 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group)) · 4 unmodified lines
69616981 * @start: first group block to examine
69626982 * @max: last group block to examine
69636983 * @minblocks: minimum extent block count
6964− * @set_trimmed: set the trimmed flag if at least one block is trimmed
69656984 *
69666985 * ext4_trim_all_free walks through group's block bitmap searching for free
69676986 * extents. When the free extent is found, mark it as used in group buddy
@@ -6971,7 +6990,7 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group)) · 3 unmodified lines
69716990 static ext4_grpblk_t
69726991 ext4_trim_all_free(struct super_block *sb, ext4_group_t group,
69736992 ext4_grpblk_t start, ext4_grpblk_t max,
6974− ext4_grpblk_t minblocks, bool set_trimmed)
6993+ ext4_grpblk_t minblocks)
69756994 {
69766995 struct ext4_buddy e4b;
69776996 int ret;
@@ -6988,13 +7007,10 @@ ext4_trim_all_free(struct super_block *sb, ext4_group_t group, · 10 unmodified lines
69887007 ext4_lock_group(sb, group);
69897008
69907009 if (!EXT4_MB_GRP_WAS_TRIMMED(e4b.bd_info) ||
6991− minblocks < EXT4_SB(sb)->s_last_trim_minblks) {
7010+ minblocks < EXT4_SB(sb)->s_last_trim_minblks)
69927011 ret = ext4_try_to_trim_range(sb, &e4b, start, max, minblocks);
6993− if (ret >= 0 && set_trimmed)
6994− EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
6995− } else {
7012+ else
69967013 ret = 0;
6997− }
69987014
69997015 ext4_unlock_group(sb, group);
70007016 ext4_mb_unload_buddy(&e4b);
@@ -7027,7 +7043,6 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) · 26 unmodified lines
70277043 ext4_fsblk_t first_data_blk =
70287044 le32_to_cpu(EXT4_SB(sb)->s_es->s_first_data_block);
70297045 ext4_fsblk_t max_blks = ext4_blocks_count(EXT4_SB(sb)->s_es);
7030− bool whole_group, eof = false;
70317046 int ret = 0;
70327047
70337048 start = range->start >> sb->s_blocksize_bits;
@@ -7046,10 +7061,8 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) · 12 unmodified lines
70467061 if (minlen > EXT4_CLUSTERS_PER_GROUP(sb))
70477062 goto out;
70487063 }
7049− if (end >= max_blks - 1) {
7064+ if (end >= max_blks - 1)
70507065 end = max_blks - 1;
7051− eof = true;
7052− }
70537066 if (end <= first_data_blk)
70547067 goto out;
70557068 if (start < first_data_blk)
@@ -7063,9 +7076,10 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) · 7 unmodified lines
70637076
70647077 /* end now represents the last cluster to discard in this group */
70657078 end = EXT4_CLUSTERS_PER_GROUP(sb) - 1;
7066− whole_group = true;
70677079
70687080 for (group = first_group; group <= last_group; group++) {
7081+ if (ext4_trim_interrupted())
7082+ break;
70697083 grp = ext4_get_group_info(sb, group);
70707084 if (!grp)
70717085 continue;
@@ -7082,13 +7096,11 @@ int ext4_trim_fs(struct super_block *sb, struct fstrim_range *range) · 10 unmodified lines
70827096 * change it for the last group, note that last_cluster is
70837097 * already computed earlier by ext4_get_group_no_and_offset()
70847098 */
7085− if (group == last_group) {
7099+ if (group == last_group)
70867100 end = last_cluster;
7087− whole_group = eof ? true : end == EXT4_CLUSTERS_PER_GROUP(sb) - 1;
7088− }
70897101 if (grp->bb_free >= minlen) {
70907102 cnt = ext4_trim_all_free(sb, group, first_cluster,
7091− end, minlen, whole_group);
7103+ end, minlen);
70927104 if (cnt < 0) {
70937105 ret = cnt;
70947106 break;
fs/ext4/namei.c+15−11
@@ -343,17 +343,17 @@ static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode, · 342 unmodified lines
343343 struct buffer_head *bh)
344344 {
345345 struct ext4_dir_entry_tail *t;
346+ int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
346347
347348 #ifdef PARANOID
348349 struct ext4_dir_entry *d, *top;
349350
350351 d = (struct ext4_dir_entry *)bh->b_data;
351352 top = (struct ext4_dir_entry *)(bh->b_data +
352− (EXT4_BLOCK_SIZE(inode->i_sb) -
353− sizeof(struct ext4_dir_entry_tail)));
354− while (d < top && d->rec_len)
353+ (blocksize - sizeof(struct ext4_dir_entry_tail)));
354+ while (d < top && ext4_rec_len_from_disk(d->rec_len, blocksize))
355355 d = (struct ext4_dir_entry *)(((void *)d) +
356− le16_to_cpu(d->rec_len));
356+ ext4_rec_len_from_disk(d->rec_len, blocksize));
357357
358358 if (d != top)
359359 return NULL;
@@ -364,7 +364,8 @@ static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode, · 4 unmodified lines
364364 #endif
365365
366366 if (t->det_reserved_zero1 ||
367− le16_to_cpu(t->det_rec_len) != sizeof(struct ext4_dir_entry_tail) ||
367+ (ext4_rec_len_from_disk(t->det_rec_len, blocksize) !=
368+ sizeof(struct ext4_dir_entry_tail)) ||
368369 t->det_reserved_zero2 ||
369370 t->det_reserved_ft != EXT4_FT_DIR_CSUM)
370371 return NULL;
@@ -445,13 +446,14 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode, · 74 unmodified lines
445446 struct ext4_dir_entry *dp;
446447 struct dx_root_info *root;
447448 int count_offset;
449+ int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
450+ unsigned int rlen = ext4_rec_len_from_disk(dirent->rec_len, blocksize);
448451
449− if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
452+ if (rlen == blocksize)
450453 count_offset = 8;
451− else if (le16_to_cpu(dirent->rec_len) == 12) {
454+ else if (rlen == 12) {
452455 dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
453− if (le16_to_cpu(dp->rec_len) !=
454− EXT4_BLOCK_SIZE(inode->i_sb) - 12)
456+ if (ext4_rec_len_from_disk(dp->rec_len, blocksize) != blocksize - 12)
455457 return NULL;
456458 root = (struct dx_root_info *)(((void *)dp + 12));
457459 if (root->reserved_zero ||
@@ -1315,6 +1317,7 @@ static int dx_make_map(struct inode *dir, struct buffer_head *bh, · 857 unmodified lines
13151317 unsigned int buflen = bh->b_size;
13161318 char *base = bh->b_data;
13171319 struct dx_hash_info h = *hinfo;
1320+ int blocksize = EXT4_BLOCK_SIZE(dir->i_sb);
13181321
13191322 if (ext4_has_metadata_csum(dir->i_sb))
13201323 buflen -= sizeof(struct ext4_dir_entry_tail);
@@ -1335,11 +1338,12 @@ static int dx_make_map(struct inode *dir, struct buffer_head *bh, · 14 unmodified lines
13351338 map_tail--;
13361339 map_tail->hash = h.hash;
13371340 map_tail->offs = ((char *) de - base)>>2;
1338− map_tail->size = le16_to_cpu(de->rec_len);
1341+ map_tail->size = ext4_rec_len_from_disk(de->rec_len,
1342+ blocksize);
13391343 count++;
13401344 cond_resched();
13411345 }
1342− de = ext4_next_entry(de, dir->i_sb->s_blocksize);
1346+ de = ext4_next_entry(de, blocksize);
13431347 }
13441348 return count;
13451349 }
fs/jbd2/commit.c+6−10
@@ -298,14 +298,12 @@ static int journal_finish_inode_data_buffers(journal_t *journal, · 297 unmodified lines
298298
299299 static __u32 jbd2_checksum_data(__u32 crc32_sum, struct buffer_head *bh)
300300 {
301− struct page *page = bh->b_page;
302301 char *addr;
303302 __u32 checksum;
304303
305− addr = kmap_atomic(page);
306− checksum = crc32_be(crc32_sum,
307− (void *)(addr + offset_in_page(bh->b_data)), bh->b_size);
308− kunmap_atomic(addr);
304+ addr = kmap_local_folio(bh->b_folio, bh_offset(bh));
305+ checksum = crc32_be(crc32_sum, addr, bh->b_size);
306+ kunmap_local(addr);
309307
310308 return checksum;
311309 }
@@ -322,7 +320,6 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, · 10 unmodified lines
322320 struct buffer_head *bh, __u32 sequence)
323321 {
324322 journal_block_tag3_t *tag3 = (journal_block_tag3_t *)tag;
325− struct page *page = bh->b_page;
326323 __u8 *addr;
327324 __u32 csum32;
328325 __be32 seq;
@@ -331,11 +328,10 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, · 2 unmodified lines
331328 return;
332329
333330 seq = cpu_to_be32(sequence);
334− addr = kmap_atomic(page);
331+ addr = kmap_local_folio(bh->b_folio, bh_offset(bh));
335332 csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq));
336− csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data),
337− bh->b_size);
338− kunmap_atomic(addr);
333+ csum32 = jbd2_chksum(j, csum32, addr, bh->b_size);
334+ kunmap_local(addr);
339335
340336 if (jbd2_has_feature_csum3(j))
341337 tag3->t_checksum = cpu_to_be32(csum32);
fs/jbd2/journal.c+2−0
@@ -1601,6 +1601,8 @@ static journal_t *journal_init_common(struct block_device *bdev, · 1600 unmodified lines
16011601
16021602 err_cleanup:
16031603 percpu_counter_destroy(&journal->j_checkpoint_jh_count);
1604+ if (journal->j_chksum_driver)
1605+ crypto_free_shash(journal->j_chksum_driver);
16041606 kfree(journal->j_wbuf);
16051607 jbd2_journal_destroy_revoke(journal);
16061608 journal_fail_superblock(journal);
fs/jbd2/transaction.c+4−8
@@ -935,19 +935,15 @@ static void warn_dirty_buffer(struct buffer_head *bh) · 934 unmodified lines
935935 /* Call t_frozen trigger and copy buffer data into jh->b_frozen_data. */
936936 static void jbd2_freeze_jh_data(struct journal_head *jh)
937937 {
938− struct page *page;
939− int offset;
940938 char *source;
941939 struct buffer_head *bh = jh2bh(jh);
942940
943941 J_EXPECT_JH(jh, buffer_uptodate(bh), "Possible IO failure.\n");
944− page = bh->b_page;
945− offset = offset_in_page(bh->b_data);
946− source = kmap_atomic(page);
942+ source = kmap_local_folio(bh->b_folio, bh_offset(bh));
947943 /* Fire data frozen trigger just before we copy the data */
948− jbd2_buffer_frozen_trigger(jh, source + offset, jh->b_triggers);
949− memcpy(jh->b_frozen_data, source + offset, bh->b_size);
950− kunmap_atomic(source);
944+ jbd2_buffer_frozen_trigger(jh, source, jh->b_triggers);
945+ memcpy(jh->b_frozen_data, source, bh->b_size);
946+ kunmap_local(source);
951947
952948 /*
953949 * Now that the frozen data is saved off, we need to store any matching
include/linux/buffer_head.h+4−1
@@ -171,7 +171,10 @@ static __always_inline int buffer_uptodate(const struct buffer_head *bh) · 170 unmodified lines
171171 return test_bit_acquire(BH_Uptodate, &bh->b_state);
172172 }
173173
174−#define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
174+static inline unsigned long bh_offset(const struct buffer_head *bh)
175+{
176+ return (unsigned long)(bh)->b_data & (page_size(bh->b_page) - 1);
177+}
175178
176179 /* If we *know* page->private refers to buffer_heads */
177180 #define page_buffers(page) \