From nobody Sun Feb 8 00:50:23 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 5E67F279330 for ; Thu, 8 May 2025 18:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746730182; cv=none; b=nKuX1lPRJz/03aVl07puTH4yL27UpqUttiOYCHqdBAm0Z3jqCa8+6SQ+ejKmxoA/8lhTAshAG08ozzJlu6BBmMvQ4Up7Tv9WveKGZIhBlw93idLDsReplLBsxD/EvsqSCVVzzsGRvHF54Ojurqvx/a22gXdvEEPqBHLS8Mxvus4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746730182; c=relaxed/simple; bh=EtAlIztMCJMKEhEt9QVGu3WJmhvR9BRPlatOT3QW0Cc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gj2ncEDj4q+Ta/o/7pdda+kuDWUR94fElmJzc1fZHMyeZbbQZ5NkTf9JTB7nEA6rPsHFBvll/elHBGrO2VCtQVYB2MpVCIW5hSq2yFSq2DKsgMHTA3hSGLdlYoNYHynel3PYwqgyf4L+Pik6fy38TAdSZ4Ikq+UWFwBZqr413vA= 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=RseYxYIN; arc=none smtp.client-ip=170.10.129.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="RseYxYIN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746730179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5lMNNiVMCGTW+5fQgycNws60/oO7fHAtilEDqG5nWlU=; b=RseYxYINvpCyHZBm2SlrGBfQXjmAYEMGXC9z4uxFDUDwQJFGUmvzBrx/PNvxtx41jfQIta S2MyXTxM0Mex1yc7ps1HkRwb6e5orGJSgeV+7dvtLNYNwE9cKUcY+6hiHM9iqBeo8qQ1mJ if00OyNupZUbDEonK80QMIKZ3pnMpY4= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-41-GeY56FcKMVGU58ugZPQ1Tw-1; Thu, 08 May 2025 14:49:37 -0400 X-MC-Unique: GeY56FcKMVGU58ugZPQ1Tw-1 X-Mimecast-MFC-AGG-ID: GeY56FcKMVGU58ugZPQ1Tw_1746730176 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 796F31800875; Thu, 8 May 2025 18:49:36 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.242]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BC544180087A; Thu, 8 May 2025 18:49:34 +0000 (UTC) From: Joel Savitz To: linux-kernel@vger.kernel.org Cc: Joel Savitz , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Christian Brauner , Al Viro , cgroups@vger.kernel.org Subject: [PATCH v2 1/2] kernel/nsproxy: remove unnecessary guards Date: Thu, 8 May 2025 14:49:29 -0400 Message-ID: <20250508184930.183040-2-jsavitz@redhat.com> In-Reply-To: <20250508184930.183040-1-jsavitz@redhat.com> References: <20250508184930.183040-1-jsavitz@redhat.com> 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" In free_nsproxy() and the error path of create_new_namesapces() the put_*_ns() calls are guarded by unnecessary NULL checks. put_pid_ns(), put_ipc_ns(), put_uts_ns(), and put_time_ns() will never receive a NULL argument unless their namespace type is disabled, and in this case all four become no-ops at compile time anyway. put_mnt_ns() will never receive a null argument at any time. This unguarded usage is in line with other call sites of put_*_ns(). Signed-off-by: Joel Savitz --- kernel/nsproxy.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c index c9d97ed20122..5f31fdff8a38 100644 --- a/kernel/nsproxy.c +++ b/kernel/nsproxy.c @@ -128,17 +128,13 @@ static struct nsproxy *create_new_namespaces(unsigned= long flags, out_net: put_cgroup_ns(new_nsp->cgroup_ns); out_cgroup: - if (new_nsp->pid_ns_for_children) - put_pid_ns(new_nsp->pid_ns_for_children); + put_pid_ns(new_nsp->pid_ns_for_children); out_pid: - if (new_nsp->ipc_ns) - put_ipc_ns(new_nsp->ipc_ns); + put_ipc_ns(new_nsp->ipc_ns); out_ipc: - if (new_nsp->uts_ns) - put_uts_ns(new_nsp->uts_ns); + put_uts_ns(new_nsp->uts_ns); out_uts: - if (new_nsp->mnt_ns) - put_mnt_ns(new_nsp->mnt_ns); + put_mnt_ns(new_nsp->mnt_ns); out_ns: kmem_cache_free(nsproxy_cachep, new_nsp); return ERR_PTR(err); @@ -189,18 +185,12 @@ int copy_namespaces(unsigned long flags, struct task_= struct *tsk) =20 void free_nsproxy(struct nsproxy *ns) { - if (ns->mnt_ns) - put_mnt_ns(ns->mnt_ns); - if (ns->uts_ns) - put_uts_ns(ns->uts_ns); - if (ns->ipc_ns) - put_ipc_ns(ns->ipc_ns); - if (ns->pid_ns_for_children) - put_pid_ns(ns->pid_ns_for_children); - if (ns->time_ns) - put_time_ns(ns->time_ns); - if (ns->time_ns_for_children) - put_time_ns(ns->time_ns_for_children); + put_mnt_ns(ns->mnt_ns); + put_uts_ns(ns->uts_ns); + put_ipc_ns(ns->ipc_ns); + put_pid_ns(ns->pid_ns_for_children); + put_time_ns(ns->time_ns); + put_time_ns(ns->time_ns_for_children); put_cgroup_ns(ns->cgroup_ns); put_net(ns->net_ns); kmem_cache_free(nsproxy_cachep, ns); --=20 2.45.2 From nobody Sun Feb 8 00:50:23 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 845BB288526 for ; Thu, 8 May 2025 18:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746730186; cv=none; b=hUqw8KNoCRzmQqmb1d8P4Zqga1X5WH9mgNkXiJrjYt9Ot0XLIuvtyUOwuNr00i1phucpPbDRxd9bPaZSLOckspIfv0GOP5iER+w0MF1O/C92x4eerv9RdsS6+9dcfSCEVPho/Az+oQnGu8iCKjgG1YIgGLQikWiU6TSGh3jm3qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746730186; c=relaxed/simple; bh=2z/dxejO94BxmJj7FeoGNO2eZMUhyKNlr+XjgI51RNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R7Lk9QdjmbxH6hnkO+fdY/tCLmYDH4ZjRGx93Cw01aGaTG1r10P3apOtAuBX7peiQBccCl2kSZkqCDgzp4UOLWRYuHVRX3XwdiMMZ3l/cQQFJsLbQw4w3SEHTbfUqWCKSpZpRLd6B9nfImloeh3MbQQc2ZqbSWMPbN/gXknVVsc= 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=Eyu4duNB; arc=none smtp.client-ip=170.10.129.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="Eyu4duNB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746730183; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l6pMU7QkTWIW4OAQj6rirBqLPufuFwpOPXFuk1c/9tI=; b=Eyu4duNBSWw5aB05gu9E0RRwd/3Ow+juQuFBRWW6gi46gbZtZB+tymqjWj4wJ4g5+tnpZ8 WFBaEpkUR6KuQ0v/vjcaKf9fxcsBo/jn4ku6mF/pqx888yvY/aVMed1vb4Hrcsjms3ZqBO z9KNl6Dwg70aRZfz5GDhrhzdu19LXcg= Received: from mx-prod-mc-04.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-169-f_o_LZ7oNpGdO3M23gL_3Q-1; Thu, 08 May 2025 14:49:40 -0400 X-MC-Unique: f_o_LZ7oNpGdO3M23gL_3Q-1 X-Mimecast-MFC-AGG-ID: f_o_LZ7oNpGdO3M23gL_3Q_1746730179 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B089E19560AB; Thu, 8 May 2025 18:49:38 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.242]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C0A901800359; Thu, 8 May 2025 18:49:36 +0000 (UTC) From: Joel Savitz To: linux-kernel@vger.kernel.org Cc: Joel Savitz , Tejun Heo , Johannes Weiner , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Christian Brauner , Al Viro , cgroups@vger.kernel.org Subject: [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case Date: Thu, 8 May 2025 14:49:30 -0400 Message-ID: <20250508184930.183040-3-jsavitz@redhat.com> In-Reply-To: <20250508184930.183040-1-jsavitz@redhat.com> References: <20250508184930.183040-1-jsavitz@redhat.com> 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 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" When CONFIG_CGROUPS is not selected, {get,put}_cgroup_ns become no-ops and therefore it is not necessary to compile in the code for changing the reference count. When CONFIG_CGROUP is selected, there is no valid case where either of {get,put}_cgroup_ns() will be called with a NULL argument. Signed-off-by: Joel Savitz Acked-by: Michal Koutn=C3=BD --- include/linux/cgroup.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index e7da3c3b098b..166d6de50dbf 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -785,6 +785,17 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long = flags, int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen, struct cgroup_namespace *ns); =20 +static inline void get_cgroup_ns(struct cgroup_namespace *ns) +{ + refcount_inc(&ns->ns.count); +} + +static inline void put_cgroup_ns(struct cgroup_namespace *ns) +{ + if (refcount_dec_and_test(&ns->ns.count)) + free_cgroup_ns(ns); +} + #else /* !CONFIG_CGROUPS */ =20 static inline void free_cgroup_ns(struct cgroup_namespace *ns) { } @@ -795,19 +806,10 @@ copy_cgroup_ns(unsigned long flags, struct user_names= pace *user_ns, return old_ns; } =20 -#endif /* !CONFIG_CGROUPS */ +static inline void get_cgroup_ns(struct cgroup_namespace *ns) { } +static inline void put_cgroup_ns(struct cgroup_namespace *ns) { } =20 -static inline void get_cgroup_ns(struct cgroup_namespace *ns) -{ - if (ns) - refcount_inc(&ns->ns.count); -} - -static inline void put_cgroup_ns(struct cgroup_namespace *ns) -{ - if (ns && refcount_dec_and_test(&ns->ns.count)) - free_cgroup_ns(ns); -} +#endif /* !CONFIG_CGROUPS */ =20 #ifdef CONFIG_CGROUPS =20 --=20 2.45.2