Skip to content

Commit 0e91d3a

Browse files
Brian FosterKent Overstreet
authored andcommitted
bcachefs: fix odebug warn and lockdep splat due to on-stack rhashtable
Guenter Roeck reports a lockdep splat and DEBUG_OBJECTS_WORK related warning when bch2_copygc_thread() initializes its rhashtable. The lockdep splat relates to a warning print caused by the fact that the rhashtable exists on the stack but is not annotated as so. This is something that could be addressed by INIT_WORK_ONSTACK(), but rhashtable doesn't expose that control and probably isnt worth the churn for just one user. Instead, dynamically allocate the buckets_in_flight structure and avoid the splat that way. Reported-by: Guenter Roeck <linux@roeck-us.net> Tested-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent e0fb0dc commit 0e91d3a

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

fs/bcachefs/movinggc.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,16 @@ static int bch2_copygc_thread(void *arg)
305305
struct moving_context ctxt;
306306
struct bch_move_stats move_stats;
307307
struct io_clock *clock = &c->io_clock[WRITE];
308-
struct buckets_in_flight buckets;
308+
struct buckets_in_flight *buckets;
309309
u64 last, wait;
310310
int ret = 0;
311311

312-
memset(&buckets, 0, sizeof(buckets));
313-
314-
ret = rhashtable_init(&buckets.table, &bch_move_bucket_params);
312+
buckets = kzalloc(sizeof(struct buckets_in_flight), GFP_KERNEL);
313+
if (!buckets)
314+
return -ENOMEM;
315+
ret = rhashtable_init(&buckets->table, &bch_move_bucket_params);
315316
if (ret) {
317+
kfree(buckets);
316318
bch_err_msg(c, ret, "allocating copygc buckets in flight");
317319
return ret;
318320
}
@@ -331,12 +333,12 @@ static int bch2_copygc_thread(void *arg)
331333
cond_resched();
332334

333335
if (!c->copy_gc_enabled) {
334-
move_buckets_wait(&ctxt, &buckets, true);
336+
move_buckets_wait(&ctxt, buckets, true);
335337
kthread_wait_freezable(c->copy_gc_enabled);
336338
}
337339

338340
if (unlikely(freezing(current))) {
339-
move_buckets_wait(&ctxt, &buckets, true);
341+
move_buckets_wait(&ctxt, buckets, true);
340342
__refrigerator(false);
341343
continue;
342344
}
@@ -347,7 +349,7 @@ static int bch2_copygc_thread(void *arg)
347349
if (wait > clock->max_slop) {
348350
c->copygc_wait_at = last;
349351
c->copygc_wait = last + wait;
350-
move_buckets_wait(&ctxt, &buckets, true);
352+
move_buckets_wait(&ctxt, buckets, true);
351353
trace_and_count(c, copygc_wait, c, wait, last + wait);
352354
bch2_kthread_io_clock_wait(clock, last + wait,
353355
MAX_SCHEDULE_TIMEOUT);
@@ -357,7 +359,7 @@ static int bch2_copygc_thread(void *arg)
357359
c->copygc_wait = 0;
358360

359361
c->copygc_running = true;
360-
ret = bch2_copygc(&ctxt, &buckets, &did_work);
362+
ret = bch2_copygc(&ctxt, buckets, &did_work);
361363
c->copygc_running = false;
362364

363365
wake_up(&c->copygc_running_wq);
@@ -374,8 +376,10 @@ static int bch2_copygc_thread(void *arg)
374376
}
375377
}
376378

377-
move_buckets_wait(&ctxt, &buckets, true);
378-
rhashtable_destroy(&buckets.table);
379+
move_buckets_wait(&ctxt, buckets, true);
380+
381+
rhashtable_destroy(&buckets->table);
382+
kfree(buckets);
379383
bch2_moving_ctxt_exit(&ctxt);
380384
bch2_move_stats_exit(&move_stats, c);
381385

0 commit comments

Comments
 (0)