On Mon, Feb 10, 2025 at 11:04:22AM +0800, Alan Huang wrote:
> acc->k.data should be used with the lock hold:

<snipped>

> 
> Signed-off-by: Alan Huang <[email protected]>


Test this with lockdep (you know how to edit the lists of tests the CI
runs, right?

mark_lock usage is a giant mess, and calling percpu_down_read()
recursively by accident will mostly work, until it doesn't.

> ---
>  fs/bcachefs/disk_accounting.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/bcachefs/disk_accounting.h b/fs/bcachefs/disk_accounting.h
> index 5360cbb3ec29..f4372cafea2e 100644
> --- a/fs/bcachefs/disk_accounting.h
> +++ b/fs/bcachefs/disk_accounting.h
> @@ -210,11 +210,13 @@ static inline void 
> bch2_accounting_mem_read_counters(struct bch_accounting_mem *
>  static inline void bch2_accounting_mem_read(struct bch_fs *c, struct bpos p,
>                                           u64 *v, unsigned nr)
>  {
> +     percpu_down_read(&c->mark_lock);
>       struct bch_accounting_mem *acc = &c->accounting;
>       unsigned idx = eytzinger0_find(acc->k.data, acc->k.nr, 
> sizeof(acc->k.data[0]),
>                                      accounting_pos_cmp, &p);
>  
>       bch2_accounting_mem_read_counters(acc, idx, v, nr, false);
> +     percpu_up_read(&c->mark_lock);
>  }
>  
>  static inline struct bversion journal_pos_to_bversion(struct journal_res 
> *res, unsigned offset)
> -- 
> 2.47.0
> 

Reply via email to