public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: "Boy Wu (吳勃誼)" <Boy.Wu@mediatek.com>
To: "linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
	"Markus.Elfring@web.de" <Markus.Elfring@web.de>,
	"axboe@kernel.dk" <axboe@kernel.dk>,
	"josef@toxicpanda.com" <josef@toxicpanda.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"tj@kernel.org" <tj@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"boris@bur.io" <boris@bur.io>,
	"Iverlin Wang (王苳霖)" <Iverlin.Wang@mediatek.com>,
	"angelogioacchino.delregno@collabora.com"
	<angelogioacchino.delregno@collabora.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>
Subject: Re: [PATCH] blk-cgroup: add spin_lock for u64_stats_update
Date: Mon, 8 Jul 2024 02:52:05 +0000	[thread overview]
Message-ID: <554f09bc6fc8f3b2a71b346f5e363950a1f8cb18.camel@mediatek.com> (raw)
In-Reply-To: <8f3765db-842d-4568-9ac5-1bd9cab9e952@web.de>

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


  reply	other threads:[~2024-07-08  2:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05  7:55 [PATCH] blk-cgroup: add spin_lock for u64_stats_update boy.wu
2024-07-05 17:05 ` Markus Elfring
2024-07-08  2:52   ` Boy Wu (吳勃誼) [this message]
2024-07-08  5:43     ` Markus Elfring
2024-07-10  6:19       ` Boy Wu (吳勃誼)
2024-07-05 17:13 ` [PATCH] " Tejun Heo
2024-07-08  2:00   ` Boy Wu (吳勃誼)
2024-07-08 18:36     ` tj

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554f09bc6fc8f3b2a71b346f5e363950a1f8cb18.camel@mediatek.com \
    --to=boy.wu@mediatek.com \
    --cc=Iverlin.Wang@mediatek.com \
    --cc=Markus.Elfring@web.de \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=axboe@kernel.dk \
    --cc=boris@bur.io \
    --cc=cgroups@vger.kernel.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox