* [PATCH v2 0/2] Minor namespace code simplication
@ 2025-05-08 18:49 Joel Savitz
2025-05-08 18:49 ` [PATCH v2 1/2] kernel/nsproxy: remove unnecessary guards Joel Savitz
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Joel Savitz @ 2025-05-08 18:49 UTC (permalink / raw)
To: linux-kernel
Cc: Joel Savitz, Tejun Heo, Johannes Weiner, Michal Koutný,
Christian Brauner, Al Viro, cgroups
The two patches are independent of each other. The first patch removes
unnecssary NULL guards from free_nsproxy() and create_new_namespaces()
in line with other usage of the put_*_ns() call sites. The second patch
slightly reduces the size of the kernel when CONFIG_CGROUPS is not
selected.
Joel Savitz (2):
kernel/nsproxy: remove unnecessary guards
include/cgroup: separate {get,put}_cgroup_ns no-op case
Changes from v1:
- now removing the guards instead of adding them where missing since
checking that all calls in the NULL case were already no-ops
- added second patch
include/linux/cgroup.h | 26 ++++++++++++++------------
kernel/nsproxy.c | 30 ++++++++++--------------------
2 files changed, 24 insertions(+), 32 deletions(-)
--
2.45.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] kernel/nsproxy: remove unnecessary guards
2025-05-08 18:49 [PATCH v2 0/2] Minor namespace code simplication Joel Savitz
@ 2025-05-08 18:49 ` Joel Savitz
2025-05-08 18:49 ` [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case Joel Savitz
2025-05-09 11:14 ` [PATCH v2 0/2] Minor namespace code simplication Christian Brauner
2 siblings, 0 replies; 6+ messages in thread
From: Joel Savitz @ 2025-05-08 18:49 UTC (permalink / raw)
To: linux-kernel
Cc: Joel Savitz, Tejun Heo, Johannes Weiner, Michal Koutný,
Christian Brauner, Al Viro, cgroups
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 <jsavitz@redhat.com>
---
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)
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);
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case
2025-05-08 18:49 [PATCH v2 0/2] Minor namespace code simplication Joel Savitz
2025-05-08 18:49 ` [PATCH v2 1/2] kernel/nsproxy: remove unnecessary guards Joel Savitz
@ 2025-05-08 18:49 ` Joel Savitz
2025-05-09 13:35 ` Michal Koutný
2025-05-09 17:34 ` Tejun Heo
2025-05-09 11:14 ` [PATCH v2 0/2] Minor namespace code simplication Christian Brauner
2 siblings, 2 replies; 6+ messages in thread
From: Joel Savitz @ 2025-05-08 18:49 UTC (permalink / raw)
To: linux-kernel
Cc: Joel Savitz, Tejun Heo, Johannes Weiner, Michal Koutný,
Christian Brauner, Al Viro, cgroups
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 <jsavitz@redhat.com>
---
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);
+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 */
static inline void free_cgroup_ns(struct cgroup_namespace *ns) { }
@@ -795,19 +806,10 @@ copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,
return old_ns;
}
-#endif /* !CONFIG_CGROUPS */
+static inline void get_cgroup_ns(struct cgroup_namespace *ns) { }
+static inline void put_cgroup_ns(struct cgroup_namespace *ns) { }
-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 */
#ifdef CONFIG_CGROUPS
--
2.45.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/2] Minor namespace code simplication
2025-05-08 18:49 [PATCH v2 0/2] Minor namespace code simplication Joel Savitz
2025-05-08 18:49 ` [PATCH v2 1/2] kernel/nsproxy: remove unnecessary guards Joel Savitz
2025-05-08 18:49 ` [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case Joel Savitz
@ 2025-05-09 11:14 ` Christian Brauner
2 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2025-05-09 11:14 UTC (permalink / raw)
To: linux-kernel, Joel Savitz
Cc: Christian Brauner, Tejun Heo, Johannes Weiner, Michal Koutný,
Al Viro, cgroups
On Thu, 08 May 2025 14:49:28 -0400, Joel Savitz wrote:
> The two patches are independent of each other. The first patch removes
> unnecssary NULL guards from free_nsproxy() and create_new_namespaces()
> in line with other usage of the put_*_ns() call sites. The second patch
> slightly reduces the size of the kernel when CONFIG_CGROUPS is not
> selected.
>
> Joel Savitz (2):
> kernel/nsproxy: remove unnecessary guards
> include/cgroup: separate {get,put}_cgroup_ns no-op case
>
> [...]
Applied to the vfs-6.16.misc branch of the vfs/vfs.git tree.
Patches in the vfs-6.16.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-6.16.misc
[1/2] kernel/nsproxy: remove unnecessary guards
https://git.kernel.org/vfs/vfs/c/5caa2d89b7f1
[2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case
https://git.kernel.org/vfs/vfs/c/79fb8d8d93e4
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case
2025-05-08 18:49 ` [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case Joel Savitz
@ 2025-05-09 13:35 ` Michal Koutný
2025-05-09 17:34 ` Tejun Heo
1 sibling, 0 replies; 6+ messages in thread
From: Michal Koutný @ 2025-05-09 13:35 UTC (permalink / raw)
To: Joel Savitz
Cc: linux-kernel, Tejun Heo, Johannes Weiner, Christian Brauner,
Al Viro, cgroups
[-- Attachment #1: Type: text/plain, Size: 615 bytes --]
On Thu, May 08, 2025 at 02:49:30PM -0400, Joel Savitz <jsavitz@redhat.com> wrote:
> 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 <jsavitz@redhat.com>
> ---
> include/linux/cgroup.h | 26 ++++++++++++++------------
> 1 file changed, 14 insertions(+), 12 deletions(-)
Acked-by: Michal Koutný <mkoutny@suse.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case
2025-05-08 18:49 ` [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case Joel Savitz
2025-05-09 13:35 ` Michal Koutný
@ 2025-05-09 17:34 ` Tejun Heo
1 sibling, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2025-05-09 17:34 UTC (permalink / raw)
To: Joel Savitz
Cc: linux-kernel, Johannes Weiner, Michal Koutný,
Christian Brauner, Al Viro, cgroups
On Thu, May 08, 2025 at 02:49:30PM -0400, Joel Savitz wrote:
> 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 <jsavitz@redhat.com>
Applied to cgroup/for-6.16.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-09 17:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-08 18:49 [PATCH v2 0/2] Minor namespace code simplication Joel Savitz
2025-05-08 18:49 ` [PATCH v2 1/2] kernel/nsproxy: remove unnecessary guards Joel Savitz
2025-05-08 18:49 ` [PATCH v2 2/2] include/cgroup: separate {get,put}_cgroup_ns no-op case Joel Savitz
2025-05-09 13:35 ` Michal Koutný
2025-05-09 17:34 ` Tejun Heo
2025-05-09 11:14 ` [PATCH v2 0/2] Minor namespace code simplication Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox