Skip to content

Commit 79eb2c0

Browse files
committed
Merge tag 'for-6.12-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - in incremental send, fix invalid clone operation for file that got its size decreased - fix __counted_by() annotation of send path cache entries, we do not store the terminating NUL - fix a longstanding bug in relocation (and quite hard to hit by chance), drop back reference cache that can get out of sync after transaction commit - wait for fixup worker kthread before finishing umount - add missing raid-stripe-tree extent for NOCOW files, zoned mode cannot have NOCOW files but RST is meant to be a standalone feature - handle transaction start error during relocation, avoid potential NULL pointer dereference of relocation control structure (reported by syzbot) - disable module-wide rate limiting of debug level messages - minor fix to tracepoint definition (reported by checkpatch.pl) * tag 'for-6.12-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: disable rate limiting when debug enabled btrfs: wait for fixup workers before stopping cleaner kthread during umount btrfs: fix a NULL pointer dereference when failed to start a new trasacntion btrfs: send: fix invalid clone operation for file that got its size decreased btrfs: tracepoints: end assignment with semicolon at btrfs_qgroup_extent event class btrfs: drop the backref cache during relocation if we commit btrfs: also add stripe entries for NOCOW writes btrfs: send: fix buffer overflow detection when copying path to cache entry
2 parents b7a838e + d6e7ac6 commit 79eb2c0

File tree

7 files changed

+58
-83
lines changed

7 files changed

+58
-83
lines changed

fs/btrfs/backref.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,10 +3179,14 @@ void btrfs_backref_release_cache(struct btrfs_backref_cache *cache)
31793179
btrfs_backref_cleanup_node(cache, node);
31803180
}
31813181

3182-
cache->last_trans = 0;
3183-
3184-
for (i = 0; i < BTRFS_MAX_LEVEL; i++)
3185-
ASSERT(list_empty(&cache->pending[i]));
3182+
for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
3183+
while (!list_empty(&cache->pending[i])) {
3184+
node = list_first_entry(&cache->pending[i],
3185+
struct btrfs_backref_node,
3186+
list);
3187+
btrfs_backref_cleanup_node(cache, node);
3188+
}
3189+
}
31863190
ASSERT(list_empty(&cache->pending_edge));
31873191
ASSERT(list_empty(&cache->useless_node));
31883192
ASSERT(list_empty(&cache->changed));

fs/btrfs/disk-io.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,6 +4255,17 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
42554255
/* clear out the rbtree of defraggable inodes */
42564256
btrfs_cleanup_defrag_inodes(fs_info);
42574257

4258+
/*
4259+
* Wait for any fixup workers to complete.
4260+
* If we don't wait for them here and they are still running by the time
4261+
* we call kthread_stop() against the cleaner kthread further below, we
4262+
* get an use-after-free on the cleaner because the fixup worker adds an
4263+
* inode to the list of delayed iputs and then attempts to wakeup the
4264+
* cleaner kthread, which was already stopped and destroyed. We parked
4265+
* already the cleaner, but below we run all pending delayed iputs.
4266+
*/
4267+
btrfs_flush_workqueue(fs_info->fixup_workers);
4268+
42584269
/*
42594270
* After we parked the cleaner kthread, ordered extents may have
42604271
* completed and created new delayed iputs. If one of the async reclaim

fs/btrfs/inode.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3111,6 +3111,11 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
31113111
ret = btrfs_update_inode_fallback(trans, inode);
31123112
if (ret) /* -ENOMEM or corruption */
31133113
btrfs_abort_transaction(trans, ret);
3114+
3115+
ret = btrfs_insert_raid_extent(trans, ordered_extent);
3116+
if (ret)
3117+
btrfs_abort_transaction(trans, ret);
3118+
31143119
goto out;
31153120
}
31163121

fs/btrfs/messages.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ void __cold _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt,
239239
vaf.fmt = fmt;
240240
vaf.va = &args;
241241

