From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796536475; b=OVzmlyD22A57E5fZ3/qO2z88/RyQ5ncCbY0nmLtrCvbUBs+prQ+HuLrdTyqYWI6XpWqf ToVIHmWniPGKXcfFDXj7k1/ZmhAtPGzeyocVfOYPilPI3iu08i3qFcC9mblokTKEX5zGF q/7XUF75mRAa+kFvLoZKQ9/IZV9AVbzme7AsnUs5r/5UCOVmoUmDiTYdD7aBfvGRnCyiz C6YhIsbyS519sEsZO2AA2yBGKgBg9bfrLXZLPT+eQbgmsouSo/jyL+1OfwuZwLwgE6DXJ o3vPDKnd9peg8mOk4XOaIYizrraG6NwgzjCl5uS+jTe001LMr1HKuPR+7WEy4b0XZdQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796536475; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Cc:Subject:To:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=uF2Y+khVSfyjYU86H8CVs8wBr/XzuveIqW76XXEUSpw=; b=pqRVjOjw7Uv1aVIo0CO3nhiolORYdJhjVWtdgD0UoPg6EMjUfUdEP/FnT2C8wOh7bZlU BwQRrZSSURianfiS7tW24vc1+oGSYCeVHrXtytIDRkDh5Gdn7pV4PNzZ2mpoLeYJZoerO /HFVGqJ2XgcXt6omAifZfpV2//OhJMKdzbKKql3veMTpOH5W2nrKLxTZkkTNn5yRmc60n 28z9a2HdlsUxZpkOgB+gta1VUjLpioAckAP/+nyduPp2piVhKiAMvyB/SIL+kkPzRaQIR Jbe3pKjDVQjsvNUMdglp1RG8Ks4NQ2cuN2pCwK3FEn8ijfhr3L/CJuLQyYiZ+Y6w6Iw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=HICJMeZ5; arc=none smtp.remote-ip=95.215.58.45 Received: from mta1.migadu.com (out-45.mta1.migadu.com [95.215.58.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC236606A31F for ; Sun, 6 Dec 2026 05:54:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC236606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=HICJMeZ5 X-Envelope-To: linux-fsdevel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=6b3qEn1YMj4UxT2p3dCOtgac8jR3FeNzkgMLJTKgm24=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796536471; v=1; x=1797141271; b=HICJMeZ5cLbIBFX++ze8iFp0jGQ2xrNNsXLDL76moPxb3fBUu5lbezwJQ3JEvBRBlJDdVDGK 7e+ynN6Da3pilOOAx0IpGok3S4mwF6mUZHd3YYYHmDHkT3cw2v+KhsIA3cXATYrfEqqYTPd699a A4FN828oc8tEDPfFozqumwJk= X-Envelope-To: linux-fsdevel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 67502aba75d346cc; Sun, 06 Dec 2026 05:54:31 +0000 X-Mizu-Trace-ID: 67502aba75d346cc X-Migadu-Flow: FLOW_OUT Message-ID: Date: Sun, 6 Dec 2026 13:54:24 +0800 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: cui.tao@linux.dev, Jan Kara , Seth Forshee , Alexander Viro , Bradley Morgan , 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 To: Li Qiang , Christian Brauner , Alexander Mikhalitsyn References: <20261205095025.185272-1-liqiang01@kylinos.cn> From: Tao Cui In-Reply-To: <20261205095025.185272-1-liqiang01@kylinos.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello, Qiang, 在 2026/12/5 17:49, Li Qiang 写道: > 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% > I tested v2 on top of your base 007722b8211f (7.4.0-rc5), KVM guest on a Hygon host with rethunk active, gcc 12.3 build. Medians over 3 boots x 3 rounds: getuid() 100.2 -> 95.9 ns (-4.3%) getresuid() 265.5 -> 251.1 ns (-5.4%) setfsuid(-1) 108.2 -> 100.9 ns (-6.8%) fstat() on tmpfs 326.1 -> 319.2 ns (-2.1%) fstat(), 16 threads +13.9% fstat(), child userns unchanged A getpid() control run in between stayed flat. FWIW these numbers are with gcc, which keeps the extent lookup out-of-line. clang inlines it into make_kuid()/from_kuid(), so there v2 only drops the single-extent loop (~1 ns per call, measured from a module) and the syscall numbers are within noise. Maybe mention the compiler in the commit message? Otherwise looks correct to me. (u32)-1 falls outside the identity extent so the early return matches the lookup failure value, and from_kuid_munged()/kuid_has_mapping() go through from_kuid()/ make_kuid() anyway. Tested-by: Tao Cui Reviewed-by: Tao Cui Thanks, Tao > Signed-off-by: Li Qiang > --- > 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. > > 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