Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shakeel Butt" <shakeel.butt@linux.dev>, "Tejun Heo" <tj@kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutny" <mkoutny@suse.com>,
	"Michal Hocko" <mhocko@kernel.org>,
	"Roman Gushchin" <roman.gushchin@linux.dev>,
	"Christian Brauner" <brauner@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"T . J . Mercier" <tjmercier@google.com>,
	"Usama Arif" <usama.arif@linux.dev>,
	"Meta kernel team" <kernel-team@meta.com>,
	linux-mm@kvack.org
Subject: Re: [PATCH v3 05/12] cgroup/freezer: don't update the frozen state of removed cgroups
Date: Sat, 05 Dec 2026 18:42:20 +0000	[thread overview]
Message-ID: <sashiko-outbox-251802@kernel.org> (raw)
In-Reply-To: <20261204184041.1489976-6-shakeel.butt@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] cgroup: unmarked css->flags writes race with READ_ONCE in
  cgroup_is_dead()
--

commit 21d3aff2251d5e17e40c0226f10d1d998fb6f9d1
Author: Shakeel Butt <shakeel.butt@linux.dev>

cgroup/freezer: don't update the frozen state of removed cgroups

This commit moves the CSS_ONLINE clear and ancestor count updates in
cgroup_destroy_locked() into a single css_set_lock section, rechecks the
parent's frozen state, and makes cgroup_update_frozen() skip dead cgroups.
It also switches cgroup_is_dead() and the CSS_ONLINE clear to READ_ONCE()
and WRITE_ONCE().

> diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
> index f38da8b810f10..29e4c5160c6a7 100644
> --- a/kernel/cgroup/cgroup.c
> +++ b/kernel/cgroup/cgroup.c
> @@ -6441,25 +6441,17 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
[ ... ]
>  	spin_lock_irq(&css_set_lock);
> +	WRITE_ONCE(cgrp->self.flags, cgrp->self.flags & ~CSS_ONLINE);
>  	list_for_each_entry(link, &cgrp->cset_links, cset_link)
>  		link->cset->dead = true;
[ ... ]
> +	/* @cgrp may have been the last unfrozen descendant of a freezing parent */
> +	cgroup_update_frozen(parent);
>  	spin_unlock_irq(&css_set_lock);
>  
> +	for_each_css(css, ssid, cgrp)
> +		kill_css_sync(css);
> +
> +	/* clear and remove @cgrp dir, @cgrp has an extra ref on its kn */
> +	css_clear_dir(&cgrp->self);

[Severity: Medium]
Does css_clear_dir() still race with READ_ONCE(cgrp->self.flags) in
cgroup_is_dead()?

Clearing CSS_ONLINE in cgroup_destroy_locked() already runs under
css_set_lock, so cgroup_update_frozen() cannot run concurrently with it.
After css_set_lock is released, css_clear_dir(&cgrp->self) updates
cgrp->self.flags with an unmarked write under cgroup_mutex alone:

CPU0 (rmdir)                       CPU1 (exiting task)
cgroup_destroy_locked()
  /* holds cgroup_mutex */
  spin_lock_irq(&css_set_lock)
  WRITE_ONCE(cgrp->self.flags, ...)
  spin_unlock_irq(&css_set_lock)
                                   do_cgroup_task_dead()
                                     spin_lock_irqsave(&css_set_lock, ...)
                                     cgroup_update_frozen()
                                       cgroup_is_dead()
  css_clear_dir(&cgrp->self)
    css->flags &= ~CSS_VISIBLE
                                         READ_ONCE(cgrp->self.flags)
                                           <-- data race

Under KCSAN, a READ_ONCE() racing with an unmarked write to the same word
is still a data race and triggers splats on the exiting-task-after-rmdir
path.  The other cgroup_mutex-only writers in css_populate_dir()
(CSS_VISIBLE) and css_release_work_fn() (CSS_RELEASED) are also unmarked.

Should all cgroup_mutex-only updates to css->flags use WRITE_ONCE()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204184041.1489976-1-shakeel.butt@linux.dev?part=5


  reply	other threads:[~2026-12-05 18:42 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 18:40 [PATCH v3 00/12] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 01/12] cgroup: don't lose a task in css_task_iter when a migration fails Shakeel Butt
2026-12-05  7:54   ` Tejun Heo
2026-12-04 18:40 ` [PATCH v3 02/12] cgroup: kill a child forked while cgroup.kill runs Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 03/12] cgroup: refuse cgroup.kill below a threaded cgroup Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 04/12] cgroup/freezer: check own tasks and descendants for the frozen state Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 05/12] cgroup/freezer: don't update the frozen state of removed cgroups Shakeel Butt
2026-12-05 18:42   ` sashiko-bot [this message]
2026-12-04 18:40 ` [PATCH v3 06/12] cgroup/freezer: test the freeze trap bit under siglock Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 07/12] selftests/cgroup: test cgroup.procs reads across a failed migration Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 08/12] selftests/cgroup: test the frozen state of a cgroup with tasks and children Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 09/12] selftests/cgroup: test cgroup.kill in and below a threaded cgroup Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 10/12] cgroup: factor out cgroup_kn_break_active() and cgroup_kn_unbreak_active() Shakeel Butt
2026-12-04 18:40 ` [PATCH v3 11/12] cgroup: don't hold cgroup_mutex for cgroup.kill Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:40 ` [PATCH v3 12/12] cgroup/freezer: don't hold cgroup_mutex for cgroup.freeze Shakeel Butt
2026-12-05 18:42   ` sashiko-bot
2026-12-04 18:54 ` [PATCH v3 00/12] cgroup: don't hold cgroup_mutex for cgroup.kill and cgroup.freeze Shakeel Butt

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=sashiko-outbox-251802@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=brauner@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mkoutny@suse.com \
    --cc=oleg@redhat.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=tj@kernel.org \
    --cc=tjmercier@google.com \
    --cc=usama.arif@linux.dev \
    /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