From patchwork Sun Dec 5 14:50:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12694807 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 40BD7C433F5 for ; Sun, 5 Dec 2021 14:53:08 +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=62cG3/Odwne9Z01ItW13uD383kNuhlvD7Zt4Mpwt0Zk=; b=nT+plJI9pVHzfN DTQTtH96ORMnlykDXh2dgunOf5kEvmpLR0Yvx9SH0ANzbQbWM6e3QWnfluShqdhvr+5kUIogHB1ji PkXZlOL/qxAuMC8lqCewyv2ok++3TG4fYZb4fKTKbQESgb5/ee1fIjcqspijgEOBWH2FAQJzOxUIz 7nF66l1T7ILyh/6vAsqFKhFJDb08Ygx+THhbQughHmWv8R8m96mD7ENFF0PopkYQn+kNYQ65XVTWs aPKutoEQ7Q09WNA/+ZdPbUI8gCWYyRdWg+awPtZYV1F17mRireBHeQYSpljqPxMcOXsQUD7Gul/tQ cAqyU2++VjLd3Hb2yr5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mtsrS-001Y8s-Pl; Sun, 05 Dec 2021 14:51:31 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mtsrH-001Y60-Tz for linux-arm-kernel@lists.infradead.org; Sun, 05 Dec 2021 14:51:21 +0000 Received: by mail-pj1-x102c.google.com with SMTP id gx15-20020a17090b124f00b001a695f3734aso6370393pjb.0 for ; Sun, 05 Dec 2021 06:51:19 -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=YNiShhLycQhgX5gYnC4y4VBBuFZNS7ZHSY9AFesdrV8=; b=CMUN9P+RYDkzOLIKctNBP/6VANWwm6cOuLLsJD3LtQMfK65VWY+CtG+idsfLifL1lM Kai4/V2FAJa43SAL6u0ZK9haIclc89AinTlGqu1q6mOC4pS+rnK7mQhFl4kzcOHrSqGd M3ZPCvnCUbFiOiY5Ns7QSi3DDuskgjDRdTibTIoHKyNlvHl58PMZ8MZiD6t00CAxJo1Q UmuVgW/UDFjyLdXt1a/98lf7eCoHBTQPErjGfMXah86NtZVSSj/XGg0eBOtGJFR8E+Mb KDBBBe05Qop9MmT/s/O1jKd5VCY2Ii1kvVsxVxY4c1WMLnbyLHHA/0SrUheLWKYORnBv axTA== 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=YNiShhLycQhgX5gYnC4y4VBBuFZNS7ZHSY9AFesdrV8=; b=Ov35aGKh2ar43q2JM2VtK/iPnYTVjF06miemnL9tIP5m6g9txJEHSVE/02qtsfVx5E 7fTI587QZAWpZ2yH1YylaTufXBs24b0GbhY8ZX6dHamC9xTyRLrRfNb8r4aNZTQ7r1+3 JvhjoMeNO6qzF2KPDWP2OOLTg+dNXlA6dm1vfDkrJDP8KVMiGri58souYEtbeQ8kQFIv mkmufwhqG1r0c3DFLxSH9NgIldER3w0/fJKNt2WQP28cNQ4+X1Pr5wkhN3KTsDiZEZ0K PQR24MWn57Ik/sx7FBvdUJJ/7ZodIW44+saGcKLd7t5AjzWNKxi2XJafCwdalf3SdCg2 rLIg== X-Gm-Message-State: AOAM532v+ytf+8JbNYDECs7yG5WqocBEYIs/MjOvbhgfogrnCGKwjER1 nouwqmz3+GdJZQRgkOEn78E9ug== X-Google-Smtp-Source: ABdhPJzc9deUn8Xmj0L2AU7C6UVvRT82dukgejEcgPuHYSOcdCGBPFUz1V0TrkJ2f6OtnuKQPz44Jw== X-Received: by 2002:a17:90a:fe0b:: with SMTP id ck11mr29446156pjb.15.1638715878962; Sun, 05 Dec 2021 06:51:18 -0800 (PST) Received: from localhost ([2602:feda:dd1:19c7:f5dc:98c2:a1a4:6c61]) by smtp.gmail.com with ESMTPSA id o2sm9507666pfu.206.2021.12.05.06.51.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 06:51:18 -0800 (PST) From: Leo Yan To: "David S. Miller" , Jakub Kicinski , 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 v1 1/7] pid: Introduce helper task_is_in_root_ns() Date: Sun, 5 Dec 2021 22:50:59 +0800 Message-Id: <20211205145105.57824-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211205145105.57824-1-leo.yan@linaro.org> References: <20211205145105.57824-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-20211205_065119_997528_890D3FE9 X-CRM114-Status: GOOD ( 11.35 ) 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_root_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 --- 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..bf82b373f022 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_root_ns(struct task_struct *tsk) +{ + return task_active_pid_ns(tsk) == &init_pid_ns; +} + #endif /* _LINUX_PID_NS_H */