From nobody Thu Apr 9 16:33:21 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57D0A7081E for ; Fri, 6 Mar 2026 19:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772823672; cv=none; b=uaWiR6mFnexIG0n1gR+7ZmVTuLxJh2ivxK3VTadXH283C14wsnEiuNdNZ+TuIpXfPsDBMIQ9/Rp14f9YBI0/7bRVkz5Iaei5CFQcNzbNzBnkc7fZN2jWKs3akPJIvYF3CFyqUDxspGLk9kS0kJsi7CvLnL3SkgLWfKEJni/pkfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772823672; c=relaxed/simple; bh=c4E16MRlbW4tyZtO6qWYn63lIM61AACwhTnTBIVWZgU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PfjcbRy9Tk3Qxmr0lntrJzXZbKup3aMU/PM8SZTgah/uv5Hn72YFHEX5Uro4+QyMaUDFQbTyB8GsHU5N3pH0NasJlYVaKoXCqD8iZdRqbpZZy5gI69joI05o+SLfDibTESp3qOLnPnUbSzIdrqgYwHg7k15RbC6wovntC1ucuxs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VdeJFYBg; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VdeJFYBg" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-48371bb515eso141759005e9.1 for ; Fri, 06 Mar 2026 11:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772823670; x=1773428470; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=egP4uheYvC9sMPollgo9xc+pktivTQM4ujp0h14jJjQ=; b=VdeJFYBgkw/stldm5tuL3jSgw1K0L+PsuQMmCiyB49FhE19hSTHAp8YPaYw8p6z1kv GGyS0stJ6SKwFYo+aXTaTeXhsfQ9ZqRC0zXAVrJ8n6SytNHq743h5bU042spxb7HxCz6 pze+X5WzUmScy//SGtros7JxKMM8ZB/01ggqQzNheBf6XU/aJj+gOVNaFFAGEV7l6FoI QQ94CGRmU+83OR6i+NLrJskmNwXI5JP5+kB98uOilRvFXnzahuhtQddkUnaCDtv4A+8k 5MIJsrTmpsSXZ31ttL/ivpxUanAPHZEiqSTU4U0I3kVs1JduXq653bfpGRGzMBfwv/CX i8uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772823670; x=1773428470; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=egP4uheYvC9sMPollgo9xc+pktivTQM4ujp0h14jJjQ=; b=AiYsFeqiUx/QeTP6h94oOyCyHyMIKPSIQSTcpRJuS0DQyIINfc4gzMDrLGBHPbTbOJ J9qhrqH3OxRGKVUUIUoF8DS4XvYuBR658ObOuQfr+eSHjz/DM3CIPJULk96vTzpB/Gnq dSowkrSK1gs7BvbmKUtFr1OHfkmx/x2BKEgt+JssQCNPCv4fLZD/wKwYSTB91x9KmNUe Lbv7AaLOUEiVDMZqnY/LNsGyUoaW0QGGbEWngQSjvJ5Kmd4j6uEwzkNiKFuJ61OFwcBk oTJx2z4i8iFbHz0dbNBBFj+EExJk6TjMzZiBVXdIwa0/2ZkfCGT/OfwSkqNMrnb5DiMs IGLw== X-Gm-Message-State: AOJu0YzlyeNCsY9s7zNBuDGxGPkz7j4dkeaMZiLlXTNWP7xnYDvlpSbn fVnsbZ0tRqLEgDR7Jwr9WVwF+SqHq8/pzO4M/6G1NqeClYBZe2xqk7QC X-Gm-Gg: ATEYQzwJGGoqHzn+eU/8Ivlr3SXUxd5Z8U5hKG6uRISM9KnU652/78H6XB5LOh0fPD2 r/NsZNp6tStcpTVn2xD3ZYaJeFw4//IEbSC3oUA6CpIfazAEB0h4NQlypQTzuA6qj3LJNZBnoOX 6K22LYnbWpSUs6KCtnTGdWiqzYz3XSkKhq5Ip6ml7ixAirBZAO2eAP7jvW4EJUBR39nuIaLYqT4 sGmBQr/05eQP8ryacVIaSrPcGjO4d0DZufkKBloIvebt9kn3oqI5IDVPzKhzg5CMaCoOV7fPP8X NtSfyaEoeagecaG25+lzlhDWEBwEVhU4yGvXbmpNncWI7ZciwSYwYt4x9UNViERL0Fp94BgWLD0 IPeOEfMFbxB/sY1bOtcMNBnBUv9qIMrIt4JWZV3cbP2sWKXhf+22/OBDoREkY/OMjEsyuHToFsE T5BJM7ObKjpLRKzxcgFAR5Sni0K96ZwcfIVX/PER/mKFDq8Ew+mOvLnbMwvWqwyfkeSMlqeVAMY +vQRIi+ZBXT X-Received: by 2002:a05:600c:8714:b0:477:6374:6347 with SMTP id 5b1f17b1804b1-48526957d50mr47893785e9.22.1772823669332; Fri, 06 Mar 2026 11:01:09 -0800 (PST) Received: from f.. (cst-prg-92-188.cust.vodafone.cz. [46.135.92.188]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4852767d8e4sm50717025e9.2.2026.03.06.11.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2026 11:01:08 -0800 (PST) From: Mateusz Guzik To: brauner@kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, oleg@redhat.com, Mateusz Guzik Subject: [PATCH] pid: cosmetic changes to alloc_pid() Date: Fri, 6 Mar 2026 20:01:00 +0100 Message-ID: <20260306190100.1900572-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 6d864a1b182532e7 ("pid: only take pidmap_lock once on alloc") landed v2 of the patch instead of v3. This patch remedies the problem. No functional changes. Signed-off-by: Mateusz Guzik Reviewed-by: Pavel Tikhomirov --- kernel/pid.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/kernel/pid.c b/kernel/pid.c index 2f1dbcbc2349..dbe82062e683 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -177,7 +177,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= arg_set_tid, * for a process in all nested PID namespaces but arg_set_tid_size must * never be greater than the current ns->level + 1. */ - if (arg_set_tid_size > ns->level + 1) + if (unlikely(arg_set_tid_size > ns->level + 1)) return ERR_PTR(-EINVAL); =20 /* @@ -186,7 +186,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= arg_set_tid, * 1. allocate and fill in pid struct */ pid =3D kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL); - if (!pid) + if (unlikely(!pid)) return ERR_PTR(retval); =20 get_pid_ns(ns); @@ -205,7 +205,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= arg_set_tid, * This stores found pid_max to make sure the used value is the same shou= ld * later code need it. */ - for (tmp =3D ns, i =3D ns->level; i >=3D 0; i--) { + for (tmp =3D ns, i =3D ns->level; i >=3D 0;) { pid_max[ns->level - i] =3D READ_ONCE(tmp->pid_max); =20 if (arg_set_tid_size) { @@ -227,6 +227,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *= arg_set_tid, } =20 tmp =3D tmp->parent; + i--; } =20 /* @@ -247,10 +248,9 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t = *arg_set_tid, tid + 1, GFP_ATOMIC); /* * If ENOSPC is returned it means that the PID is - * alreay in use. Return EEXIST in that case. + * already in use. Return EEXIST in that case. */ if (nr =3D=3D -ENOSPC) - nr =3D -EEXIST; } else { int pid_min =3D 1; @@ -276,12 +276,11 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t= *arg_set_tid, * Preload more memory if idr_alloc{,cyclic} failed with -ENOMEM. * * The IDR API only allows us to preload memory for one call, while we = may end - * up doing several under pidmap_lock with GFP_ATOMIC. The situation ma= y be - * salvageable with GFP_KERNEL. But make sure to not loop indefinitely = if preload - * did not help (the routine unfortunately returns void, so we have no = idea - * if it got anywhere). + * up doing several with GFP_ATOMIC. It may be the situation is salvage= able with + * GFP_KERNEL. But make sure to not loop indefinitely if preload did no= t help + * (the routine unfortunately returns void, so we have no idea if it go= t anywhere). * - * The lock can be safely dropped and picked up as historically pid all= ocation + * The pidmap lock can be safely dropped and picked up as historically = pid allocation * for different namespaces was *not* atomic -- we try to hold on to it= the * entire time only for performance reasons. */ --=20 2.48.1