2022-01-26 18:37:17

by Leo Yan

[permalink] [raw]
Subject: [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns()

This patch series introduces a helper function task_is_in_init_pid_ns()
to replace open code. The two patches are extracted from the original
series [1] for network subsystem.

As a plan, we can firstly land this patch set into kernel 5.18; there
have 5 patches are left out from original series [1], as a next step,
I will resend them for appropriate linux-next merging.

[1] https://lore.kernel.org/lkml/[email protected]/

Changes from v2:
* No any code change.
* Extract two patches for network subsystem. (Jakub)
* Added reviewed and acked tags. (Leon, Suzuki and Balbir)

Changes from v1:
* Renamed helper function from task_is_in_root_ns() to
task_is_in_init_pid_ns(). (Leon Romanovsky)
* Improved patches' commit logs for more neat.


Leo Yan (2):
pid: Introduce helper task_is_in_init_pid_ns()
connector/cn_proc: Use task_is_in_init_pid_ns()

drivers/connector/cn_proc.c | 2 +-
include/linux/pid_namespace.h | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)

--
2.25.1


2022-01-26 18:37:19

by Leo Yan

[permalink] [raw]
Subject: [PATCH net v3 1/2] pid: Introduce helper task_is_in_init_pid_ns()

Currently the kernel uses open code in multiple places to check if a
task is in the root PID namespace with the kind of format:

if (task_active_pid_ns(current) == &init_pid_ns)
do_something();

This patch creates a new helper function, task_is_in_init_pid_ns(), it
returns true if a passed task is in the root PID namespace, otherwise
returns false. So it will be used to replace open codes.

Suggested-by: Suzuki K Poulose <[email protected]>
Signed-off-by: Leo Yan <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Acked-by: Suzuki K Poulose <[email protected]>
Acked-by: Balbir Singh <[email protected]>
---
include/linux/pid_namespace.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index 7c7e627503d2..07481bb87d4e 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -86,4 +86,9 @@ extern struct pid_namespace *task_active_pid_ns(struct task_struct *tsk);
void pidhash_init(void);
void pid_idr_init(void);

+static inline bool task_is_in_init_pid_ns(struct task_struct *tsk)
+{
+ return task_active_pid_ns(tsk) == &init_pid_ns;
+}
+
#endif /* _LINUX_PID_NS_H */
--
2.25.1

2022-01-26 18:37:48

by Leo Yan

[permalink] [raw]
Subject: [PATCH net v3 2/2] connector/cn_proc: Use task_is_in_init_pid_ns()

This patch replaces open code with task_is_in_init_pid_ns() to check if
a task is in root PID namespace.

Signed-off-by: Leo Yan <[email protected]>
Acked-by: Balbir Singh <[email protected]>
---
drivers/connector/cn_proc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
index 646ad385e490..ccac1c453080 100644
--- a/drivers/connector/cn_proc.c
+++ b/drivers/connector/cn_proc.c
@@ -358,7 +358,7 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
* other namespaces.
*/
if ((current_user_ns() != &init_user_ns) ||
- (task_active_pid_ns(current) != &init_pid_ns))
+ !task_is_in_init_pid_ns(current))
return;

/* Can only change if privileged. */
--
2.25.1

2022-01-27 11:10:40

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns()

Hello:

This series was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:

On Wed, 26 Jan 2022 13:04:25 +0800 you wrote:
> This patch series introduces a helper function task_is_in_init_pid_ns()
> to replace open code. The two patches are extracted from the original
> series [1] for network subsystem.
>
> As a plan, we can firstly land this patch set into kernel 5.18; there
> have 5 patches are left out from original series [1], as a next step,
> I will resend them for appropriate linux-next merging.
>
> [...]

Here is the summary with links:
- [net,v3,1/2] pid: Introduce helper task_is_in_init_pid_ns()
https://git.kernel.org/netdev/net/c/d7e4f8545b49
- [net,v3,2/2] connector/cn_proc: Use task_is_in_init_pid_ns()
https://git.kernel.org/netdev/net/c/42c66d167564

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html