From: Bradley Morgan <bradley.morgan@linux.dev>
To: Li Qiang <liqiang01@kylinos.cn>,
Christian Brauner <brauner@kernel.org>,
Alexander Mikhalitsyn <alex@amutable.com>
Cc: Jan Kara <jack@suse.cz>, Seth Forshee <sforshee@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org, containers@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] userns: skip id map lookup for init_user_ns
Date: Sat, 05 Dec 2026 17:52:14 +0000 [thread overview]
Message-ID: <4313D3B8-E5B0-42CA-84A7-147779C0C67F@linux.dev> (raw)
In-Reply-To: <20261205095025.185272-1-liqiang01@kylinos.cn>
On 5 December 2026 09:49:48 GMT, Li Qiang <liqiang01@kylinos.cn> wrote:
>Converting a UID, GID or project ID in init_user_ns calls
>map_id_down()/map_id_up(), executes smp_rmb(), and walks a single
>immutable identity extent. Return the input directly in the six
>make_k*() and from_k*() helpers when the namespace is init_user_ns,
>avoiding the call overhead and barrier. For (u32)-1, this returns the
>same value as a failed lookup.
>
>An earlier equivalent version measured on a 256-CPU Hygon C86-4G
>running a 6.6 kernel with user namespaces and return thunks enabled
>gave:
>
> Workload Baseline Patched Delta
> getuid() 141.8 ns 128.5 ns -9.4%
> getresuid() 366.1 ns 326.6 ns -10.8%
> setfsuid(-1) 167.1 ns 141.6 ns -15.2%
> fstat() on tmpfs 437.4 ns 413.0 ns -5.6%
> fstat(), 256 threads 447.3 Mop/s 485.3 Mop/s +8.5%
> fstat() in a child userns 437.6 ns 437.6 ns 0.0%
>
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
>Signed-off-by: Li Qiang <liqiang01@kylinos.cn>
>---
>Changes in v2:
>- Drop the two three-argument wrappers. Check for init_user_ns in each
> conversion function so the fallback uses that ID type's map (Alex).
>- Drop the long comment (Alex, Bradley) and clarify the (u32)-1 case
> in the commit message.
>- Identify the 6.6 kernel used for the v1 measurements.
Why even use 6.6 kernel for any measurements, we are in 7.4. could you
provide results for 7.4?
>
>v1: https://lore.kernel.org/r/20261204064759.49001-1-liqiang01@kylinos.cn
>
> kernel/user_namespace.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
>diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
>index cd748e1cbace..6bfd7a0d1ad2 100644
>--- a/kernel/user_namespace.c
>+++ b/kernel/user_namespace.c
>@@ -422,7 +422,9 @@ u32 map_id_up(const struct uid_gid_map *map, u32 id)
> */
> kuid_t make_kuid(struct user_namespace *ns, uid_t uid)
> {
>- /* Map the uid to a global kernel uid */
>+ if (ns == &init_user_ns)
>+ return KUIDT_INIT(uid);
>+
> return KUIDT_INIT(map_id_down(&ns->uid_map, uid));
> }
> EXPORT_SYMBOL(make_kuid);
>@@ -441,7 +443,9 @@ EXPORT_SYMBOL(make_kuid);
> */
> uid_t from_kuid(struct user_namespace *targ, kuid_t kuid)
> {
>- /* Map the uid from a global kernel uid */
>+ if (targ == &init_user_ns)
>+ return __kuid_val(kuid);
>+
> return map_id_up(&targ->uid_map, __kuid_val(kuid));
> }
> EXPORT_SYMBOL(from_kuid);
>@@ -490,7 +494,9 @@ EXPORT_SYMBOL(from_kuid_munged);
> */
> kgid_t make_kgid(struct user_namespace *ns, gid_t gid)
> {
>- /* Map the gid to a global kernel gid */
>+ if (ns == &init_user_ns)
>+ return KGIDT_INIT(gid);
>+
> return KGIDT_INIT(map_id_down(&ns->gid_map, gid));
> }
> EXPORT_SYMBOL(make_kgid);
>@@ -509,7 +515,9 @@ EXPORT_SYMBOL(make_kgid);
> */
> gid_t from_kgid(struct user_namespace *targ, kgid_t kgid)
> {
>- /* Map the gid from a global kernel gid */
>+ if (targ == &init_user_ns)
>+ return __kgid_val(kgid);
>+
> return map_id_up(&targ->gid_map, __kgid_val(kgid));
> }
> EXPORT_SYMBOL(from_kgid);
>@@ -557,7 +565,9 @@ EXPORT_SYMBOL(from_kgid_munged);
> */
> kprojid_t make_kprojid(struct user_namespace *ns, projid_t projid)
> {
>- /* Map the uid to a global kernel uid */
>+ if (ns == &init_user_ns)
>+ return KPROJIDT_INIT(projid);
>+
> return KPROJIDT_INIT(map_id_down(&ns->projid_map, projid));
> }
> EXPORT_SYMBOL(make_kprojid);
>@@ -576,7 +586,9 @@ EXPORT_SYMBOL(make_kprojid);
> */
> projid_t from_kprojid(struct user_namespace *targ, kprojid_t kprojid)
> {
>- /* Map the uid from a global kernel uid */
>+ if (targ == &init_user_ns)
>+ return __kprojid_val(kprojid);
>+
> return map_id_up(&targ->projid_map, __kprojid_val(kprojid));
> }
> EXPORT_SYMBOL(from_kprojid);
>
>base-commit: 007722b8211f7b34fdf21b1e6a9c32497633ea29
>
--- Thanks!
next prev parent reply other threads:[~2026-12-05 17:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 9:49 [PATCH v2] userns: skip id map lookup for init_user_ns Li Qiang
2026-12-05 17:52 ` Bradley Morgan [this message]
2026-12-06 5:54 ` Tao Cui
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=4313D3B8-E5B0-42CA-84A7-147779C0C67F@linux.dev \
--to=bradley.morgan@linux.dev \
--cc=alex@amutable.com \
--cc=brauner@kernel.org \
--cc=containers@lists.linux.dev \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liqiang01@kylinos.cn \
--cc=sforshee@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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