Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull btrfs fixes from David Sterba:

- fix a regression in nowait + buffered write

- in zoned mode fix endianness when comparing super block generation

- locking and lockdep fixes:
- fix potential sleeping under spinlock when setting qgroup limit
- lockdep warning fixes when btrfs_path is freed after copy_to_user
- do not modify log tree while holding a leaf from fs tree locked

- fix freeing of sysfs files of static features on error

- use kv.alloc for zone map allocation as a fallback to avoid warnings
due to high order allocation

- send, avoid unaligned encoded writes when attempting to clone range

* tag 'for-6.1-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: sysfs: normalize the error handling branch in btrfs_init_sysfs()
btrfs: do not modify log tree while holding a leaf from fs tree locked
btrfs: use kvcalloc in btrfs_get_dev_zone_info
btrfs: qgroup: fix sleep from invalid context bug in btrfs_qgroup_inherit()
btrfs: send: avoid unaligned encoded writes when attempting to clone range
btrfs: zoned: fix missing endianness conversion in sb_write_pointer
btrfs: free btrfs_path before copying subvol info to userspace
btrfs: free btrfs_path before copying fspath to userspace
btrfs: free btrfs_path before copying inodes to userspace
btrfs: free btrfs_path before copying root refs to userspace
btrfs: fix assertion failure and blocking during nowait buffered write

