From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45ED123505E for ; Sat, 7 Mar 2026 09:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772875439; cv=none; b=UxA/6ayEfdME/wk+5ZIqz2Se/eA8UIsx/3QPWZOQFT6Ydv+VZbHbZDM96Ii/A1ziqUxSLLz82Yon0cOpsI5UJANIvcV1PZRqIwBA+HL8ip3vwkiHyuhfdGZL7X1jxYBjHdyFoGGJ0pxjrBoCC5MjtjAadgx/SfC4fMUMfVOyD84= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772875439; c=relaxed/simple; bh=RX5MAl049wB+IN7XEcrV5Cpt3DogmEYfWSfwXszPT/4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O5EoxyPoQwFemDb8agZaVLLZVmkvjZ64equNtbTkOkod5NzSIpjw0mONEurL94fjHc2gdKQuvRvpEbkfkT0KOj/jg3OsuHkSveqnb/odywuWaj+/xQyyPzUi3Y4lUNmxnHQCdKozNwJB1dbE+zE+PqwIk3n4Xhe/MoqXLvcpH7Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PQI1Ckli; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PQI1Ckli" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772875436; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kPoaumSQGQDHjPKkao9qJkcUuFlJLf7irl7NQ7E98l0=; b=PQI1CkliG8/onpCgXNs4taPG8BVph8hUHsSdRtz0l5h0hAElCKQ9ssqiIZNu6M4cr5B0t7 rD5Xldj2sx1JDqF3gntBDOQpC0asqJkx4oxobFMGpkY6TRF1z9ryQq7+iNJKXsAXeJk0bs sckzcKAteQwpT48LNO63flpvb+HIs74= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-Pkc55JnhPzCzPM9390S7BA-1; Sat, 07 Mar 2026 04:23:50 -0500 X-MC-Unique: Pkc55JnhPzCzPM9390S7BA-1 X-Mimecast-MFC-AGG-ID: Pkc55JnhPzCzPM9390S7BA_1772875429 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 63A7919560B5; Sat, 7 Mar 2026 09:23:49 +0000 (UTC) Received: from fedora (unknown [10.45.224.43]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 074A11956095; Sat, 7 Mar 2026 09:23:46 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 7 Mar 2026 10:23:48 +0100 (CET) Date: Sat, 7 Mar 2026 10:23:45 +0100 From: Oleg Nesterov To: Mateusz Guzik , Andrew Morton , Pavel Tikhomirov Cc: brauner@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] pid: cosmetic changes to alloc_pid() Message-ID: References: <20260306190100.1900572-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260306190100.1900572-1-mjguzik@gmail.com> X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 On 03/06, Mateusz Guzik wrote: > > 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 The patch looks obviously good, but it conflicts with Pavel's [PATCH v4 0/4] pid_namespace: make init creation more flexible https://lore.kernel.org/all/20260225133229.550302-1-ptikhomirov@virtuozzo.com/#t In particular, this change: - for (tmp = ns, i = ns->level; i >= 0; i--) { + for (tmp = ns, i = ns->level; i >= 0;) { With 2/4 from Pavel we need to decrement "i" before the ->child_reaper check. Pavel, it seems you need to resend your series anyway, may be on top of this patch, I dunno. And probably this all should be routed via -mm tree? Oleg. > --- > 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); > > /* > @@ -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 = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL); > - if (!pid) > + if (unlikely(!pid)) > return ERR_PTR(retval); > > 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 should > * later code need it. > */ > - for (tmp = ns, i = ns->level; i >= 0; i--) { > + for (tmp = ns, i = ns->level; i >= 0;) { > pid_max[ns->level - i] = READ_ONCE(tmp->pid_max); > > if (arg_set_tid_size) { > @@ -227,6 +227,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *arg_set_tid, > } > > tmp = tmp->parent; > + i--; > } > > /* > @@ -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 == -ENOSPC) > - > nr = -EEXIST; > } else { > int pid_min = 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 may 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 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). > * > - * The lock can be safely dropped and picked up as historically pid allocation > + * 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. > */ > -- > 2.48.1 >