Re: [PATCH] cgroup: Publish css ID after online_css() succeeds in css_create()

From: Tejun Heo

Date: Tue Dec 01 2026 - 09:15:17 EST


Hello, Xinyao.

On Tue, Dec 01, 2026 at 06:10:22PM +0900, Hu Xinyao wrote:
> None of the subsystem ->css_online() callbacks look up the new css via
> ss->css_idr, and css->id itself is already assigned by
> cgroup_idr_alloc(). Move cgroup_idr_replace(&ss->css_idr, css, css->id)
> to after online_css(css) succeeds so a failed css_create() keeps the
> IDR slot as NULL until css_free_rwork_fn() removes the ID reservation.

The ordering is intentional. A css should become visible to iteration and
ID lookups before it goes online and stay visible while it's online. With
this change, a css which is already online can't be found by its ID for a
while.

This means that both iteration and ID lookups can yield a css which isn't
online, and the users need to be able to handle that. AFAICS, the problem
here is that the failure path of css_create() frees the css without
honoring its refcnt. Maybe the failure path should honor the refcnt like
the regular destruction path does?

Thanks.

--
tejun