From patchwork Thu Feb 1 19:53:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10195991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DEE3360600 for ; Thu, 1 Feb 2018 21:15:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71147288B5 for ; Thu, 1 Feb 2018 21:15:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F9162873B; Thu, 1 Feb 2018 21:15:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A2AB28A33 for ; Thu, 1 Feb 2018 20:39:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D8F706EF04; Thu, 1 Feb 2018 19:53:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8C9CB6EEFF; Thu, 1 Feb 2018 19:53:50 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Feb 2018 11:53:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,444,1511856000"; d="scan'208";a="24211612" Received: from mdroper-desk.fm.intel.com ([10.1.134.220]) by FMSMGA003.fm.intel.com with ESMTP; 01 Feb 2018 11:53:50 -0800 From: Matt Roper To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, cgroups@vger.kernel.org Subject: [PATCH RFC v2 3/7] cgroup: Add interface to allow drivers to lookup process cgroup membership Date: Thu, 1 Feb 2018 11:53:11 -0800 Message-Id: <20180201195315.4956-4-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180201195315.4956-1-matthew.d.roper@intel.com> References: <20180201195315.4956-1-matthew.d.roper@intel.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tejun Heo MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Drivers will need to save/restore the appropriate cgroup data for the process submitting a driver request. Add an interface for drivers to determine the cgroup for the userspace process submitting a driver request. Cc: Tejun Heo Cc: cgroups@vger.kernel.org Signed-off-by: Matt Roper --- include/linux/cgroup.h | 6 ++++++ kernel/cgroup/cgroup_driver.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 0ba1374122c7..05ebfb97bcde 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -842,6 +842,7 @@ void cgroup_driver_release(struct cgroup_driver *drv); struct cgroup_driver_data * cgroup_driver_get_data(struct cgroup_driver *drv, struct cgroup *cgrp, bool *is_new); +struct cgroup *cgroup_for_driver_process(struct pid *pid); #else /* !CONFIG_CGROUP_DRIVER */ @@ -857,6 +858,11 @@ cgroup_driver_get_data(struct cgroup_driver *drv, { return ERR_PTR(-EINVAL); } +static inline struct cgroup * +cgroup_for_driver_process(struct pid *pid) +{ + return NULL; +} #endif /* !CONFIG_CGROUP_DRIVER */ diff --git a/kernel/cgroup/cgroup_driver.c b/kernel/cgroup/cgroup_driver.c index 0d893395dc7b..4f870cbb9212 100644 --- a/kernel/cgroup/cgroup_driver.c +++ b/kernel/cgroup/cgroup_driver.c @@ -128,3 +128,27 @@ cgroup_driver_get_data(struct cgroup_driver *drv, return data; } EXPORT_SYMBOL(cgroup_driver_get_data); + +/** + * cgroup_for_driver_process - return the cgroup for a process + * @pid: process to lookup cgroup for + * + * Returns the cgroup from the v2 hierarchy that a process belongs to. + * This function is intended to be called from drivers and will obtain + * the necessary cgroup locks. + * + * RETURNS: + * Process' cgroup in the default (v2) hierarchy + */ +struct cgroup * +cgroup_for_driver_process(struct pid *pid) +{ + struct task_struct *task = pid_task(pid, PIDTYPE_PID); + + mutex_lock(&cgroup_mutex); + spin_lock_irq(&css_set_lock); + task_cgroup_from_root(task, &cgrp_dfl_root); + spin_unlock_irq(&css_set_lock); + mutex_unlock(&cgroup_mutex); +} +EXPORT_SYMBOL(cgroup_for_driver_process);