From patchwork Wed Dec 8 08:33:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12695296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6A6DAC433F5 for ; Wed, 8 Dec 2021 08:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CbIU2m4/vMgvfu91GNuzyL+d/GetdhCmBQYm1fAzm8A=; b=SZGQ2Yq8MPUsCf EzR5FY4xVNQEulcR638p+oNZFxtVLobne/rRQ/MNeE+xml+w4DWLG8peeVkUpegfXvYGSHEf9/BsS vitkpzSA6tVsqtKYWey5Vo56S49tycc9XqWJa5eIvQf3VpKGRFzm/+eUxQfa/eZiWQME+czC7Xwrb MG8QAT7BgRlBlIei3fXjp9AnObYRA/A4T4lx5GRf0+s8vln7RDul43gRVdQCAgcsKE7YLFOijBaEO GTOsca4m5jPPPByaDoErExddR9mW3F8OlzmJ3I73P2n4MdbOcfjbYgBFO7pXAtJRA+izTBoZwCFlD ABKCLMvVMEDLhB4VOHSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1musOT-00Bi32-8D; Wed, 08 Dec 2021 08:33:41 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1musOI-00Bhxy-Ed for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 08:33:31 +0000 Received: by mail-ed1-x536.google.com with SMTP id y13so5621060edd.13 for ; Wed, 08 Dec 2021 00:33:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HhbhdM+UVkV69ylyGAUrfry6xL5WJfe10RQ3MgDri3E=; b=eaX02OEPSS+RjOClG9DGc+v6cgQ88a34E72u12SEvVTKae7LfSyBfOb82cG4ik+ihQ vMC/UinqwVByxQYNyaTphU4u1cPFoa3FXqjaXb9X9cmergltDcgJY6geO6dTNjMs/2Cr 2ckYlk3wDqtGK3dMjrahko4FFZAV2ZLENLDoRtZJulXk1fVkjlKnE9ISE0Zkh/Lv5x6d 3WHnHmdLbdozO2mDzEn3AK9XR42fFN9yqUlC6TVJAjiG2+oVvxbL3wlzbFnUlZMr9iVU YwDGI5KC09SF8tOHXYvP5dtqvieq6x4p02D04zO16Lh/5pIAR3UtwpUgEBbKD8H37KIh 9+ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HhbhdM+UVkV69ylyGAUrfry6xL5WJfe10RQ3MgDri3E=; b=dYwwZFMODG6V5g1JImIgAQp9LnC5cvaDs4oeFxjoAqq3yk/iu3P6SNiNCzpOidcTKx kf8ZgclA83DF+25rrWN123L/3hTathVl8lCNfHmFZl9cgEbryJ4SbhjAIXa94bBUKFsy I0pL75pLspeFmlgSfd06nwPnGbhH4CpgUnLHyYCKhgsAAXvpcTmGbtQIcW6RtqnSImmG rZ1Rs/vv/ZaIlw0ezvL/KFFuoHf4t1PsgDV8yef3kmH06gZZ03KzpZ4uPzHJGzWNB2OI ZWXZ3fx1hd7ATz/XjSJNS4OFz7bpGVwUZ8MjNzd7HgBUPD62MMqubVvIYAM18HqUrBYZ eQkQ== X-Gm-Message-State: AOAM531A3sC2vNnnXIj7jOzVo/qQEnUbAYiSJ802eEYsQjTooWfshN2F 9iN/RovMG43q9TmsBOXwbqFmhw== X-Google-Smtp-Source: ABdhPJz/Aub/CN7cwflA5aTaNqCW0zeff09QK+an5jfSI+P/yEVmx3XrZ525aOOBfp2sz8qeApVlag== X-Received: by 2002:a17:906:40c4:: with SMTP id a4mr5430305ejk.185.1638952407946; Wed, 08 Dec 2021 00:33:27 -0800 (PST) Received: from localhost ([104.245.96.202]) by smtp.gmail.com with ESMTPSA id z22sm1716370edd.78.2021.12.08.00.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Dec 2021 00:33:27 -0800 (PST) From: Leo Yan To: "David S. Miller" , Jakub Kicinski , Leon Romanovsky , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , Jan Harkes , coda@cs.cmu.edu, Paul Moore , Eric Paris , Balbir Singh , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, codalist@coda.cs.cmu.edu, linux-audit@redhat.com Cc: Leo Yan Subject: [PATCH v2 1/7] pid: Introduce helper task_is_in_init_pid_ns() Date: Wed, 8 Dec 2021 16:33:14 +0800 Message-Id: <20211208083320.472503-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211208083320.472503-1-leo.yan@linaro.org> References: <20211208083320.472503-1-leo.yan@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211208_003330_521867_643B0ACE X-CRM114-Status: GOOD ( 11.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Signed-off-by: Leo Yan Reviewed-by: Leon Romanovsky Acked-by: Suzuki K Poulose Acked-by: Balbir Singh --- 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 */