History

Merge tag 'for-7.2-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux

Pull btrfs fixes from David Sterba: "I'm catching up with the fix backlog in the development branch, so here's a number of them and will probably send one more for this or the next rc: - relocation fixes: - skip attempting compression on reloc inodes - exclude inline extents from file extent offset checks - fix minor memory leak after error when adding reloc root - fix root cleanup after inserting and merging - fix clearing folio tags after writeback - clear logging flag of extent map before splitting - fix unsigned 32/64 type conversions when accounting dirty metadata, leading to continually exceeding threshold - fix regression in 32bit compat ioctl for subvolume info - fix type of SEARCH_TREE ioctl buffer in UAPI header - fix expression in ASSERT expression which can be unconditionally evaluated on some compilers - only account delalloc bytes for regular inodes" * tag 'for-7.2-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: fix GET_SUBVOL_INFO after compat refactor btrfs: free mapping node on duplicate reloc root insert btrfs: fix a regression where PAGECACHE_TAG_DIRTY is never cleared btrfs: don't propagate EXTENT_FLAG_LOGGING to split extent maps btrfs: fix u32 to s64 type conversion in dirty_metadata_bytes accounting btrfs: fix NULL pointer deref during assertion in btrfs_backref_free_node() btrfs: only account delalloc bytes for regular file inodes in btrfs_getattr() btrfs: reject inline file extents item in get_new_location() btrfs: do not try compression for data reloc inodes btrfs: declare btrfs_ioctl_search_args_v2::buf as __u8 btrfs: fix reloc root cleanup in merge_reloc_roots() btrfs: fix use-after-free on reloc root after error in insert_dirty_subvol()

Linus Torvalds committed 3 months ago

Commit 51f247c2 parents b95f03f 75a41e39 files · +80 −22Browse files

Unified · Split

9 files
  1. fs/btrfs/backref.c +4 −1
  2. fs/btrfs/btrfs_inode.h +2 −0
  3. fs/btrfs/extent_io.c +2 −2
  4. fs/btrfs/extent_map.c +2 −2
  5. fs/btrfs/inode.c +2 −1
  6. fs/btrfs/ioctl.c +1 −0
  7. fs/btrfs/relocation.c +43 −12
  8. fs/btrfs/subpage.c +23 −3
  9. include/uapi/linux/btrfs.h +1 −1
