From: Shakeel Butt <shakeel.butt@linux.dev>
To: Tejun Heo <tj@kernel.org>
Cc: "Christian Brauner" <brauner@kernel.org>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jori Koolstra" <jkoolstra@xs4all.nl>,
"Meta kernel team" <kernel-team@meta.com>,
cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org,
driver-core@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cgroup: allocate the inode for cgroup_may_write() before cgroup_mutex
Date: Fri, 20 Nov 2026 10:24:46 -0800 [thread overview]
Message-ID: <awCLBDApSWwDsBB_@linux.dev> (raw)
In-Reply-To: <b8b2c07c12f5a156e2d72ab4ee4444cc@kernel.org>
On Fri, Nov 20, 2026 at 01:24:18AM -1000, Tejun Heo wrote:
> Hello, Shakeel.
>
> On Wed, Nov 18, 2026 at 03:03:45PM -0800, Shakeel Butt wrote:
> > + dst_cgrp = cgroup_kn_break_active(of->kn);
> > if (IS_ERR(dst_cgrp))
> > return PTR_ERR(dst_cgrp);
> > + new = new_inode(of->file->f_path.dentry->d_sb);
> > + cgroup_lock();
>
> I don't really like new_inode() being called on every write, and twice on
> every clone3(CLONE_INTO_CGROUP). The inode is often not cached but not
> mostly. It's not a lot of overhead, but doing it the right way isn't that
> complicated either. How about peeking at the inode cache before taking the
> locks, preallocating only when the peek misses, and then looking up again
> under cgroup_mutex? If the peek turns out wrong, it can drop the locks,
> allocate and retry, so that nothing is allocated under the lock.
Thanks for taking a look and yes, this makes sense.
> Can we
> apply the same shape in other places too?
Yes, I agree, though I will do that in followup patches. More specifically I
think I can do the same approach in __kernfs_fh_to_dentry() and
kernfs_get_parent_dentry() for inode. For kernfs_setattr(), I think I can use
the same approach for iattrs. Also I am working on allocating css for new cgroup
before cgroup_mutex in mkdir wich will use similar approach.
>
> > scoped_with_creds(of->file->f_cred)
> > - ret = cgroup_attach_permissions(src_cgrp, dst_cgrp,
> > - of->file->f_path.dentry->d_sb,
> > + ret = cgroup_attach_permissions(src_cgrp, dst_cgrp, &new,
> > threadgroup, ctx->ns);
>
> AFAICS, this changes behavior under Smack. Smack labels a new inode from the
> allocating task's creds, and the allocation used to be inside
> scoped_with_creds(). Now the inode gets the writer's label and the
> permission check runs with the opener's creds, which can fail when the two
> differ. Maybe the allocation can use the opener's creds too?
Thanks for catching this. I will make sure this remain the same in the v2.
prev parent reply other threads:[~2026-11-20 18:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 23:03 [PATCH] cgroup: allocate the inode for cgroup_may_write() before cgroup_mutex Shakeel Butt
2026-11-20 11:24 ` Tejun Heo
2026-11-20 18:24 ` Shakeel Butt [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=awCLBDApSWwDsBB_@linux.dev \
--to=shakeel.butt@linux.dev \
--cc=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=jkoolstra@xs4all.nl \
--cc=kernel-team@meta.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox