| Age | Commit message (Collapse) | Author |
|
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba:
- zoned mode fixes
- fix counting active zones after activation
- redo zone reset after error
- update device lock range during mount and zone loading
to avoid lockdep warnings with device drivers (virtio)
- space accounting and extent buffer handling fixes
- fix keeping zstd workspace for the last level
- handle a real case of a subvolume with 0 refs in the SUBVOL_SYNC
ioctl
- properly handle case of zero num_stripes when reading chunk items
- exclude reloc tree from xarray as it is special and its key does
does not fit unsigned long on 32bit platforms
- in tree-checker, handle extent item tree owner depending on the
features (enabled in simple quota mode)
- fix bio control structure leak when checksumming fails
* tag 'for-7.4-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: fix bio counter and bioc leak when async checksumming fails
btrfs: tree-checker: reject extent owner ref without simple quota
btrfs: do not insert the data reloc tree into fs_roots_radix
btrfs: handle zero num_stripes in btrfs_chunk_item_size()
btrfs: reject refs=0 subvolume without DEAD in SUBVOL_SYNC_WAIT
btrfs: zstd: prevent leak of workspace below maximum level
btrfs: zoned: fix lockdep splat on mount
btrfs: zoned: don't wait for ordered extents in do_zone_finish()
btrfs: zoned: avoid underflow of space info bytes_zone_unusable
btrfs: zoned: requeue block group if zone reset bails out
btrfs: zoned: fix possible UAF in wait_eb_writebacks()
btrfs: zoned: only change active zone counter on successful (de)activation
|
|
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull vfs fixes from Christian Brauner:
- libfs: Make readdir on tmpfs walk the offset tree in offset order
instead of d_children to avoid skipping entries or relisting the
whole directory
It's faster too. Listing a million entries takes 114ms instead of
146ms, and 113ms instead of 470ms with four processes listing in
parallel
- iomap: Finish the ->iomap_next() conversion that started in v7.3
The nilfs2 and fuse ext_map iomap code added this merge window is
converted so now we can remove the ->iomap_begin()/->iomap_end()
fallback. We waited until the new iomap users from other trees were
in mainline otherwise this would have been very messy
- errseq: Retry with the current value when the cmpxchg() in
errseq_check_and_advance() fails to avoid an old value coming back
later hiding the errors
- aio: Hold an extra count for exit_aio() itself so it can't return
before the last free_ioctx_reqs() callback has called complete()
- pidfd: Fail the namespace ioctls with EREMOTE unless the target is
visible in the caller's pid namespace like PIDFD_GET_INFO does
- eventpoll: Wake the next waiter when a woken waiter returns early
because of a fatal signal to avoid sleeping forever
- backing-file: Pass RWF_NOAPPEND on to synchronous writes to the
backing file
- initrd: Flush the deferred fput() of the ramdisk file before mounting
root
- iov_iter: Take an unsigned long segment count in import_iovec()
The upper 32 bits of the count passed to readv(), writev() and
friends were dropped before the UIO_MAXIOV check
- splice: Advance the pipe tail before checking for a full bvec array
in splice_to_socket(). The last buffer was counted again, so MSG_MORE
was set although the pipe was empty and small TCP transfers waited
for the cork timeout
- vfs:
- Reject negative offsets for SEEK_DATA and SEEK_HOLE in
default_llseek() and use must_set_pos() for its whence handling
- Only clear tv_nsec in timestamp_truncate() when clamping changed
the seconds. Timestamps whose seconds were exactly at a
filesystem time limit lost their subsecond part
- Don't leak the kernel-internal STATX_ATTR_CHANGE_MONOTONIC in
stx_attributes_mask
- Clamp the FIONREAD result to the int range so a file with 4 GiB
left isn't reported as empty
- Fix the SEEK_CUR f_lock check
- selftests: Fix the statmount and mount_setattr tests on 32-bit and
s390, build the fchmodat2 and openat2 tests without sanitizers when
the toolchain lacks the runtimes and fix a clang warning in the
mount-notify test
- docs: Fix a docutils warning in porting.rst
* tag 'vfs-7.4-rc3.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (28 commits)
fs: fix the SEEK_CUR f_lock condition
splice, net: avoid MSG_MORE when the bvec array fills
aio: don't let exit_aio() return before complete() is done
fs: porting.rst: use literal string to avoid warning
selftests/fs/mount-notify: fix the indentation in the fsmount test
selftests: probe for sanitizer support in fchmodat2 and openat2
selftests/mount_setattr: build with a 64-bit off_t
selftests/statmount: fix format warnings on 32-bit and s390
fs: use must_set_pos() in default_llseek()
fs: reject negative offsets for SEEK_DATA and SEEK_HOLE in default_llseek()
pidfd: restrict task access ioctls to the caller's pid namespace
fs: clamp FIONREAD result to int range
eventpoll: wake the next waiter when a woken waiter is killed
statx: don't leak STATX_ATTR_CHANGE_MONOTONIC in stx_attributes_mask
vfs: preserve subsecond timestamps at filesystem time limits
iov_iter: take an unsigned long segment count in import_iovec()
lib/tests: errseq: add a concurrent check_and_advance test
errseq: don't let errseq_check_and_advance() hide later errors
backing-file: pass RWF_NOAPPEND to synchronous writes
initrd: flush deferred fput() before mounting root
...
|
|
A single failed checksum allocation can make a later device replace
hang forever. btrfs_submit_chunk() takes a dev-replace bio counter
reference and a bioc before it hands a write to the checksum worker.
If the checksum fails there (e.g., its allocation fails),
run_one_async_done() ends the bio but drops neither. The counter then
never gets back to zero and the next replace waits for it:
[ 8.369] BTRFS info (device ram0): dev_replace from /dev/ram0 (devid 1) to /dev/ram1 finished
[41.534] INFO: task btrfscsum:80 blocked for more than 20 seconds.
[41.534] btrfs_rm_dev_replace_blocked+0x135/0x180
[41.534] btrfs_dev_replace_finishing+0xefe/0x13b0
The worker is only used when CONFIG_BTRFS_EXPERIMENTAL is off and the
checksum isn't a fast one, e.g., sha256. We hit it on a sha256
filesystem.
We put the bioc and drop the counter in that error branch. We also
put the bioc on the synchronous error path and on the btrfs_split_bio()
error path, which both only drop the counter. With the fix, the
replace doesn't hang anymore.
This bug was identified and confirmed with the help of fault-injection
testing on a deterministic hypervisor currently under development. Our
C reproducer however hits it within about 35s.
Fixes: f8a53bb58ec7 ("btrfs: handle checksum generation in the storage layer")
Fixes: c7c97ceff98c ("btrfs: handle bio_split() errors")
CC: stable@vger.kernel.org # 6.6+
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Mani Tofigh <mt4022@columbia.edu>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
[BUG]
An extent item can contain an owner ref. The owner ref is correct only
when the super block has the SIMPLE_QUOTA bit. If the bit is not set,
check_extent_item() gives a WARN_ON() and then accepts the leaf :
case BTRFS_EXTENT_OWNER_REF_KEY:
WARN_ON(!btrfs_fs_incompat(fs_info, SIMPLE_QUOTA));
break;
For all other incorrect inline refs, check_extent_item() returns
-EUCLEAN. After the tree-checker accepts the leaf, a free of the extent
calls btrfs_get_extent_inline_ref_type(). This function ASSERT()s the
SIMPLE_QUOTA bit.
On a kernel with CONFIG_BTRFS_ASSERT=y, a free of such an extent gives :
WARNING: fs/btrfs/tree-checker.c:1782 at __btrfs_check_leaf
assertion failed: btrfs_fs_incompat(fs_info, SIMPLE_QUOTA),
in fs/btrfs/extent-tree.c:354
kernel BUG at fs/btrfs/extent-tree.c:354!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
RIP: 0010:btrfs_get_extent_inline_ref_type.cold
(fs/btrfs/extent-tree.c:354)
Call Trace:
lookup_inline_extent_backref (fs/btrfs/extent-tree.c:919)
lookup_extent_backref (fs/btrfs/extent-tree.c:1100)
__btrfs_free_extent.isra.0 (fs/btrfs/extent-tree.c:3319)
__btrfs_run_delayed_refs (fs/btrfs/extent-tree.c:2134)
btrfs_run_delayed_refs (fs/btrfs/extent-tree.c:2246)
btrfs_commit_transaction (fs/btrfs/transaction.c:2278)
ksys_sync (fs/sync.c:104)
Without CONFIG_BTRFS_ASSERT, the kernel gives only the WARN_ON(). Then
btrfs continues to use the owner ref.
[CAUSE]
I made a crafted image : an owner ref, no SIMPLE_QUOTA bit, and no quota
tree. I removed the file of the extent. At the next commit, btrfs
frees the extent and gives the BUG above.
For an owner ref without the SIMPLE_QUOTA bit, the tree-checker gives a
WARN_ON() and keeps the leaf. For all other inline ref types, it
rejects the leaf. Two sources can put owner refs without the
SIMPLE_QUOTA bit on a disk : a damaged or crafted image, and a kernel
without commit f2363e6fcc79 ("btrfs: fix transaction atomicity bug when
enabling simple quotas").
[FIX]
Reject the leaf with -EUCLEAN, as for all other incorrect inline refs.
Then btrfs finds the problem when it reads the leaf, and the ASSERT() is
not reached.
Link: https://syzkaller.appspot.com/bug?extid=d7d1fc7e21835ca19219
Link: https://syzkaller.appspot.com/bug?extid=4983e68a6d77180bfe33
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Siddharth Mishra <smish149@asu.edu>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
The reasons not to do so are:
- There is already a global pointer fs_info->data_reloc_root
And data reloc tree itself has TRACK_DIRTY flag set, thus its treated
as a COW-only root, not a SHAREABLE root, unlike regular subvolume
trees.
- 32-bit conflicts
Radix tree keys are unsigned longs, and therefore on 32-bit platforms
they are 32 bits wide
This means a subvolume with id 0xfffffff7, will conflict with the
truncated data reloc tree id (0xfffffffffffffff7 -> 0xfffffff7).
This will prevent btrfs from reading or creating such subvolume.
Thankfully this should be very rare, as the subvolume id is reusable,
and it's very hard to keep so many subvolumes before hitting other
limits (e.g. anon_dev limits).
So change the code to not insert data reloc tree into fs_roots_radix:
- Load the tree with a dedicated helper
The new helper, read_data_reloc_root() will call
btrfs_read_tree_root(), with refs check, then call
btrfs_init_fs_root().
It skips the fs_roots_radix tree insert completely.
- Grab data_reloc_tree as a global root
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
validate_sys_chunk_array() calls btrfs_chunk_item_size() with the
on-disk num_stripes before btrfs_check_chunk_valid() has checked the
chunk. With CONFIG_BTRFS_ASSERT=y, a zero-stripe system chunk trips
ASSERT(num_stripes) instead of being rejected:
assertion failed: num_stripes, in fs/btrfs/volumes.h:714
kernel BUG at fs/btrfs/volumes.h:714!
RIP: 0010:btrfs_validate_super+0x3ce7/0x4210
Call Trace:
open_ctree
btrfs_get_tree
vfs_get_tree
do_new_mount
Drop the assertion and compute the size as the chunk header plus
num_stripes stripes. The size is unchanged for num_stripes > 0, and a
zero-stripe chunk now reaches btrfs_check_chunk_valid(), which rejects
it, so the mount fails with -EUCLEAN.
Suggested-by: Qu Wenruo <wqu@suse.com>
Link: https://lore.kernel.org/linux-btrfs/d2ee0cc1-674e-4447-88da-d346122a43a4@suse.com/
Fixes: 2a9bb78cfd36 ("btrfs: validate system chunk array at btrfs_validate_super()")
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
[ Slightly rework the commit message. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
btrfs_ioctl_subvol_sync() assumes that a cached root with zero
references has BTRFS_ROOT_SUBVOL_DEAD set, and asserts that before
waiting for the cleaner. Two states break the assumption:
- A corrupt ROOT_ITEM with zero references and a matching orphan item,
on a writable filesystem.
- A failed subvolume deletion. btrfs_delete_subvolume() zeroes the
root references, aborts the transaction, which forces the filesystem
read-only, and then clears DEAD again. No on-disk metadata is
corrupted in this case.
With CONFIG_BTRFS_ASSERT=y, both reach a BUG().
Change the ASSERT() into a proper rejection to avoid triggering a BUG().
Fixes: 6c83d153ed86 ("btrfs: add new ioctl to wait for cleaned subvolumes")
CC: stable@vger.kernel.org
Suggested-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Link: https://lore.kernel.org/linux-btrfs/dd97efe9-91ec-495b-b698-acff1447421c@gmx.com/
Signed-off-by: Cheng Yongkang <teel4res@gmail.com>
[ Rework the commit message, drop the ad-hoc RW check. ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
When putting a workspace we always protect the workspace for the maximum
level from reclaim, since it can be used not just for that level but as
well for any level below it. However the logic is flawed because if we do
the put for a workspace at level 10 for example (maximum is level 15) and
there is currently no idle workspace for the maximum level because all
are currently being used, we don't add the workspace to the LRU list and
that can result in leaking it if we don't get more compression or
decompression requests for level 10 or any level below 10.
Fix this by skipping the addition to the LRU list only if the level of
the workspace matches the maximum level too (besides the list of idle
workspaces for the maximum level being empty).
Fixes: 3f93aef535c8 ("btrfs: add zstd compression level support")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
When mounting a filesystem on a zoned drive passed into a VM via a
virtio-blk disk lockdep sporadically complains about a possible deadlock
between BTRFS' dev_replace::rwsem and virtio-blk's vdev_mutex:
======================================================
WARNING: possible circular locking dependency detected
7.3.0-rc6+ #317 Not tainted
------------------------------------------------------
mount/7418 is trying to acquire lock:
ffff888102c07860 (&vblk->vdev_mutex){+.+.}-{4:4}, at: virtblk_report_zones+0xda/0x440
but task is already holding lock:
ffff8881fd725ea8 (&fs_info->dev_replace.rwsem){++++}-{4:4}, at: btrfs_load_block_group_zone_info+0x186/0xe50
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #4 (&fs_info->dev_replace.rwsem){++++}-{4:4}:
down_read+0x42/0x170
btrfs_map_block+0x1a6/0xe70
btrfs_submit_bbio+0x1a3/0x910
submit_one_bio+0x93/0xd0
btrfs_readahead+0x1c4/0x200
read_pages+0x56/0x200
page_cache_ra_order+0x27c/0x410
filemap_get_pages+0x12f/0x4a0
filemap_read+0xed/0x400
vfs_read+0x240/0x340
ksys_read+0x61/0xd0
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
-> #3 (mapping.invalidate_lock#3){++++}-{4:4}:
down_read+0x42/0x170
filemap_fault+0xb0/0x1a40
__do_fault+0x34/0xc0
__handle_mm_fault+0x919/0x1db0
handle_mm_fault+0x97/0x240
do_user_addr_fault+0x21d/0x690
exc_page_fault+0x8e/0x230
asm_exc_page_fault+0x26/0x30
-> #2 (vm_lock){++++}-{0:0}:
__vma_start_exclude_readers+0x91/0x1b0
__vma_start_write+0x47/0xd0
vma_expand+0x4c/0x2a0
relocate_vma_down+0x126/0x200
setup_arg_pages+0x240/0x3e0
load_elf_binary+0x1be/0x1860
bprm_execve+0x2d2/0x7b0
kernel_execve+0x107/0x130
kernel_init+0xc2/0x130
ret_from_fork+0x1ff/0x2f0
ret_from_fork_asm+0x1a/0x30
-> #1 (&mm->mmap_lock){++++}-{4:4}:
__might_fault+0x68/0xa0
_copy_to_user+0x22/0x70
blkdev_copy_zone_to_user+0x22/0x40
virtblk_report_zones+0x297/0x440
blkdev_report_zones_ioctl+0xfd/0x130
blkdev_ioctl+0x20f/0x2c0
__x64_sys_ioctl+0x86/0xd0
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
-> #0 (&vblk->vdev_mutex){+.+.}-{4:4}:
__lock_acquire+0x15a8/0x2850
lock_acquire+0xea/0x2f0
__mutex_lock+0xa7/0x10d0
virtblk_report_zones+0xda/0x440
blkdev_report_zones_cached+0x162/0x190
btrfs_get_dev_zones+0xdc/0x2c0
btrfs_load_block_group_zone_info+0x2b6/0xe50
btrfs_read_block_groups+0x338/0xc80
open_ctree+0x1aca/0x24b3
btrfs_get_tree.cold+0x105/0x26c
vfs_get_tree+0x28/0xb0
__do_sys_fsconfig+0x324/0x690
do_syscall_64+0xa3/0x4f0
entry_SYSCALL_64_after_hwframe+0x76/0x7e
other info that might help us debug this:
Chain exists of:
&vblk->vdev_mutex --> mapping.invalidate_lock#3 --> &fs_info->dev_replace.rwsem
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
rlock(&fs_info->dev_replace.rwsem);
lock(mapping.invalidate_lock#3);
lock(&fs_info->dev_replace.rwsem);
lock(&vblk->vdev_mutex);
*** DEADLOCK ***
locks held by mount/7418: 3, last CPU#0:
#0: ffff888110aa6868 (&fc->uapi_mutex){+.+.}-{4:4}, at: __do_sys_fsconfig+0x2ae/0x690
#1: ffff888112ba20e8 (&type->s_umount_key#31/1){+.+.}-{4:4}, at: sget_fc+0x148/0x8d0
#2: ffff8881fd725ea8 (&fs_info->dev_replace.rwsem){++++}-{4:4}, at: btrfs_load_block_group_zone_info+0x186/0xe50
Holding the rwsem was widened in 0090d6e1b210 ("btrfs: zoned: fix
use-after-free due to race with dev replace"), but it now also covers
calling into blkdev_report_zones_cached(). The device replace ioctl()
only works on a mounted filesystem and the only caller with setting
'new' to false is read_one_block_group() which is only called during
mount, so it is safe to drop the rwsem before calling into
blkdev_report_zones_cached().
Fixes: 0090d6e1b210 ("btrfs: zoned: fix use-after-free due to race with dev replace")
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
do_zone_finish() calls btrfs_wait_ordered_roots(), which holds
fs_info->ordered_operations_mutex while waiting for writeback. It can be
reached from writeback itself:
cow_file_range()
`-> btrfs_reserve_extent()
`-> find_free_extent()
`-> btrfs_zone_finish_one_bg()
`-> do_zone_finish()
If another task holds the mutex and waits for that writeback, this
deadlocks.
In general, we want to ensure all writes in the block group to
complete before finishing the zone, as relocation does. However, the
current callers do not need the wait (or cannot wait) in do_zone_finish():
- Relocation already waits for reservations and ordered extents itself
before calling btrfs_zone_finish().
- btrfs_delete_unused_bgs() checks that ->reserved is zero and sets the
block group read-only while holding groups_sem, so there can be no
in-flight data write.
- btrfs_zone_finish_one_bg() is called from the allocation path and
cannot wait.
Dropping the wait is still safe. Once the block group is read-only,
->reserved can only drop, and for data it only drops after the ordered
extent's I/O has completed. So if ->reserved is zero, no data write is
left in flight. If it is non-zero, do_zone_finish() returns -EAGAIN,
which all callers handle.
This makes btrfs_zone_finish_one_bg() fail with -EAGAIN when it races
with an allocation in the selected block group.
Fixes: 393f646e34c1 ("btrfs: zoned: finish least available block group on data bg allocation")
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
The two functions btrfs_free_reserved_bytes() and
btrfs_reset_unused_block_groups() both manipulate
space_info->bytes_zone_unusable without using the accessor function
btrfs_space_info_update_bytes_zone_unusable() potentially risking an
underflow (in case of btrfs_reset_unused_block_groups()).
Use btrfs_space_info_update_bytes_zone_unusable() in both function, in
the case of btrfs_free_reserved_bytes() it is mostly for documenting
purposes.
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
btrfs_reset_unused_block_groups() drops the block-group from
fs_info->unused_bgs before performing the work that can actually fail,
the actual submission of a REQ_OP_ZONE_RESET.
Every failed operation after this leaves the block-group dangling,
physically reset, but the in-memory structures aren't and it is not
requeued to be reset on fs_info->unused_bgs.
Instead of bailing out, re-add this block-group to fs_info->unused_bgs
list.
Fixes: 453a73c3069a ("btrfs: zoned: reclaim unused zone by zone resetting")
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
wait_eb_writebacks() iterates the fs_info->buffer_tree xarray and waits
for the writeback of these extent-buffers. Waiting for writeback needs
to be done without the rcu_read_lock() held (because it can sleep) and
thus the loop drops the rcu_read_lock() before calling into
wait_on_extent_buffer_writeback(). But extent_buffers are freed through
RCU, so if btrfs_release_extent_buffer_rcu() is scheduled while we're
still waiting on the writeback, the extent_buffer will be freed causing
a use-after-free.
Similar to what is done in find_extent_buffer_nolock(), get a reference
to the extent_buffer before calling into
wait_on_extent_buffer_writeback() so a successful writeback does not
free the extent_buffer while we still have a reference to it.
Fixes: 2dd7e7bc0282 ("btrfs: zoned: wait for extent buffer IOs before finishing a zone")
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
btrfs_zone_activate() unconditionally decrements the reserved_active_zones
counter regardless if btrfs_dev_set_active_zone() fails to set the zone
active, i.e. because it raced with another call that already set the bit
in the bitmask, or not.
This can lead to a double decrement of the counter in case the bit has
already been set.
Only decrement the counter *iff* btrfs_dev_set_active_zone() successfully
marked the zone in the bitmap.
Mirror this behaviour when clearing the bit again.
Fixes: a7e1ac7bdc5a ("btrfs: zoned: reserve zones for an active metadata/system block group")
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba:
"A btrfs fixes. The ones that could have some user noticeable impact
are enumerated, the rest is one-liners.
- fix chattr failing on files with nodatasum and compress flags
- fix inode defrag status with concurrent truncation so it's not
skipped in defrag in the future
- fix merging compressed extent in fiemap output
- fix deleting wrong subvolume by id if it gets renamed during the
ioctl
- error handling fixes: sysfs, quotas, fs-verity, scrub, zoned mode"
* tag 'for-7.4-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: zoned: fix double free of bitmaps on clone failure
btrfs: prevent deleting the wrong subvolume by ID
btrfs: scrub: fix race between scrub and scrub progress ioctl
btrfs: scrub: fix race leading to use-after-free in the scrub progress ioctl
btrfs: scrub: fix lost wakeup and hang when cancelling a scrub that is finishing
btrfs: scrub: fix lost error return value when scrubbing raid56 parity stripe
btrfs: fix fiemap merging compressed extents
btrfs: fix the fsverity callback where unexpected range is verified
btrfs: verity: propagate orphan insertion errors when enabling verity
btrfs: sysfs: restore NOFS context on early return in btrfs_sysfs_add_block_group_type()
btrfs: defrag: prevent inode truncated to zero from not being defragged again
btrfs: cleanup dirty_cowonly_roots during btrfs_free_fs_roots()
btrfs: cleanup qgroup swapped blocks at root release
btrfs: always remove quota_root from dirty_cowonly_roots
btrfs: unwind device add when sysfs registration fails
btrfs: fix chattr failing on nodatasum files that have the compress flag
|
|
Now that all filesystems implement ->iomap_next() and the legacy
->iomap_begin()/->iomap_end() fallback is gone, struct iomap_ops only
wraps a single iomap_next function pointer. Drop the struct entirely and
pass the iomap_iter_next_fn directly to iomap_iter() and all the
iomap/dax entry points. Filesystems pass their iomap_iter_next_fn
callback directly instead of an ops struct. Several iomap_iter_next_fn
callbacks become non-static and gain header declarations since callers
now reference them directly.
The iomap_iter tracepoint's ops field is renamed to next to match. These
tracepoints are explicitly not stable ABI (see the note in iomap/trace.h).
No functional change intended other than the tracepoint field rename
noted above.
Acked-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Link: https://patch.msgid.link/20261027215326.2693300-5-joannelkoong@gmail.com
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
|
|
btrfs_clone_dev_zone_info() duplicates the original orig_dev->zone_info
with kmemdup(), which also copies the seq_zones, empty_zones and
active_zones pointers. The clone then replaces them one by one with
fresh bitmaps. If one of the allocations fails, the error path frees all
three pointers, including those not yet replaced, which still point to
the bitmaps owned by the original device.
Clear the three pointers right after kmemdup() so the error path only frees
what this function allocated.
Fixes: 21e61ec6d0bb ("btrfs: zoned: clone zoned device info when cloning a device")
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
When deleting a subvolume by ID, btrfs_ioctl_snap_destroy() first
resolves the requested ID to a name, then looks up that name again
under the parent directory lock.
A concurrent rename can change which subvolume is associated with
the name between these operations. Since the deletion path does not
verify the ID of the resolved subvolume, it can delete a different
subvolume while leaving the requested one intact.
This was reproduced by repeatedly exchanging the names of two
subvolumes using renameat2(RENAME_EXCHANGE) while deleting one of
them by ID. The wrong subvolume was deleted in 9 out of 14 independent
tests.
Fix this by checking that the resolved subvolume ID matches the
requested ID while holding the parent directory lock. Return -EAGAIN
on a mismatch so that userspace can retry the operation instead of
being told that the requested subvolume does not exist.
Fixes: 949964c92843 ("btrfs: add new BTRFS_IOC_SNAP_DESTROY_V2 ioctl")
CC: stable@vger.kernel.org
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: guolingxing <guolingxing@tju.edu.cn>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
The scrub progress ioctl is copying the scrub progress stats without
acquiring the spinlock that protects it and a concurrent scrub can be
updating the stats at the same time which can lead to load tearing
issues. So take the spinlock when copying the progress stats.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
If the scrub progress ioctl is called when replace is about to finish, we
have a race that can result in a use-after-free of the scrub context:
1) A scrub is finishing and is at btrfs_scrub_dev();
2) A concurrent task called the scrub progress ioctl and is in
btrfs_scrub_progress(), where it takes the device_list_mutex and grabs
the device. Then it starts using the device's scrub context (for a
memcpy operation);
3) While the scrub progress ioctl task is running, the scrub task sets
the device's scrub_ctx to NULL (acquiring fs_info->scrub_lock) and
then calls scrub_put_ctx() against the scrub context, dropping the
last reference and freeing the memory - while the scrub progress ioctl
task is still using it, resulting in a use-after-free.
Fix this by changing btrfs_scrub_progress() to take fs_info->scrub_lock
before using the scrub context.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
When scrub finishes, it does a wakeup on the fs_info->scrub_pause_wait
wait queue and then sets dev->scrub_sctx to NULL. On the other hand the
scrub cancel code (btrfs_scrub_cancel_dev()) waits on that wait queue
for dev->scrub_sctx to be NULL. So this means if btrfs_scrub_cancel_dev()
is called right when scrub is finishing and sees the wakeup before the
NULL is assigned to dev->scrub_sctx by btrfs_scrub_dev(), it hangs.
Fix this by doing the wakeup in btrfs_scrub_dev() after setting
dev->scrub_sctx to NULL.
Fixes: a2de733c78fa ("btrfs: scrub")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
If we find errors we are returning the value of 'ret', which has a value
of 0 from some previous function call that succeeded, instead of returning
an -EIO error. Fix this by returning -EIO instead of 'ret'.
Fixes: fab0c0f03cfd ("btrfs: introduce BTRFS_PATH_AUTO_RELEASE() helper")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Compressed extents are never supposed to be merged by the fiemap code and
reported as a single extent, as each extent's content comes from a
different compression stream and has its own header and context.
We currently rely on checking the logical and physical address adjacency
to prevent merging compressed extents but that is broken. Consider the
following reproducer which explains why the merging happens:
$ cat test.sh
#!/bin/bash
DEV=/dev/sdi
MNT=/mnt/sdi
mkfs.btrfs -s 4K -f $DEV
mount -o compress $DEV $MNT
# Do a write that compresses to a single 4K extent and represents the
# maximum compressed chunk size (128K).
xfs_io -f -c "pwrite 0 128K" $MNT/foo
# Sync to flush delalloc and allocate the 4K extent.
sync -f $MNT
# Now allocate a 124K extent in some other file, which will be adjacent
# (to the right) of the 4K extent previously allocated.
xfs_io -f -c "falloc 0 124K" $MNT/filler
# Do another write to the main file at its current EOF that is
# compressible and fits in a 4K extent.
xfs_io -c "pwrite 128K 128K" $MNT/foo
# Sync to flush delalloc and allocate the 4K extent.
sync -f $MNT
# Run fiemap which should report 2 encoded extents, each with a
# logical size of 128K.
xfs_io -c "fiemap -v" $MNT/foo
umount $MNT
Running this, fiemap will report a single extent:
$ ./test.sh
(...)
/mnt/sdi/foo:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..511]: 26624..27135 512 0x9
Fix this by never attempting to merge extents if the flags contain
FIEMAP_EXTENT_ENCODED.
Fixes: 4751832da990 ("btrfs: fiemap: Cache and merge fiemap extent before submit it to user")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
[BUG]
There is a bug report that on v7.2 kernel, compressed extents with
fsverity enabled can lead to warnings like the following:
fs-verity (dm-3, inode 257): FILE CORRUPTED! pos=7471104, level=-1, want_hash=sha256:bedf0e7bc93b48694db719001a8d3e79229cc58ee638b41d4149193505090774, real_hash=sha256:ad7facb2586fc6e966c004d7d1d16b024f5805ff7cb47c7a85dabd8b48892ca7
The read itself eventually succeeds, and no read error is returned to
user space.
[CAUSE]
Since v7.2 btrfs has enabled large data folio support, now a folio can
contain multiple blocks even if the page size matches the fs block size.
And even before that, btrfs already has block size < page size support,
thus all involved code should assume a folio can contain multiple
blocks.
However the function btrfs_verify_folio() calls fsverity_verify_folio(),
which verifies the whole folio, even if the read range only covers part
of the folio.
This forces fsverity to verify garbage data that is not yet read from
disk, and causes verification failure.
This is a long-standing bug, but previously it only affected bs < ps
cases which is not that common.
Now with the large folio support, it's much easier to trigger with bs ==
ps cases.
[FIX]
Instead of calling fsverity_verify_folio(), call
fsverity_verify_blocks() to verify only the read range.
Reported-by: Roger Alasà <vonbloom@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/CAELqY9==Ter2XQPRp=gjW5T75T+7kcZCXpn5roF2L6tY6mQNxw@mail.gmail.com/
Fixes: 146054090b08 ("btrfs: initial fsverity support")
Tested-by: Roger Alasà <vonbloom@gmail.com>
Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Tested-by: Tito Duarte <duartito@gmail.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
btrfs_begin_enable_verity() ignores the return value of
btrfs_orphan_add() and unconditionally returns 0. If orphan insertion
fails, btrfs_orphan_add() aborts the transaction, but the generic
fs-verity code still proceeds with Merkle tree construction because
the begin_enable_verity callback reported success.
Return the error so that fs-verity stops immediately instead of
continuing after the initialization failure.
The transaction is already aborted by btrfs_orphan_add() and the
handle is released by btrfs_end_transaction(), so no additional
cleanup is needed.
Fixes: 705242538ff3 ("btrfs: verity metadata orphan items")
Signed-off-by: guolingxing <guolingxing@tju.edu.cn>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
btrfs_sysfs_add_block_group_type()
btrfs_sysfs_add_block_group_type() sets up a NOFS context with
memalloc_nofs_save() because kobject_add() performs GFP_KERNEL
allocations deep in its call chain, and the function may be called
while holding a transaction handle or a lock required for a
transaction commit, where reclaim could deadlock.
Every other return path of this function calls memalloc_nofs_restore()
except the early return taken when another thread has already created
the kobject for the same raid index (this can happen when restriping).
Taking that path leaves PF_MEMALLOC_NOFS set on the calling task, so
all subsequent memory allocations performed by that task remain
restricted to the NOFS scope, which may lead to unexpected allocation
failures or deadlocks later on.
Restore the NOFS context before returning from that path.
Fixes: 49ea112da0e6 ("btrfs: do not create raid sysfs entries under any locks")
CC: stable@vger.kernel.org
Signed-off-by: guolingxing <guolingxing@tju.edu.cn>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
If we add an inode to autodefrag and the inode is truncated to an i_size
of zero before it's picked by autodefrag (run by the cleaner kthread),
we exit btrfs_run_defrag_inode() leaving the BTRFS_INODE_IN_DEFRAG flag
set in the inode, which prevents the inode from being auto defragged in
the future until it's evicted, loaded again and small writes happen to
it again.
Fix this by clearing BTRFS_INODE_IN_DEFRAG before we check if the current
offset is at or beyond the inode's i_size.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
[EXISTING ERROR HANDLING QUIRK]
Sashiko mentioned an existing problem that, if btrfs_abort_transaction()
is triggered during the following call site, some roots will be attached
to dirty_cowonly_roots without being cleaned up:
btrfs_commit_transaction()
|- commit_cowonly_roots()
|- list_move_tail();
| One root's dirty_list is moved from dirty_cowonly_roots to
| switch_commits.
| But there are still other dirty roots in dirty_cowonly_roots.
|
|- update_cowonly_root()
| |- btrfs_update_root()
| |- btrfs_abort_transaction()
|
|- return ret;
In that case, those dirty roots linked into dirty_cowonly_roots will
never be removed from that list.
As normally we require a transaction commit to move them, but since the
fs is already marked error, no new transaction can be started.
For roots that are already moved to switch_commits list, they are
cleaned up by btrfs_cleanup_one_transaction().
This is not going to cause memory leak on the btrfs_root structure
itself, as after a transaction is aborted, no one will read
dirty_cowonly_roots.
Furthermore dirty_cowonly_roots only tracks trees that are not
subvolume or log trees. They should not have root->dirty_log_pages.
And qgroup swapped blocks are going to be released during
btrfs_put_root().
Thus no memory leak from those two members either.
But we're still relying on a hidden behavior to keep us from leaking
memory.
[ENHANCEMENT]
Unlink all roots that are still linked to dirty_cowonly_roots during
btrfs_free_fs_roots(), and do one extra ASSERT() to make sure that their
dirty_log_pages are empty.
At that timing there is no other thread thus we're safe to unlink roots
without holding trans_lock.
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Normally btrfs_qgroup_clean_swapped_blocks() is called when switching
the commit root of a subvolume tree.
However if a transaction is aborted before all dirty subvolumes are
linked to switch_commits, those left-over dirty subvolumes won't get
their qgroup swapped blocks cleaned up.
And since a transaction is already aborted, no new transaction is
allowed to be started, thus no way to cleanup the qgroup swapped blocks
for those subvolume trees.
Fix the problem by calling btrfs_qgroup_clean_swapped_blocks() inside
btrfs_put_root() when the last ref is dropped, so that at unmount time
those left-over qgroup swapped blocks are properly released.
This fix is inspired by the recent Sashiko reports about similar cases
on cowonly roots.
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
[ERROR HANDLING QUIRK]
When btrfs_quota_disable() failed at btrfs_clean_quota_tree() or
btrfs_del_root(), the quota_root->dirty_list is not removed from
fs_info->dirty_cowonly_roots, but the quota_root itself will be freed.
This leaves a dangling pointer in the dirty_cowonly_roots.
This is not a huge problem, as the transaction is aborted thus no one
will read the dirty_cowonly_roots for now.
Furthermore, quota_root should never be logged nor have qgroup swapped
tree blocks, thus it won't cause leaks from extent io tree nor qgroup
swapped blocks.
[ENHANCEMENT]
For the incoming cleanup of dirty_cowonly_roots during
btrfs_free_fs_roots(), any root that is still linked to
dirty_cowonly_roots will be read again, and this existing dangling
pointer is going to cause problem.
To prepare for that cleanup, move the list_del() call into the out
label, so that even if the transaction is aborted, we still unlink
quota_root from dirty_cowonly_roots before freeing it.
Assisted-by: LLM (exposing the bug during review)
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
btrfs_init_new_device() ignored the return value of
btrfs_sysfs_add_device(). When sysfs link creation failed (e.g. -EEXIST),
the add path continued, aborted the transaction with the same errno, and
tripped WARN_ON(btrfs_abort_should_print_stack()) while leaving the device
half-registered in memory.
Check the return value and unwind when registration fails, without
aborting the filesystem for errnos like -EEXIST. If add failed before
anything was published in sysfs, tear down the in-memory device state only
and do not call btrfs_sysfs_remove_device(). When the block-device link
was created but devid kobject registration fails, drop the link inside
btrfs_sysfs_add_device() before returning the error.
Reported-by: syzbot+3bf3e110b2d406b8166c@syzkaller.appspotmail.com
Link: https://lore.kernel.org/all/6a791c94.01d0871a.3a0d52.0099.GAE@google.com
Tested-by: syzbot+3bf3e110b2d406b8166c@syzkaller.appspotmail.com
Assisted-by: LLM
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Adarsh Das <adarshdas950@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Commit cf1afec09e9f ("btrfs: validate properties before setting them")
made btrfs_set_prop() validate a property before setting it. For the
compression property, the validation fails with -EINVAL when the inode
has NODATASUM.
However, chattr writes back all the flags it read from the file, and
btrfs_fileattr_set() sets the compression property whenever the new
flags include FS_COMPR_FL, even when the compression flags do not
change. A file created on a filesystem mounted with nodatasum has
NODATASUM and still inherits the compress flag from its directory. As
of now, chattr fails on such a file when it changes any other flag.
The issue can be reproduced with:
mkfs.btrfs -f /dev/sdb
mount -o nodatasum /dev/sdb /mnt
mkdir /mnt/dir
chattr +c /mnt/dir
touch /mnt/dir/file
chattr +A /mnt/dir/file
Before commit cf1afec09e9f ("btrfs: validate properties before setting
them"), the last command succeeds.
After that commit, it fails with EINVAL.
This patch will make btrfs_fileattr_set() leave the compression flags
and the compression property alone when the call changes neither
FS_COMPR_FL nor FS_NOCOMP_FL.
Fixes: cf1afec09e9f ("btrfs: validate properties before setting them")
CC: stable@vger.kernel.org # 7.2+
Suggested-by: Qu Wenruo <wqu@suse.com>
Assisted-by: LLM
Signed-off-by: Hengyu Liang <hengyul@cs.unc.edu>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Commit f77f281b6118 ("fsverity: use a hashtable to find the
fsverity_info") changed the implementation of FS_IOC_ENABLE_VERITY to
make concurrent reads start going through fsverity verification slightly
earlier than they did before.
Instead of it happening when enable_verity() calls fsverity_set_info(),
it now happens when ->end_enable_verity() sets S_VERITY.
However, ext4 and btrfs can roll back verity after they set S_VERITY,
causing a use-after-free.
Fix that by making ext4 and btrfs set S_VERITY only after rollback is no
longer possible. On failure, don't roll back S_VERITY, but do roll back
the filesystem-specific verity flag.
Also update enable_verity() to handle any future instances of this bug
more safely by warning and *not* freeing the fsverity_info.
Finally, tweak some comments. Clarify one, and move information from
another to its proper place in the comment for ->end_enable_verity().
Fixes: f77f281b6118 ("fsverity: use a hashtable to find the fsverity_info")
Cc: stable@vger.kernel.org
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://patch.msgid.link/20261025204807.122875-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
|
|
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull more btrfs updates from David Sterba:
"This removes unused code of free space caching, disabled in 7.3
(commit 545e560a5b0f: "btrfs: disable v1 space cache").
It's been the original free space cache feature, superseded by free
space tree (4.5) and mkfs default since 5.15. The grace period was
sufficiently long, backward compatibility still exists with a
performance impact, effectively as if mounted with '-o nospace_cache'"
* tag 'for-7.4-part2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux:
btrfs: remove TRANS_JOIN_NOLOCK
btrfs: stop reading free space inodes from the commit root
btrfs: stop special-casing free space inodes in the delalloc accounting
btrfs: remove the free space inode special cases from the COW paths
btrfs: remove the free space inode ordered extent special cases
btrfs: remove BTRFS_RESERVE_FLUSH_FREE_SPACE_INODE
btrfs: remove the free space cache trimming ranges
btrfs: replace btrfs_set_free_space_cache_v1_active() with a cleanup helper
btrfs: remove the SPACE_CACHE mount option flag
btrfs: remove btrfs_disk_cache_state
btrfs: remove the v1 space cache load path
btrfs: drop the transaction handle from the prealloc helpers
btrfs: rename cache_write_mutex to dirty_bgs_update_mutex
btrfs: remove the v1 space cache write path
btrfs: remove the free space cache endio workqueue
btrfs: remove the v1 space cache writeout from the transaction commit
btrfs: stop enabling the v1 space cache from the on-disk state
btrfs: update the inode item when removing a free space inode
btrfs: drop the extent maps of the written part of a failed ordered extent
btrfs: fix use-after-free on quota enable allocation failure
|
|
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs updates from David Sterba:
"User visible changes:
- remove tweakable sysfs way to enable features, used only for
extent-irefs which has been default since 3.12; the sysfs interface
makes it complicated due to locking and context, unlike ioctl
- change which backup superblock does mount option
'rescue=usebackuproot' choose, skip the last one due to rotation,
for more fine grained control add options selecting a specific
backup superblock by index (usebackuproot_N)
Notable fixes:
- syslog message fixup of error state description, duplicate 'E'
renamed to 'H' (emergency shutdown), added 'I 'when delayed iputs
are blocked
- use kvmalloc for b-tree buffer allocations, as we're using more
contig ranges because of large folios, the allocations started to
warn on fragmented memory
- handle unknown commands for the /dev/btrfs-control ioctls
- tune timing of transaction commit when the space is getting low
- in raid56, skip verifications if data checksums are not available
Performance improvements:
- reflink speedup, reorder locking and flushing to optimize for more
common cases where the reflinked ranges are accessed, avoid
unnecessary contention
- minor speedup in zstd decompression (+8MB/s)
- reduced contention of inode extent map lock, improves e.g. when
shrinker processes inodes without extent maps, measured time
reduction 10-20%
Core changes:
- move allocation errors out of some contexts (new
inode/dentry/rename) to avoid transaction aborts
- allocate system new chunks earlier, e.g. when consumed by
fallocate, and tune deleting unused block groups if the system
space is low
- tree checker: reject extents for special files
- many qgroup fixes regarding enabling/disabling, other state changes
and qgroup relation updates
- error handling fixes
- refactoring, cleanups:
- page to folio cleanups
- transaction state macros/enums simplification
- parameter simplifications"
* tag 'for-7.4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (92 commits)
btrfs: fix use-after-free on quota enable allocation failure
btrfs: prevent use-after-free in btrfs_transaction::switch_commits
btrfs: return -ENOTTY for unknown ioctls on the control device
btrfs: defrag: fix check to see if next extent can be defragged too
btrfs: defrag: fix key comparison with max defrag key in btrfs_defrag_leaves()
btrfs: use READ_ONCE() to read the chunk size from the data space_info
btrfs: qgroup: make btrfs_record_squota_delta() return void
btrfs: fix lost error return value in btrfs_alloc_logged_file_extent()
btrfs: qgroup: fix off-by-one max level check in qgroup_trace_new_subtree_blocks()
btrfs: abort transaction on qgroup failures in create_pending_snapshot()
btrfs: qgroup: merge error labels in btrfs_quota_enable()
btrfs: qgroup: fix leak of qgroups in rb tree after failure to enable quotas
btrfs: qgroup: abort transaction on failure to add qgroup relation
btrfs: qgroup: fix swapped blocks existence check when tracing after COW
btrfs: introduce more accurate usebackuproot options
btrfs: always use the second newest slot for rescue=usebackuproot
btrfs: raid56: do not verify the content if there is no data checksum
btrfs: qgroup: do not leak -ENOENT from btrfs_remove_qgroup()
btrfs: qgroup: use qgroup_mark_inconsistent() in quick_update_accounting()
btrfs: qgroup: do not treat "ret > 0" as error when deleting a qgroup
...
|
|
Pull fsverity updates from Eric Biggers:
"Patches from Andrey Albershteyn to prepare for XFS fsverity support:
- Report verification errors through fserror, instead of only through
an unstructured log message and generic I/O error return
- Move the reporting of STATX_ATTR_VERITY into the VFS, so that each
fsverity-capable filesystem doesn't need to do it. This also fixes
a bug where btrfs didn't return STATX_ATTR_VERITY in
attributes_mask
- Make the VFS prevent enabling DAX on fsverity files, so that it
will be handled in a single place for ext4 and XFS
- Move ext4 and f2fs's code to read verity metadata from the
pagecache into shared code, so that XFS will be able to use it too
- Export fsverity_ensure_verity_info() for XFS scrub to use
- Pass all-zeroes hash to ->write_merkle_tree_block() so that XFS
will be able to implement an optimization for sparse files"
* tag 'fsverity-for-linus' of git://git.kernel.org/pub/scm/fs/fsverity/linux:
fsverity: hoist statx reporting of fs-verity flag
fsverity: don't allow setting DAX file attribute on fsverity files
fsverity: hoist pagecache_read from f2fs/ext4 to fsverity
fsverity: pass digest size and hash of the all-zeroes block to ->write
fsverity: expose ensure_fsverity_info()
fsverity: report validation errors through fserror to fsnotify
MAINTAINERS: List the fsverity branches
|
|
git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull vfs idmap constification from Christian Brauner:
"This makes struct mnt_idmap const throughout the tree.
A mount's idmapping is immutable. The only thing modified after
alloc_mnt_idmap() is the reference count and that is hidden behind
mnt_idmap_get() and mnt_idmap_put(). Everything else only reads from
it. That is the same model struct cred uses and the idmapping is
sensitive enough to deserve it.
The conversion goes bottom up through the vfs{g,u}id and fs{g,u}id
helpers, the privilege checks, acl, xattr and quota and then every
inode operation that takes an idmap, so ->permission(), ->getattr(),
->setattr(), ->create(), ->mkdir(), ->mknod(), ->symlink(),
->rename(), ->tmpfile(), ->get_acl(), ->set_acl() and ->fileattr_set()
with their implementations in every filesystem, plus the LSM hooks.
struct vfsmount, struct mount_kattr and struct kstatmount store a
const pointer and nop_mnt_idmap and invalid_mnt_idmap live in rodata,
so anything that tries to modify them faults instead of silently
corrupting the initial idmapping"
* tag 'vfs-7.4-rc1.idmap' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (27 commits)
fs: make nop_mnt_idmap and invalid_mnt_idmap const
fs: port mnt_idmap() and file_mnt_idmap() to const mnt_idmap
fs: port vfs_*() helpers to const mnt_idmap
fs: port ->setattr() to pass const mnt_idmap
fs: port ->getattr() to pass const mnt_idmap
fs: port ->create() to pass const mnt_idmap
fs: port ->symlink() to pass const mnt_idmap
fs: port ->mkdir() to pass const mnt_idmap
fs: port ->rename() to pass const mnt_idmap
fs: port ->mknod() to pass const mnt_idmap
fs: port ->tmpfile() to pass const mnt_idmap
fs: port ->get_acl() to pass const mnt_idmap
fs: port ->set_acl() to pass const mnt_idmap
fs: port ->fileattr_set() to pass const mnt_idmap
fs: port xattr to const mnt_idmap
fs: port ->permission() to pass const mnt_idmap
fs: port acl to const mnt_idmap
fs: port inode_init_owner() to const mnt_idmap
fs: port inode_owner_or_capable() to const mnt_idmap
fs: port privilege checking helpers to const mnt_idmap
...
|
|
btrfs_join_transaction_spacecache() was the only user of
TRANS_JOIN_NOLOCK and is gone, so remove the join type, its entries in
the blocked types table, and the special cases in join_transaction() and
start_transaction().
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Free space inode data was only read when loading the v1 cache, which is
gone, so btrfs_get_extent() and btrfs_lookup_bio_sums() no longer need
to search the commit root for them.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Free space inodes never have delalloc or outstanding extents any more,
so they don't need to be kept off the root's delalloc inode list, out of
the outstanding extents tracepoint, or exempt from the delalloc metadata
release, which skipped the tree root since free space inodes are its
only inodes with data.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Free space inodes are never written anymore, so drop the special cases
for them in cow_file_range(), fallback_to_cow(),
can_nocow_file_extent() and btrfs_finish_one_ordered().
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Free space inodes never have ordered extents anymore. Drop the lockdep
exceptions for them and btrfs_join_transaction_spacecache(), which was
only used to finish their ordered extents during a commit.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Free space inodes no longer reserve data or delalloc space, as nothing
writes to them. Remove the flush mode and the special cases that
selected it.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
cache_writeout_mutex and trimming_ranges let the v1 cache writer see
ranges that were unlinked from the free space tree while being
discarded. Nothing consumes the list anymore, and the tree itself is
protected by tree_lock, so remove them.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
The only caller passes active = false. Turn it into
btrfs_cleanup_free_space_cache_v1() and fold the block group loop into
it.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Nothing sets BTRFS_MOUNT_SPACE_CACHE anymore, so every test of it is
false. Remove the flag, the checks rejecting the v1 cache on zoned
filesystems and for sector sizes other than the page size, and the
deprecation warning. Show a read-only filesystem that still has an old
cache as nospace_cache, since that's what's in effect. space_cache and
space_cache=v1 keep falling back to no space cache with a warning.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
With neither the writer nor the loader left, nothing acts on
disk_cache_state. Remove it, the need_clear handling when reading block
groups, and the enum. While at it, drop the unused cache_generation
field from struct btrfs_block_group.
lookup_free_space_inode() converted old style space inodes by clearing
disk_cache_state so the cache would be rewritten with the new inode
flags. Without that it only sets flags on the in-memory inode, which
every remaining caller truncates or deletes right after, so drop the
conversion too.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
Nothing writes a v1 space cache any more, and since commit 545e560a5b0f
("btrfs: disable v1 space cache") the mount option can't be enabled to
read one either. Remove load_free_space_cache(), its io_ctl helpers and
struct btrfs_io_ctl. Drop the gfp constraint on the inode mapping as
well, it only covered the cache's page cache allocations.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
The v1 space cache created its inode during the transaction commit, and
btrfs_prealloc_file_range_trans() existed so that preallocation could
reuse the open handle. It was the only caller passing a transaction, so
__btrfs_prealloc_file_range() and insert_prealloc_file_extent() now
always start their own. Fold the wrapper into
btrfs_prealloc_file_range() and drop the parameter.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|
|
The v1 space cache writeout is gone, but the mutex is still needed. It
keeps btrfs_remove_block_group() from deleting a block group item while
btrfs_start_dirty_block_groups() is updating it outside the commit
critical section.
Rename it to reflect what it protects, and update the comments around
the dirty block group writeout that still refer to the space cache.
Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
|