From: Waiman Long <longman@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, Tejun Heo <tj@kernel.org>,
Josef Bacik <josef@toxicpanda.com>,
Zefan Li <lizefan.x@bytedance.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
"Michal Koutný" <mkoutny@suse.com>,
"Dennis Zhou (Facebook)" <dennisszhou@gmail.com>,
"Waiman Long" <longman@redhat.com>
Subject: [PATCH-block 2/3] blk-cgroup: Don't flush a blkg if destroyed
Date: Thu, 8 Dec 2022 17:01:40 -0500 [thread overview]
Message-ID: <20221208220141.2625775-3-longman@redhat.com> (raw)
In-Reply-To: <20221208220141.2625775-1-longman@redhat.com>
Before commit 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()"),
blkg's stats is only flushed if they are online. In addition, the
stat flushing of blkgs in blkcg_rstat_flush() includes propagating
the rstat data to its parent. However, if a blkg has been destroyed
(offline), the validity of its parent may be questionable. For safety,
revert back to the old behavior by ignoring offline blkg's.
Signed-off-by: Waiman Long <longman@redhat.com>
---
block/blk-cgroup.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 21cc88349f21..c466aef0d467 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -885,6 +885,12 @@ static void blkcg_rstat_flush(struct cgroup_subsys_state *css, int cpu)
WRITE_ONCE(bisc->lqueued, false);
+ /* Don't flush its stats if blkg is offline */
+ if (unlikely(!blkg->online)) {
+ percpu_ref_put(&blkg->refcnt);
+ continue;
+ }
+
/* fetch the current per-cpu values */
do {
seq = u64_stats_fetch_begin(&bisc->sync);
--
2.31.1
next prev parent reply other threads:[~2022-12-08 22:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-08 22:01 [PATCH-block 0/3] blk-cgroup: Fix potential UAF & miscellaneous cleanup Waiman Long
2022-12-08 22:01 ` Waiman Long
2022-12-08 22:01 ` [PATCH-block 1/3] bdi, blk-cgroup: Fix potential UAF of blkcg Waiman Long
2022-12-08 22:01 ` Waiman Long
2022-12-08 22:01 ` Waiman Long [this message]
2022-12-08 22:01 ` [PATCH-block 3/3] blk-cgroup: Flush stats at blkgs destruction path Waiman Long
[not found] ` <20221208220141.2625775-4-longman-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2022-12-08 23:00 ` Jens Axboe
2022-12-08 23:00 ` Jens Axboe
[not found] ` <e8a09f5d-afce-608f-220b-6b32b3ae37b9-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>
2022-12-09 15:58 ` Waiman Long
2022-12-09 15:58 ` Waiman Long
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=20221208220141.2625775-3-longman@redhat.com \
--to=longman@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=cgroups@vger.kernel.org \
--cc=dennisszhou@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=mkoutny@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.