From: JP Kobryn <inwardvessel@gmail.com>
To: tj@kernel.org, shakeel.butt@linux.dev, mkoutny@suse.com,
yosryahmed@google.com, hannes@cmpxchg.org,
akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
kernel-team@meta.com
Subject: [PATCH 2/5 cgroup/for-6.16-fixes] cgroup: check for rstat flush callback at css rstat init/exit call sites
Date: Mon, 21 Jul 2025 18:40:27 -0700 [thread overview]
Message-ID: <20250722014030.297537-3-inwardvessel@gmail.com> (raw)
In-Reply-To: <20250722014030.297537-1-inwardvessel@gmail.com>
The css rstat init/exit functions have a dependency on the associated
subsystem which is inspected to see if the flush callback exists. Move this
logic out of these functions and instead let callers perform this check in
advance. This decoupling allows greater flexibility in where
css_rstat_init() may be called.
Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
---
kernel/cgroup/cgroup.c | 18 ++++++++++++------
kernel/cgroup/rstat.c | 6 +-----
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index d684d33236b8..b034f47580f6 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -5452,7 +5452,9 @@ static void css_free_rwork_fn(struct work_struct *work)
struct cgroup_subsys_state *parent = css->parent;
int id = css->id;
- css_rstat_exit(css);
+ if (ss->css_rstat_flush)
+ css_rstat_exit(css);
+
ss->css_free(css);
cgroup_idr_remove(&ss->css_idr, id);
cgroup_put(cgrp);
@@ -5679,9 +5681,11 @@ static struct cgroup_subsys_state *css_create(struct cgroup *cgrp,
goto err_free_css;
css->id = err;
- err = css_rstat_init(css);
- if (err)
- goto err_free_css;
+ if (ss->css_rstat_flush) {
+ err = css_rstat_init(css);
+ if (err)
+ goto err_free_css;
+ }
/* @css is ready to be brought online now, make it visible */
list_add_tail_rcu(&css->sibling, &parent_css->children);
@@ -6141,8 +6145,10 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss, bool early)
css->id = cgroup_idr_alloc(&ss->css_idr, css, 1, 2, GFP_KERNEL);
BUG_ON(css->id < 0);
- BUG_ON(ss_rstat_init(ss));
- BUG_ON(css_rstat_init(css));
+ if (ss->css_rstat_flush) {
+ BUG_ON(ss_rstat_init(ss));
+ BUG_ON(css_rstat_init(css));
+ }
}
/* Update the init_css_set to contain a subsys
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 8c3cb4a989ad..ba656a53136a 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -449,8 +449,7 @@ static int __css_rstat_init(struct cgroup_subsys_state *css, bool is_self)
if (!cgrp->rstat_base_cpu)
return -ENOMEM;
}
- } else if (css->ss->css_rstat_flush == NULL)
- return 0;
+ }
/* the root cgrp's self css has rstat_cpu preallocated */
if (!css->rstat_cpu) {
@@ -484,9 +483,6 @@ static void __css_rstat_exit(struct cgroup_subsys_state *css, bool is_self)
{
int cpu;
- if (!css_uses_rstat(css))
- return;
-
css_rstat_flush(css);
/* sanity check */
--
2.47.1
next prev parent reply other threads:[~2025-07-22 1:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-22 1:40 [PATCH 0/5 cgroup/for-6.16-fixes] harden css_create() for safe placement of call to css_rstat_init() JP Kobryn
2025-07-22 1:40 ` [PATCH 1/5 cgroup/for-6.16-fixes] cgroup: add exclusive css rstat init/exit api for base stats JP Kobryn
2025-07-22 1:40 ` JP Kobryn [this message]
2025-07-22 1:40 ` [PATCH 3/5 cgroup/for-6.16-fixes] cgroup: split init_and_link_css() JP Kobryn
2025-07-22 1:40 ` [PATCH 4/5 cgroup/for-6.16-fixes] cgroup: initialize css rstat before linking to cgroups in css_create() JP Kobryn
2025-07-22 1:40 ` [PATCH 5/5 cgroup/for-6.16-fixes] cgroup: break up the internal rstat init/exit logic by subsys and base JP Kobryn
2025-07-25 17:23 ` [PATCH 0/5 cgroup/for-6.16-fixes] harden css_create() for safe placement of call to css_rstat_init() Michal Koutný
2025-07-28 18:04 ` JP Kobryn
2025-07-29 9:42 ` Michal Koutný
2025-07-29 23:53 ` JP Kobryn
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=20250722014030.297537-3-inwardvessel@gmail.com \
--to=inwardvessel@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mkoutny@suse.com \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=yosryahmed@google.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
all inboxes | Powered by JetHome®