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
3054 if (node) {3054 if (node) {
3055 ASSERT(list_empty(&node->list));3055 ASSERT(list_empty(&node->list));
3056 ASSERT(list_empty(&node->lower));3056 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);
3058 cache->nr_nodes--;3061 cache->nr_nodes--;
3059 btrfs_put_root(node->root);3062 btrfs_put_root(node->root);
3060 kfree(node);3063 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
476 if (inode->flags & BTRFS_INODE_NODATACOW ||476 if (inode->flags & BTRFS_INODE_NODATACOW ||
477 inode->flags & BTRFS_INODE_NODATASUM)477 inode->flags & BTRFS_INODE_NODATASUM)
478 return false;478 return false;
479 if (btrfs_is_data_reloc_root(inode->root))
480 return false;
479 return true;481 return true;
480}482}
481 483
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
2004 2004
2005 btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);2005 btrfs_set_header_flag(eb, BTRFS_HEADER_FLAG_WRITTEN);
2006 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes,2006 percpu_counter_add_batch(&fs_info->dirty_metadata_bytes,
2007 -eb->len,2007 -(s64)eb->len,
2008 fs_info->dirty_metadata_batch);2008 fs_info->dirty_metadata_batch);
2009 ret = true;2009 ret = true;
2010 } else {2010 } else {
@@ -3774,7 +3774,7 @@ void btrfs_clear_buffer_dirty(struct btrfs_trans_handle *trans, · 1763 unmodified lines
3774 return;3774 return;
3775 3775
3776 buffer_tree_clear_mark(eb, PAGECACHE_TAG_DIRTY);3776 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,
3778 fs_info->dirty_metadata_batch);3778 fs_info->dirty_metadata_batch);
3779 3779
3780 for (int i = 0; i < num_extent_folios(eb); i++) {3780 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
866 goto next;866 goto next;
867 }867 }
868 868
869 flags = em->flags;
870 /*869 /*
871 * In case we split the extent map, we want to preserve the870 * In case we split the extent map, we want to preserve the
872 * EXTENT_FLAG_LOGGING flag on our extent map, but we don't want871 * EXTENT_FLAG_LOGGING flag on our extent map, but we don't want
873 * it on the new extent maps.872 * it on the new extent maps.
874 */873 */
875 em->flags &= ~(EXTENT_FLAG_PINNED | EXTENT_FLAG_LOGGING);874 flags = em->flags & ~EXTENT_FLAG_LOGGING;
875 em->flags &= ~EXTENT_FLAG_PINNED;
876 modified = !list_empty(&em->list);876 modified = !list_empty(&em->list);
877 877
878 /*878 /*
fs/btrfs/inode.c+2−1
@@ -8068,7 +8068,8 @@ static int btrfs_getattr(struct mnt_idmap *idmap, · 8067 unmodified lines
8068 stat->result_mask |= STATX_SUBVOL;8068 stat->result_mask |= STATX_SUBVOL;
8069 8069
8070 spin_lock(&BTRFS_I(inode)->lock);8070 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;
8072 inode_bytes = inode_get_bytes(inode);8073 inode_bytes = inode_get_bytes(inode);
8073 spin_unlock(&BTRFS_I(inode)->lock);8074 spin_unlock(&BTRFS_I(inode)->lock);
8074 stat->blocks = (ALIGN(inode_bytes, blocksize) +8075 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
2048 ret = -ENOENT;2048 ret = -ENOENT;
2049 goto out;2049 goto out;
2050 }2050 }
2051 ret = 0;
2051 }2052 }
2052 2053
2053out:2054out:
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
588 btrfs_err(fs_info,588 btrfs_err(fs_info,
589 "Duplicate root found for start=%llu while inserting into relocation tree",589 "Duplicate root found for start=%llu while inserting into relocation tree",
590 node->bytenr);590 node->bytenr);
591 kfree(node);
591 return -EEXIST;592 return -EEXIST;
592 }593 }
593 594
@@ -890,6 +891,13 @@ static int get_new_location(struct inode *reloc_inode, u64 *new_bytenr, · 296 unmodified lines
890 leaf = path->nodes[0];891 leaf = path->nodes[0];
891 fi = btrfs_item_ptr(leaf, path->slots[0],892 fi = btrfs_item_ptr(leaf, path->slots[0],
892 struct btrfs_file_extent_item);893 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 }
893 901
894 /*902 /*
895 * The cluster-boundary key searched above is always written by903 * 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
1518 return 0;1526 return 0;
1519}1527}
1520 1528
1529static 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
1521static int clean_dirty_subvols(struct reloc_control *rc)1540static int clean_dirty_subvols(struct reloc_control *rc)
1522{1541{
1523 struct btrfs_root *root;1542 struct btrfs_root *root;
@@ -1532,13 +1551,7 @@ static int clean_dirty_subvols(struct reloc_control *rc) · 8 unmodified lines
1532 struct btrfs_root *reloc_root = root->reloc_root;1551 struct btrfs_root *reloc_root = root->reloc_root;
1533 1552
1534 list_del_init(&root->reloc_dirty_list);1553 list_del_init(&root->reloc_dirty_list);
1535 root->reloc_root = NULL;1554 clear_reloc_root(root);
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);
1542 if (reloc_root) {1555 if (reloc_root) {
1543 /*1556 /*
1544 * btrfs_drop_snapshot drops our ref we hold for1557 * btrfs_drop_snapshot drops our ref we hold for
@@ -1914,21 +1927,39 @@ again: · 369 unmodified lines
1914 goto out;1927 goto out;
1915 }1928 }
1916 ret = merge_reloc_root(rc, root);1929 ret = merge_reloc_root(rc, root);
1917 btrfs_put_root(root);
1918 if (ret) {1930 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)) {
1920 list_add_tail(&reloc_root->root_list,1947 list_add_tail(&reloc_root->root_list,
1921 &reloc_roots);1948 &reloc_roots);
1949 btrfs_grab_root(reloc_root);
1950 }
1951 /* Now drop the ref for root->reloc_root. */
1952 btrfs_put_root(reloc_root);
1922 goto out;1953 goto out;
1923 }1954 }
1955 btrfs_put_root(root);
1924 } else {1956 } else {
1925 if (!IS_ERR(root)) {1957 if (!IS_ERR(root)) {
1926 if (root->reloc_root == reloc_root) {1958 if (root->reloc_root == reloc_root) {
1927 root->reloc_root = NULL;1959 clear_reloc_root(root);
1960 /* Drop the ref for root->reloc_root. */
1928 btrfs_put_root(reloc_root);1961 btrfs_put_root(reloc_root);
1929 }1962 }
1930 clear_bit(BTRFS_ROOT_DEAD_RELOC_TREE,
1931 &root->state);
1932 btrfs_put_root(root);1963 btrfs_put_root(root);
1933 }1964 }
1934 1965
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
359 folio_mark_dirty(folio);359 folio_mark_dirty(folio);
360}360}
361 361
362static 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
362/*379/*
363 * Extra clear_and_test function for subpage dirty bitmap.380 * Extra clear_and_test function for subpage dirty bitmap.
364 *381 *
@@ -403,7 +420,6 @@ void btrfs_subpage_set_writeback(const struct btrfs_fs_info *fs_info, · 38 unmodified lines
403 unsigned int start_bit = subpage_calc_start_bit(fs_info, folio,420 unsigned int start_bit = subpage_calc_start_bit(fs_info, folio,
404 writeback, start, len);421 writeback, start, len);
405 unsigned long flags;422 unsigned long flags;
406 bool keep_write;
407 423
408 spin_lock_irqsave(&bfs->lock, flags);424 spin_lock_irqsave(&bfs->lock, flags);
409 bitmap_set(bfs->bitmaps, start_bit, len >> fs_info->sectorsize_bits);425 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
413 * folio. Doing so can cause WB_SYNC_ALL writepages() to overlook it,429 * folio. Doing so can cause WB_SYNC_ALL writepages() to overlook it,
414 * assume writeback is complete, and exit too early — violating sync430 * assume writeback is complete, and exit too early — violating sync
415 * ordering guarantees.431 * ordering guarantees.
432 *
433 * Instead we manually clear the DIRTY and TOWRITE tags after the folio
434 * is no longer dirty.
416 */435 */
417 keep_write = folio_test_dirty(folio);
418 if (!folio_test_writeback(folio))436 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);
420 spin_unlock_irqrestore(&bfs->lock, flags);440 spin_unlock_irqrestore(&bfs->lock, flags);
421}441}
422 442
include/uapi/linux/btrfs.h+1−1
@@ -598,7 +598,7 @@ struct btrfs_ioctl_search_args_v2 { · 597 unmodified lines
598 __u64 buf_size; /* in - size of buffer598 __u64 buf_size; /* in - size of buffer
599 * out - on EOVERFLOW: needed size599 * out - on EOVERFLOW: needed size
600 * to store item */600 * to store item */
601 __u64 buf[]; /* out - found items */601 __u8 buf[]; /* out - found items */
602};602};
603 603
604/* With a @src_length of zero, the range from @src_offset->EOF is cloned! */604/* 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