From: "tj@kernel.org" <tj@kernel.org>
To: "Boy Wu (吳勃誼)" <Boy.Wu@mediatek.com>
Cc: "boris@bur.io" <boris@bur.io>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
"linux-mediatek@lists.infradead.org"
<linux-mediatek@lists.infradead.org>,
"axboe@kernel.dk" <axboe@kernel.dk>,
"Iverlin Wang (王苳霖)" <Iverlin.Wang@mediatek.com>,
"josef@toxicpanda.com" <josef@toxicpanda.com>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
"angelogioacchino.delregno@collabora.com"
<angelogioacchino.delregno@collabora.com>
Subject: Re: [PATCH] blk-cgroup: add spin_lock for u64_stats_update
Date: Mon, 8 Jul 2024 08:36:36 -1000 [thread overview]
Message-ID: <ZowxtI69yd4IexQY@slm.duckdns.org> (raw)
In-Reply-To: <709276ca279982cf0014e93eafaa2272f847ff4a.camel@mediatek.com>
Hello,
On Mon, Jul 08, 2024 at 02:00:42AM +0000, Boy Wu (吳勃誼) wrote:
> When accessing /sys/fs/cgroup/io.stat, blkcg_print_stat will be called,
> and there is a small chance that four processes on each CPU core are
> accessing /sys/fs/cgroup/io.stat, which means four CPUs are calling
> blkcg_print_stat. As a result, blkcg_fill_root_iostats will be called
> simultaneously. However, u64_stats_update_begin_irqsave and
> u64_stats_update_end_irqrestore are not protect by spin_locks, so there
> is a small chance that the sync.seq.sequence will be an odd number
> after u64_stats_update_end_irqrestore due to the concurrent CPUs acess,
> because sync.seq.sequence plus one is not an atomic operation.
>
> do_raw_write_seqcount_begin():
> /usr/src/kernel/common/include/linux/seqlock.h:469
> c05e5cfc: e5963030 ldr r3, [r6, #48] ; 0x30
> c05e5d00: e2833001 add r3, r3, #1
> c05e5d04: e5863030 str r3, [r6, #48] ; 0x30
> /usr/src/kernel/common/include/linux/seqlock.h:470
> c05e5d08: f57ff05a dmb ishst
>
> do_raw_write_seqcount_end():
> /usr/src/kernel/common/include/linux/seqlock.h:489
> c05e5d30: f57ff05a dmb ishst
> /usr/src/kernel/common/include/linux/seqlock.h:490
> c05e5d34: e5963030 ldr r3, [r6, #48] ; 0x30
> c05e5d38: e2833001 add r3, r3, #1
> c05e5d3c: e5863030 str r3, [r6, #48] ; 0x30
>
> To prevent this problem, I added spin_locks in blkcg_fill_root_iostats,
> and this solution works fine to me when I use the stress-ng --sysfs
> test.
Ah, okay, so, there are two usages of u64_sync synchronization - one is for
blkg->iostat_cpu and the other for blkg->iostat. The former makes sense and
is safe as there can ever be only one updater with irq disabled. The latter
doesn't work as there can be multiple updaters and should be removed (and
replaced with spinlock). There's already blkg_stat_lock which probably was
added for a similar reason in __blkcg_rstat_flush(). Can you please update
the patch to remove the u64_sync usage for blkg->iostat and replace it with
blkg_stat_lock?
Thanks.
--
tejun
prev parent reply other threads:[~2024-07-08 18:36 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 (吳勃誼)
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 [this message]
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=ZowxtI69yd4IexQY@slm.duckdns.org \
--to=tj@kernel.org \
--cc=Boy.Wu@mediatek.com \
--cc=Iverlin.Wang@mediatek.com \
--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 \
/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