fs/btrfs/backref.c+4−1
@@ -3054,7 +3054,10 @@ void btrfs_backref_free_node(struct btrfs_backref_cache *cache, · 3053 unmodified lines
30543054 if (node) {
30553055 ASSERT(list_empty(&node->list));
30563056 ASSERT(list_empty(&node->lower));
3057− ASSERT(node->eb == NULL, "node->eb->start=%llu", node->eb->start);
3057+ ASSERT(node->eb == NULL, "node->eb->start=%llu level=%d owner=%llu",
3058+ node->eb ? node->eb->start : 0,
3059+ node->eb ? btrfs_header_level(node->eb) : 0,
3060+ node->eb ? btrfs_header_owner(node->eb) : 0);
30583061 cache->nr_nodes--;
30593062 btrfs_put_root(node->root);
30603063 kfree(node);
fs/btrfs/btrfs_inode.h+2−0
@@ -476,6 +476,8 @@ static inline bool btrfs_inode_can_compress(const struct btrfs_inode *inode) · 475 unmodified lines
476476 if (inode->flags & BTRFS_INODE_NODATACOW ||
477477 inode->flags & BTRFS_INODE_NODATASUM)
478478 return false;
479+ if (btrfs_is_data_reloc_root(inode->root))
480+ return false;
479481 return true;
480482 }
481483
fs/btrfs/extent_io.c+2−2
@@ -2004,7 +2004,7 @@ static noinline_for_stack bool lock_extent_buffer_for_io(struct extent_buffer *e · 2003 unmodified lines
20042004
20052005 btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);
20062006 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes,
2007− -eb->len,
2007+ -(s64)eb->len,
20082008 fs_info->dirty_metadata_batch);
20092009 ret = true;
20102010 } else {
@@ -3774,7 +3774,7 @@ void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans, · 1763 unmodified lines
37743774 return;
37753775
37763776 buffer_tree_clear_mark(eb, PAGECACHE_TAG_DIRTY);
3777− percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, -eb->len,
3777+ percpu_counter_add_batch(&fs_info->dirty_metadata_bytes, -(s64)eb->len,
37783778 fs_info->dirty_metadata_batch);
37793779
37803780 for (int i = 0; i < num_extent_folios(eb); i++) {
fs/btrfs/extent_map.c+2−2
@@ -866,13 +866,13 @@ void btrfs_drop_extent_map_range(struct btrfs_inode *inode, u64 start, u64 end, · 865 unmodified lines
866866 goto next;
867867 }
868868
869− flags = em->flags;
870869 /*
871870 * In case we split the extent map, we want to preserve the
872871 * EXTENT_FLAG_LOGGING flag on our extent map, but we don't want
873872 * it on the new extent maps.
874873 */
875− em->flags &= ~(EXTENT_FLAG_PINNED | EXTENT_FLAG_LOGGING);
874+ flags = em->flags & ~EXTENT_FLAG_LOGGING;
875+ em->flags &= ~EXTENT_FLAG_PINNED;
876876 modified = !list_empty(&em->list);
877877
878878 /*
fs/btrfs/inode.c+2−1
@@ -8068,7 +8068,8 @@ static int btrfs_getattr(struct mnt_idmap *idmap, · 8067 unmodified lines
80688068 stat->result_mask |= STATX_SUBVOL;
80698069
80708070 spin_lock(&BTRFS_I(inode)->lock);
8071− delalloc_bytes = BTRFS_I(inode)->new_delalloc_bytes;
8071+ delalloc_bytes = S_ISREG(inode->i_mode) ?
8072+ BTRFS_I(inode)->new_delalloc_bytes : 0;
80728073 inode_bytes = inode_get_bytes(inode);
80738074 spin_unlock(&BTRFS_I(inode)->lock);
80748075 stat->blocks = (ALIGN(inode_bytes, blocksize) +
fs/btrfs/ioctl.c+1−0
@@ -2048,6 +2048,7 @@ static int _btrfs_ioctl_get_subvol_info(struct inode *inode, · 2047 unmodified lines
20482048 ret = -ENOENT;
20492049 goto out;
20502050 }
2051+ ret = 0;
20512052 }
20522053
20532054 out:
fs/btrfs/relocation.c+43−12
@@ -588,6 +588,7 @@ static int __add_reloc_root(struct btrfs_root *root, struct reloc_control *rc) · 587 unmodified lines
588588 btrfs_err(fs_info,
589589 "Duplicate root found for start=%llu while inserting into relocation tree",
590590 node->bytenr);
591+ kfree(node);
591592 return -EEXIST;
592593 }
593594
@@ -890,6 +891,13 @@ static int get_new_location(struct inode *reloc_inode, u64 *new_bytenr, · 296 unmodified lines
890891 leaf = path->nodes[0];
891892 fi = btrfs_item_ptr(leaf, path->slots[0],
892893 struct btrfs_file_extent_item);
894+ if (unlikely(btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE)) {
895+ btrfs_print_leaf(leaf);
896+ btrfs_err(fs_info,
897+ "unexpected inline file extent item for data reloc inode %llu key offset %llu",
898+ btrfs_ino(BTRFS_I(reloc_inode)), bytenr);
899+ return -EUCLEAN;
900+ }
893901
894902 /*
895903 * The cluster-boundary key searched above is always written by
@@ -1518,6 +1526,17 @@ static int insert_dirty_subvol(struct btrfs_trans_handle *trans, · 622 unmodified lines
15181526 return 0;
15191527 }
15201528
1529+static void clear_reloc_root(struct btrfs_root *root)
1530+{
1531+ root->reloc_root = NULL;
1532+ /*
1533+ * Need barrier to ensure clear_bit() only happens after
1534+ * root->reloc_root = NULL. Pairs with have_reloc_root().
1535+ */
1536+ smp_wmb();
1537+ clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
1538+}
1539+
15211540 static int clean_dirty_subvols(struct reloc_control *rc)
15221541 {
15231542 struct btrfs_root *root;
@@ -1532,13 +1551,7 @@ static int clean_dirty_subvols(struct reloc_control *rc) · 8 unmodified lines
15321551 struct btrfs_root *reloc_root = root->reloc_root;
15331552
15341553 list_del_init(&root->reloc_dirty_list);
1535− root->reloc_root = NULL;
1536− /*
1537− * Need barrier to ensure clear_bit() only happens after
1538− * root->reloc_root = NULL. Pairs with have_reloc_root.
1539− */
1540− smp_wmb();
1541− clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
1554+ clear_reloc_root(root);
15421555 if (reloc_root) {
15431556 /*
15441557 * btrfs_drop_snapshot drops our ref we hold for
@@ -1914,21 +1927,39 @@ again: · 369 unmodified lines
19141927 goto out;
19151928 }
19161929 ret = merge_reloc_root(rc, root);
1917− btrfs_put_root(root);
19181930 if (ret) {
1919− if (list_empty(&reloc_root->root_list))
1931+ /*
1932+ * Clear the reloc root since below we will call
1933+ * free_reloc_roots(), otherwise we leave
1934+ * root->reloc_root pointing to a freed reloc
1935+ * root and trigger a use-after-free during
1936+ * unmount or elsewhere.
1937+ */
1938+ clear_reloc_root(root);
1939+ btrfs_put_root(root);
1940+ /*
1941+ * We are adding the reloc_root to the local
1942+ * reloc_roots list, so we add a ref for this
1943+ * list which will be dropped below by the call
1944+ * to free_reloc_roots().
1945+ */
1946+ if (list_empty(&reloc_root->root_list)) {
19201947 list_add_tail(&reloc_root->root_list,
19211948 &reloc_roots);
1949+ btrfs_grab_root(reloc_root);
1950+ }
1951+ /* Now drop the ref for root->reloc_root. */
1952+ btrfs_put_root(reloc_root);
19221953 goto out;
19231954 }
1955+ btrfs_put_root(root);
19241956 } else {
19251957 if (!IS_ERR(root)) {
19261958 if (root->reloc_root == reloc_root) {
1927− root->reloc_root = NULL;
1959+ clear_reloc_root(root);
1960+ /* Drop the ref for root->reloc_root. */
19281961 btrfs_put_root(reloc_root);
19291962 }
1930− clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE,
1931− &root->state);
19321963 btrfs_put_root(root);
19331964 }
19341965
fs/btrfs/subpage.c+23−3
@@ -359,6 +359,23 @@ void btrfs_subpage_set_dirty(const struct btrfs_fs_info *fs_info, · 358 unmodified lines
359359 folio_mark_dirty(folio);
360360 }
361361
362+static void folio_clear_tags(struct folio *folio)
363+{
364+ struct address_space *mapping = folio_mapping(folio);
365+ XA_STATE(xas, &mapping->i_pages, folio->index);
366+ unsigned long flags;
367+
368+ ASSERT(folio_test_locked(folio));
369+ ASSERT(mapping);
370+ ASSERT(mapping_use_writeback_tags(mapping));
371+
372+ xas_lock_irqsave(&xas, flags);
373+ xas_load(&xas);
374+ xas_clear_mark(&xas, PAGECACHE_TAG_DIRTY);
375+ xas_clear_mark(&xas, PAGECACHE_TAG_TOWRITE);
376+ xas_unlock_irqrestore(&xas, flags);
377+}
378+
362379 /*
363380 * Extra clear_and_test function for subpage dirty bitmap.
364381 *
@@ -403,7 +420,6 @@ void btrfs_subpage_set_writeback(const struct btrfs_fs_info *fs_info, · 38 unmodified lines
403420 unsigned int start_bit = subpage_calc_start_bit(fs_info, folio,
404421 writeback, start, len);
405422 unsigned long flags;
406− bool keep_write;
407423
408424 spin_lock_irqsave(&bfs->lock, flags);
409425 bitmap_set(bfs->bitmaps, start_bit, len >> fs_info->sectorsize_bits);
@@ -413,10 +429,14 @@ void btrfs_subpage_set_writeback(const struct btrfs_fs_info *fs_info, · 3 unmodified lines
413429 * folio. Doing so can cause WB_SYNC_ALL writepages() to overlook it,
414430 * assume writeback is complete, and exit too early — violating sync
415431 * ordering guarantees.
432+ *
433+ * Instead we manually clear the DIRTY and TOWRITE tags after the folio
434+ * is no longer dirty.
416435 */
417− keep_write = folio_test_dirty(folio);
418436 if (!folio_test_writeback(folio))
419− __folio_start_writeback(folio, keep_write);
437+ __folio_start_writeback(folio, true);
438+ if (!folio_test_dirty(folio))
439+ folio_clear_tags(folio);
420440 spin_unlock_irqrestore(&bfs->lock, flags);
421441 }
422442
include/uapi/linux/btrfs.h+1−1
@@ -598,7 +598,7 @@ struct btrfs_ioctl_search_args_v2 { · 597 unmodified lines
598598 __u64 buf_size; /* in - size of buffer
599599 * out - on EOVERFLOW: needed size
600600 * to store item */
601− __u64 buf[]; /* out - found items */
601+ __u8 buf[]; /* out - found items */
602602 };
603603
604604 /* With a @src_length of zero, the range from @src_offset->EOF is cloned! */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t