242-
if (__ratelimit(ratelimit)) {
242+
/* Do not ratelimit if CONFIG_BTRFS_DEBUG is enabled. */
243+
if (IS_ENABLED(CONFIG_BTRFS_DEBUG) || __ratelimit(ratelimit)) {
243244
if (fs_info) {
244245
char statestr[STATE_STRING_BUF_LEN];
245246

fs/btrfs/relocation.c

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -232,70 +232,6 @@ static struct btrfs_backref_node *walk_down_backref(
232232
return NULL;
233233
}
234234

235-
static void update_backref_node(struct btrfs_backref_cache *cache,
236-
struct btrfs_backref_node *node, u64 bytenr)
237-
{
238-
struct rb_node *rb_node;
239-
rb_erase(&node->rb_node, &cache->rb_root);
240-
node->bytenr = bytenr;
241-
rb_node = rb_simple_insert(&cache->rb_root, node->bytenr, &node->rb_node);
242-
if (rb_node)
243-
btrfs_backref_panic(cache->fs_info, bytenr, -EEXIST);
244-
}
245-
246-
/*
247-
* update backref cache after a transaction commit
248-
*/
249-
static int update_backref_cache(struct btrfs_trans_handle *trans,
250-
struct btrfs_backref_cache *cache)
251-
{
252-
struct btrfs_backref_node *node;
253-
int level = 0;
254-
255-
if (cache->last_trans == 0) {
256-
cache->last_trans = trans->transid;
257-
return 0;
258-
}
259-
260-
if (cache->last_trans == trans->transid)
261-
return 0;
262-
263-
/*
264-
* detached nodes are used to avoid unnecessary backref
265-
* lookup. transaction commit changes the extent tree.
266-
* so the detached nodes are no longer useful.
267-
*/
268-
while (!list_empty(&cache->detached)) {
269-
node = list_entry(cache->detached.next,
270-
struct btrfs_backref_node, list);
271-
btrfs_backref_cleanup_node(cache, node);
272-
}
273-
274-
while (!list_empty(&cache->changed)) {
275-
node = list_entry(cache->changed.next,
276-
struct btrfs_backref_node, list);
277-
list_del_init(&node->list);
278-
BUG_ON(node->pending);
279-
update_backref_node(cache, node, node->new_bytenr);
280-
}
281-
282-
/*
283-
* some nodes can be left in the pending list if there were
284-
* errors during processing the pending nodes.
285-
*/
286-
for (level = 0; level < BTRFS_MAX_LEVEL; level++) {
287-
list_for_each_entry(node, &cache->pending[level], list) {
288-
BUG_ON(!node->pending);
289-
if (node->bytenr == node->new_bytenr)
290-
continue;
291-
update_backref_node(cache, node, node->new_bytenr);
292-
}
293-
}
294-
295-
cache->last_trans = 0;
296-
return 1;
297-
}
298-
299235
static bool reloc_root_is_dead(const struct btrfs_root *root)
300236
{
301237
/*
@@ -551,9 +487,6 @@ static int clone_backref_node(struct btrfs_trans_handle *trans,
551487
struct btrfs_backref_edge *new_edge;
552488
struct rb_node *rb_node;
553489

554-
if (cache->last_trans > 0)
555-
update_backref_cache(trans, cache);
556-
557490
rb_node = rb_simple_search(&cache->rb_root, src->commit_root->start);
558491
if (rb_node) {
559492
node = rb_entry(rb_node, struct btrfs_backref_node, rb_node);
@@ -923,7 +856,7 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
923856
btrfs_grab_root(reloc_root);
924857

925858
/* root->reloc_root will stay until current relocation finished */
926-
if (fs_info->reloc_ctl->merge_reloc_tree &&
859+
if (fs_info->reloc_ctl && fs_info->reloc_ctl->merge_reloc_tree &&
927860
btrfs_root_refs(root_item) == 0) {
928861
set_bit(BTRFS_ROOT_DEAD_RELOC_TREE, &root->state);
929862
/*
@@ -3698,11 +3631,9 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
36983631
break;
36993632
}
37003633
restart:
3701-
if (update_backref_cache(trans, &rc->backref_cache)) {
3702-
btrfs_end_transaction(trans);
3703-
trans = NULL;
3704-
continue;
3705-
}
3634+
if (rc->backref_cache.last_trans != trans->transid)
3635+
btrfs_backref_release_cache(&rc->backref_cache);
3636+
rc->backref_cache.last_trans = trans->transid;
37063637

37073638
ret = find_next_extent(rc, path, &key);
37083639
if (ret < 0)

fs/btrfs/send.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,10 @@ struct name_cache_entry {
346346
u64 parent_gen;
347347
int ret;
348348
int need_later_update;
349+
/* Name length without NUL terminator. */
349350
int name_len;
350-
char name[] __counted_by(name_len);
351+
/* Not NUL terminated. */
352+
char name[] __counted_by(name_len) __nonstring;
351353
};
352354

353355
/* See the comment at lru_cache.h about struct btrfs_lru_cache_entry. */
@@ -2388,7 +2390,7 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx,
23882390
/*
23892391
* Store the result of the lookup in the name cache.
23902392
*/
2391-
nce = kmalloc(sizeof(*nce) + fs_path_len(dest) + 1, GFP_KERNEL);
2393+
nce = kmalloc(sizeof(*nce) + fs_path_len(dest), GFP_KERNEL);
23922394
if (!nce) {
23932395
ret = -ENOMEM;
23942396
goto out;
@@ -2400,7 +2402,7 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx,
24002402
nce->parent_gen = *parent_gen;
24012403
nce->name_len = fs_path_len(dest);
24022404
nce->ret = ret;
2403-
strcpy(nce->name, dest->start);
2405+
memcpy(nce->name, dest->start, nce->name_len);
24042406

24052407
if (ino < sctx->send_progress)
24062408
nce->need_later_update = 0;
@@ -6187,8 +6189,29 @@ static int send_write_or_clone(struct send_ctx *sctx,
61876189
if (ret < 0)
61886190
return ret;
61896191

6190-
if (clone_root->offset + num_bytes == info.size)
6192+
if (clone_root->offset + num_bytes == info.size) {
6193+
/*
6194+
* The final size of our file matches the end offset, but it may
6195+
* be that its current size is larger, so we have to truncate it
6196+
* to any value between the start offset of the range and the
6197+
* final i_size, otherwise the clone operation is invalid
6198+
* because it's unaligned and it ends before the current EOF.
6199+
* We do this truncate to the final i_size when we finish
6200+
* processing the inode, but it's too late by then. And here we
6201+
* truncate to the start offset of the range because it's always
6202+
* sector size aligned while if it were the final i_size it
6203+
* would result in dirtying part of a page, filling part of a
6204+
* page with zeroes and then having the clone operation at the
6205+
* receiver trigger IO and wait for it due to the dirty page.
6206+
*/
6207+
if (sctx->parent_root != NULL) {
6208+
ret = send_truncate(sctx, sctx->cur_ino,
6209+
sctx->cur_inode_gen, offset);
6210+
if (ret < 0)
6211+
return ret;
6212+
}
61916213
goto clone_data;
6214+
}
61926215

61936216
write_data:
61946217
ret = send_extent_data(sctx, path, offset, num_bytes);

include/trace/events/btrfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ DECLARE_EVENT_CLASS(btrfs_qgroup_extent,
17161716
),
17171717

17181718
TP_fast_assign_btrfs(fs_info,
1719-
__entry->bytenr = rec->bytenr,
1719+
__entry->bytenr = rec->bytenr;
17201720
__entry->num_bytes = rec->num_bytes;
17211721
),
17221722

0 commit comments

Comments
 (0)