[PATCH] blk-cgroup: add spin_lock for u64_stats_update

Boy Wu (吳勃誼) Boy.Wu at mediatek.com
Sun Jul 7 19:52:05 PDT 2024


On Fri, 2024-07-05 at 19:05 +0200, Markus Elfring wrote:
>  	 
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
>  > In 32bit SMP systems, if the system is stressed on the sys node
> > by processes, it may cause blkcg_fill_root_iostats to have a
> concurrent
> > problem on the seqlock in u64_stats_update, which will cause a
> deadlock
> > on u64_stats_fetch_begin in blkcg_print_one_stat.
> 
> Would you like to mark any references to functions with parentheses?
> 
When deadlock happens, there are 3 CPUs in

do_raw_spin_lock
blkcg_print_stat
seq_read_iter
vfs_read
ksys_read

another 1 CPU is in

u64_stats_fetch_begin
blkcg_print_one_stat
blkcg_print_stat
seq_read_iter
vfs_read
ksys_read

> 
> > To prevent this problem, add spin_locks.
> 
> Another wording suggestion:
>   Thus use an additional spin lock.
> 
> 
> How do you think about to use a summary phrase like “Add a spin lock
> for stats update
> in blkcg_fill_root_iostats()”?
> 
> 
I can refine commit message as

blk-cgroup: Add a spin lock for stats update

In 32bit SMP systems, if multiple CPUs call blkcg_print_stat, it may
cause blkcg_fill_root_iostats to have a concurrent problem on the
seqlock in u64_stats_update, which will cause a deadlock
on u64_stats_fetch_begin in blkcg_print_one_stat.

Thus use an additional spin lock.
>> > +++ b/block/blk-cgroup.c
> > @@ -1134,9 +1134,15 @@ static void blkcg_fill_root_iostats(void)
> >  cpu_dkstats->sectors[STAT_DISCARD] << 9;
> >  }
> >
> > +#if BITS_PER_LONG == 32
> > +spin_lock_irq(&blkg->q->queue_lock);
> > +#endif
> >  flags = u64_stats_update_begin_irqsave(&blkg->iostat.sync);
> >  blkg_iostat_set(&blkg->iostat.cur, &tmp);
> >  u64_stats_update_end_irqrestore(&blkg->iostat.sync, flags);
> > +#if BITS_PER_LONG == 32
> > +spin_unlock_irq(&blkg->q->queue_lock);
> > +#endif
>> 
> Under which circumstances would you become interested to apply a
> statement
> like “guard(spinlock_irq)(&blkg->q->queue_lock);”?
> 
https://elixir.bootlin.com/linux/v6.10-rc6/source/include/linux/spinlock.h#L567
> 
> Regards,
> Markus

The spin lock usage is reference from blkcg_print_stat (v6.1.25).

I can try 
guard(spinlock_irq)(&blkg->q->queue_lock);
instead.

--
boy.wu



More information about the Linux-mediatek mailing list