+132 -35
+30 -6
fs/btrfs/ctree.c
··· 4663 4663 int ret; 4664 4664 int i; 4665 4665 4666 - ASSERT(!path->nowait); 4666 + /* 4667 + * The nowait semantics are used only for write paths, where we don't 4668 + * use the tree mod log and sequence numbers. 4669 + */ 4670 + if (time_seq) 4671 + ASSERT(!path->nowait); 4667 4672 4668 4673 nritems = btrfs_header_nritems(path->nodes[0]); 4669 4674 if (nritems == 0) ··· 4688 4683 if (path->need_commit_sem) { 4689 4684 path->need_commit_sem = 0; 4690 4685 need_commit_sem = true; 4691 - down_read(&fs_info->commit_root_sem); 4686 + if (path->nowait) { 4687 + if (!down_read_trylock(&fs_info->commit_root_sem)) { 4688 + ret = -EAGAIN; 4689 + goto done; 4690 + } 4691 + } else { 4692 + down_read(&fs_info->commit_root_sem); 4693 + } 4692 4694 } 4693 4695 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 4694 4696 } ··· 4771 4759 next = c; 4772 4760 ret = read_block_for_search(root, path, &next, level, 4773 4761 slot, &key); 4774 - if (ret == -EAGAIN) 4762 + if (ret == -EAGAIN && !path->nowait) 4775 4763 goto again; 4776 4764 4777 4765 if (ret < 0) { ··· 4781 4769 4782 4770 if (!path->skip_locking) { 4783 4771 ret = btrfs_try_tree_read_lock(next); 4772 + if (!ret && path->nowait) { 4773 + ret = -EAGAIN; 4774 + goto done; 4775 + } 4784 4776 if (!ret && time_seq) { 4785 4777 /* 4786 4778 * If we don't get the lock, we may be racing ··· 4815 4799 4816 4800 ret = read_block_for_search(root, path, &next, level, 4817 4801 0, &key); 4818 - if (ret == -EAGAIN) 4802 + if (ret == -EAGAIN && !path->nowait) 4819 4803 goto again; 4820 4804 4821 4805 if (ret < 0) { ··· 4823 4807 goto done; 4824 4808 } 4825 4809 4826 - if (!path->skip_locking) 4827 - btrfs_tree_read_lock(next); 4810 + if (!path->skip_locking) { 4811 + if (path->nowait) { 4812 + if (!btrfs_try_tree_read_lock(next)) { 4813 + ret = -EAGAIN; 4814 + goto done; 4815 + } 4816 + } else { 4817 + btrfs_tree_read_lock(next); 4818 + } 4819 + } 4828 4820 } 4829 4821 ret = 0; 4830 4822 done:
+13 -10
fs/btrfs/ioctl.c
··· 3105 3105 } 3106 3106 } 3107 3107 3108 + btrfs_free_path(path); 3109 + path = NULL; 3108 3110 if (copy_to_user(argp, subvol_info, sizeof(*subvol_info))) 3109 3111 ret = -EFAULT; 3110 3112 ··· 3196 3194 } 3197 3195 3198 3196 out: 3197 + btrfs_free_path(path); 3198 + 3199 3199 if (!ret || ret == -EOVERFLOW) { 3200 3200 rootrefs->num_items = found; 3201 3201 /* update min_treeid for next search */ ··· 3209 3205 } 3210 3206 3211 3207 kfree(rootrefs); 3212 - btrfs_free_path(path); 3213 3208 3214 3209 return ret; 3215 3210 } ··· 4234 4231 ipath->fspath->val[i] = rel_ptr; 4235 4232 } 4236 4233 4234 + btrfs_free_path(path); 4235 + path = NULL; 4237 4236 ret = copy_to_user((void __user *)(unsigned long)ipa->fspath, 4238 4237 ipath->fspath, size); 4239 4238 if (ret) { ··· 4286 4281 size = min_t(u32, loi->size, SZ_16M); 4287 4282 } 4288 4283 4284 + inodes = init_data_container(size); 4285 + if (IS_ERR(inodes)) { 4286 + ret = PTR_ERR(inodes); 4287 + goto out_loi; 4288 + } 4289 + 4289 4290 path = btrfs_alloc_path(); 4290 4291 if (!path) { 4291 4292 ret = -ENOMEM; 4292 4293 goto out; 4293 4294 } 4294 - 4295 - inodes = init_data_container(size); 4296 - if (IS_ERR(inodes)) { 4297 - ret = PTR_ERR(inodes); 4298 - inodes = NULL; 4299 - goto out; 4300 - } 4301 - 4302 4295 ret = iterate_inodes_from_logical(loi->logical, fs_info, path, 4303 4296 inodes, ignore_offset); 4297 + btrfs_free_path(path); 4304 4298 if (ret == -EINVAL) 4305 4299 ret = -ENOENT; 4306 4300 if (ret < 0) ··· 4311 4307 ret = -EFAULT; 4312 4308 4313 4309 out: 4314 - btrfs_free_path(path); 4315 4310 kvfree(inodes); 4316 4311 out_loi: 4317 4312 kfree(loi);
+1 -8
fs/btrfs/qgroup.c
··· 2951 2951 dstgroup->rsv_rfer = inherit->lim.rsv_rfer; 2952 2952 dstgroup->rsv_excl = inherit->lim.rsv_excl; 2953 2953 2954 - ret = update_qgroup_limit_item(trans, dstgroup); 2955 - if (ret) { 2956 - qgroup_mark_inconsistent(fs_info); 2957 - btrfs_info(fs_info, 2958 - "unable to update quota limit for %llu", 2959 - dstgroup->qgroupid); 2960 - goto unlock; 2961 - } 2954 + qgroup_dirty(fs_info, dstgroup); 2962 2955 } 2963 2956 2964 2957 if (srcid) {
+23 -1
fs/btrfs/send.c
··· 5702 5702 u64 ext_len; 5703 5703 u64 clone_len; 5704 5704 u64 clone_data_offset; 5705 + bool crossed_src_i_size = false; 5705 5706 5706 5707 if (slot >= btrfs_header_nritems(leaf)) { 5707 5708 ret = btrfs_next_leaf(clone_root->root, path); ··· 5760 5759 if (key.offset >= clone_src_i_size) 5761 5760 break; 5762 5761 5763 - if (key.offset + ext_len > clone_src_i_size) 5762 + if (key.offset + ext_len > clone_src_i_size) { 5764 5763 ext_len = clone_src_i_size - key.offset; 5764 + crossed_src_i_size = true; 5765 + } 5765 5766 5766 5767 clone_data_offset = btrfs_file_extent_offset(leaf, ei); 5767 5768 if (btrfs_file_extent_disk_bytenr(leaf, ei) == disk_byte) { ··· 5824 5821 ret = send_clone(sctx, offset, clone_len, 5825 5822 clone_root); 5826 5823 } 5824 + } else if (crossed_src_i_size && clone_len < len) { 5825 + /* 5826 + * If we are at i_size of the clone source inode and we 5827 + * can not clone from it, terminate the loop. This is 5828 + * to avoid sending two write operations, one with a 5829 + * length matching clone_len and the final one after 5830 + * this loop with a length of len - clone_len. 5831 + * 5832 + * When using encoded writes (BTRFS_SEND_FLAG_COMPRESSED 5833 + * was passed to the send ioctl), this helps avoid 5834 + * sending an encoded write for an offset that is not 5835 + * sector size aligned, in case the i_size of the source 5836 + * inode is not sector size aligned. That will make the 5837 + * receiver fallback to decompression of the data and 5838 + * writing it using regular buffered IO, therefore while 5839 + * not incorrect, it's not optimal due decompression and 5840 + * possible re-compression at the receiver. 5841 + */ 5842 + break; 5827 5843 } else { 5828 5844 ret = send_extent_data(sctx, dst_path, offset, 5829 5845 clone_len);
+5 -2
fs/btrfs/sysfs.c
··· 2321 2321 2322 2322 #ifdef CONFIG_BTRFS_DEBUG 2323 2323 ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_debug_feature_attr_group); 2324 - if (ret) 2325 - goto out2; 2324 + if (ret) { 2325 + sysfs_unmerge_group(&btrfs_kset->kobj, 2326 + &btrfs_static_feature_attr_group); 2327 + goto out_remove_group; 2328 + } 2326 2329 #endif 2327 2330 2328 2331 return 0;
+55 -4
fs/btrfs/tree-log.c
··· 3694 3694 u64 *last_old_dentry_offset) 3695 3695 { 3696 3696 struct btrfs_root *log = inode->root->log_root; 3697 - struct extent_buffer *src = path->nodes[0]; 3698 - const int nritems = btrfs_header_nritems(src); 3697 + struct extent_buffer *src; 3698 + const int nritems = btrfs_header_nritems(path->nodes[0]); 3699 3699 const u64 ino = btrfs_ino(inode); 3700 3700 bool last_found = false; 3701 3701 int batch_start = 0; 3702 3702 int batch_size = 0; 3703 3703 int i; 3704 3704 3705 - for (i = path->slots[0]; i < nritems; i++) { 3705 + /* 3706 + * We need to clone the leaf, release the read lock on it, and use the 3707 + * clone before modifying the log tree. See the comment at copy_items() 3708 + * about why we need to do this. 3709 + */ 3710 + src = btrfs_clone_extent_buffer(path->nodes[0]); 3711 + if (!src) 3712 + return -ENOMEM; 3713 + 3714 + i = path->slots[0]; 3715 + btrfs_release_path(path); 3716 + path->nodes[0] = src; 3717 + path->slots[0] = i; 3718 + 3719 + for (; i < nritems; i++) { 3706 3720 struct btrfs_dir_item *di; 3707 3721 struct btrfs_key key; 3708 3722 int ret; ··· 4317 4303 { 4318 4304 struct btrfs_root *log = inode->root->log_root; 4319 4305 struct btrfs_file_extent_item *extent; 4320 - struct extent_buffer *src = src_path->nodes[0]; 4306 + struct extent_buffer *src; 4321 4307 int ret = 0; 4322 4308 struct btrfs_key *ins_keys; 4323 4309 u32 *ins_sizes; ··· 4327 4313 int dst_index; 4328 4314 const bool skip_csum = (inode->flags & BTRFS_INODE_NODATASUM); 4329 4315 const u64 i_size = i_size_read(&inode->vfs_inode); 4316 + 4317 + /* 4318 + * To keep lockdep happy and avoid deadlocks, clone the source leaf and 4319 + * use the clone. This is because otherwise we would be changing the log 4320 + * tree, to insert items from the subvolume tree or insert csum items, 4321 + * while holding a read lock on a leaf from the subvolume tree, which 4322 + * creates a nasty lock dependency when COWing log tree nodes/leaves: 4323 + * 4324 + * 1) Modifying the log tree triggers an extent buffer allocation while 4325 + * holding a write lock on a parent extent buffer from the log tree. 4326 + * Allocating the pages for an extent buffer, or the extent buffer 4327 + * struct, can trigger inode eviction and finally the inode eviction 4328 + * will trigger a release/remove of a delayed node, which requires 4329 + * taking the delayed node's mutex; 4330 + * 4331 + * 2) Allocating a metadata extent for a log tree can trigger the async 4332 + * reclaim thread and make us wait for it to release enough space and 4333 + * unblock our reservation ticket. The reclaim thread can start 4334 + * flushing delayed items, and that in turn results in the need to 4335 + * lock delayed node mutexes and in the need to write lock extent 4336 + * buffers of a subvolume tree - all this while holding a write lock 4337 + * on the parent extent buffer in the log tree. 4338 + * 4339 + * So one task in scenario 1) running in parallel with another task in 4340 + * scenario 2) could lead to a deadlock, one wanting to lock a delayed 4341 + * node mutex while having a read lock on a leaf from the subvolume, 4342 + * while the other is holding the delayed node's mutex and wants to 4343 + * write lock the same subvolume leaf for flushing delayed items. 4344 + */ 4345 + src = btrfs_clone_extent_buffer(src_path->nodes[0]); 4346 + if (!src) 4347 + return -ENOMEM; 4348 + 4349 + i = src_path->slots[0]; 4350 + btrfs_release_path(src_path); 4351 + src_path->nodes[0] = src; 4352 + src_path->slots[0] = i; 4330 4353 4331 4354 ins_data = kmalloc(nr * sizeof(struct btrfs_key) + 4332 4355 nr * sizeof(u32), GFP_NOFS);
+5 -4
fs/btrfs/zoned.c
··· 134 134 super[i] = page_address(page[i]); 135 135 } 136 136 137 - if (super[0]->generation > super[1]->generation) 137 + if (btrfs_super_generation(super[0]) > 138 + btrfs_super_generation(super[1])) 138 139 sector = zones[1].start; 139 140 else 140 141 sector = zones[0].start; ··· 467 466 goto out; 468 467 } 469 468 470 - zones = kcalloc(BTRFS_REPORT_NR_ZONES, sizeof(struct blk_zone), GFP_KERNEL); 469 + zones = kvcalloc(BTRFS_REPORT_NR_ZONES, sizeof(struct blk_zone), GFP_KERNEL); 471 470 if (!zones) { 472 471 ret = -ENOMEM; 473 472 goto out; ··· 586 585 } 587 586 588 587 589 - kfree(zones); 588 + kvfree(zones); 590 589 591 590 switch (bdev_zoned_model(bdev)) { 592 591 case BLK_ZONED_HM: ··· 618 617 return 0; 619 618 620 619 out: 621 - kfree(zones); 620 + kvfree(zones); 622 621 out_free_zone_info: 623 622 btrfs_destroy_dev_zone_info(device); 624 623