linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns()
@ 2022-01-26  5:04 Leo Yan
  2022-01-26  5:04 ` [PATCH net v3 1/2] pid: Introduce helper task_is_in_init_pid_ns() Leo Yan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Leo Yan @ 2022-01-26  5:04 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Suzuki K Poulose,
	Leon Romanovsky, Balbir Singh, netdev, linux-kernel
  Cc: Leo Yan

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/20211208083320.472503-1-leo.yan@linaro.org/

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net v3 1/2] pid: Introduce helper task_is_in_init_pid_ns()
  2022-01-26  5:04 [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns() Leo Yan
@ 2022-01-26  5:04 ` Leo Yan
  2022-01-26  5:04 ` [PATCH net v3 2/2] connector/cn_proc: Use task_is_in_init_pid_ns() Leo Yan
  2022-01-27  3:10 ` [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns() patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Leo Yan @ 2022-01-26  5:04 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Suzuki K Poulose,
	Leon Romanovsky, Balbir Singh, netdev, linux-kernel
  Cc: Leo Yan, Leon Romanovsky

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 <suzuki.poulose@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Acked-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Acked-by: Balbir Singh <bsingharora@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH net v3 2/2] connector/cn_proc: Use task_is_in_init_pid_ns()
  2022-01-26  5:04 [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns() Leo Yan
  2022-01-26  5:04 ` [PATCH net v3 1/2] pid: Introduce helper task_is_in_init_pid_ns() Leo Yan
@ 2022-01-26  5:04 ` Leo Yan
  2022-01-27  3:10 ` [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns() patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Leo Yan @ 2022-01-26  5:04 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Suzuki K Poulose,
	Leon Romanovsky, Balbir Singh, netdev, linux-kernel
  Cc: Leo Yan

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 <leo.yan@linaro.org>
Acked-by: Balbir Singh <bsingharora@gmail.com>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns()
  2022-01-26  5:04 [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns() Leo Yan
  2022-01-26  5:04 ` [PATCH net v3 1/2] pid: Introduce helper task_is_in_init_pid_ns() Leo Yan
  2022-01-26  5:04 ` [PATCH net v3 2/2] connector/cn_proc: Use task_is_in_init_pid_ns() Leo Yan
@ 2022-01-27  3:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-27  3:10 UTC (permalink / raw)
  To: Leo Yan
  Cc: davem, kuba, suzuki.poulose, leon, bsingharora, netdev, linux-kernel

Hello:

This series was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-27  3:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26  5:04 [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns() Leo Yan
2022-01-26  5:04 ` [PATCH net v3 1/2] pid: Introduce helper task_is_in_init_pid_ns() Leo Yan
2022-01-26  5:04 ` [PATCH net v3 2/2] connector/cn_proc: Use task_is_in_init_pid_ns() Leo Yan
2022-01-27  3:10 ` [PATCH net v3 0/2] pid: Introduce helper task_is_in_root_ns() patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).